Skip to content

Commit 9662b1f

Browse files
committed
Simplify build (#2757)
* Made the bash,dos script dumber for by introducing pretty horrible command line parser in F# :) * travis still called inc target, equivalent is now test Conflicts: build.bat
1 parent 8809c81 commit 9662b1f

File tree

9 files changed

+129
-192
lines changed

9 files changed

+129
-192
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: csharp
22
solution: src/Elasticsearch.sln
3-
script: ./build.sh inc
3+
script: ./build.sh test
44
dist: trusty
55
mono: 4.6.2
66
dotnet: 1.0.1

build.bat

Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,6 @@
11
@echo off
22

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)
22-
23-
SET TARGET="build"
24-
SET VERSION=
25-
SET ESVERSIONS=
26-
SET SKIPTESTS=0
27-
SET APIKEY=
28-
SET APIKEYPROVIDED="<empty>"
29-
SET FEED="elasticsearch-net"
30-
SET NEST_INTEGRATION_CLUSTER=
31-
SET NEST_TEST_FILTER=
32-
SET ELASTICSEARCH=
33-
SET INTEGRATE_CLR="one"
34-
35-
IF /I "%1"=="skiptests" (
36-
set SKIPTESTS="1"
37-
SHIFT
38-
)
39-
IF NOT [%1]==[] (set TARGET=%1)
40-
41-
SET SKIPPAKET=0
42-
IF /I "%TARGET%"=="inc" SET SKIPPAKET=1
43-
IF /I "%TARGET%"=="canary" SET SKIPTESTS=1
44-
45-
IF "%SKIPPAKET%" neq "1" (
46-
.paket\paket.bootstrapper.exe
47-
IF EXIST paket.lock (.paket\paket.exe restore)
48-
IF NOT EXIST paket.lock (.paket\paket.exe install)
49-
)
50-
51-
REM if `build quick` is called on a fresh checkout force a restore anyway
52-
IF "%SKIPPAKET%"=="1" (
53-
IF NOT EXIST .paket\paket.exe (
54-
.paket\paket.bootstrapper.exe
55-
)
56-
IF EXIST paket.lock (.paket\paket.exe restore)
57-
IF NOT EXIST paket.lock (.paket\paket.exe install)
58-
)
59-
60-
IF /I "%TARGET%"=="version" (
61-
IF NOT [%2]==[] (set VERSION="%2")
62-
)
63-
IF /I "%TARGET%"=="release" (
64-
IF NOT [%2]==[] (set VERSION="%2")
65-
IF /I "%JAVA_HOME%"=="" (
66-
ECHO JAVA_HOME not set exiting release early!
67-
EXIT /B 1
68-
)
69-
)
70-
IF /I "%TARGET%"=="inc" (
71-
IF NOT [%2]==[] (set NEST_TEST_FILTER="%2")
72-
)
73-
IF /I "%TARGET%"=="integrate-all" (
74-
SET TARGET="integrate"
75-
SET INTEGRATE_CLR="all"
76-
IF NOT [%2]==[] (set ESVERSIONS="%2")
77-
IF NOT [%3]==[] (set NEST_INTEGRATION_CLUSTER="%~3")
78-
IF NOT [%4]==[] (set NEST_TEST_FILTER="%4")
79-
)
80-
IF /I "%TARGET%"=="integrate" (
81-
IF NOT [%2]==[] (set ESVERSIONS="%2")
82-
IF NOT [%3]==[] (set NEST_INTEGRATION_CLUSTER="%~3")
83-
IF NOT [%4]==[] (set NEST_TEST_FILTER="%4")
84-
IF /I "%JAVA_HOME%"=="" (
85-
ECHO JAVA_HOME not set exiting release early!
86-
EXIT /B 1
87-
)
88-
)
89-
IF /I "%TARGET%"=="canary" (
90-
IF NOT [%2]==[] (
91-
set APIKEY="%2"
92-
SET APIKEYPROVIDED="<redacted>"
93-
)
94-
IF NOT [%3]==[] set FEED="%3"
95-
)
96-
IF /I "%TARGET%"=="profile" (
97-
IF NOT [%2]==[] (set ELASTICSEARCH="%2")
98-
IF NOT [%3]==[] (set NEST_TEST_FILTER="%3")
99-
)
100-
101-
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% elasticsearch=%ELASTICSEARCH% integrateclr=%INTEGRATE_CLR%
102-
"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%" "elasticsearch=%ELASTICSEARCH%" "integrateclr=%INTEGRATE_CLR%"
3+
.paket\paket.bootstrapper.exe
4+
IF EXIST paket.lock (.paket\paket.exe restore)
5+
IF NOT EXIST paket.lock (.paket\paket.exe install)
6+
"packages\build\FAKE\tools\Fake.exe" "build\\scripts\\Targets.fsx" "cmdline=%*"

build.sh

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,7 @@
22
FAKE="packages/build/FAKE/tools/FAKE.exe"
33
BUILDSCRIPT="build/scripts/Targets.fsx"
44

