Merge pull request #708 from Frassle/xunitmath
[platform/core/csapi/opentk.git] / build.fsx
1 // --------------------------------------------------------------------------------------
2 // FAKE build script
3 // --------------------------------------------------------------------------------------
4
5 #r @"packages/FAKE/tools/FakeLib.dll"
6 open Fake
7 open Fake.Git
8 open Fake.AssemblyInfoFile
9 open Fake.ReleaseNotesHelper
10 open Fake.UserInputHelper
11 open Fake.Testing
12 open System
13 open System.IO
14 open System.Diagnostics
15
16 // --------------------------------------------------------------------------------------
17 // START TODO: Provide project-specific details below
18 // --------------------------------------------------------------------------------------
19
20 // Information about the project are used
21 //  - for version and project name in generated AssemblyInfo file
22 //  - by the generated NuGet package
23 //  - to run tests and to publish documentation on GitHub gh-pages
24 //  - for documentation, you also need to edit info in "docs/tools/generate.fsx"
25
26 // The name of the project
27 // (used by attributes in AssemblyInfo, name of a NuGet package and directory in 'src')
28 let project = "OpenTK"
29
30 // Short summary of the project
31 // (used as description in AssemblyInfo and as a short summary for NuGet package)
32 let summary = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."
33
34 // Longer description of the project
35 // (used as a description for NuGet package; line breaks are automatically cleaned up)
36 let description = "The Open Toolkit is set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL. It runs on all major platforms and powers hundreds of apps, games and scientific research."
37
38 // List of author names (for NuGet package)
39 let authors = [ "Stefanos Apostolopoulos" ]
40
41 // Tags for your project (for NuGet package)
42 let tags = "OpenTK OpenGL OpenGLES GLES OpenAL C# F# VB .NET Mono Vector Math Game Graphics Sound"
43
44 let copyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos <stapostol@gmail.com> for the Open Toolkit library."
45
46 // File system information
47 let solutionFile  = "OpenTK.sln"
48
49 // Pattern specifying assemblies to be tested using NUnit
50 let testAssemblies = "tests/**/bin/Release/*Tests*.dll"
51
52 // Git configuration (used for publishing documentation in gh-pages branch)
53 // The profile where the project is posted
54 let gitOwner = "opentk"
55 let gitHome = "https://github.com/" + gitOwner
56
57 // The name of the project on GitHub
58 let gitName = "opentk"
59
60 // The url for the raw files hosted
61 let gitRaw = environVarOrDefault "gitRaw" "https://raw.github.com/opentk"
62
63 // --------------------------------------------------------------------------------------
64 // END TODO: The rest of the file includes standard build steps
65 // --------------------------------------------------------------------------------------
66
67 // Read additional information from the release notes document
68 let release = LoadReleaseNotes "RELEASE_NOTES.md"
69
70 let isXamarinPlatform = false //EnvironmentHelper.isMacOS || Environment.OSVersion.Platform = PlatformID.Win32NT
71
72
73 // Helper active pattern for project types
74 let (|Fsproj|Csproj|Vbproj|) (projFileName:string) =
75     match projFileName with
76     | f when f.EndsWith "fsproj" -> Fsproj
77     | f when f.EndsWith "csproj" -> Csproj
78     | f when f.EndsWith "vbproj" -> Vbproj
79     | _                           -> failwith (sprintf "Project file %s not supported. Unknown project type." projFileName)
80
81
82 let buildProjects =
83     !! "src/Generator.*/**.csproj"
84
85 let runtimeProjects =
86     let xamarinFilter f =
87         if isXamarinPlatform then
88             f
89         else
90             f
91             -- "**/OpenTK.Android.csproj"
92             -- "**/OpenTK.iOS.csproj"
93
94     !! "src/**/*.??proj"
95     ++ "tests/**/OpenTK.Tests*.??proj"
96     -- "src/Generator.*/**.csproj"
97     |> xamarinFilter
98
99 let activeProjects =
100     Seq.concat [buildProjects; runtimeProjects]
101
102
103 // Generate assembly info files with the right version & up-to-date information
104 Target "AssemblyInfo" (fun _ ->
105     let getAssemblyInfoAttributes (projectName:string) =
106         let projectName =
107             if projectName.Contains(".iOS") || projectName.Contains(".Android") then
108                 projectName.Split('.').[0]
109             else
110                 projectName
111         [ Attribute.Title (projectName)
112           Attribute.Product project
113           Attribute.Description summary
114           Attribute.Version release.AssemblyVersion
115           Attribute.FileVersion release.AssemblyVersion
116           Attribute.CLSCompliant true
117           Attribute.Copyright copyright
118         ]
119
120     let getProjectDetails projectPath =
121         let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
122         ( projectPath,
123           projectName,
124           System.IO.Path.GetDirectoryName(projectPath),
125           (getAssemblyInfoAttributes projectName)
126         )
127
128     activeProjects
129     |> Seq.map getProjectDetails
130     |> Seq.iter (fun (projFileName, projectName, folderName, attributes) ->
131         match projFileName with
132         | Fsproj -> CreateFSharpAssemblyInfo (folderName @@ "AssemblyInfo.fs") attributes
133         | Csproj -> CreateCSharpAssemblyInfo ((folderName @@ "Properties") @@ "AssemblyInfo.cs") attributes
134         | Vbproj -> CreateVisualBasicAssemblyInfo ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes
135         )
136 )
137
138 // Copies binaries from default VS location to expected bin folder
139 // But keeps a subdirectory structure for each project in the
140 // src folder to support multiple project outputs
141 Target "CopyBinaries" (fun _ ->
142     activeProjects
143     |>  Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) @@ "bin/Release", "bin" @@ (System.IO.Path.GetFileNameWithoutExtension f)))
144     |>  Seq.iter (fun (fromDir, toDir) -> CopyDir toDir fromDir (fun _ -> true))
145 )
146
147 // --------------------------------------------------------------------------------------
148 // Clean build results
149
150 Target "Clean" (fun _ ->
151     CleanDirs ["bin"; "temp"]
152 )
153
154 // --------------------------------------------------------------------------------------
155 // Build generator projects, and generate bindings if neccesary
156 Target "GenerateBindings" (fun _ ->
157     if not (File.Exists(".bindingsGenerated")) then
158         buildProjects
159             |> MSBuildRelease "" "Build"
160             |> ignore
161         let bindingProcess = new Process()
162         bindingProcess.StartInfo.FileName <- Path.Combine("src", "Generator.Bind", "bin", "Release", "Bind.exe")
163         if bindingProcess.Start() then
164             bindingProcess.WaitForExit()
165             File.Create(".bindingsGenerated").Close()
166         else
167             failwith "Could not start Bind.exe"
168 )
169
170 // --------------------------------------------------------------------------------------
171 // Build library & test project
172
173 Target "Build" (fun _ ->
174     activeProjects
175     |> MSBuildRelease "" "Build"
176     |> ignore
177 )
178
179 // --------------------------------------------------------------------------------------
180 // Run the unit tests using test runner
181
182 Target "RunTests" (fun _ ->
183     !! testAssemblies
184     |> xUnit2 (fun p ->
185         { p with
186             ShadowCopy = true
187             TimeOut = TimeSpan.FromMinutes 2.
188             XmlOutputPath = Some "TestResults.xml" })
189 )
190
191 // --------------------------------------------------------------------------------------
192 // Build a NuGet package
193
194 Target "NuGet" (fun _ ->
195     let xamExcludes =
196         if isXamarinPlatform then
197             []
198         else
199             [ "OpenTK.Android"
200               "OpenTK.iOS" ]
201
202
203     Paket.Pack(fun p ->
204         { p with
205             OutputPath = "bin"
206             ExcludedTemplates = xamExcludes
207             Version = release.NugetVersion
208             ReleaseNotes = toLines release.Notes})
209 )
210
211
212 Target "BuildPackage" DoNothing
213
214 // --------------------------------------------------------------------------------------
215 // Run all targets by default. Invoke 'build <Target>' to override
216
217 Target "All" DoNothing
218
219 "Clean"
220   ==> "AssemblyInfo"
221   ==> "GenerateBindings"
222   ==> "Build"
223   ==> "CopyBinaries"
224   ==> "RunTests"
225   ==> "All"
226
227 "All"
228   ==> "NuGet"
229
230
231 RunTargetOrDefault "All"