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