5-
6-
TARGET="build"
7-
VERSION=
8-
ESVERSIONS=
9-
SKIPTESTS=0
10-
APIKEY=
11-
APIKEYPROVIDED="<empty>"
12-
FEED="elasticsearch-net"
13-
NEST_INTEGRATION_CLUSTER=
14-
NEST_TEST_FILTER=
15-
16-
if [[ "${1,,}" == "skiptests" ]]; then SKIPTESTS=1; shift; fi
17-
18-
if [[ ! -z "$1" ]]; then TARGET=$1; fi
19-
20-
if [[ "${TARGET,,}" == "inc" ]]; then SKIPPAKET=1; fi
21-
if [[ "${TARGET,,}" == "forever" ]]; then SKIPPAKET=1; fi
22-
23-
if [[ $SKIPPAKET -ne 1 ]]; then
24-
mono .paket/paket.bootstrapper.exe
25-
mono .paket/paket.exe restore
26-
fi
27-
if [[ $SKIPPAKET -eq 1 && ! -f .paket/paket.exe ]]; then
28-
mono .paket/paket.bootstrapper.exe
29-
mono .paket/paket.exe restore
30-
fi
31-
if [[ "${TARGET,,}" == "inc" ]] || [[ "${TARGET,,}" == "forever" ]]; then
32-
if [[ ! -z "$2" ]]; then NEST_TEST_FILTER=$2; fi
33-
fi
34-
35-
if [[ "${TARGET,,}" == "integrate" ]]; then
36-
if [[ ! -z "$2" ]]; then ESVERSIONS=$2; fi
37-
if [[ ! -z "$3" ]]; then NEST_INTEGRATION_CLUSTER=$3; fi
38-
if [[ ! -z "$4" ]]; then NEST_TEST_FILTER=$4; fi
39-
if [[ ! -z "$JAVA_HOME" ]]; then
40-
echo JAVA_HOME not set so no point in running integration tests is there?!
41-
exit /b 1
42-
fi
43-
fi
44-
45-
if [[ "${TARGET,,}" == "canary" ]]; then
46-
if [[ ! -z "$2" ]]; then
47-
APIKEY=$2
48-
APKEYPROVIDED="<redacted>"
49-
fi
50-
if [[ ! -z "$3" ]]; then FEED=$3; fi
51-
fi
52-
53-
echo build.sh: target=$TARGET skippakket=$SKIPPAKET version=$VERSION esversions=$ESVERSIONS skiptests=$SKIPTESTS apiKey=$APIKEYPROVIDED feed=$FEED escluster=$NEST_INTEGRATION_CLUSTER testfilter=$NEST_TEST_FILTER
54-
55-
export TARGET
56-
export VERSION
57-
export ESVERSIONS
58-
export NEST_INTEGRATION_CLUSTER
59-
export NEST_TEST_FILTER
60-
mono $FAKE $@ --fsiargs -d:MONO $BUILDSCRIPT "target=$TARGET" "version=$VERSION" "esversions=$ESVERSIONS" "skiptests=$SKIPTESTS" "apiKey=$APIKEY" "feed=$FEED" "escluster=$NEST_INTEGRATION_CLUSTER" "testfilter=$NEST_TEST_FILTER"
5+
mono .paket/paket.bootstrapper.exe
6+
if [[ -f .paket.lock ]]; then mono .paket/paket.exe restore; fi
7+
if [[ ! -f .paket.lock ]]; then mono .paket/paket.exe install; fi
8+
mono $FAKE $@ --fsiargs -d:MONO $BUILDSCRIPT "cmdline=$@"

