|
1 | 1 | namespace Build.FableLibrary |
2 | 2 |
|
3 | 3 | open BlackFox.CommandLine |
4 | | -open Fake.IO |
5 | 4 | open System.IO |
6 | 5 | open Build.Utils |
7 | | -open Build.Utils |
8 | | -open System.Diagnostics |
9 | 6 | open SimpleExec |
| 7 | +open Microsoft.Extensions.FileSystemGlobbing |
| 8 | +open Microsoft.Extensions.FileSystemGlobbing.Abstractions |
10 | 9 |
|
11 | 10 | /// <summary> |
12 | 11 | /// Building fable-library is similar enough for all the targets |
13 | 12 | /// that we can use this class to standardise the process. |
14 | 13 | /// </summary> |
15 | 14 | type BuildFableLibrary |
16 | | - (language: string, libraryDir: string, sourceDir: string, buildDir: string, outDir: string, ?fableLibArg: string) |
| 15 | + ( |
| 16 | + language: string, |
| 17 | + libraryDir: string, |
| 18 | + sourceDir: string, |
| 19 | + buildDir: string, |
| 20 | + outDir: string, |
| 21 | + inputPatterns: string list, |
| 22 | + ?fableLibArg: string |
| 23 | + ) |
17 | 24 | = |
18 | 25 |
|
19 | 26 | // It seems like the different target have a different way of supporting |
@@ -62,37 +69,50 @@ type BuildFableLibrary |
62 | 69 |
|
63 | 70 | tryDelete 3 |
64 | 71 |
|
65 | | - member this.Run(?skipIfExist: bool) = |
| 72 | + member this.Run(?forceBuild: bool) = |
66 | 73 | let toConsole (s: string) = System.Console.WriteLine(s) |
67 | 74 |
|
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() |
| 75 | + let matcher = new Matcher() |
| 76 | + matcher.AddIncludePatterns(inputPatterns) |
| 77 | + // Ignore well-known build output folders from MSBuild |
| 78 | + matcher.AddExcludePatterns([ "**/obj/**"; "**/bin/**" ]) |
| 79 | + |
| 80 | + let directoryInfo = DirectoryInfo(Path.Resolve()) |
| 81 | + let dirWrapper = DirectoryInfoWrapper(directoryInfo) |
| 82 | + |
| 83 | + let inputFiles = |
| 84 | + matcher.Execute(dirWrapper).Files |
| 85 | + |> Seq.map (fun file -> Path.Combine(directoryInfo.FullName, file.Path)) |
| 86 | + |> Seq.toList |
| 87 | + |
| 88 | + IncrementalBuild.run |
| 89 | + $"fable-library-%s{this.Language}" |
| 90 | + (defaultArg forceBuild false) |
| 91 | + inputFiles |
| 92 | + [ Path.Resolve(this.OutDir) ] |
| 93 | + (fun () -> |
| 94 | + "Cleaning build directory" |> toConsole |
| 95 | + |
| 96 | + this.deleteDirectoryRobust buildDir |
| 97 | + |
| 98 | + "Building Fable.Library" |> toConsole |
| 99 | + |
| 100 | + let args = |
| 101 | + CmdLine.appendRaw sourceDir |
| 102 | + >> CmdLine.appendPrefix "--outDir" outDir |
| 103 | + >> CmdLine.appendPrefix "--fableLib" fableLibArg |
| 104 | + >> CmdLine.appendPrefix "--lang" language |
| 105 | + >> CmdLine.appendPrefix "--exclude" "Fable.Core" |
| 106 | + >> CmdLine.appendPrefix "--define" "FABLE_LIBRARY" |
| 107 | + >> CmdLine.appendRaw "--noCache" |
| 108 | + // Target implementation can require additional arguments |
| 109 | + >> this.FableArgsBuilder |
| 110 | + |
| 111 | + Command.Fable(args) |
| 112 | + |
| 113 | + "Copy stage" |> toConsole |
| 114 | + this.CopyStage() |
| 115 | + |
| 116 | + "Post Fable build stage" |> toConsole |
| 117 | + this.PostFableBuildStage() |
| 118 | + ) |
0 commit comments