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

Rework Fake.Core.Target package #1664

Merged
merged 11 commits into from
Sep 25, 2017
Merged
2 changes: 1 addition & 1 deletion build-web-bundles.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ Target "Default" DoNothing
==> "Default"

// start build
RunParameterTargetOrDefault "target" "Default"
RunTargetOrDefault "Default"
Copy link
Member

Choose a reason for hiding this comment

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

Target.RunParameterOrDefault or Target.RunOrDefault?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind

Copy link
Contributor Author

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?

Copy link
Member

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...

Copy link
Contributor Author

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?

Copy link
Member

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

2 changes: 1 addition & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ let dotnetAssemblyInfos =
"Fake.Core.ReleaseNotes", "Parsing ReleaseNotes"
"Fake.Core.SemVer", "Parsing and working with SemVer"
"Fake.Core.String", "Core String manipulations"
"Fake.Core.Targets", "Defining and running Targets"
"Fake.Core.Target", "Defining and running Targets"
"Fake.Core.Tasks", "Repeating and managing Tasks"
"Fake.Core.Tracing", "Core Logging functionality"
"Fake.Core.Xml", "Core Xml functionality"
Expand Down
8 changes: 6 additions & 2 deletions help/markdown/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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>`)

Expand Down
22 changes: 11 additions & 11 deletions help/markdown/core-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Copy link
Member

Choose a reason for hiding this comment

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

Should we write Target.ActivateFinal here to advertise the new usage?

Copy link
Member

Choose a reason for hiding this comment

The 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 _ ->
Copy link
Member

Choose a reason for hiding this comment

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

Target.?

Copy link
Member

Choose a reason for hiding this comment

The 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"
Copy link
Member

Choose a reason for hiding this comment

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

Target.?

Copy link
Member

Choose a reason for hiding this comment

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

fixed.


## Visualising target dependencies

Expand All @@ -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
Expand All @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions help/markdown/fake-commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

👍


If you are on windows then create this small redirect script:

Expand Down
2 changes: 1 addition & 1 deletion help/markdown/fake-fake5-custom-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ One example would be:
(* -- Fake Dependencies paket-inline
source https://nuget.org/api/v2

nuget Fake.Core.Targets prerelease
nuget Fake.Core.Target prerelease
nuget MyTaskNuGetPackage
-- Fake Dependencies -- *)
#load "./.fake/build.fsx/intellisense.fsx"
Expand Down
4 changes: 2 additions & 2 deletions help/markdown/fake-fake5-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Create a new file `paket.dependencies` and add the following content
group NetcoreBuild
source https://nuget.org/api/v2

nuget Fake.Core.Targets prerelease
nuget Fake.Core.Target prerelease
```

Now you can directly use `open Fake.Core` and use the [Target module](core-targets.html).
Expand Down Expand Up @@ -86,7 +86,7 @@ To write your build dependencies in-line you can put the following at the top of
(* -- Fake Dependencies paket-inline
source https://nuget.org/api/v2

nuget Fake.Core.Targets prerelease
nuget Fake.Core.Target prerelease
-- Fake Dependencies -- *)
#load "./.fake/build.fsx/intellisense.fsx"

Expand Down
35 changes: 18 additions & 17 deletions help/markdown/fake-migrate-to-fake-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

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

We may need to remember to remove prerelease after releasing FAKE.


- 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.

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ storage: none
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 -- *)

Expand Down
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ group NetcoreBuild
nuget FSharp.Core ~> 4.1.0
nuget System.AppContext prerelease
nuget Paket.Core prerelease
nuget Fake.Core.Targets prerelease
nuget Fake.Core.Target prerelease
nuget Fake.Core.Globbing prerelease
nuget Fake.Core.SemVer prerelease
nuget Fake.IO.FileSystem prerelease
Expand Down
2 changes: 1 addition & 1 deletion src/Fake-netcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Core.String", "app\Fak
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Core.Tracing", "app\Fake.Core.Tracing\Fake.Core.Tracing.fsproj", "{9430365D-C956-4290-A006-A87F9083DC4B}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Core.Targets", "app\Fake.Core.Targets\Fake.Core.Targets.fsproj", "{0C28F2FB-2B12-4893-AAA4-2C2548926847}"
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Core.Target", "app\Fake.Core.Target\Fake.Core.Target.fsproj", "{0C28F2FB-2B12-4893-AAA4-2C2548926847}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Core.Tasks", "app\Fake.Core.Tasks\Fake.Core.Tasks.fsproj", "{83860B89-4A95-49A5-B4D6-B8F3345498E9}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netstandard1.6</TargetFramework>
<DebugType>pdbonly</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Fake.Core.Targets</AssemblyName>
<AssemblyName>Fake.Core.Target</AssemblyName>
<OutputType>Library</OutputType>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);portable-net45+win8;dnxcore50</PackageTargetFallback>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 | _ -> "")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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"

Expand Down Expand Up @@ -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 -> ()
Expand Down Expand Up @@ -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()
Loading