forked from dotnet-bluetooth-le/dotnet-bluetooth-le
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
193 lines (156 loc) · 6.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// don't forget nuget setapikey <key> before publish ;)
#r @"FAKE.4.10.5/tools/FakeLib.dll"
#r "System.Xml.Linq"
open System.Xml.Linq
open System.Xml;
open System.IO
open System.Text.RegularExpressions
open Fake
open Fake.XMLHelper;
open Fake.Git;
open Fake.NuGet.Update;
let (+/) path1 path2 = Path.Combine(path1, path2)
let RepositoryRootDir = Path.Combine("..", ".");
let NuGetTargetDir = Path.Combine("out" ,"nuget");
let BuildTargetDir = Path.Combine("out" ,"lib");
let BootstrapFile = "BlePluginBootstrap.cs.pp"
let NugetPath = Path.Combine("..", "Source", ".nuget", "NuGet.exe");
let ProjectSources = Path.Combine("..", "Source");
let NuspecFiles = ["Plugin.BLE.nuspec"; "MvvmCross.Plugin.BLE.nuspec"];
let VanillaPluginId = "Plugin.BLE";
let Build (projectName:string, targetSubDir:string) =
[Path.Combine(ProjectSources, projectName, projectName + ".csproj")]
|> MSBuildRelease (BuildTargetDir +/ targetSubDir) "Build"
|> Log "Output: "
let NuVersionGet (specFile:string) =
let doc = System.Xml.Linq.XDocument.Load(specFile)
let versionElements = doc.Descendants(XName.Get("version", doc.Root.Name.NamespaceName))
(Seq.head versionElements).Value
let NuVersionVanillaDependencySet (specFile:string, version:string) =
let xmlDocument = new XmlDocument()
xmlDocument.Load specFile
let nsmgr = XmlNamespaceManager(xmlDocument.NameTable)
nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd")
let dependencyNodes = xmlDocument.DocumentElement.SelectNodes("//ns:dependency", nsmgr)
let setAttributeVersion (node:XmlElement) =
if node.GetAttribute("id").Equals(VanillaPluginId) then
node.SetAttribute("version", version)
for node in dependencyNodes do
node :?> XmlElement |> setAttributeVersion
xmlDocument.Save specFile
let NuVersionSet (specFile:string, version:string) =
let xmlDocument = new XmlDocument()
xmlDocument.Load specFile
let nsmgr = XmlNamespaceManager(xmlDocument.NameTable)
nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd")
let node = xmlDocument.DocumentElement.SelectSingleNode("//ns:version", nsmgr)
node.InnerText <- version
xmlDocument.Save specFile
let NuPack (specFile:string, publish:bool) =
let version = NuVersionGet(specFile)
let project = Path.GetFileNameWithoutExtension(specFile)
NuGet (fun p ->
{p with
ToolPath = NugetPath
Version = version
OutputPath = NuGetTargetDir
WorkingDir = BuildTargetDir
Project = project
Publish = publish
}) specFile
let NuPackAll (publish:bool) =
NuspecFiles |> List.iter (fun file -> NuPack(file, publish))
let RestorePackages() =
!! "../Source/**/packages.config"
|> Seq.iter (RestorePackage (fun p ->
{ p with
ToolPath = NugetPath
OutputPath = Path.Combine(ProjectSources, "packages")
}))
let RestorePackagesForSanityCheck() =
!! "./**/packages.config"
|> Seq.iter (RestorePackage (fun p ->
{ p with
ToolPath = NugetPath
OutputPath = Path.Combine("PluginNugetTest", "packages")
Sources = [Path.Combine(currentDirectory, "out", "nuget"); "https://api.nuget.org/v3/index.json"]
}))
let UpdatePackagesForSanityCheck() =
!! "./**/packages.config"
|> Seq.iter (NugetUpdate (fun p ->
{ p with
ToolPath = NugetPath
Prerelease = true
RepositoryPath = Path.Combine("PluginNugetTest", "packages")
Sources = Path.Combine(currentDirectory, "out", "nuget") :: p.Sources
}))
// Targets
Target "clean" (fun _ ->
trace "cleaning up..."
CleanDir NuGetTargetDir
CleanDir BuildTargetDir
)
Target "build" (fun _ ->
trace "restoring packages..."
RestorePackages()
trace "building libraries..."
Build("Plugin.BLE", "pcl")
Build("Plugin.BLE.Abstractions", "pcl")
Build("Plugin.BLE.Android", "android")
Build("Plugin.BLE.iOS", "ios")
Build("MvvmCross.Plugins.BLE", Path.Combine("mvx","pcl"))
Build("MvvmCross.Plugins.BLE.Droid", Path.Combine("mvx", "android"))
Build("MvvmCross.Plugins.BLE.iOS", Path.Combine("mvx","ios"))
trace "copy mvvm cross bootstrap files..."
File.Copy(Path.Combine(ProjectSources, "MvvmCross.Plugins.BLE.Droid",BootstrapFile), Path.Combine(BuildTargetDir, "mvx", "android", BootstrapFile))
File.Copy(Path.Combine(ProjectSources, "MvvmCross.Plugins.BLE.iOS", BootstrapFile), Path.Combine(BuildTargetDir, "mvx", "ios", BootstrapFile))
)
Target "sanity-check" (fun _ ->
trace "restoring packages..."
RestorePackagesForSanityCheck()
UpdatePackagesForSanityCheck()
[Path.Combine("PluginNugetTest", "PluginNugetTest.sln")]
|> MSBuildRelease ("PluginNugetTest" +/ "testbuild") "Build"
|> Log "Output: "
)
Target "nupack" (fun _ ->
NuPackAll false
)
//call: build version v=1.0.0
Target "version" (fun _ ->
let version = getBuildParam "v"
let cleanVersion = Regex.Replace(version, @"[^\d\.].*$", "")
BulkReplaceAssemblyInfoVersions ".." (fun info ->
{info with
AssemblyVersion = cleanVersion
AssemblyFileVersion = cleanVersion
AssemblyInformationalVersion = version
})
let updateVersions(file : string, version : string) =
NuVersionSet(file, version)
NuVersionVanillaDependencySet(file, version)
NuspecFiles |> List.iter (fun file ->
updateVersions(file, version)
)
)
Target "publish" (fun _ ->
if not (Fake.Git.Information.isCleanWorkingCopy RepositoryRootDir) then
failwith "Uncommited changes. Please commit everything!"
NuPackAll true
let version = NuVersionGet(Seq.head NuspecFiles)
let branchName = Fake.Git.Information.getBranchName RepositoryRootDir
trace ("Current GIT Branch: " + branchName)
let tagName = ("v" + version)
trace ("Creating Tag: " + tagName)
tag RepositoryRootDir tagName
pushTag RepositoryRootDir "origin" tagName
)
// Dependencies
"clean"
==> "build"
==> "nupack"
==> "sanity-check"
"build"
==> "publish"
// start build
RunTargetOrDefault "build"