@@ -9,14 +9,8 @@ open Fake.IO.Globbing.Operators
99open Fake.Core .TargetOperators
1010open Fake.Tools .Git
1111
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-
1812// ========================================================================================================
19- // === F# / Public Library fake build ============================================================= 1.1 .0 =
13+ // === F# / Public Library fake build ============================================================= 2.0 .0 =
2014// --------------------------------------------------------------------------------------------------------
2115// Options:
2216// - no-clean - disables clean of dirs in the first step (required on CI)
@@ -36,12 +30,10 @@ type ToolDir =
3630let project = " Tuc Parser"
3731let summary = " A parser for TUC files."
3832
39- let release = ReleaseNotes.parse ( System.IO.File.ReadAllLines " CHANGELOG.md" |> Seq.filter ((<>) " ## Unreleased " ))
33+ let changeLog = " CHANGELOG.md"
4034let gitCommit = Information.getCurrentSHA1( " ." )
4135let gitBranch = Information.getBranchName( " ." )
4236
43- let toolsDir = Local " tools"
44-
4537// --------------------------------------------------------------------------------------------------------
4638// 2. Utilities, DotnetCore functions, etc.
4739// --------------------------------------------------------------------------------------------------------
@@ -57,63 +49,45 @@ module private Utils =
5749 then Trace.tracefn " Skipped ..."
5850 else action p
5951
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
6556
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
7360 |> ignore
7461
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"
11791
11892// --------------------------------------------------------------------------------------------------------
11993// 3. Targets for FAKE
@@ -130,6 +104,7 @@ Target.create "Clean" <| skipOn "no-clean" (fun _ ->
130104Target.create " AssemblyInfo" ( fun _ ->
131105 let getAssemblyInfoAttributes projectName =
132106 let now = DateTime.Now
107+ let release = ReleaseNotes.parse ( System.IO.File.ReadAllLines changeLog |> Seq.filter ((<>) " ## Unreleased" ))
133108
134109 let gitValue initialValue =
135110 initialValue
@@ -149,65 +124,45 @@ Target.create "AssemblyInfo" (fun _ ->
149124 ]
150125
151126 let getProjectDetails ( projectPath : string ) =
152- let projectName = IO.Path.GetFileNameWithoutExtension( projectPath)
127+ let projectName = System. IO.Path.GetFileNameWithoutExtension( projectPath)
153128 (
154129 projectPath,
155130 projectName,
156- IO.Path.GetDirectoryName( projectPath),
131+ System. IO.Path.GetDirectoryName( projectPath),
157132 ( getAssemblyInfoAttributes projectName)
158133 )
159134
160- !! " **/*.fsproj"
161- -- " example/**/*.*proj"
135+ ProjectSources.all
162136 |> Seq.map getProjectDetails
163137 |> Seq.iter ( fun ( _ , _ , folderName , attributes ) ->
164138 AssemblyInfoFile.createFSharp ( folderName </> " AssemblyInfo.fs" ) attributes
165139 )
166140)
167141
168142Target.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
171149 |> Seq.iter ( DotNet.build id)
172150)
173151
174152Target.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
203159 )
204- |> Seq.iter checkResult
205160)
206161
207162Target.create " Tests" ( fun _ ->
208- if !! " tests/*.fsproj " |> Seq.isEmpty
163+ if ProjectSources.tests |> Seq.isEmpty
209164 then Trace.tracefn " There are no tests yet."
210- else DotnetCore .runOrFail " run" " tests"
165+ else Dotnet .runOrFail " run" " tests"
211166)
212167
213168Target.create " Release" ( fun _ ->
@@ -242,7 +197,7 @@ Target.create "Release" (fun _ ->
242197
243198" Clean"
244199 ==> " AssemblyInfo"
245- ==> " Build"
200+ ==> " Build" <=> " BuildTests "
246201 ==> " Lint"
247202 ==> " Tests"
248203 ==> " Release"
0 commit comments