-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
133 lines (122 loc) · 4.32 KB
/
build.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket:
nuget Fake.Core.Target
nuget Fake.Core.Process
nuget Fake.DotNet.Cli
nuget Fake.Core.ReleaseNotes
nuget Fake.DotNet.AssemblyInfoFile
nuget Fake.DotNet.Paket
nuget Fake.Tools.Git
nuget Fake.Core.Environment
nuget Fake.Core.UserInput
nuget Fake.IO.FileSystem
nuget Fake.IO.Zip
nuget Fake.DotNet.MsBuild
nuget Fake.Api.GitHub
nuget Microsoft.Build //"
#load ".fake/build.fsx/intellisense.fsx"
open Fake.IO.Globbing.Operators
open Fake.Core
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let f projName =
let pattern = sprintf @"**/%s.fsproj" projName
let xs = !! pattern
xs
|> Seq.tryExactlyOne
|> Option.defaultWith (fun () ->
xs
|> List.ofSeq
|> failwithf "'%s' expected exactly one but:\n%A" pattern
)
let testProjName = "Test"
let testProjPath = @"Test/Test.fsproj"
let serverProjName = "UrqlServer"
let parserProjName = "UrqlParser"
let serverProjPath = f serverProjName
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
open Fake.DotNet
let buildConf = DotNet.BuildConfiguration.Release
let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson
let inline dtntSmpl arg = DotNet.Options.lift dotnetSdk.Value arg
let targetFrameworks = ["net461"; "netcoreapp3.1"]
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
let dotnetBuild =
DotNet.build (fun x ->
// Чтобы в Linux'е не компилировался net461, дан этот костыль:
{ x with
Configuration = buildConf
Framework =
if not Environment.isWindows then
Some "netcoreapp3.1"
else
None
}
|> dtntSmpl)
Target.create "BuildServer" (fun _ ->
serverProjPath
|> Fake.IO.Path.getDirectory
|> dotnetBuild
)
Target.create "BuildTest" (fun _ ->
testProjPath
|> Fake.IO.Path.getDirectory
|> dotnetBuild
)
let run projName targetFramework projPath =
let dir = Fake.IO.Path.getDirectory projPath
let localpath = sprintf "bin/%A/%s/%s.exe" buildConf targetFramework projName
let path = Fake.IO.Path.combine dir localpath
if not <| Fake.IO.File.exists path then
failwithf "not found %s" path
Command.RawCommand(path, Arguments.Empty)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory (Fake.IO.Path.getDirectory path)
|> Proc.run
Target.create "RunTest" (fun _ ->
let targetFramework = targetFrameworks.[0]
let x = run testProjName targetFramework testProjPath
if x.ExitCode <> 0 then
failwith "test error"
)
Target.create "TrimTrailingWhitespace" (fun _ ->
// по-хорошему, нужно использовать .gitignore, но и так пока сойдет
let files =
!! "**/*.fs"
++ "**/*.fsx"
++ "**/*.fsproj"
++ "**/*.cs"
++ "**/*.csproj"
-- "**/obj/**"
-- "**/paket-files/**"
-- "**/packages/**"
files
|> Seq.iter (fun path ->
System.IO.File.ReadAllLines path
|> Array.map (fun x -> x.TrimEnd())
|> fun content -> System.IO.File.WriteAllLines(path, content)
)
)
Target.create "CopyToMainProj" (fun _ ->
let srcDir = sprintf @"UrqlServer/bin/%A" buildConf
let dstDir = @"e:/Project/Urql/UrqlVscodeExtension/release/bin"
Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
)
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
open Fake.Core.TargetOperators
Target.create "Default" ignore
"BuildServer"
==> "Default"
"BuildTest"
==> "CopyToMainProj"
==> "RunTest"
Target.runOrDefault "Default"