Skip to content

Commit 00ea25d

Browse files
committed
chore: implement incremental build for FableLibrary task
1 parent 4c6c93a commit 00ea25d

22 files changed

Lines changed: 202 additions & 84 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,5 @@ Cargo.lock
232232

233233
# This file is copied as part of the Restore task
234234
tests/React/Components.Copied.fs
235+
236+
.build-cache/

src/Fable.Build/Fable.Build.fsproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<Compile Include="Utils.fs" />
9-
<Compile Include="Utils/LastVersionFinder.fs" />
109
<Compile Include="Workspace.fs" />
10+
<Compile Include="Utils/LastVersionFinder.fs" />
11+
<Compile Include="Utils/IncrementalBuild.fs" />
1112
<Compile Include="SimpleExec.Extensions.fs" />
1213
<Compile Include="FableLibrary/Core.fs" />
1314
<Compile Include="FableLibrary/Python.fs" />
@@ -46,6 +47,7 @@
4647
<PackageReference Include="EasyBuild.Tools" Version="6.0.0" />
4748
<PackageReference Include="Fake.IO.FileSystem" Version="6.1.4" />
4849
<PackageReference Include="FsToolkit.ErrorHandling" Version="5.2.0" />
50+
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="10.0.5" />
4951
<PackageReference Include="SimpleExec" Version="13.0.0" />
5052
<PackageReference Include="Thoth.Json.Net" Version="12.0.0" />
5153
<PackageReference Include="Semver" Version="3.0.0" />

src/Fable.Build/FableLibrary/Beam.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ type BuildFableLibraryBeam() =
99
Path.Combine("src", "fable-library-beam"),
1010
Path.Combine("src", "fable-library-beam"),
1111
Path.Combine("temp", "fable-library-beam"),
12-
Path.Combine("temp", "fable-library-beam")
12+
Path.Combine("temp", "fable-library-beam"),
13+
[
14+
Path.Combine("src", "fable-library-beam", "**", "*.erl")
15+
Path.Combine("src", "fable-library-beam", "**", "*.fs")
16+
Path.Combine("src", "fable-library-ts", "**", "*.fs")
17+
]
1318
)
1419

1520
override this.CopyStage() =

src/Fable.Build/FableLibrary/Core.fs

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
namespace Build.FableLibrary
22

3+
open System
34
open BlackFox.CommandLine
45
open Fake.IO
56
open System.IO
67
open Build.Utils
78
open Build.Utils
89
open System.Diagnostics
910
open SimpleExec
11+
open Microsoft.Extensions.FileSystemGlobbing
12+
open Microsoft.Extensions.FileSystemGlobbing.Abstractions
1013

1114
/// <summary>
1215
/// Building fable-library is similar enough for all the targets
1316
/// that we can use this class to standardise the process.
1417
/// </summary>
1518
type BuildFableLibrary
16-
(language: string, libraryDir: string, sourceDir: string, buildDir: string, outDir: string, ?fableLibArg: string)
19+
(
20+
language: string,
21+
libraryDir: string,
22+
sourceDir: string,
23+
buildDir: string,
24+
outDir: string,
25+
inputPatterns: string list,
26+
?fableLibArg: string
27+
)
1728
=
1829

1930
// It seems like the different target have a different way of supporting
@@ -62,37 +73,50 @@ type BuildFableLibrary
6273

6374
tryDelete 3
6475

65-
member this.Run(?skipIfExist: bool) =
76+
member this.Run(?forceBuild: bool) =
6677
let toConsole (s: string) = System.Console.WriteLine(s)
6778

