-
Notifications
You must be signed in to change notification settings - Fork 585
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
Rework Fake.Core.Target package #1664
Changes from all commits
bbfefb5
1b40731
2c14e9b
1858aba
5271233
95014c2
a5fc7cb
b474d43
ea42789
ba4a4ba
a48b02e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ to automatically deploy a preconfigured virtual machine. See the [Vagrant docs]( | |
|
||
## API-Design | ||
|
||
We [learned from our mistakes](fake-fake5-learn-more.html), so we use the following guidelines: | ||
We [learned from our mistakes](fake-fake5-learn-more.html), so we use the following guidelines, **please read them very carefully** (ask if you don't understand any rule): | ||
|
||
- AutoOpen is no longer used | ||
- we replace `<verb><module>` functions with `<module>.<verb>` | ||
|
@@ -113,7 +113,11 @@ We [learned from our mistakes](fake-fake5-learn-more.html), so we use the follow | |
- For compatibility reasons (migration from legacy). We assume the user doesn't open the global `Fake` namespace. | ||
|
||
-> This means we don't add anything in there in the new API. | ||
- Old APIs are marked as Obsolete with a link (hint) to the new API location. | ||
- Old APIs are marked as Obsolete with a link (hint) to the new API location. We use codes to make explicit | ||
- FAKE0001 for moving part from one Module to another | ||
- FAKE0002 for removed API we don't know who is using it and how => please open an issue if you use it | ||
- FAKE0003 for API that is no more accessible (basically became internal) => please open an issue if you use it | ||
- FAKE0004 for API not yet migrated, waiting for your contribution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice idea. |
||
- Operators are opened seperatly with a separate `Operators` module | ||
- We avoid the `Helpers` suffix (because we now expect users to write `<module>.<function>`) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,27 +53,27 @@ Now we have the following options: | |
## Final targets | ||
|
||
Final targets can be used for TearDown functionality. | ||
These targets will be executed even if the build fails but have to be activated via ActivateFinalTarget(). | ||
These targets will be executed even if the build fails but have to be activated via ActivateFinal(). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
|
||
FinalTarget "CloseSomePrograms" (fun _ -> | ||
Target.CreateFinal "CloseSomePrograms" (fun _ -> | ||
// close stuff and release resources | ||
) | ||
|
||
// Activate FinalTarget somewhere during build | ||
ActivateFinalTarget "CloseSomePrograms" | ||
// Activate Final target somewhere during build | ||
Target.ActivateFinal "CloseSomePrograms" | ||
|
||
|
||
## Build failure targets | ||
|
||
Build failure targets can be used to execute tasks after a build failure. | ||
These targets will be executed only after a build failure but have to be activated via ActivateBuildFailureTarget(). | ||
These targets will be executed only after a build failure but have to be activated via ActivateBuildFailure(). | ||
|
||
BuildFailureTarget "ReportErrorViaMail" (fun _ -> | ||
CreateBuildFailure "ReportErrorViaMail" (fun _ -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
// send mail about the failure | ||
) | ||
|
||
// Activate BuildFailureTarget somewhere during build | ||
ActivateBuildFailureTarget "ReportErrorViaMail" | ||
// Activate Build Failure Target somewhere during build | ||
ActivateBuildFailure "ReportErrorViaMail" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
|
||
## Visualising target dependencies | ||
|
||
|
@@ -87,7 +87,7 @@ the dependency graph to the standard output *instead* of building anything. This | |
the build script contains a call like this: | ||
|
||
``` | ||
RunTargetOrDefault "Default" | ||
Target.RunOrDefault "Default" | ||
``` | ||
|
||
### Example | ||
|
@@ -113,15 +113,15 @@ resulting in an image like this: | |
![graph](pics/specifictargets/graph.png "Dependency graph") | ||
|
||
|
||
# Using FAKE's parallel option | ||
## Using FAKE's parallel option | ||
|
||
Since multithreading is beneficial (especially for large projects) FAKE allows to specify the | ||
number of threads used for traversing the dependency tree. | ||
This option of course only affects independent targets whereas dependent targets will | ||
still be exectued in order. | ||
|
||
|
||
## Setting the number of threads | ||
### Setting the number of threads | ||
The number of threads used can be set using the environment variable ``parallel-jobs``. | ||
This can be achieved in various ways where the easiest one is to use FAKE's built-in support for | ||
setting environment variables: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,24 +96,23 @@ For this short sample we assume you have the latest version of FAKE installed an | |
source https://nuget.org/api/v2 | ||
source ../../../nuget/dotnetcore | ||
|
||
nuget Fake.Core.Targets prerelease | ||
nuget Fake.Core.Target prerelease | ||
nuget FSharp.Core prerelease | ||
-- Fake Dependencies -- *) | ||
open Fake.Core | ||
open Fake.Core.Targets | ||
|
||
Target "Clean" (fun () -> trace " --- Cleaning stuff --- ") | ||
Target.Create "Clean" (fun () -> trace " --- Cleaning stuff --- ") | ||
|
||
Target "Build" (fun () -> trace " --- Building the app --- ") | ||
Target.Create "Build" (fun () -> trace " --- Building the app --- ") | ||
|
||
Target "Deploy" (fun () -> trace " --- Deploying app --- ") | ||
Target.Create "Deploy" (fun () -> trace " --- Deploying app --- ") | ||
|
||
|
||
"Clean" | ||
==> "Build" | ||
==> "Deploy" | ||
|
||
RunTargetOrDefault "Deploy" | ||
Target.RunOrDefault "Deploy" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
If you are on windows then create this small redirect script: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
In this tutorial you will learn how to migrate your existing build scripts to the new FAKE 5 dotnet-core version. | ||
|
||
First we want you to know that there are two version of FAKE 5. One is just an update to the regular FAKE 4, but contains the new netcore API. | ||
First we want you to know that there are two versions of FAKE 5. One is just an update to the regular FAKE 4, but also contains the new API. | ||
We will call this the "legacy FAKE version" it is just like the FAKE you are already used to. The second version is the "new/dotnetcore/standalone FAKE 5" or just "FAKE 5". | ||
This "new" version has several advantages: | ||
|
||
|
@@ -13,30 +13,35 @@ This "new" version has several advantages: | |
* Paket bootstrapper / build.cmd and build.sh are no longer required (you can still use them) | ||
* This will be the only Version available in FAKE 6 | ||
|
||
Therefore you have the FAKE 5 timeframe to update your build scripts to the new version. | ||
Therefore you have the FAKE 5 timeframe to update your build scripts to the new version. If you have any issues in the migration process, please see [how to fill issues or discuss about your issues](/contributing.html) (don't be shy about contributing ;)). | ||
|
||
## Migration Guide | ||
|
||
Upgrading to FAKE 5 is a multi step process and has various manual steps in between. Here are the steps: | ||
Upgrading to FAKE 5 is a multi step process and has various manual steps in between. **If you do these steps out of order it will be a lot harder for you to migrate the script successfully**. Here are the steps: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
|
||
- Regular update to FAKE 5. This should not be breaking. If it breaks you please open an issue. | ||
- Fix all the (obsolete) warnings in your build-script to use the new API (see the 'Use the new FAKE-API' section). | ||
- Update to legacy FAKE 5. This should not be breaking. If it breaks you please open an issue. | ||
|
||
- With Paket: add `prerelease` after `nuget FAKE` in paket.dependencies file then `.paket/paket.exe update FAKE`, check that paket.lock references FAKE version 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to remember to remove |
||
|
||
- Fix all the (obsolete) warnings in your build-script to use the new API (see the [Use the new FAKE-API](#Use-the-new-FAKE-API) section). | ||
This should still not break your build. If things break here or you have difficulties after reading the 'Use the new FAKE-API' section | ||
please open an issue. | ||
- Becareful if you update only some warning, it could break. For example, if you use `Target.Create`, but continue to use old operators definition, you will probably experiment some errors like "Target [...] is not defined". | ||
- Change to the new version of FAKE 5. | ||
|
||
- This is for example done by installing FAKE as dependency on your build infrastructure. | ||
There are a variety of installing options available. (TODO: Link to 'installing FAKE' section) | ||
- Add a FAKE header (TODO: add Link), and tell FAKE which features/packages you want to use in the dependencies file or in-line. | ||
See the 'Adding FAKE dependencies' section below. | ||
- Run the build with the new version of FAKE :). You might want to read the 'CLI migration' section | ||
See the [Adding FAKE dependencies](#Adding-FAKE-dependencies) section below. | ||
- Run the build with the new version of FAKE :). You might want to read the [CLI migration](#CLI-Migration) section | ||
|
||
If things break in the last step please let us know as well. | ||
|
||
If you do these steps out of order it will be a lot harder for you to migrate the script successfully. | ||
|
||
### Use the new FAKE-API | ||
|
||
After upgrading to legacy FAKE 5 the warnings should tell you exactly what you do. If there is stuff missing or a warning message should be improved let us know. | ||
Some warnings indicate how we want the new FAKE version to be used. | ||
|
||
The most important part to know is that basically every feature/function changes its location and sometimes they were even grouped in different modules | ||
as the old API was growing several years now and we never could do breaking changes. | ||
|
||
|
@@ -49,21 +54,17 @@ as the old API was growing several years now and we never could do breaking chan | |
So please try it out and if stuff breaks let us know :). | ||
The good thing is you can always "lock" the versions of the FAKE modules until you are ready to upgrade. | ||
|
||
After upgrading to legacy FAKE 5 the warnings should tell you exactly what you do. If there is stuff missing or a warning message should be improved let us know. | ||
Some warnings indicate how we want the new FAKE version to be used. | ||
|
||
The "open Fake" and AutoOpen modules are completely obsolete. | ||
We urge you to finish your API-Migration (after fixing all warnings) by removing "open Fake". | ||
This removes a lot of automatically opened stuff and if your build fails you ar probably stuff where we forgot to add the obsolete warning (let us know) or that | ||
stuff you are using was not migrated yet (let us know or send a PR, TODO: Add link to guideline). | ||
|
||
In this new work you should write "Module.Method a b" instead of "MethodModule a b". Which means in the old world we had lots of methods like | ||
"ReadFile argument" (the module probably even opened via `[<AutoOpen>]`), which is considered bad style now. | ||
In the new world we would open the `Fake.IO.FileSystem` namespace to indicate that we are using the file-system. | ||
At the same time we would write `File.Read argument`, which is only a bit longer but now the IDE can help you a lot better and the code looks a lot more ideomatic and clean. | ||
|
||
> If you still find places where we use the "bad" style in the new API, let us know (open an issue). | ||
|
||
The "open Fake" and AutoOpen modules are completely obsolete. | ||
We urge you to finish your API-Migration (after fixing all warnings) by removing "open Fake". | ||
This removes a lot of automatically opened stuff and if your build fails you have probably stuff where we forgot to add the obsolete warning (let us know) or that | ||
stuff you are using was not migrated yet (let us know or send a PR, TODO: Add link to guideline). | ||
|
||
### Add FAKE dependencies | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,8 +301,8 @@ module Target = | |
| exn -> targetError name exn) | ||
|
||
|
||
/// Prints all targets. | ||
let Print() = | ||
/// List all targets available. | ||
let ListAvailable() = | ||
Trace.log "The following targets are available:" | ||
for t in getTargetDict().Values do | ||
Trace.logfn " %s%s" t.Name (match t.Description with Some s -> sprintf " - %s" s | _ -> "") | ||
|
@@ -348,7 +348,7 @@ module Target = | |
/// <param name="target">The target for which the dependencies should be printed.</param> | ||
let PrintDependencyGraph verbose target = | ||
match getTargetDict().TryGetValue (target) with | ||
| false,_ -> Print() | ||
| false,_ -> ListAvailable() | ||
| true,target -> | ||
Trace.logfn "%sDependencyGraph for Target %s:" (if verbose then String.Empty else "Shortened ") target.Name | ||
|
||
|
@@ -407,14 +407,6 @@ module Target = | |
/// [omit] | ||
let internal isListMode = Environment.hasEnvironVar "list" | ||
|
||
/// Prints all available targets. | ||
let internal listTargets() = | ||
Trace.tracefn "Available targets:" | ||
getTargetDict().Values | ||
|> Seq.iter (fun target -> | ||
Trace.tracefn " - %s %s" target.Name (match target.Description with Some d -> " - " + d | _ -> "") | ||
Trace.tracefn " Depends on: %A" target.Dependencies) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. |
||
|
||
// Instead of the target can be used the list dependencies graph parameter. | ||
let internal doesTargetMeanListTargets target = target = "--listTargets" || target = "-lt" | ||
|
||
|
@@ -480,7 +472,7 @@ module Target = | |
|
||
/// Runs a target and its dependencies. | ||
let internal run targetName = | ||
if doesTargetMeanListTargets targetName then listTargets() else | ||
if doesTargetMeanListTargets targetName then ListAvailable() else | ||
match getLastDescription() with | ||
| Some d -> failwithf "You set a task description (%A) but didn't specify a task. Make sure to set the Description above the Target." d | ||
| None -> () | ||
|
@@ -543,39 +535,33 @@ module Target = | |
| [] -> () | ||
| errors -> failwithf "A target failed: %A" errors | ||
|
||
/// Registers a BuildFailureTarget (not activated). | ||
let BuildFailureTarget name body = | ||
/// Creates a target in case of build failure (not activated). | ||
let CreateBuildFailure name body = | ||
Create name body | ||
getBuildFailureTargets().Add(name,false) | ||
|
||
/// Activates the BuildFailureTarget. | ||
let ActivateBuildFailureTarget name = | ||
/// Activates the build failure target. | ||
let ActivateBuildFailure name = | ||
let t = Get name // test if target is defined | ||
getBuildFailureTargets().[name] <- true | ||
|
||
/// Registers a final target (not activated). | ||
let FinalTarget name body = | ||
/// Creates a final target (not activated). | ||
let CreateFinal name body = | ||
Create name body | ||
getFinalTargets().Add(name,false) | ||
|
||
/// Activates the FinalTarget. | ||
let ActivateFinalTarget name = | ||
/// Activates the final target. | ||
let ActivateFinal name = | ||
let t = Get name // test if target is defined | ||
getFinalTargets().[name] <- true | ||
|
||
/// Runs a Target and its dependencies | ||
let RunTarget targetName = run targetName | ||
|
||
// Runs the target given by the build script parameter or the given default target | ||
//let RunParameterTargetOrDefault parameterName defaultTarget = Environment.environVarOrDefault parameterName defaultTarget |> Run | ||
/// Runs a target and its dependencies | ||
let Run targetName = run targetName | ||
|
||
/// Runs the target given by the target parameter or the given default target | ||
let RunOrDefault defaultTarget = Environment.environVarOrDefault "target" defaultTarget |> RunTarget | ||
let RunOrDefault defaultTarget = Environment.environVarOrDefault "target" defaultTarget |> Run | ||
|
||
/// Runs the target given by the target parameter or lists the available targets | ||
let RunOrList() = | ||
if Environment.hasEnvironVar "target" then Environment.environVar "target" |> RunTarget | ||
else listTargets() | ||
|
||
/// Runs the target given by the target parameter | ||
let Run() = Environment.environVarOrDefault "target" "" |> RunTarget | ||
if Environment.hasEnvironVar "target" then Environment.environVar "target" |> Run | ||
else ListAvailable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target.RunParameterOrDefault
orTarget.RunOrDefault
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I like your suggestion...I will do it and normalize casing in a new PR, do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I was wrong on this. I have no idea where this file is used and if updating this breaks anything...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking you were saying that RunParameterOrDefault would be a better name than just RunOrDefault?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No your change is fine. I'm not sure why we even have runparameterordefault