build/scripts/Commandline.fsx

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#I @"../../packages/build/FAKE/tools"
2+
#r @"FakeLib.dll"
3+
4+
open System
5+
open Fake
6+
7+
8+
//this is ugly but a direct port of what used to be duplicated in our DOS and bash scripts
9+
10+
let private usage = """
11+
USAGE:
12+
13+
build <target> [params] [skiptests]
14+
15+
Targets:
16+
17+
* build-all
18+
- default target if non provided. Performs rebuild and tests all TFM's
19+
* clean
20+
- cleans build output folders
21+
* test [testfilter]
22+
- incremental build and unit test for .NET 4.5, [testfilter] allows you to do
23+
a contains match on the tests to be run.
24+
* release <version>
25+
- 0 create a release worthy nuget packages for [version] under build\output
26+
* integrate <elasticsearch_versions> [clustername] [testfilter] -
27+
- run integration tests for <elasticsearch_versions> which is a semicolon separated list of
28+
elasticsearch versions to test or `latest`. Can filter tests by <clustername> and <testfilter>
29+
* canary [apikey] [feed]
30+
- create a canary nuget package based on the current version if [feed] and [apikey] are provided
31+
also pushes to upstream (myget)
32+
33+
NOTE: both the `test` and `integrate` targets can be suffixed with `-all` to force the tests against all suported TFM's
34+
"""
35+
36+
module Commandline =
37+
type MultiTarget = All | One
38+
39+
let private args = getBuildParamOrDefault "cmdline" "build" |> split ' '
40+
let skipTests = args |> List.exists (fun x -> x = "skiptests")
41+
let private filteredArgs = args |> List.filter (fun x -> x <> "skiptests")
42+
43+
let multiTarget =
44+
match (filteredArgs |> List.tryHead) with
45+
| Some t when t.EndsWith("-all") -> MultiTarget.All
46+
| _ -> MultiTarget.One
47+
48+
let target =
49+
match (filteredArgs |> List.tryHead) with
50+
| Some t -> t.Replace("-all", "")
51+
| _ -> "build"
52+
53+
let needsFullBuild =
54+
match (target, skipTests) with
55+
| (_, true) -> true
56+
//dotnet-xunit needs to a build of its own anyways
57+
| ("test", _)
58+
| ("integrate", _) -> false
59+
| _ -> true
60+
61+
let arguments =
62+
match filteredArgs with
63+
| _ :: tail -> target :: tail
64+
| [] -> [target]
65+
66+
let parse () =
67+
setEnvironVar "FAKEBUILD" "1"
68+
match arguments with
69+
| [] | ["build"] | ["test"] | ["clean"] -> ignore()
70+
| ["release"; version] -> setBuildParam "version" version
71+
72+
| ["test"; testFilter] -> setBuildParam "testfilter" testFilter
73+
74+
| ["profile"; esVersions] -> setBuildParam "esversions" esVersions
75+
| ["profile"; esVersions; testFilter] ->
76+
setBuildParam "esversions" esVersions
77+
setBuildParam "testfilter" testFilter
78+
79+
| ["integrate"; esVersions] -> setBuildParam "esversions" esVersions
80+
| ["integrate"; esVersions; clusterFilter] ->
81+
setBuildParam "esversions" esVersions
82+
setBuildParam "clusterfilter" clusterFilter
83+
| ["integrate"; esVersions; clusterFilter; testFilter] ->
84+
setBuildParam "esversions" esVersions
85+
setBuildParam "clusterfilter" clusterFilter
86+
setBuildParam "testfilter" testFilter
87+
88+
| ["canary"; apiKey ] ->
89+
setBuildParam "apiKey" apiKey
90+
setBuildParam "feed" "elasticsearch-net"
91+
| ["canary"; apiKey; feed ] ->
92+
setBuildParam "apiKey" apiKey
93+
setBuildParam "feed" feed
94+
| _ ->
95+
traceError usage
96+
exit 2
97+
98+
traceHeader target

build/scripts/Targets.fsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#load @"Commandline.fsx"
12
#load @"Projects.fsx"
23
#load @"Paths.fsx"
34
#load @"Tooling.fsx"
@@ -12,7 +13,7 @@
1213
#load @"XmlDocPatcher.fsx"
1314

1415
open System
15-
open Fake
16+
open Fake
1617

1718
open Paths
1819
open Building
@@ -26,14 +27,11 @@ open XmlDocPatcher
2627
open Documentation
2728
open Signing
2829

29-
// Default target
30+
open Commandline
31+
Commandline.parse()
3032

3133
Target "Build" <| fun _ -> traceHeader "STARTING BUILD"
3234

33-
Target "Inc" <| fun _ -> traceHeader "STARTING INCREMENTAL BUILD"
34-
35-
Target "IncrementalTest" Tests.IncrementalTest
36-
3735
Target "Clean" Build.Clean
3836

3937
Target "Restore" Build.Restore
@@ -42,16 +40,14 @@ Target "IncrementalBuild" <| fun _ -> Build.Compile false
4240

4341
Target "FullBuild" <| fun _ -> Build.Compile false
4442

45-
Target "UnitTests" Tests.RunUnitTests
43+
Target "Test" Tests.RunUnitTests
4644

4745
Target "Profile" <| fun _ ->
4846
Profiler.Run()
4947
let url = getBuildParam "elasticsearch"
5048
Profiler.IndexResults url
5149

52-
Target "Integrate" <| fun _ ->
53-
let target = if getBuildParam "integrateclr" = "one" then Tests.MultiTarget.One else Tests.MultiTarget.All
54-
Tests.RunIntegrationTests target
50+
Target "Integrate" <| Tests.RunIntegrationTests
5551

5652
Target "Benchmark" Benchmarker.Run
5753

@@ -77,8 +73,8 @@ Target "Canary" <| fun _ ->
7773
"Clean"
7874
=?> ("Version", hasBuildParam "version")
7975
==> "Restore"
80-
==> "FullBuild"
81-
=?> ("UnitTests", (not ((getBuildParam "skiptests") = "1")))
76+
=?> ("FullBuild", Commandline.needsFullBuild)
77+
=?> ("Test", (not Commandline.skipTests))
8278
==> "InheritDoc"
8379
==> "Documentation"
8480
==> "Build"
@@ -97,13 +93,8 @@ Target "Canary" <| fun _ ->
9793
"FullBuild"
9894
==> "Integrate"
9995

100-
"Restore"
101-
==> "IncrementalBuild"
102-
=?> ("IncrementalTest", (not ((getBuildParam "skiptests") = "1")))
103-
==> "Inc"
104-
10596
"Build"
10697
==> "Release"
10798

10899
// start build
109-
RunTargetOrDefault "Build"
100+
RunTargetOrDefault Commandline.target

0 commit comments

Comments
 (0)