68-
let skipIfExist = defaultArg skipIfExist false
69-
70-
if skipIfExist && Directory.Exists outDir then
71-
"Skipping Fable build stage" |> toConsole
72-
73-
else
74-
75-
"Cleaning build directory" |> toConsole
76-
77-
this.deleteDirectoryRobust buildDir
78-
79-
"Building Fable.Library" |> toConsole
80-
81-
let args =
82-
CmdLine.appendRaw sourceDir
83-
>> CmdLine.appendPrefix "--outDir" outDir
84-
>> CmdLine.appendPrefix "--fableLib" fableLibArg
85-
>> CmdLine.appendPrefix "--lang" language
86-
>> CmdLine.appendPrefix "--exclude" "Fable.Core"
87-
>> CmdLine.appendPrefix "--define" "FABLE_LIBRARY"
88-
>> CmdLine.appendRaw "--noCache"
89-
// Target implementation can require additional arguments
90-
>> this.FableArgsBuilder
91-
92-
Command.Fable(args)
93-
94-
"Copy stage" |> toConsole
95-
this.CopyStage()
96-
97-
"Post Fable build stage" |> toConsole
98-
this.PostFableBuildStage()
79+
let matcher = new Matcher()
80+
matcher.AddIncludePatterns(inputPatterns)
81+
// Ignore well-known build output folders from MSBuild
82+
matcher.AddExcludePatterns([ "**/obj/**"; "**/bin/**" ])
83+
84+
let directoryInfo = DirectoryInfo(Path.Resolve())
85+
let dirWrapper = DirectoryInfoWrapper(directoryInfo)
86+
87+
let inputFiles =
88+
matcher.Execute(dirWrapper).Files
89+
|> Seq.map (fun file -> Path.Combine(directoryInfo.FullName, file.Path))
90+
|> Seq.toList
91+
92+
IncrementalBuild.run
93+
$"fable-libary-%s{this.Language}"
94+
(defaultArg forceBuild false)
95+
inputFiles
96+
[ Path.Resolve(this.OutDir) ]
97+
(fun () ->
98+
"Cleaning build directory" |> toConsole
99+
100+
this.deleteDirectoryRobust buildDir
101+
102+
"Building Fable.Library" |> toConsole
103+
104+
let args =
105+
CmdLine.appendRaw sourceDir
106+
>> CmdLine.appendPrefix "--outDir" outDir
107+
>> CmdLine.appendPrefix "--fableLib" fableLibArg
108+
>> CmdLine.appendPrefix "--lang" language
109+
>> CmdLine.appendPrefix "--exclude" "Fable.Core"
110+
>> CmdLine.appendPrefix "--define" "FABLE_LIBRARY"
111+
>> CmdLine.appendRaw "--noCache"
112+
// Target implementation can require additional arguments
113+
>> this.FableArgsBuilder
114+
115+
Command.Fable(args)
116+
117+
"Copy stage" |> toConsole
118+
this.CopyStage()
119+
120+
"Post Fable build stage" |> toConsole
121+
this.PostFableBuildStage()
122+
)

src/Fable.Build/FableLibrary/Dart.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ type BuildFableLibraryDart() =
1111
Path.Combine("src", "fable-library-dart"),
1212
Path.Combine("temp", "fable-library-dart"),
1313
Path.Combine("temp", "fable-library-dart"),
14+
[
15+
Path.Combine("src", "fable-library-dart", "**", "dart")
16+
Path.Combine("src", "fable-library-dart", "**", "*.fs")
17+
],
1418
Path.Combine(".", "temp", "fable-library-dart")
1519
)
1620

src/Fable.Build/FableLibrary/Python.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ type BuildFableLibraryPython(?skipCore: bool) =
1313
libraryDir = Path.Combine("src", "fable-library-py"),
1414
sourceDir = Path.Combine("src", "fable-library-py", "fable_library"),
1515
buildDir = Path.Combine("temp", "fable-library-py"),
16-
outDir = Path.Combine("temp", "fable-library-py", "fable_library")
16+
outDir = Path.Combine("temp", "fable-library-py", "fable_library"),
17+
inputPatterns =
18+
[
19+
Path.Combine("src", "fable-library-py", "**", "*.py")
20+
Path.Combine("src", "fable-library-py", "**", "*.fs")
21+
Path.Combine("src", "fable-library-ts", "**", "*.fs")
22+
]
1723
)
1824

1925
let skipCore = defaultArg skipCore false

src/Fable.Build/FableLibrary/Rust.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ type BuildFableLibraryRust() =
1212
Path.Combine("src", "fable-library-rust"),
1313
Path.Combine("src", "fable-library-rust", "src"),
1414
Path.Combine("temp", "fable-library-rust"),
15-
Path.Combine("temp", "fable-library-rust", "src")
15+
Path.Combine("temp", "fable-library-rust", "src"),
16+
inputPatterns =
17+
[
18+
Path.Combine("src", "fable-library-rust", "**", "*.rs")
19+
Path.Combine("src", "fable-library-rust", "**", "*.fs")
20+
]
1621
)
1722

