-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.cmd
189 lines (161 loc) · 4.67 KB
/
build.cmd
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@ECHO OFF
REM Make environment variables local to the batch script
SETLOCAL
REM Default local parameters (BUILD_MODE must remain empty, otherwise, 'help' doesn't work)
SET BUILD_CONFIG=Release
SET BUILD_MODE=
SET DOTNET_TEST_ARGS=
SET DOTNET_TEST_PROJECT_LOCATION=
SET DOTNET_CI_ARGS=--blame-hang-timeout 60000ms --logger "console;verbosity=detailed"
SET DOTNET_TEST_ARGS=--logger "console;verbosity=detailed"
SET DOTNET_TEST_PROJECT_LOCATION=".\src\FSharp.Control.TaskSeq.Test\FSharp.Control.TaskSeq.Test.fsproj"
REM This is used to get a 'rest of arguments' list, which allows passing
REM other arguments to the dotnet build and test commands
SET REST_ARGS=%*
:parseArgs
IF "%~1"=="build" (
SET BUILD_MODE=build
REM Drop 'build' from the remaining args
CALL :shiftArg %REST_ARGS%
) ELSE IF "%~1"=="test" (
SET BUILD_MODE=test
REM Drop 'test' from the remaining args
CALL :shiftArg %REST_ARGS%
) ELSE IF "%~1"=="ci" (
SET BUILD_MODE=ci
REM Drop 'ci' from the remaining args
CALL :shiftArg %REST_ARGS%
) ELSE IF "%~1"=="help" (
GOTO :showHelp
) ELSE IF "%~1"=="/help" (
GOTO :showHelp
) ELSE IF "%~1"=="-help" (
GOTO :showHelp
) ELSE IF "%~1"=="" (
REM No args, default: build
SET BUILD_MODE=build
SET BUILD_CONFIG=release
)
CALL :tryBuildConfig %REST_ARGS%
ECHO Additional arguments: %REST_ARGS%
REM Main branching starts here
IF "%BUILD_MODE%"=="build" GOTO :runBuild
IF "%BUILD_MODE%"=="test" GOTO :runTest
IF "%BUILD_MODE%"=="ci" GOTO :runCi
REM Something wrong, we don't recognize the given arguments
REM Display help:
ECHO Argument not recognized
:showHelp
ECHO.
ECHO Available options are:
ECHO.
ECHO build Run 'dotnet build' (default if omitted)
ECHO test Run 'dotnet test' with default configuration and no CI logging.
ECHO ci Run 'dotnet test' with CI configuration and TRX logging.
ECHO.
ECHO Optionally combined with:
ECHO.
ECHO release Build release configuration (default).
ECHO debug Build debug configuration.
ECHO.
ECHO Any arguments that follow the special arguments will be passed on to 'dotnet test' or 'dotnet build'
ECHO Such user-supplied arguments can only be given when one of the above specific commands is used.
ECHO
ECHO Optional arguments may be given with a leading '/' or '-', if so preferred.
ECHO.
ECHO Examples:
ECHO.
ECHO Run default build (release):
ECHO build
ECHO.
ECHO Run debug build:
ECHO build debug
ECHO.
ECHO Run debug build with detailed verbosity:
ECHO build debug --verbosity detailed
ECHO.
ECHO Run the tests in default CI configuration
ECHO build ci
ECHO.
ECHO Run the tests as in CI, but with the Debug configuration
ECHO build ci -debug
ECHO.
ECHO Run the tests without TRX logging
ECHO build test -release
ECHO.
GOTO :EOF
REM Normal building
:runBuild
SET BUILD_COMMAND=dotnet build src/FSharp.Control.TaskSeq.sln -c %BUILD_CONFIG% %REST_ARGS%
ECHO Building for %BUILD_CONFIG% configuration...
ECHO.
ECHO Executing:
ECHO %BUILD_COMMAND%
ECHO.
ECHO Restoring dotnet tools...
dotnet tool restore
%BUILD_COMMAND%
GOTO :EOF
REM Testing
:runTest
SET TEST_COMMAND=dotnet test -c %BUILD_CONFIG% %DOTNET_TEST_ARGS% %DOTNET_TEST_PROJECT_LOCATION% %REST_ARGS%
ECHO.
ECHO Testing: %BUILD_CONFIG% configuration...
ECHO.
ECHO Restoring dotnet tools...
dotnet tool restore
ECHO Executing:
ECHO %TEST_COMMAND%
%TEST_COMMAND%
GOTO :EOF
REM Continuous integration
:runCi
SET TRX_LOGGER=--logger "trx;LogFileName=test-results-%BUILD_CONFIG%.trx"
SET CI_COMMAND=dotnet test -c %BUILD_CONFIG% %DOTNET_CI_ARGS% %DOTNET_TEST_PROJECT_LOCATION% %TRX_LOGGER% %REST_ARGS%
ECHO.
ECHO Continuous integration: %BUILD_CONFIG% configuration...
ECHO.
ECHO Restoring dotnet tools...
dotnet tool restore
ECHO Executing:
ECHO %CI_COMMAND%
%CI_COMMAND%
GOTO :EOF
REM Callable label, will resume after 'CALL' line
:tryBuildConfig
IF "%~1"=="release" (
SET BUILD_CONFIG=release
CALL :shiftArg %REST_ARGS%
)
IF "%~1"=="-release" (
SET BUILD_CONFIG=release
CALL :shiftArg %REST_ARGS%
)
IF "%~1"=="/release" (
SET BUILD_CONFIG=release
CALL :shiftArg %REST_ARGS%
)
IF "%~1"=="debug" (
SET BUILD_CONFIG=debug
CALL :shiftArg %REST_ARGS%
)
IF "%~1"=="-debug" (
SET BUILD_CONFIG=debug
CALL :shiftArg %REST_ARGS%
)
IF "%~1"=="/debug" (
SET BUILD_CONFIG=debug
CALL :shiftArg %REST_ARGS%
)
GOTO :EOF
REM Callable label, will resume after 'CALL' line
:shiftArg
REM WARNING!!!
REM If called from inside an IF-statement, it will NOT keep the resulting
REM variable %REST_ARGS%, until execution gets OUTSIDE of the IF-block
REM Do not call 'SHIFT' here, as we do it manually
REM Here, '%*' means the arguments given in the CALL command to this label
SET REST_ARGS=%*
REM Shift by stripping until and including the first argument
IF NOT "%REST_ARGS%"=="" CALL SET REST_ARGS=%%REST_ARGS:*%1=%%
GOTO :EOF