@@ -28,7 +28,7 @@ import Development.Shake
28
28
( Action , Change (.. ), pattern Chatty , CmdOption (.. ), Rules
29
29
, ShakeOptions (.. ), Stdout (.. ), (%>) , actionOnException
30
30
, alwaysRerun , cmd , command_ , copyFileChanged
31
- , getDirectoryFiles , liftIO , need , phony , putNormal
31
+ , getDirectoryFiles , liftIO , need , phony , putInfo
32
32
, removeFilesAfter , shakeArgsWith , shakeOptions , want
33
33
)
34
34
import Development.Shake.FilePath
@@ -72,10 +72,12 @@ main = shakeArgsWith
72
72
let gAllowDirty = False
73
73
Platform arch _ = buildPlatform
74
74
gArch = arch
75
+ gTargetOS = platformOS
75
76
gBinarySuffix = " "
76
77
gTestHaddocks = True
77
78
gProjectRoot = " " -- Set to real value below.
78
79
gBuildArgs = [" --flag" , " stack:-developer-mode" ]
80
+ gStackArgs = []
79
81
gCertificateName = Nothing
80
82
global0 = foldl
81
83
(flip id )
@@ -87,9 +89,11 @@ main = shakeArgsWith
87
89
, gProjectRoot
88
90
, gHomeDir
89
91
, gArch
92
+ , gTargetOS
90
93
, gBinarySuffix
91
94
, gTestHaddocks
92
95
, gBuildArgs
96
+ , gStackArgs
93
97
, gCertificateName
94
98
}
95
99
flags
@@ -131,13 +135,23 @@ options =
131
135
g { gBuildArgs =
132
136
gBuildArgs g
133
137
++ [ " --flag=stack:static"
134
- , " --docker"
138
+ ]
139
+ , gStackArgs =
140
+ gStackArgs g
141
+ ++ [ " --docker"
135
142
, " --system-ghc"
136
143
, " --no-install-ghc"
137
144
]
145
+ , gTargetOS = Linux
138
146
}
139
147
)
140
- " Build a statically linked binary using an Alpine Docker image."
148
+ " Build a statically-linked binary using an Alpine Linux Docker image."
149
+ , Option " " [stackArgsOptName]
150
+ ( ReqArg
151
+ (\ v -> Right $ \ g -> g{gStackArgs = gStackArgs g ++ words v})
152
+ " \" ARG1 ARG2 ...\" "
153
+ )
154
+ " Additional arguments to pass to 'stack'."
141
155
, Option " " [buildArgsOptName]
142
156
( ReqArg
143
157
(\ v -> Right $ \ g -> g{gBuildArgs = gBuildArgs g ++ words v})
@@ -184,25 +198,27 @@ rules global args = do
184
198
stackExeFileName
185
199
]
186
200
(stackArgs global)
201
+ global. gStackArgs
187
202
[" build" ]
188
203
global. gBuildArgs
189
204
integrationTestFlagArgs
190
205
[" --pedantic" , " --no-haddock-deps" , " --test" ]
191
206
[" --haddock" | global. gTestHaddocks]
192
207
[" stack" ]
193
208
() <- cmd
194
- [ global. gProjectRoot </> releaseBinDir </> binaryName </>
195
- stackExeFileName
196
- ]
197
- [" exec" ]
198
- [ global. gProjectRoot </> releaseBinDir </> binaryName </>
199
- " stack-integration-test"
200
- ]
209
+ [ global. gProjectRoot </> releaseBinDir </> binaryName </>
210
+ stackExeFileName
211
+ ]
212
+ (stackArgs global)
213
+ [" exec" ]
214
+ [ global. gProjectRoot </> releaseBinDir </> binaryName </>
215
+ " stack-integration-test"
216
+ ]
201
217
copyFileChanged (releaseBinDir </> binaryName </> stackExeFileName) out
202
218
203
219
releaseDir </> binaryPkgZipFileName %> \ out -> do
204
220
stageFiles <- getBinaryPkgStageFiles
205
- putNormal $ " zip " ++ out
221
+ putInfo $ " zip " ++ out
206
222
liftIO $ do
207
223
entries <- forM stageFiles $ \ stageFile -> do
208
224
Zip. readEntry
@@ -233,14 +249,23 @@ rules global args = do
233
249
234
250
releaseDir </> binaryExeFileName %> \ out -> do
235
251
need [releaseBinDir </> binaryName </> stackExeFileName]
236
- (Stdout versionOut) <-
237
- cmd (releaseBinDir </> binaryName </> stackExeFileName) " --version"
238
- when (not global. gAllowDirty && " dirty" `isInfixOf` lower versionOut) $
239
- error
240
- ( " Refusing continue because 'stack --version' reports dirty. Use --"
241
- ++ allowDirtyOptName
242
- ++ " option to continue anyway."
243
- )
252
+ if platformOS == global. gTargetOS
253
+ then do
254
+ (Stdout versionOut) <-
255
+ cmd (releaseBinDir </> binaryName </> stackExeFileName) " --version"
256
+ when (not global. gAllowDirty && " dirty" `isInfixOf` lower versionOut) $
257
+ error
258
+ ( " Refusing continue because 'stack --version' reports dirty. Use --"
259
+ ++ allowDirtyOptName
260
+ ++ " option to continue anyway."
261
+ )
262
+ else
263
+ putInfo $
264
+ " The current and target operating systems differ ("
265
+ <> show platformOS
266
+ <> " , "
267
+ <> show global. gTargetOS
268
+ <> " ). Not checking if 'stack --version' reports dirty."
244
269
case platformOS of
245
270
Windows -> do
246
271
-- Windows doesn't have or need a 'strip' command, so skip it.
@@ -336,7 +361,7 @@ rules global args = do
336
361
releaseBinDir = releaseDir </> " bin"
337
362
338
363
binaryPkgFileNames =
339
- case platformOS of
364
+ case global . gTargetOS of
340
365
Windows ->
341
366
[ binaryExeFileName
342
367
, binaryPkgZipFileName
@@ -357,7 +382,7 @@ rules global args = do
357
382
, " -"
358
383
, stackVersionStr global
359
384
, " -"
360
- , display platformOS
385
+ , display global . gTargetOS
361
386
, " -"
362
387
, display global. gArch
363
388
, if null global. gBinarySuffix then " " else " -" ++ global. gBinarySuffix
@@ -438,6 +463,10 @@ binaryVariantOptName = "binary-variant"
438
463
noTestHaddocksOptName :: String
439
464
noTestHaddocksOptName = " no-test-haddocks"
440
465
466
+ -- | @--stack-args@ command-line option name.
467
+ stackArgsOptName :: String
468
+ stackArgsOptName = " stack-args"
469
+
441
470
-- | @--build-args@ command-line option name.
442
471
buildArgsOptName :: String
443
472
buildArgsOptName = " build-args"
@@ -469,9 +498,11 @@ data Global = Global
469
498
, gProjectRoot :: ! FilePath
470
499
, gHomeDir :: ! FilePath
471
500
, gArch :: ! Arch
501
+ , gTargetOS :: ! OS
472
502
, gBinarySuffix :: ! String
473
503
, gTestHaddocks :: ! Bool
474
504
, gBuildArgs :: [String ]
505
+ , gStackArgs :: [String ]
475
506
, gCertificateName :: ! (Maybe String )
476
507
}
477
508
deriving Show
0 commit comments