Skip to content

Commit

Permalink
Ignore target name case when determining build order, fixes #2000
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Jul 1, 2018
1 parent 6217870 commit 18c1e98
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/app/Fake.Core.Target/Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,12 @@ module Target =

let rec visitDependenciesAux fGetDependencies (visited:string list) level (_depType, targetName) =
let target = get targetName
let isVisited = visited |> Seq.contains targetName
let isVisited = visited |> Seq.exists (fun t -> t = String.toLower targetName)
//fVisit (target, depType, level, isVisited)
let dependencies =
fGetDependencies target
|> Seq.collect (visitDependenciesAux fGetDependencies (targetName::visited) (level + 1))
|> Seq.distinctBy (fun t -> t.Name)
|> Seq.collect (visitDependenciesAux fGetDependencies (String.toLower targetName::visited) (level + 1))
|> Seq.distinctBy (fun t -> String.toLower t.Name)
|> Seq.toList
if not isVisited then target :: dependencies
else dependencies
Expand All @@ -472,7 +472,7 @@ module Target =

// Try to build the optimal tree by starting with the targets without dependencies and remove them from the list iteratively
let rec findOrder (targetLeft:Target list) =
let isValidTarget name = targetLeft |> Seq.exists (fun t -> t.Name = name)
let isValidTarget name = targetLeft |> Seq.exists (fun t -> String.toLower t.Name = String.toLower name)
let canBeExecuted (t:Target) =
t.Dependencies @ t.SoftDependencies
|> Seq.filter isValidTarget
Expand Down Expand Up @@ -509,11 +509,11 @@ module Target =
let internal mergeContext (ctx1:TargetContext) (ctx2:TargetContext) =
let known =
ctx1.PreviousTargets
|> Seq.map (fun tres -> tres.Target.Name, tres)
|> Seq.map (fun tres -> String.toLower tres.Target.Name, tres)
|> dict
let filterKnown targets =
targets
|> List.filter (fun tres -> not (known.ContainsKey tres.Target.Name))
|> List.filter (fun tres -> not (known.ContainsKey (String.toLower tres.Target.Name)))
{ ctx1 with
PreviousTargets =
ctx1.PreviousTargets @ filterKnown ctx2.PreviousTargets
Expand All @@ -530,8 +530,8 @@ module Target =
let body (inbox:MailboxProcessor<RunnerHelper>) = async {
let targetCount =
order |> Seq.sumBy (fun t -> t.Length)
let resolution = Set.ofSeq(order |> Seq.concat |> Seq.map (fun t -> t.Name))
let inResolution (t:string) = resolution.Contains t
let resolution = Set.ofSeq(order |> Seq.concat |> Seq.map (fun t -> String.toLower t.Name))
let inResolution (t:string) = resolution.Contains (String.toLower t)
let mutable ctx = ctx
let mutable waitList = []
let mutable runningTasks = []
Expand All @@ -547,11 +547,11 @@ module Target =
ctx <- mergeContext ctx newCtx
let known =
ctx.PreviousTargets
|> Seq.map (fun tres -> tres.Target.Name, tres)
|> Seq.map (fun tres -> String.toLower tres.Target.Name, tres)
|> dict
runningTasks <-
runningTasks
|> List.filter (fun t -> not(known.ContainsKey t.Name))
|> List.filter (fun t -> not(known.ContainsKey (String.toLower t.Name)))
if known.Count = targetCount then
for (w:System.Threading.Tasks.TaskCompletionSource<TargetContext * Target option>) in waitList do
w.SetResult (ctx, None)
Expand All @@ -560,8 +560,8 @@ module Target =
else

let isRunnable (t:Target) =
not (known.ContainsKey t.Name) && // not already finised
not (runningTasks |> Seq.exists (fun r -> r.Name = t.Name)) && // not already running
not (known.ContainsKey (String.toLower t.Name)) && // not already finised
not (runningTasks |> Seq.exists (fun r -> String.toLower r.Name = String.toLower t.Name)) && // not already running
t.Dependencies @ List.filter inResolution t.SoftDependencies // all dependencies finished
|> Seq.forall (fun d -> known.ContainsKey d)
let runnable =
Expand Down
35 changes: 35 additions & 0 deletions src/test/Fake.Core.UnitTests/Fake.Core.Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ let tests =
| _ ->
failwithf "unexpected order: %A" order


Fake.ContextHelper.fakeContextTestCase "casing in targets - #2000" <| fun _ ->

Target.create "CleanUp" DoNothing

Target.create "RunUnitTests" DoNothing

Target.create "RunAllTests" DoNothing

Target.create "Default" DoNothing

"CleanUp"
==> "RunUnitTests"
==> "RunAlltests"
==> "Default"

[ "CleanUp";
"RunUnitTests";
"RunAlltests";
"Default" ]
|> Seq.iter (fun i ->
let t = i |> Target.get
Trace.tracefn "%s has %A" i t.Dependencies )


let order = determineBuildOrder "Default" 1
validateBuildOrder order "Default"
match order with
| [[|Target "CleanUp"|];[|Target "RunUnitTests"|];[|Target "RunAllTests"|];[|Target "Default"|]] ->
// as expected
()
| _ ->
failwithf "unexpected order: %A" order
Target.runOrDefault "Default"

Fake.ContextHelper.fakeContextTestCase "Diamonds are resolved correctly" <| fun _ ->
Target.create "a" DoNothing
Target.create "b" DoNothing
Expand Down

0 comments on commit 18c1e98

Please sign in to comment.