-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.fsx
216 lines (173 loc) · 7.19 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#I "./packages/FAKE.1.58.9/tools"
#I "c:/windows/System32/inetsrv"
#r "FakeLib.dll"
#r "System.Xml.dll"
#r "Microsoft.Web.Administration.dll"
open Fake
open Microsoft.Web.Administration
open System
open System.Runtime.InteropServices
// properties
let projectName = "Crosswalk"
let version = "0.1.0"
let projectSummary = "A native IIS module to run .NET code."
let projectDescription = "A native IIS module to run .NET code."
let authors = ["loudej"]
let mail = "[email protected]"
let homepage = "http://github.com/loudej/crosswalk"
// directories
let buildDir = "./build/compile/"
let buildDir64 = buildDir + "x64/"
let testDir = "./build/test/"
let deployDir = "./build/deploy/"
//let docsDir = "./build/docs/"
let inetsrvDir = (environVar("windir") + "/SysWOW64/inetsrv/")
let inetsrvDir64 = (environVar("windir") + "/System32/inetsrv/")
// files
let applicationHostConfig = inetsrvDir64 + "config/applicationHost.config"
// tools
let fakePath = "./packages/FAKE.1.58.9/tools"
let nunitPath = "./packages/NUnit.2.5.10.11092/Tools"
// Filesets
let appReferences =
!+ @"src\app\**\*.csproj"
++ @"src\app\**\*.fsproj"
|> Scan
let testReferences =
!+ @"src\test\**\*.csproj"
|> Scan
let vcxReferences =
!+ @"src\app\**\*.vcxproj"
|> Scan
let vcxOutputs =
!+ @"src\app\CrosswalkModule\bin\Release\*.dll"
++ @"src\app\CrosswalkModule\bin\Release\*.pdb"
|> Scan
let vcxOutputs64 =
!+ @"src\app\CrosswalkModule\bin\x64\Release\*.dll"
++ @"src\app\CrosswalkModule\bin\x64\Release\*.pdb"
|> Scan
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; buildDir64; testDir; deployDir]
CreateDir buildDir
CreateDir buildDir64
CreateDir testDir
CreateDir deployDir
)
Target "BuildApp32" (fun _ ->
MSBuild buildDir "Build" ["Configuration", "Release"; "Platform", "Win32"] vcxReferences
|> Log "BuildApp32-Output: "
Copy buildDir vcxOutputs
)
Target "BuildApp64" (fun _ ->
MSBuild buildDir "Build" ["Configuration", "Release"; "Platform", "x64"] vcxReferences
|> Log "BuildApp64-Output: "
Copy (buildDir + "x64/") vcxOutputs64
)
Target "BuildApp" (fun _ ->
MSBuildRelease buildDir "Build" appReferences
|> Log "BuildApp-Output: "
)
Target "BuildTest" (fun _ ->
MSBuildRelease testDir "Build" testReferences
|> Log "BuildTest-Output: "
)
Target "Test" (fun _ ->
let dirinfo = System.IO.Directory.CreateDirectory testDir
!+ (testDir + "/*.Tests.dll")
|> Scan
|> NUnit (fun p ->
{p with
ToolPath = nunitPath
DisableShadowCopy = true
OutputFile = testDir + "TestResults.xml" })
)
Target "Default" (fun _ ->
trace " --- Default --- "
)
module InteropWithNative =
[<DllImport(@"kernel32.dll", CallingConvention = CallingConvention.Cdecl)>]
extern int Wow64DisableWow64FsRedirection([<Out>] IntPtr ppv)
[<DllImport(@"kernel32.dll", CallingConvention = CallingConvention.Cdecl)>]
extern int Wow64RevertWow64FsRedirection(IntPtr pv)
Target "Install" (fun _ ->
let pv = System.IntPtr.Zero
let ok = InteropWithNative.Wow64DisableWow64FsRedirection pv
Copy inetsrvDir vcxOutputs
Copy inetsrvDir64 vcxOutputs64
let ok = InteropWithNative.Wow64RevertWow64FsRedirection pv
let serverManager = new ServerManager()
let config = serverManager.GetApplicationHostConfiguration()
let pools = serverManager.ApplicationPools
pools |> Seq.filter (fun x -> x.State = ObjectState.Started ) |> Seq.iter (fun x -> x.Stop() |> ignore )
let removeConfigurationElementName = fun (collection : ConfigurationElementCollection, name) ->
let isName = fun (x : ConfigurationElement) -> x.["name"].ToString() = name
let oldElement = collection |> Seq.tryFind isName
if (oldElement.IsSome) then collection.Remove(oldElement.Value)
let removeAndAddConfigurationElement = fun (sectionName, elementType, elementName, configure) ->
let section = config.GetSection sectionName
let collection = section.GetCollection()
let isName = fun (x : ConfigurationElement) -> x.["name"].ToString() = elementName
let oldElement = collection |> Seq.tryFind isName
if (oldElement.IsSome) then collection.Remove(oldElement.Value)
let addElement = collection.CreateElement elementType
addElement.["name"] <- elementName
configure addElement
collection.Add addElement
removeAndAddConfigurationElement ("system.webServer/globalModules", "add", "CrosswalkModule", (fun elt->
elt.["image"] <- @"%windir%\system32\inetsrv\CrosswalkModule.dll"
))
removeAndAddConfigurationElement ("system.applicationHost/applicationPools", "add", "CrosswalkSamplePool", (fun elt->
elt.["managedRuntimeVersion"] <- @""
elt.["CLRConfigFile"] <- @"hello.config"
))
removeAndAddConfigurationElement ("system.applicationHost/sites", "site", "CrosswalkSample", (fun siteElement->
siteElement.["id"] <- 6803
let bindingsCollection = siteElement.GetCollection("bindings");
let bindingElement = bindingsCollection.CreateElement("binding");
bindingElement.["protocol"] <- @"http";
bindingElement.["bindingInformation"] <- @"*:6803:";
bindingsCollection.Add(bindingElement);
let siteCollection = siteElement.GetCollection();
let applicationElement = siteCollection.CreateElement("application");
applicationElement.["path"] <- @"/";
applicationElement.["applicationPool"] <- @"CrosswalkSamplePool";
let applicationCollection = applicationElement.GetCollection();
let virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
virtualDirectoryElement.["path"] <- @"/";
virtualDirectoryElement.["physicalPath"] <- @"C:\Projects\Crosswalk\build\compile\_PublishedWebsites\Sandbox";
applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement) |> ignore
))
serverManager.CommitChanges()
pools |> Seq.filter (fun x -> x.State = ObjectState.Stopped ) |> Seq.iter (fun x -> x.Start() |> ignore )
trace " --- Installed --- "
//Copy inetsrvDir, [(buildDir + "Crosswalk.dll")]
// Copy buildDir64, vcxOutputs64
// |> Log "BuildTest-Output: "
// let doc = new XmlDocument()
// doc.Load applicationHostConfig
// XPathReplaceNS xpath value namespaces doc
// |> fun x -> x.Save fileName
)
Target "Deploy" (fun _ ->
!+ (buildDir + "\**\*.*")
-- "*.zip"
|> Scan
|> Zip buildDir (deployDir + "Crosswalk." + version + ".zip")
)
// Dependencies
"BuildApp" <== ["Clean"]
"BuildApp32" <== ["Clean"]
"BuildApp64" <== ["Clean"]
"BuildTest" <== ["Clean"]
"BuildApp" <== ["BuildApp32"]
"BuildApp" <== ["BuildApp64"]
"Test" <== ["BuildTest"]
"Deploy" <== ["BuildApp"]
"Default" <== ["Test"]
"Default" <== ["Deploy"]
"Install" <== ["BuildApp"]
// Start build
Run <| getBuildParamOrDefault "target" "Default"