Skip to content

Commit 091d2f1

Browse files
authored
Merge pull request #25 from OlegZee/dev
Publishing new features (cp + fixes)
2 parents 296b1d3 + 6c3c921 commit 091d2f1

23 files changed

+280
-146
lines changed

XakeLibTests/StorageTests.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ module private impl =
3131
let logger = ConsoleLogger Verbosity.Diag
3232

3333
let createResult name =
34-
{ (name
34+
{ ([name
3535
|> File.make
36-
|> FileTarget
36+
|> FileTarget]
3737
|> makeResult) with Depends =
3838
[ "abc.c" |> mkFileTarget |> ArtifactDep
3939
Var("DEBUG", Some "false") ]
@@ -55,7 +55,7 @@ let Setup() =
5555
[<Test>]
5656
let ``persists simple data``() =
5757

58-
let testee = makeResult <| (mkFileTarget "abc.exe")
58+
let testee = makeResult <| [mkFileTarget "abc.exe"]
5959

6060
let testee =
6161
{ testee with

XakeLibTests/SystemTaskTests.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ let ``shell``() =
1818
rules [
1919
"main" => recipe {
2020

21-
do! Shell {ShellOptions.Default with
21+
do! Shell {
22+
ShellOptions.Default with
2223
Command = "dir"; Args = ["*.*"]
2324
WorkingDir = Some "."; UseClr = true; FailOnErrorLevel = true} |> Recipe.Ignore
2425

XakeLibTests/XakeLibTests.fsproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@
5858
<None Include="paket.references" />
5959
<Compile Include="SystemTaskTests.fs" />
6060
</ItemGroup>
61-
<ItemGroup>
62-
<ProjectReference Include="..\core\Xake.Core.fsproj">
63-
<Name>Xake.Core</Name>
64-
<Project>{6b39c22f-6741-428d-b21a-33580af7bd8e}</Project>
65-
<Private>True</Private>
66-
</ProjectReference>
67-
</ItemGroup>
6861
<PropertyGroup>
6962
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
7063
</PropertyGroup>
@@ -106,4 +99,11 @@
10699
<Paket>True</Paket>
107100
</Reference>
108101
</ItemGroup>
102+
<ItemGroup>
103+
<ProjectReference Include="..\core\Xake.fsproj">
104+
<Name>Xake</Name>
105+
<Project>{6b39c22f-6741-428d-b21a-33580af7bd8e}</Project>
106+
<Private>True</Private>
107+
</ProjectReference>
108+
</ItemGroup>
109109
</Project>

XakeLibTests/XakeScriptTests.fs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,56 @@ let ``executes several dependent rules``() =
384384

385385
Assert.AreEqual(11, !count)
386386

387+
[<Test>]
388+
let ``executes in parallel``() =
389+
390+
let steps = System.Collections.Generic.List<int>()
391+
392+
do xake { XakeOptions with Threads = 4 } {
393+
rules [
394+
"main" <== ["rule1"; "rule2"; "rule3"]
395+
"rule1" => action {
396+
do! Async.Sleep(40)
397+
steps.Add 1
398+
}
399+
"rule2" => action {
400+
do! Async.Sleep(20)
401+
steps.Add 2
402+
}
403+
"rule3" => action {
404+
do! Async.Sleep(10)
405+
steps.Add 3
406+
}
407+
]
408+
}
409+
410+
Assert.That(steps, Is.EqualTo([3; 2; 1] |> List.toArray))
411+
412+
[<Test>]
413+
let ``op <<< executes one by one``() =
414+
415+
let steps = System.Collections.Generic.List<int>()
416+
417+
do xake { XakeOptions with Threads = 4 } {
418+
rules [
419+
"main" <<< ["rule1"; "rule2"; "rule3"]
420+
"rule1" => action {
421+
do! Async.Sleep(40)
422+
steps.Add 1
423+
}
424+
"rule2" => action {
425+
do! Async.Sleep(20)
426+
steps.Add 2
427+
}
428+
"rule3" => action {
429+
do! Async.Sleep(10)
430+
steps.Add 3
431+
}
432+
]
433+
}
434+
435+
Assert.AreEqual(steps, [1; 2; 3] |> List.toArray)
436+
387437
[<Test>]
388438
let ``writes dependencies to a build database``() =
389439

@@ -424,7 +474,7 @@ let ``writes dependencies to a build database``() =
424474
try
425475
match testee.PostAndReply <| fun ch -> DatabaseApi.GetResult ((PhonyAction "test"), ch) with
426476
| Some {
427-
BuildResult.Result = PhonyAction "test"
477+
BuildResult.Targets = [PhonyAction "test"]
428478
Depends = [
429479
ArtifactDep (PhonyAction "aaa"); ArtifactDep (PhonyAction "deeplyNested");
430480
FileDep (fileDep, depDate)
@@ -437,8 +487,8 @@ let ``writes dependencies to a build database``() =
437487

438488
match testee.PostAndReply <| fun ch -> DatabaseApi.GetResult ((PhonyAction "test1"), ch) with
439489
| Some {
440-
BuildResult.Result = PhonyAction "test1"
441-
BuildResult.Depends = [ArtifactDep (PhonyAction "aaa")]
490+
Targets = [PhonyAction "test1"]
491+
Depends = [ArtifactDep (PhonyAction "aaa")]
442492
//BuildResult.Steps = []
443493
} -> true
444494
| _ -> false

core/CommonLib.fs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module internal CommonLib =
1111
/// <param name="f"></param>
1212
let memoize f =
1313
let cache = ref Map.empty
14-
let lck = new System.Object()
14+
let lck = System.Object()
1515
fun x ->
1616
match !cache |> Map.tryFind (K x) with
1717
| Some v -> v
@@ -24,6 +24,23 @@ module internal CommonLib =
2424
cache := !cache |> Map.add (K x) res
2525
res)
2626

27+
28+
///**Description**
29+
/// Memoizes the recursive function. Memoized function is passed as first argument to f.
30+
///**Parameters**
31+
/// * `f` - parameter of type `('a -> 'b) -> 'a -> 'b` The function to be memoized.
32+
///
33+
///**Output Type**
34+
/// * `'a -> 'b`
35+
///
36+
///**Exceptions**
37+
///
38+
let memoizeRec f =
39+
let rec fn x = f fm x
40+
and fm = fn |> memoize
41+
in
42+
fm
43+
2744
/// <summary>
2845
/// Takes n first elements from a list.
2946
/// </summary>

core/Database.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ module BuildLog =
44
open Xake
55
open System
66

7-
let XakeDbVersion = "0.3"
7+
let XakeDbVersion = "0.4"
88

99
type Database = { Status : Map<Target, BuildResult> }
1010

1111
(* API *)
1212

1313
/// Creates a new build result
1414
let makeResult target =
15-
{ Result = target
15+
{ Targets = target
1616
Built = DateTime.Now
1717
Depends = []
1818
Steps = [] }
@@ -21,8 +21,8 @@ module BuildLog =
2121
let newDatabase() = { Database.Status = Map.empty }
2222

2323
/// Adds result to a database
24-
let internal addResult db result =
25-
{ db with Status = db.Status |> Map.add (result.Result) result }
24+
let internal addResult db result =
25+
{ db with Status = result.Targets |> List.fold (fun m i -> Map.add i result m) db.Status }
2626

2727
type 't Agent = 't MailboxProcessor
2828

@@ -72,12 +72,12 @@ module Storage =
7272
let result =
7373
wrap
7474
((fun (r, built, deps, steps) ->
75-
{ Result = r
75+
{ Targets = r
7676
Built = built
7777
Depends = deps
7878
Steps = steps }),
79-
fun r -> (r.Result, r.Built, r.Depends, r.Steps))
80-
(quad target date (list dependency) (list step))
79+
fun r -> (r.Targets, r.Built, r.Depends, r.Steps))
80+
(quad (list target) date (list dependency) (list step))
8181

8282
let dbHeader =
8383
wrap

core/DependencyAnalysis.fs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ let getChangeReasons ctx getTargetDeps target =
8585
| Some {BuildResult.Depends = []} ->
8686
[ChangeReason.Other "No dependencies", Some "It means target is not \"pure\" and depends on something beyond our control (oracle)"]
8787

88-
| Some {BuildResult.Depends = depends; Result = result} ->
89-
let dep_state = getDepState (Util.getVar ctx.Options) (toFileList ctx.Options.ProjectRoot) getTargetDeps
88+
| Some {BuildResult.Depends = depends; Targets = result} ->
89+
let depState = getDepState (Util.getVar ctx.Options) (toFileList ctx.Options.ProjectRoot) getTargetDeps
9090

9191
depends
92-
|> List.map dep_state
92+
|> List.map depState
9393
|> List.filter (fst >> (<>) ChangeReason.NotChanged)
9494
|> collapseFilesChanged
9595
|> function
9696
| [] ->
9797
match result with
98-
| FileTarget file when not (File.exists file) ->
98+
| targetList when targetList |> List.exists (function | FileTarget file when not (File.exists file) -> true | _ -> false) ->
9999
[ChangeReason.Other "target file does not exist", Some "The file has to be rebuilt regardless all its dependencies were not changed"]
100100
| _ -> []
101101
| ls -> ls
@@ -118,8 +118,9 @@ let getDurationDeps ctx getDeps t =
118118
/// Dumps all dependencies for particular target
119119
let dumpDeps (ctx: ExecContext) (target: Target list) =
120120

121-
let rec getDeps = getChangeReasons ctx (fun x -> getDeps x) |> memoize
122-
let doneTargets = new System.Collections.Hashtable()
121+
let getDeps = getChangeReasons ctx |> memoizeRec
122+
123+
let doneTargets = System.Collections.Hashtable()
123124
let indent i = String.replicate i " "
124125

125126
let rec displayNestedDeps ii =

core/DotnetTasks.fs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ module internal Impl =
4040
let getRelative (root:string) (path:string) =
4141

4242
// TODO reimplement and test
43-
44-
if isEmpty root then path
45-
elif path.ToLowerInvariant().StartsWith (root.ToLowerInvariant()) then
46-
// cut the trailing "\"
47-
let d = if root.Length < path.Length then 1 else 0
48-
path.Substring(root.Length + d)
49-
else
43+
match true with
44+
| _ when isEmpty root ->
5045
path
46+
| _ when path.ToLowerInvariant().StartsWith (root.ToLowerInvariant()) ->
47+
path.Substring(root.Length).TrimStart('/', '\\')
48+
| _ -> path
5149

5250
let endsWith e (str:string) = str.EndsWith (e, System.StringComparison.OrdinalIgnoreCase)
5351
let (|EndsWith|_|) e str = if endsWith e str then Some () else None
@@ -67,8 +65,8 @@ module internal Impl =
6765

6866
/// Parses the compiler output and returns messageLevel
6967
let levelFromString defaultLevel (text:string) :Level =
70-
if text.IndexOf "): warning " > 0 then Level.Warning
71-
else if text.IndexOf "): error " > 0 then Level.Error
68+
if text.Contains "): warning " then Level.Warning
69+
else if text.Contains "): error " then Level.Error
7270
else defaultLevel
7371
let inline coalesce ls = //: 'a option list -> 'a option =
7472
ls |> List.fold (fun r a -> if Option.isSome r then r else a) None

0 commit comments

Comments
 (0)