@@ -9,14 +9,8 @@ open Fake.IO.Globbing.Operators
9
9
open Fake.Core .TargetOperators
10
10
open Fake.Tools .Git
11
11
12
- type ToolDir =
13
- /// Global tool dir must be in PATH - ${PATH}:/root/.dotnet/tools
14
- | Global
15
- /// Just a dir name, the location will be used as: ./{LocalDirName}
16
- | Local of string
17
-
18
12
// ========================================================================================================
19
- // === F# / Public Library fake build ============================================================= 1.1 .0 =
13
+ // === F# / Public Library fake build ============================================================= 2.0 .0 =
20
14
// --------------------------------------------------------------------------------------------------------
21
15
// Options:
22
16
// - no-clean - disables clean of dirs in the first step (required on CI)
@@ -36,12 +30,10 @@ type ToolDir =
36
30
let project = " Tuc Parser"
37
31
let summary = " A parser for TUC files."
38
32
39
- let release = ReleaseNotes.parse ( System.IO.File.ReadAllLines " CHANGELOG.md" |> Seq.filter ((<>) " ## Unreleased " ))
33
+ let changeLog = " CHANGELOG.md"
40
34
let gitCommit = Information.getCurrentSHA1( " ." )
41
35
let gitBranch = Information.getBranchName( " ." )
42
36
43
- let toolsDir = Local " tools"
44
-
45
37
// --------------------------------------------------------------------------------------------------------
46
38
// 2. Utilities, DotnetCore functions, etc.
47
39
// --------------------------------------------------------------------------------------------------------
@@ -57,63 +49,45 @@ module private Utils =
57
49
then Trace.tracefn " Skipped ..."
58
50
else action p
59
51
60
- module private DotnetCore =
61
- let run cmd workingDir =
62
- let options =
63
- DotNet.Options.withWorkingDirectory workingDir
64
- >> DotNet.Options.withRedirectOutput true
52
+ let createProcess exe arg dir =
53
+ CreateProcess.fromRawCommandLine exe arg
54
+ |> CreateProcess.withWorkingDirectory dir
55
+ |> CreateProcess.ensureExitCode
65
56
66
- DotNet.exec options cmd " "
67
-
68
- let runOrFail cmd workingDir =
69
- run cmd workingDir
70
- |> tee ( fun result ->
71
- if result.ExitCode <> 0 then failwithf " 'dotnet %s ' failed in %s " cmd workingDir
72
- )
57
+ let run proc arg dir =
58
+ proc arg dir
59
+ |> Proc.run
73
60
|> ignore
74
61
75
- let runInRoot cmd = run cmd " ."
76
- let runInRootOrFail cmd = runOrFail cmd " ."
77
-
78
- let installOrUpdateTool toolDir tool =
79
- let toolCommand action =
80
- match toolDir with
81
- | Global -> sprintf " tool %s --global %s " action tool
82
- | Local dir -> sprintf " tool %s --tool-path ./%s %s " action dir tool
83
-
84
- match runInRoot ( toolCommand " install" ) with
85
- | { ExitCode = code } when code <> 0 ->
86
- match runInRoot ( toolCommand " update" ) with
87
- | { ExitCode = code } when code <> 0 -> Trace.tracefn " Warning: Install and update of %A has failed." tool
88
- | _ -> ()
89
- | _ -> ()
90
-
91
- let execute command args ( dir : string ) =
92
- let cmd =
93
- sprintf " %s /%s "
94
- ( dir.TrimEnd( '/' ))
95
- command
96
-
97
- let processInfo = System.Diagnostics.ProcessStartInfo( cmd)
98
- processInfo.RedirectStandardOutput <- true
99
- processInfo.RedirectStandardError <- true
100
- processInfo.UseShellExecute <- false
101
- processInfo.CreateNoWindow <- true
102
- processInfo.Arguments <- args |> String.concat " "
103
-
104
- use proc =
105
- new System.Diagnostics.Process(
106
- StartInfo = processInfo
107
- )
108
- if proc.Start() |> not then failwith " Process was not started."
109
- proc.WaitForExit()
110
-
111
- if proc.ExitCode <> 0 then failwithf " Command '%s ' failed in %s ." command dir
112
- ( proc.StandardOutput.ReadToEnd(), proc.StandardError.ReadToEnd())
113
-
114
- let stringToOption = function
115
- | null | " " -> None
116
- | string -> Some string
62
+ let orFail = function
63
+ | Error e -> raise e
64
+ | Ok ok -> ok
65
+
66
+ let stringToOption = function
67
+ | null | " " -> None
68
+ | string -> Some string
69
+
70
+ [<RequireQualifiedAccess>]
71
+ module Dotnet =
72
+ let dotnet = createProcess " dotnet"
73
+
74
+ let run command dir = try run dotnet command dir |> Ok with e -> Error e
75
+ let runInRoot command = run command " ."
76
+ let runOrFail command dir = run command dir |> orFail
77
+
78
+ [<RequireQualifiedAccess>]
79
+ module ProjectSources =
80
+ let library =
81
+ !! " ./*.fsproj"
82
+ ++ " src/*.fsproj"
83
+ ++ " src/**/*.fsproj"
84
+
85
+ let tests =
86
+ !! " tests/*.fsproj"
87
+
88
+ let all =
89
+ library
90
+ ++ " tests/*.fsproj"
117
91
118
92
// --------------------------------------------------------------------------------------------------------
119
93
// 3. Targets for FAKE
@@ -130,6 +104,7 @@ Target.create "Clean" <| skipOn "no-clean" (fun _ ->
130
104
Target.create " AssemblyInfo" ( fun _ ->
131
105
let getAssemblyInfoAttributes projectName =
132
106
let now = DateTime.Now
107
+ let release = ReleaseNotes.parse ( System.IO.File.ReadAllLines changeLog |> Seq.filter ((<>) " ## Unreleased" ))
133
108
134
109
let gitValue initialValue =
135
110
initialValue
@@ -149,65 +124,45 @@ Target.create "AssemblyInfo" (fun _ ->
149
124
]
150
125
151
126
let getProjectDetails ( projectPath : string ) =
152
- let projectName = IO.Path.GetFileNameWithoutExtension( projectPath)
127
+ let projectName = System. IO.Path.GetFileNameWithoutExtension( projectPath)
153
128
(
154
129
projectPath,
155
130
projectName,
156
- IO.Path.GetDirectoryName( projectPath),
131
+ System. IO.Path.GetDirectoryName( projectPath),
157
132
( getAssemblyInfoAttributes projectName)
158
133
)
159
134
160
- !! " **/*.fsproj"
161
- -- " example/**/*.*proj"
135
+ ProjectSources.all
162
136
|> Seq.map getProjectDetails
163
137
|> Seq.iter ( fun ( _ , _ , folderName , attributes ) ->
164
138
AssemblyInfoFile.createFSharp ( folderName </> " AssemblyInfo.fs" ) attributes
165
139
)
166
140
)
167
141
168
142
Target.create " Build" ( fun _ ->
169
- !! " **/*.fsproj"
170
- -- " example/**/*.*proj"
143
+ ProjectSources.library
144
+ |> Seq.iter ( DotNet.build id)
145
+ )
146
+
147
+ Target.create " BuildTests" ( fun _ ->
148
+ ProjectSources.tests
171
149
|> Seq.iter ( DotNet.build id)
172
150
)
173
151
174
152
Target.create " Lint" <| skipOn " no-lint" ( fun _ ->
175
- DotnetCore.installOrUpdateTool toolsDir ( " dotnet-fsharplint" )
176
-
177
- let checkResult ( messages : string list ) =
178
- let rec check : string list -> unit = function
179
- | [] -> failwithf " Lint does not yield a summary."
180
- | head :: rest ->
181
- if head.Contains " Summary" then
182
- match head.Replace( " = " , " " ) .Replace( " =" , " " ) .Replace( " =" , " " ) .Replace( " Summary: " , " " ) with
183
- | " 0 warnings" -> Trace.tracefn " Lint: OK"
184
- | warnings -> failwithf " Lint ends up with %s ." warnings
185
- else check rest
186
- messages
187
- |> List.rev
188
- |> check
189
-
190
- !! " **/*.*proj"
191
- -- " example/**/*.*proj"
192
- |> Seq.map ( fun fsproj ->
193
- match toolsDir with
194
- | Global ->
195
- DotnetCore.runInRoot ( sprintf " fsharplint lint %s " fsproj)
196
- |> fun ( result : ProcessResult ) -> result.Messages
197
- | Local dir ->
198
- DotnetCore.execute " dotnet-fsharplint" [ " lint" ; fsproj] dir
199
- |> fst
200
- |> tee ( Trace.tracefn " %s " )
201
- |> String.split '\n'
202
- |> Seq.toList
153
+ ProjectSources.all
154
+ ++ " ./Build.fsproj"
155
+ |> Seq.iter ( fun fsproj ->
156
+ match Dotnet.runInRoot ( sprintf " fsharplint lint %s " fsproj) with
157
+ | Ok () -> Trace.tracefn " Lint %s is Ok" fsproj
158
+ | Error e -> raise e
203
159
)
204
- |> Seq.iter checkResult
205
160
)
206
161
207
162
Target.create " Tests" ( fun _ ->
208
- if !! " tests/*.fsproj " |> Seq.isEmpty
163
+ if ProjectSources.tests |> Seq.isEmpty
209
164
then Trace.tracefn " There are no tests yet."
210
- else DotnetCore .runOrFail " run" " tests"
165
+ else Dotnet .runOrFail " run" " tests"
211
166
)
212
167
213
168
Target.create " Release" ( fun _ ->
@@ -242,7 +197,7 @@ Target.create "Release" (fun _ ->
242
197
243
198
" Clean"
244
199
==> " AssemblyInfo"
245
- ==> " Build"
200
+ ==> " Build" <=> " BuildTests "
246
201
==> " Lint"
247
202
==> " Tests"
248
203
==> " Release"
0 commit comments