-
Notifications
You must be signed in to change notification settings - Fork 72
/
build.fsx
159 lines (130 loc) · 4.41 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
#r "packages/FAKE/tools/FakeLib.dll"
#r "System.IO.Compression.FileSystem.dll"
#r "packages/FSharp.Management/lib/net40/FSharp.Management.dll"
open Microsoft.FSharp.Core.Printf
open Fake
open Fake.AssemblyInfoFile
open Fake.Git
open Fake.ReleaseNotesHelper
open System
open System.IO
open FSharp.Management
MSBuildDefaults <- { MSBuildDefaults with Verbosity = Some MSBuildVerbosity.Minimal }
let artifactDir = "artifacts"
let tempDir = "temp"
let tikaLibDir = "lib"
let solutionFile = "src/TikaOnDotNet.sln"
let keyFile = (fileInfo "TikaOnDotNet.snk")
let [<Literal>]rootPath = __SOURCE_DIRECTORY__
let testAssemblies = "src/**/bin/Release/*Tests*.dll"
type root = FileSystem<rootPath>
let release =
ReadFile "Release-Notes.md"
|> ReleaseNotesHelper.parseReleaseNotes
// --------------------------------------------------------------------------------------
// IKVM.NET compilation helpers
let ikvmc = root.``paket-files``.``www.frijters.net``.``ikvm-8.1.5717.0``.bin.``ikvmc.exe``
type IKVMcTask(jar:string, assembly:string) =
member val JarFile = jar
member val AssemblyName = assembly
member val Version = "" with get, set
let timeOut = TimeSpan.FromSeconds(300.0)
let IKVMCompile workingDirectory tasks =
let getNewFileName newExtension (fileName:string) =
Path.GetFileName(fileName).Replace(Path.GetExtension(fileName), newExtension)
let startProcess fileName args =
let result =
ExecProcess
(fun info ->
info.FileName <- fileName
info.WorkingDirectory <- FullName workingDirectory
info.Arguments <- args)
timeOut
if result<> 0 then
failwithf "Process '%s' failed with exit code '%d'" fileName result
let rec compile (task:IKVMcTask) =
let getIKVMCommandLineArgs() =
let sb = Text.StringBuilder()
if keyFile.Exists
then bprintf sb "-keyfile:%s -target:library -assembly:%s" keyFile.FullName task.AssemblyName
if not <| String.IsNullOrEmpty(task.Version)
then task.Version |> bprintf sb " -version:%s"
bprintf sb " %s -out:%s"
(task.JarFile |> getNewFileName ".jar")
(task.AssemblyName + ".dll")
sb.ToString()
File.Copy(task.JarFile, workingDirectory @@ (Path.GetFileName(task.JarFile)) ,true)
startProcess ikvmc (getIKVMCommandLineArgs())
tasks |> Seq.iter compile
Target "Clean" (fun _ ->
CleanDirs [artifactDir; tempDir; tikaLibDir]
)
Target "SetVersions" (fun _ ->
let commitHash =
try
Information.getCurrentSHA1 "."
with
| ex -> "n/a"
CreateCSharpAssemblyInfo "./SolutionInfo.cs"
[Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion
Attribute.Trademark commitHash]
)
Target "Build" (fun _ ->
let strongName =
if keyFile.Exists
then ["SignAssembly","true"; "AssemblyOriginatorKeyFile",keyFile.FullName]
else []
!! solutionFile
|> MSBuildReleaseExt "" strongName "Clean;Rebuild"
|> ignore
)
Target "RunTests" (fun _ ->
!! testAssemblies
|> NUnit (fun p ->
{ p with
OutputFile = artifactDir + "\TestResults.xml"})
)
type tikaDir = root.``paket-files``.``www-us.apache.org``
Target "CompileTikaLib" (fun _ ->
!! "paket-files/www-us.apache.org/tika-app-*.jar"
|> Seq.map (fun name -> IKVMcTask(name, "TikaOnDotNet", Version=release.AssemblyVersion))
|> IKVMCompile tikaLibDir
)
Target "PackageNugets" (fun _ ->
Paket.Pack (fun p ->
{ p with
Version = release.NugetVersion
OutputPath = artifactDir
ReleaseNotes = toLines release.Notes
Symbols = true })
)
Target "PublishNugets" (fun _ ->
Paket.Push(fun p ->
{ p with
DegreeOfParallelism = 2
WorkingDir = artifactDir })
)
Target "BuildSNK" (fun _ ->
let snkBase64 = environVarOrNone "snk"
match snkBase64 with
| Some env ->
(
trace "Replacing .snk"
keyFile.Delete |> ignore
let snkbytes = System.Convert.FromBase64String(env)
System.IO.File.WriteAllBytes(keyFile.FullName, snkbytes)
)
| None -> trace "No key found in the \"snk\" environment"
)
"Clean"
==> "SetVersions"
==> "BuildSNK"
==> "CompileTikaLib"
==> "Build"
==> "RunTests"
"Build"
==> "PackageNugets"
==> "PublishNugets"
// start build
RunTargetOrDefault "RunTests"