Skip to content

Commit 3961581

Browse files
authored
Improvement/build (#2523)
* Several build related fixes - Normalize module vs type usages in fsx files - unit methods now all in Method() = form - cleaned up build.bat and its skiptests leniency, now only accepted as the first argument - Improved usage notice in build.bat - Building now checks if `dotnet.exe` resolves to using the proper SDK - Moved to DotNetCli FAKE helper (#2395) - Separated Projects and Tooling out of Paths.fsx - Now have a truly quick compile target `build quick [test_filter]` does an incremental build and runs the unit tests from the bin output folder. it also skips paket. - moved global.json to the root of repos * Explict separation of unit/integration custom runners - unit tests now parallizes over all tests ignoring all clusters rather then piggy backing on xunit which we do in 5.x (our own routine is 10+seconds faster) or on the integration routine (which we currently do in master) * moved testing over to DotNetCli helper too * Build resiliency changes build quick can optionally does a paket bootstrap/restore if paket is not found, allowing you to do build quick on a clean checkout too. The general build now cleans the bin folders after itself so that running build build quick Does not end up in the latter resolving 4.6 assemblies from the previous build
1 parent 1d462dd commit 3961581

File tree

24 files changed

+1107
-1409
lines changed

24 files changed

+1107
-1409
lines changed

build.bat

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
@echo off
22

3-
REM build
4-
REM build build [skiptests]
5-
REM build release [version] [skiptests]
6-
REM build version [version] [skiptests]
7-
REM build integrate [elasticsearch_versions] [clustername]
8-
REM build canary [apikey] [feed] [skiptests]
9-
10-
REM - elasticsearch_versions can be multiple separated with a semi-colon ';'
11-
12-
.paket\paket.bootstrapper.exe
13-
if errorlevel 1 (
14-
exit /b %errorlevel%
15-
)
16-
.paket\paket.exe restore
17-
if errorlevel 1 (
18-
exit /b %errorlevel%
19-
)
3+
REM USAGE:
4+
REM
5+
REM build [skiptests] <command> [params]
6+
REM
7+
REM COMMANDS:
8+
REM
9+
REM * build
10+
REM default target if non provided. Performs a clean, rebuild and test of all target frameworks
11+
REM * quick [testfilter]
12+
REM incremental build and unit test for .NET 4.5, [testfilter] allows you to do
13+
REM a contains match on the tests to be run.
14+
REM * build release <version>
15+
REM create a release worthy nuget packages for [version] under build\output
16+
REM * build integrate <elasticsearch_versions> [clustername] [testfilter] -
17+
REM run integration tests for <elasticsearch_versions> which is a semicolon separated list of
18+
REM elasticsearch versions to test or `latest`. Can filter tests by <clustername> and <testfilter>
19+
REM * build canary [apikey] [feed] [skiptests]
20+
REM create a canary nuget package based on the current version if [feed] and [apikey] are provided
21+
REM also pushes to upstream (myget)
2022

2123
SET TARGET="build"
2224
SET VERSION=
@@ -32,25 +34,42 @@ IF /I "%1"=="skiptests" (
3234
set SKIPTESTS="1"
3335
SHIFT
3436
)
37+
IF NOT [%1]==[] (set TARGET=%1)
3538

36-
IF NOT [%1]==[] (set TARGET="%1")
39+
SET SKIPPAKET=0
40+
IF /I "%TARGET%"=="quick" SET SKIPPAKET=1
41+
IF /I "%TARGET%"=="forever" SET SKIPPAKET=1
3742

38-
IF /I "%1"=="version" (
43+
IF "%SKIPPAKET%" neq "1" (
44+
.paket\paket.bootstrapper.exe
45+
.paket\paket.exe restore
46+
)
47+
48+
REM if `build quick` is called on a fresh checkout force a restore anyway
49+
IF "%SKIPPAKET%"=="1" (
50+
IF NOT EXIST .paket\paket.exe (
51+
.paket\paket.bootstrapper.exe
52+
.paket\paket.exe restore
53+
)
54+
)
55+
56+
IF /I "%TARGET%"=="version" (
3957
IF NOT [%2]==[] (set VERSION="%2")
40-
IF /I "%3"=="skiptests" (set SKIPTESTS=1)
41-
IF /I "%2"=="skiptests" (set SKIPTESTS=1)
4258
)
43-
IF /I "%1"=="release" (
59+
IF /I "%TARGET%"=="release" (
4460
IF NOT [%2]==[] (set VERSION="%2")
45-
IF /I "%3"=="skiptests" (set SKIPTESTS=1)
46-
IF /I "%2"=="skiptests" (set SKIPTESTS=1)
4761
IF /I "%JAVA_HOME%"=="" (
4862
ECHO JAVA_HOME not set exiting release early!
4963
EXIT /B 1
5064
)
5165
)
52-
53-
IF /I "%1%"=="integrate" (
66+
IF /I "%TARGET%"=="quick" (
67+
IF NOT [%2]==[] (set NEST_TEST_FILTER="%2")
68+
)
69+
IF /I "%TARGET%"=="forever" (
70+
IF NOT [%2]==[] (set NEST_TEST_FILTER="%2")
71+
)
72+
IF /I "%TARGET%"=="integrate" (
5473
IF NOT [%2]==[] (set ESVERSIONS="%2")
5574
IF NOT [%3]==[] (set NEST_INTEGRATION_CLUSTER="%3")
5675
IF NOT [%4]==[] (set NEST_TEST_FILTER="%4")
@@ -59,17 +78,13 @@ IF /I "%1%"=="integrate" (
5978
EXIT /B 1
6079
)
6180
)
62-
63-
IF /I "%1%"=="canary" (
64-
IF NOT [%2]==[] IF NOT "%2"=="skiptests" (
81+
IF /I "%TARGET%"=="canary" (
82+
IF NOT [%2]==[] (
6583
set APIKEY="%2"
6684
SET APIKEYPROVIDED="<redacted>"
6785
)
68-
IF NOT [%3]==[] IF NOT "%3"=="skiptests" set FEED="%3"
69-
IF /I "%4"=="skiptests" (set SKIPTESTS=1)
70-
IF /I "%3"=="skiptests" (set SKIPTESTS=1)
71-
IF /I "%2"=="skiptests" (set SKIPTESTS=1)
86+
IF NOT [%3]==[] set FEED="%3"
7287
)
7388

74-
ECHO starting build using target=%TARGET% version=%VERSION% esversions=%ESVERSIONS% skiptests=%SKIPTESTS% apiKey=%APIKEYPROVIDED% feed=%FEED% escluster=%NEST_INTEGRATION_CLUSTER% testfilter=%NEST_TEST_FILTER%
89+
ECHO build.bat: target=%TARGET% skippakket=%SKIPPAKET% version=%VERSION% esversions=%ESVERSIONS% skiptests=%SKIPTESTS% apiKey=%APIKEYPROVIDED% feed=%FEED% escluster=%NEST_INTEGRATION_CLUSTER% testfilter=%NEST_TEST_FILTER%
7590
"packages\build\FAKE\tools\Fake.exe" "build\\scripts\\Targets.fsx" "target=%TARGET%" "version=%VERSION%" "esversions=%ESVERSIONS%" "skiptests=%SKIPTESTS%" "apiKey=%APIKEY%" "feed=%FEED%" "escluster=%NEST_INTEGRATION_CLUSTER%" "testfilter=%NEST_TEST_FILTER%"

build/scripts/Building.fsx

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,90 @@
11
#I @"../../packages/build/FAKE/tools"
2+
#I @"../../packages/build/FSharp.Data/lib/net40"
23
#r @"FakeLib.dll"
4+
#r @"FSharp.Data.dll"
35

46
#load @"Paths.fsx"
7+
#load @"Tooling.fsx"
58

9+
open System
610
open Fake
11+
open FSharp.Data
712

813
open Paths
914
open Projects
10-
open Tooling;
15+
open Tooling
1116

12-
type Build() =
17+
module Build =
1318

14-
static let runningRelease = hasBuildParam "version" || hasBuildParam "apikey" || getBuildParam "target" = "canary" || getBuildParam "target" = "release"
19+
let private runningRelease = hasBuildParam "version" || hasBuildParam "apikey" || getBuildParam "target" = "canary" || getBuildParam "target" = "release"
20+
let private quickBuild = getBuildParam "target" = "quick" || getBuildParam "target" = "forever"
21+
22+
type private GlobalJson = JsonProvider<"../../global.json">
23+
let private pinnedSdkVersion = GlobalJson.GetSample().Sdk.Version
24+
25+
let private compileCore() =
26+
if not (DotNetCli.isInstalled()) then failwith "You need to install the dotnet command line SDK to build for .NET Core"
27+
let runningSdkVersion = DotNetCli.getVersion()
28+
if (runningSdkVersion <> pinnedSdkVersion) then failwithf "Attempting to run with dotnet.exe with %s but global.json mandates %s" runningSdkVersion pinnedSdkVersion
1529

16-
static let compileCore() =
1730
DotNetProject.AllPublishable
1831
|> Seq.iter(fun p ->
1932
let path = Paths.ProjectJson p.Name
2033
let o = Paths.ProjectOutputFolder p DotNetFramework.NetStandard1_3
21-
DotNet.Exec ["restore"; path]
22-
DotNet.Exec ["build"; path; "--configuration Release"; "-o"; o; "-f"; DotNetFramework.NetStandard1_3.Identifier.MSBuild]
34+
DotNetCli.Restore
35+
(fun p ->
36+
{ p with
37+
Project = path
38+
TimeOut = TimeSpan.FromMinutes(2.)
39+
}
40+
) |> ignore
41+
42+
DotNetCli.Build
43+
(fun p ->
44+
{ p with
45+
Configuration = "Release"
46+
Project = path
47+
Framework = DotNetFramework.NetStandard1_3.Identifier.MSBuild
48+
TimeOut = TimeSpan.FromMinutes(2.)
49+
AdditionalArgs = ["-o"; o]
50+
}
51+
) |> ignore
52+
2353
)
2454

25-
static let compileDesktop target =
26-
MsBuild.Build(target, DotNetFramework.Net45.Identifier)
27-
MsBuild.Build(target, DotNetFramework.Net46.Identifier)
55+
let private compileDesktop() =
56+
Tooling.MsBuild.Rebuild DotNetFramework.Net45.Identifier
57+
Tooling.MsBuild.Rebuild DotNetFramework.Net46.Identifier
2858

29-
static let gitLink() =
59+
let private gitLink() =
3060
DotNetProject.AllPublishable
3161
|> Seq.iter(fun p ->
3262
let projectName = (p.Name |> directoryInfo).Name
3363
let link framework =
34-
GitLink.Exec ["."; "-u"; Paths.Repository; "-d"; (Paths.ProjectOutputFolder p framework); "-include"; projectName]
64+
Tooling.GitLink.Exec ["."; "-u"; Paths.Repository; "-d"; (Paths.ProjectOutputFolder p framework); "-include"; projectName]
3565
|> ignore
3666
link DotNetFramework.Net45
3767
link DotNetFramework.Net46
3868
link DotNetFramework.NetStandard1_3
3969
)
4070

41-
static member Compile() =
42-
//let target = if runningRelease then "Rebuild" else "Build"
43-
compileDesktop "Rebuild"
44-
//we only need this output when doing a release otherwise depend on test to validate the build
45-
if runningRelease then compileCore()
46-
if not isMono && runningRelease then gitLink()
47-
48-
static member Clean() =
49-
CleanDir Paths.BuildOutput
50-
DotNetProject.All |> Seq.iter(fun p -> CleanDir(Paths.BinFolder p.Name))
71+
let Compile() =
72+
match quickBuild with
73+
| true -> Tooling.MsBuild.Build DotNetFramework.Net45.Identifier
74+
| false ->
75+
compileDesktop()
76+
compileCore()
77+
if not isMono && runningRelease then gitLink()
78+
79+
let Clean() =
80+
match quickBuild with
81+
| true -> ignore()
82+
| false ->
83+
CleanDir Paths.BuildOutput
84+
DotNetProject.All |> Seq.iter(fun p -> CleanDir(Paths.BinFolder p.Name))
85+
86+
let CleanAfter() =
87+
match quickBuild with
88+
| true -> ignore()
89+
| false ->
90+
DotNetProject.All |> Seq.iter(fun p -> CleanDir(Paths.BinFolder p.Name))

build/scripts/Documentation.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open System.IO
1212

1313
module Documentation =
1414

15-
let Generate() =
15+
let Generate() =
1616
let generator = "build/output/v4.6/DocGenerator/DocGenerator.exe"
1717
ExecProcess (fun p ->
1818
p.WorkingDirectory <- "src/CodeGeneration/DocGenerator"
@@ -21,7 +21,7 @@ module Documentation =
2121
(TimeSpan.FromMinutes (1.0)) |> ignore
2222

2323
// TODO: hook documentation validation into the process
24-
let Validate() =
24+
let Validate() =
2525
let elasticDocsDir = "../elasticsearch-docs"
2626
if (directoryExists elasticDocsDir = false) then
2727
let fullPath = combinePaths currentDirectory elasticDocsDir |> Path.GetFullPath

0 commit comments

Comments
 (0)