|
1 | 1 | namespace Build.FableLibrary |
2 | 2 |
|
| 3 | +open System |
3 | 4 | open BlackFox.CommandLine |
4 | 5 | open Fake.IO |
5 | 6 | open System.IO |
6 | 7 | open Build.Utils |
7 | 8 | open Build.Utils |
8 | 9 | open System.Diagnostics |
9 | 10 | open SimpleExec |
| 11 | +open Microsoft.Extensions.FileSystemGlobbing |
| 12 | +open Microsoft.Extensions.FileSystemGlobbing.Abstractions |
10 | 13 |
|
11 | 14 | /// <summary> |
12 | 15 | /// Building fable-library is similar enough for all the targets |
13 | 16 | /// that we can use this class to standardise the process. |
14 | 17 | /// </summary> |
15 | 18 | 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 | + ) |
17 | 28 | = |
18 | 29 |
|
19 | 30 | // It seems like the different target have a different way of supporting |
@@ -62,37 +73,50 @@ type BuildFableLibrary |
62 | 73 |
|
63 | 74 | tryDelete 3 |
64 | 75 |
|
65 | | - member this.Run(?skipIfExist: bool) = |
| 76 | + member this.Run(?forceBuild: bool) = |
66 | 77 | let toConsole (s: string) = System.Console.WriteLine(s) |
67 | 78 |
|
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 | + ) |
0 commit comments