Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAKE template domain specific language choice #2177

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions help/markdown/fake-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Specifies your prefered way to define the nuget packages used in your build:
- `inline` - Defines build dependencies inside the build script
- `none` - Use this if you already have a `paket.dependencies` in your folder

### --dsl
Specifies your prefered way to define build tasks inside your build script:

- `fake` (default) - Uses the default FAKE domain specific language
- `blackfox` - Uses the BlackFox domain specific language
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `blackfox` - Uses the BlackFox domain specific language
- `buildtask` - Uses a string free domain specific language, called [BuildTask](https://github.com/vbfox/FoxSharp/blob/master/src/BlackFox.Fake.BuildTask/Readme.md)


### --tool-path
Specifies the folder for the fake-cli tool. This parameter is only applicable when `tool` is used for bootstrapping. Defaults to `.fake`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
}
]
},
"dsl": {
"type": "parameter",
"dataType": "choice",
"defaultValue": "fake",
"choices": [{
"choice": "fake",
"description": "Uses the default FAKE domain specific language (see https://fake.build/core-targets.html)"
},
{
"choice": "blackfox",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"choice": "blackfox",
"choice": "buildtask",

"description": "Uses the BlackFox domain specific language (see https://github.com/vbfox/FoxSharp/blob/master/src/BlackFox.Fake.BuildTask/Readme.md)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "Uses the BlackFox domain specific language (see https://github.com/vbfox/FoxSharp/blob/master/src/BlackFox.Fake.BuildTask/Readme.md)"
"description": "Uses a string free domain specific language, called [BuildTask](https://github.com/vbfox/FoxSharp/blob/master/src/BlackFox.Fake.BuildTask/Readme.md)"

}
]
},
"tool-path": {
"type": "parameter",
"description": "Folder for the FAKE dotnet sdk global tool. This parameter is only applicable when 'tool' is used for bootstrapping",
Expand All @@ -65,7 +79,8 @@
},
"sources": [{
"exclude": "**/.template.config/**/*",
"modifiers": [{
"modifiers": [
{
"exclude": "**/fake.tool.*",
"condition": "(bootstrap != \"tool\")"
},
Expand All @@ -88,6 +103,28 @@
{
"exclude": "**/paket.dependencies",
"condition": "(dependencies != \"file\")"
},
{
"exclude": "**/fake.tool.*",
"condition": "(bootstrap != \"tool\")"
},
{
"exclude": "**/build.fake.*",
"condition": "(dsl != \"fake\")"
},
{
"rename": {
"build.fake.fsx": "build.fsx"
}
},
{
"exclude": "**/build.blackfox.*",
"condition": "(dsl != \"blackfox\")"
},
{
"rename": {
"build.blackfox.fsx": "build.fsx"
}
}
]
}],
Expand Down
29 changes: 29 additions & 0 deletions src/template/fake-template/Content/build.blackfox.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//#if (dependencies == "inline")
#r "paket:
nuget Fake.DotNet.Cli
nuget Fake.IO.FileSystem
nuget Fake.Core.Target
nuget BlackFox.Fake.BuildTask //"
//#endif
#load ".fake/(build.fsx)/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open BlackFox.Fake

let clean = BuildTask.create "Clean" [] {
!! "src/**/bin"
++ "src/**/obj"
|> Shell.cleanDirs
}

let build = BuildTask.create "Build" [clean.IfNeeded] {
!! "src/**/*.*proj"
|> Seq.iter (DotNet.build id)
}

let _all = BuildTask.createEmpty "All" [clean; build]

BuildTask.runOrDefault _all
5 changes: 4 additions & 1 deletion src/template/fake-template/Content/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ group Build
source https://api.nuget.org/v3/index.json
nuget Fake.DotNet.Cli
nuget Fake.IO.FileSystem
nuget Fake.Core.Target
nuget Fake.Core.Target
//#if (dsl == "blackfox")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//#if (dsl == "blackfox")
//#if (dsl == "buildtask")

nuget BlackFox.Fake.BuildTask
//#endif
69 changes: 61 additions & 8 deletions src/test/Fake.DotNet.Cli.IntegrationTests/TemplateTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ type BootstrapKind =
| None
with override x.ToString () = match x with | Tool -> "tool" | Project -> "project" | None -> "none"

type DslKind =
| Fake
| BlackFox
with override x.ToString () = match x with | Fake -> "fake" | BlackFox -> "blackfox"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with override x.ToString () = match x with | Fake -> "fake" | BlackFox -> "blackfox"
with override x.ToString () = match x with | Fake -> "fake" | BlackFox -> "buildtask"


type DependenciesKind =
| File
| Inline
| None
with override x.ToString () = match x with | File -> "file" | Inline -> "inline" | None -> "none"

let shouldSucceed message (r: ProcessResult) =
let errorStr =
r.Results
Expand All @@ -43,9 +54,9 @@ let shouldSucceed message (r: ProcessResult) =

let timeout = (System.TimeSpan.FromMinutes 10.)

let runTemplate rootDir kind =
let runTemplate rootDir kind dependencies dsl =
Directory.ensure rootDir
DotNet.exec (dtntWorkDir rootDir) "new" (sprintf "%s --allow-scripts yes --version 5.3.0 --bootstrap %s" templateName (string kind))
DotNet.exec (dtntWorkDir rootDir) "new" (sprintf "%s --allow-scripts yes --version 5.3.0 --bootstrap %s --dependencies %s --dsl %s" templateName (string kind) (string dependencies) (string dsl))
|> shouldSucceed "should have run the template successfully"

let invokeScript dir scriptName args =
Expand All @@ -57,11 +68,18 @@ let invokeScript dir scriptName args =
.WithFileName(fullScriptPath)
.WithArguments args) timeout

let fileContainsText dir fileName text =
let filePath = Path.Combine(dir, fileName)
let content = File.ReadAllText(filePath)
content.Contains(text: string)

let missingTarget targetName (r: ProcessResult) =
r.Errors |> Seq.exists (fun err -> err.Contains (sprintf "Target \"%s\" is not defined" targetName))

let tempDir() = Path.Combine("../../../test/fake-template", Path.GetRandomFileName())

let fileExists dir fileName = File.Exists(Path.Combine(dir, fileName))

[<Tests>]
let tests =
// we need to (uninstall) the template, install the packed version, and then execute that template
Expand All @@ -78,40 +96,75 @@ let tests =

printfn "PATH: %s" <| Environment.GetEnvironmentVariable "PATH"


printfn "DOTNET_ROOT: %s" <| Environment.GetEnvironmentVariable "DOTNET_ROOT"
let templateNupkg = GlobbingPattern.create "../../../release/dotnetcore/fake-template.*.nupkg" |> GlobbingPattern.setBaseDir __SOURCE_DIRECTORY__ |> Seq.head
let templateNupkg = GlobbingPattern.create "../../../release/dotnetcore/fake-template.*.nupkg" |> GlobbingPattern.setBaseDir __SOURCE_DIRECTORY__ |> Seq.last
installTemplateFrom templateNupkg |> shouldSucceed "should install new FAKE template"

let scriptFile =
if Environment.isUnix
then "fake.sh"
else "fake.cmd"

let buildFile = "build.fsx"
let dependenciesFile = "paket.dependencies"

yield test "can install a project-style template" {
let tempDir = tempDir()
runTemplate tempDir Project
runTemplate tempDir Project File Fake
invokeScript tempDir scriptFile "--help" |> shouldSucceed "should invoke help"
Expect.isTrue (fileExists tempDir dependenciesFile) "the dependencies file should exist"
}

yield test "can build with the project-style template" {
let tempDir = tempDir()
runTemplate tempDir Project
runTemplate tempDir Project File Fake
invokeScript tempDir scriptFile "build -t All" |> shouldSucceed "should build successfully"
}

yield test "fails to build a target that doesn't exist" {
let tempDir = tempDir()
runTemplate tempDir Project
runTemplate tempDir Project File Fake
let result = invokeScript tempDir scriptFile "build -t Nonexistent"
Expect.isFalse result.OK "the script should have failed"
Expect.isTrue (missingTarget "Nonexistent" result) "The script should recognize the target doesn't exist"
}

yield test "can install a inline-dependencies template" {
let tempDir = tempDir()
runTemplate tempDir Project Inline Fake
Expect.isTrue (fileContainsText tempDir buildFile "#r \"paket:") "the build file should contain inline dependencies"
Expect.isFalse (fileExists tempDir dependenciesFile) "the dependencies file should not exist"
}

yield test "can install a blackfox-dsl file-dependencies template" {
let tempDir = tempDir()
runTemplate tempDir Project File BlackFox
Expect.isTrue (fileContainsText tempDir buildFile "open BlackFox.Fake") "the build file should contain blackfox"
Expect.isTrue (fileContainsText tempDir dependenciesFile "nuget BlackFox.Fake.BuildTask") "the dependencies file should contain blackfox"
}

yield test "can build a blackfox-dsl file-dependencies template" {
let tempDir = tempDir()
runTemplate tempDir Project File BlackFox
invokeScript tempDir scriptFile "build -t All" |> shouldSucceed "should build successfully"
}

yield test "can install a blackfox-dsl inline-dependencies template" {
let tempDir = tempDir()
runTemplate tempDir Project Inline BlackFox
Expect.isTrue (fileContainsText tempDir buildFile "nuget BlackFox.Fake.BuildTask") "the build file should contain blackfox dependency"
}

yield test "can build a blackfox-dsl inline-dependencies template" {
let tempDir = tempDir()
runTemplate tempDir Project Inline BlackFox
invokeScript tempDir scriptFile "build -t All" |> shouldSucceed "should build successfully"
}

/// ignored because the .net tool install to a subdirectory is broken: https://github.com/fsharp/FAKE/pull/1989#issuecomment-396057330
yield ptest "can install a tool-style template" {
let tempDir = tempDir()
runTemplate tempDir Tool
runTemplate tempDir Tool File Fake
invokeScript tempDir scriptFile "--help" |> shouldSucceed "should invoke help"
}
]
Expand Down