1823
override this.PostFableBuildStage() =

src/Fable.Build/FableLibrary/TypeScript.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type BuildFableLibraryTypeScript() =
1313
Path.Combine("src", "fable-library-ts"),
1414
Path.Combine("temp", "fable-library-ts"),
1515
Path.Combine("temp", "fable-library-ts"),
16+
[
17+
Path.Combine("src", "fable-library-ts", "**", "*.ts")
18+
Path.Combine("src", "fable-library-ts", "**", "*.fs")
19+
],
1620
Path.Combine(".", "temp", "fable-library-ts")
1721
)
1822

src/Fable.Build/Main.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Available commands:
3232
beam Run for BEAM (Erlang)
3333
3434
Options:
35-
--skip-fable-library Skip building fable-library if folder already exists
35+
--force-fable-library Force building fable-library
3636
--watch Watch for changes and re-run the tests
3737
3838
test Run the main tests suite
@@ -49,7 +49,7 @@ Available commands:
4949
5050
Options for all except integration and standalone:
5151
--watch Watch for changes and re-run the tests
52-
--skip-fable-library Skip building fable-library if folder already exists
52+
--force-fable-library Force building fable-library
5353
--no-dotnet When in watch mode, do not run the .NET tests
5454
5555
Options for JavaScript:
@@ -73,28 +73,28 @@ Available commands:
7373
on top of of Node.js
7474
7575
Options:
76-
--skip-fable-library Skip building fable-library if folder already exists
76+
--force-fable-library Force building fable-library
7777
--no-minify Don't minify the JavaScript output
7878
--watch Watch for changes and recompile
7979
8080
worker-js Compile the worker for the standalone version of Fable
8181
8282
Options:
83-
--skip-fable-library Skip building fable-library if folder already exists
83+
--force-fable-library Force building fable-library
8484
--no-minify Don't minify the JavaScript output
8585
8686
compiler-js Compile the Fable compiler to JavaScript
8787
8888
Options:
89-
--skip-fable-library Skip building fable-library if folder already exists
89+
--force-fable-library Force building fable-library
9090
--no-minify Don't minify the JavaScript output
9191
9292
package Generate local package for Fable.Cli and Fable.Core
9393
allowing to use this local package for testing
9494
inside of other projects
9595
9696
Options:
97-
--skip-fable-library Skip building fable-library if folder already exists
97+
--force-fable-library Force building fable-library
9898
9999
publish Publish the different packages to NuGet and NPM
100100
based on the CHANGELOG.md files

src/Fable.Build/Package.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ open EasyBuild.Tools.PackageJson
1212
let private packageDestination = Path.Resolve("temp", "packages")
1313

1414
let handle (args: string list) =
15-
let skipFableLibrary = args |> List.contains "--skip-fable-library"
15+
let forceFableLibrary = args |> List.contains "--force-fable-library"
1616
// Build all the fable-libraries
17-
BuildFableLibraryBeam().Run(skipFableLibrary)
18-
BuildFableLibraryDart().Run(skipFableLibrary)
19-
BuildFableLibraryJavaScript().Run(skipFableLibrary)
20-
BuildFableLibraryPython().Run(skipFableLibrary)
21-
BuildFableLibraryRust().Run(skipFableLibrary)
22-
BuildFableLibraryTypeScript().Run(skipFableLibrary)
17+
BuildFableLibraryBeam().Run(forceFableLibrary)
18+
BuildFableLibraryDart().Run(forceFableLibrary)
19+
BuildFableLibraryJavaScript().Run(forceFableLibrary)
20+
BuildFableLibraryPython().Run(forceFableLibrary)
21+
BuildFableLibraryRust().Run(forceFableLibrary)
22+
BuildFableLibraryTypeScript().Run(forceFableLibrary)
2323

2424
Directory.clean packageDestination
2525

0 commit comments

Comments
 (0)