forked from fsprojects/FSharp.TypeProviders.SDK
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.fsx
167 lines (139 loc) · 5.63 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools"
#r "packages/FAKE/tools/FakeLib.dll"
open System
open System.IO
open Fake
open Fake.AssemblyInfoFile
open Fake.Git
open Fake.FscHelper
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet
// --------------------------------------------------------------------------------------
let project = "FSharp.TypeProviders.StarterPack"
let authors = ["Tomas Petricek"; "Gustavo Guerra"; "Michael Newton"]
let summary = "Helper code and examples for getting started with Type Providers"
let description = """
The F# Type Provider Starter Pack contains everything you need to start building your own
type providers."""
let tags = "F# fsharp typeprovider"
let gitHome = "https://github.com/mavnn"
let gitName = "FSharp.TypeProviders.StarterPack"
// Read release notes & version info from RELEASE_NOTES.md
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let release =
File.ReadLines "RELEASE_NOTES.md"
|> ReleaseNotesHelper.parseReleaseNotes
let PullRequest =
match getBuildParamOrDefault "APPVEYOR_PULL_REQUEST_NUMBER" "" with
| "" ->
trace "Master build detected"
None
| a ->
trace "Pull Request build detected"
Some <| int a
let buildNumber =
int (getBuildParamOrDefault "APPVEYOR_BUILD_VERSION" "0")
let version =
match PullRequest with
| None ->
sprintf "%s.%d" release.AssemblyVersion buildNumber
| Some num ->
sprintf "%s-pull-%d-%05d" release.AssemblyVersion num buildNumber
let releaseNotes = release.Notes |> String.concat "\n"
let outputPath = "./output/"
let workingDir = "./temp/"
let srcDir = "src"
let exampleDir = "examples"
let testDir = "test"
let nunitDir = "packages" @@ "Nunit.Runners" @@ "tools"
// --------------------------------------------------------------------------------------
// Clean build results
Target "Clean" (fun _ ->
CleanDirs [outputPath; workingDir;testDir]
)
let pt = [srcDir @@ "ProvidedTypes.fsi";srcDir @@ "ProvidedTypes.fs"]
// --------------------------------------------------------------------------------------
// Compile ProvidedTypes as a smoke test
Target "Compile" (fun _ ->
Fsc id pt
)
type ExampleWithTests = {
Name : string
ProviderSourceFiles : string list
TestSourceFiles : string list
}
// --------------------------------------------------------------------------------------
// Compile example providers and accompanying test dlls
Target "Examples" (fun _ ->
let examples =
[
{ Name = "StaticProperty"; ProviderSourceFiles = ["StaticProperty.fsx"]; TestSourceFiles = ["StaticProperty.Tests.fsx"]}
{ Name = "ErasedWithConstructor"; ProviderSourceFiles = ["ErasedWithConstructor.fsx"]; TestSourceFiles = ["ErasedWithConstructor.Tests.fsx"]}
]
let testNunitDll = testDir @@ "nunit.framework.dll"
do
if File.Exists testNunitDll then
File.Delete testNunitDll
File.Copy (nunitDir @@ "nunit.framework.dll", testNunitDll)
let fromExampleDir filenames =
filenames
|> List.map (fun filename -> exampleDir @@ filename)
examples
|> List.iter (fun example ->
// Compile type provider
let output = testDir @@ example.Name + ".dll"
let setOpts = fun def -> { def with Output = output; FscTarget = FscTarget.Library }
Fsc setOpts (List.concat [pt;fromExampleDir example.ProviderSourceFiles])
// Compile test dll
let setTestOpts = fun def ->
{ def with
Output = testDir @@ example.Name + ".Tests.dll"
FscTarget = FscTarget.Library
References = [output;nunitDir @@ "nunit.framework.dll"] }
Fsc setTestOpts (fromExampleDir example.TestSourceFiles)
)
)
Target "RunTests" (fun _ ->
!! (testDir @@ "*.Tests.dll")
|> NUnit id
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "NuGet" (fun _ ->
[srcDir @@ "ProvidedTypes.fsi"] |> CopyTo (workingDir @@ "content")
[srcDir @@ "ProvidedTypes.fs"; "./src/DebugProvidedTypes.fs"] |> CopyTo (workingDir @@ "content")
NuGet (fun p ->
{ p with
Authors = authors
Project = project
Summary = summary
Description = description
Version = version
ReleaseNotes = releaseNotes
Tags = tags
OutputPath = outputPath
WorkingDir = workingDir
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey"
Files = [workingDir, None, None]
Dependencies = [] })
"nuget/FSharp.TypeProviders.StarterPack.nuspec"
)
// --------------------------------------------------------------------------------------
// Help
Target "Help" (fun _ ->
printfn ""
printfn " Please specify the target by calling 'build <Target>'"
printfn ""
printfn " * NuGet (creates package only, doesn't publish unless api key provided)"
printfn " * Compile (attempts to compile ProvidedTypes.fs)"
printfn "")
"Clean"
==> "Compile"
==> "Examples"
==> "RunTests"
==> "NuGet"
RunTargetOrDefault "Help"