-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.fsx
executable file
·146 lines (121 loc) · 4.74 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
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
#if bin_sh
# Doing this because arguments can't be used with /usr/bin/env on linux, just mac
exec fsharpi --define:mono_posix --exec $0 $*
#endif
(*
* CrossPlatform FSharp Makefile bootstraper - [email protected]
*
* How to use:
* On Windows `fsi --exec build.fsx <buildtarget>
*
* On Mac Or Linux `./build.fsx <buildtarget>`
* *Note:* But if you have trouble then use `sh build.fsx <buildtarget>`
*
*)
open System
open System.IO
open System.Diagnostics
(* helper functions *)
#if mono_posix
#r "Mono.Posix.dll"
open Mono.Unix.Native
let applyExecutionPermissionUnix path =
let _,stat = Syscall.lstat(path)
Syscall.chmod(path, FilePermissions.S_IXUSR ||| stat.st_mode) |> ignore
#else
let applyExecutionPermissionUnix path = ()
#endif
let doesNotExist path =
path |> Path.GetFullPath |> File.Exists |> not
let execAt (workingDir:string) (exePath:string) (args:string seq) =
let processStart (psi:ProcessStartInfo) =
let ps = Process.Start(psi)
ps.WaitForExit ()
ps.ExitCode
let fullExePath = exePath |> Path.GetFullPath
applyExecutionPermissionUnix fullExePath
let exitCode = ProcessStartInfo(
fullExePath,
args |> String.concat " ",
WorkingDirectory = (workingDir |> Path.GetFullPath),
UseShellExecute = false)
|> processStart
if exitCode <> 0 then
exit exitCode
()
let downloadNugetTo path =
let fullPath = path |> Path.GetFullPath;
if doesNotExist fullPath then
printf "Downloading NuGet..."
use webClient = new System.Net.WebClient()
fullPath |> Path.GetDirectoryName |> Directory.CreateDirectory |> ignore
webClient.DownloadFile("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", path |> Path.GetFullPath)
printfn "Done."
let passedArg = fsi.CommandLineArgs.[1..] |> Array.tryHead
(* execution script customize below *)
downloadNugetTo "tools/NuGet/NuGet.exe"
execAt
"tools/"
"tools/NuGet/NuGet.exe"
["install"; "-OutputDirectory packages"; "-ExcludeVersion"]
execAt
"tools/std20"
"tools/NuGet/NuGet.exe"
["install"; "-OutputDirectory packages"; "-ExcludeVersion"]
#load "tools/SimpleMake.fsx"
type actions = { gen:bool; docs:bool; build:bool; clean:bool; test:bool }
let choice =
match passedArg with
| Some(x) when x.Equals("Generate", StringComparison.InvariantCultureIgnoreCase) ->
printfn "Generate target";
{ gen= true; docs=false; build =false; clean = true; test= false}
| Some(x) when x.Equals("Clean", StringComparison.InvariantCultureIgnoreCase) ->
printfn "Clean target";
{ gen= false; docs=false; build =false; clean = true; test= false}
| _ ->
printfn "Default target";
{ gen= true; docs=true; build = true; clean = true; test= true}
let msbuild = CompilerHelper.findMSBuild();
if choice.clean then
SimpleMake.clean srcDir
#if !mono_posix
SimpleMake.clean docsBuildDir
#endif
SimpleMake.clean "proj/bin/"
SimpleMake.clean "proj/obj/"
SimpleMake.clean "test/bin/"
SimpleMake.clean "test/obj/"
if choice.gen then
SimpleMake.generate ()
if choice.build then
let msbuild = CompilerHelper.findMSBuild();
let props = [
msbuildProp "Description" description
msbuildProp "Authors" (String.concat " " authors)
msbuildProp "Copyright" copyright
msbuildProp "PackageProjectUrl" projectUrl
msbuildProp "PackageLicenseUrl" licenceUrl
msbuildProp "PackageTags" (String.concat " " projectTags)
msbuildProp "PackageRequireLicenseAcceptance" (requireLicence.ToString())
msbuildProp "GeneratePackageOnBuild" "True"
]
execAt "proj/" msbuild ([
"/t:restore"
] @ props)
execAt "proj/" msbuild props
if choice.test then
execAt "test/" msbuild ["/t:restore"]
execAt "test/" msbuild []
let xunitTools = Path.Combine("tools","packages", "xunit.runner.console","tools")
let dotnet = findDotNet ()
execAt "test/" dotnet [
Path.Combine("..", xunitTools, "netcoreapp2.0","xunit.console.dll")
Path.Combine("bin", configuration, "netcoreapp2.0", "Test.dll" )
]
let xunitRunner = Path.Combine(xunitTools, "net452","xunit.console.exe") |> Path.GetFullPath
execAt "test/" xunitRunner [ Path.Combine("bin", configuration, "net47", "Test.exe" ) ]
#if !mono_posix
if choice.docs then
DocHelper.generateDocs ()
#endif