Question

In VS there is usually a distinction between Build (incremental) and Rebuild, where the latter would first clean but then do the same as Build. Can I provide similar behavior with FAKE?

Let's assume the following targets:

Target "Clean" DoNothing
Target "Work" DoNothing
Target "All" DoNothing

RunTargetOrDefault "All"

Normally I want to run all of them, Clean before Work, so I end up with:

"Clean" ==> "Work" ==> "All"

However, Work is not really depending on Clean - it is only that if both are to be run, Clean must run first. With the dependency chain above, I cannot run Work without Clean being run first. Is there way or common pattern to support this?

What I've considered so far:

A)

"Clean" ==> "All"
"Work" ==> "All"

This correctly represents the dependencies from All, but the order that Clean should be before Work - if both are run - is missing.

B)

Target "WorkOnly" DoNothing
"WorkOnly" ==> "Work"
"Clean" ==> "Work" ==> "All"

This is a bit closer, but it still does not guarantee that when building All that Clean will run before WorkOnly

C)

Target "Start" DoNothing
"Start"
  =?> ("Clean", not (hasBuildParam "noclean"))
  ==> "Work"
  ==> "All"

This way, Clean would always run, except when I specify "noclean" as parameter. This seems to fully support my scenario and is actually quite flexible, but can get a bit complicated if there are multiple optional phases.

Is this the intended way and how others do it as well, or am I missing something obvious?

Was it helpful?

Solution 2

No, there is no operator for this at the moment. You might want to create a pull request with a new operator.

We also have a prototype implementation for a future target dependency runtime. You can also try to add a new operator there.

OTHER TIPS

I'm a bit late to the party.... But I've recently run into this kind of requirement myself.

I finally settled on the following:

  • All tasks are independent
  • Create multiple end state targets that define different dependencies.

In your case that would leave you with

Target "Clean" DoNothing
Target "Work" DoNothing
Target "Build" (fun _ ->
    Run "Work"
)
Target "Rebuild" (fun _ ->
    "Clean"
        ==> "Work"

    Run "Work"
)

I'm very late here but this might help someone. You can use soft dependencies like so (substitute "Work" for "Build" if you like):

// read 'x ==> y ' as "x runs before y"
"Build" ==> "All"
"Clean" ==> "All"
"Clean" ?=> "Build" // Soft dependency: Correct order when multi-threading?
"All" ==> "Deploy"

Alternatively I prefer the <== operator.

// read 'x <== ys' as "x depends on ys" like traditional make rules
"Build"  <=? "Clean"  
"All"    <== ["Clean"; "Build"]
"Deploy" <== ["All"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top