Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 092cd31

Browse files
committedMar 25, 2024
Fix #6531 Allow cross-operating system release.hs
1 parent c55283b commit 092cd31

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed
 

‎etc/scripts/release.hs

+52-21
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Development.Shake
2828
( Action, Change (..), pattern Chatty, CmdOption (..), Rules
2929
, ShakeOptions (..), Stdout (..), (%>), actionOnException
3030
, alwaysRerun, cmd, command_, copyFileChanged
31-
, getDirectoryFiles, liftIO, need, phony, putNormal
31+
, getDirectoryFiles, liftIO, need, phony, putInfo
3232
, removeFilesAfter, shakeArgsWith, shakeOptions, want
3333
)
3434
import Development.Shake.FilePath
@@ -72,10 +72,12 @@ main = shakeArgsWith
7272
let gAllowDirty = False
7373
Platform arch _ = buildPlatform
7474
gArch = arch
75+
gTargetOS = platformOS
7576
gBinarySuffix = ""
7677
gTestHaddocks = True
7778
gProjectRoot = "" -- Set to real value below.
7879
gBuildArgs = ["--flag", "stack:-developer-mode"]
80+
gStackArgs = []
7981
gCertificateName = Nothing
8082
global0 = foldl
8183
(flip id)
@@ -87,9 +89,11 @@ main = shakeArgsWith
8789
, gProjectRoot
8890
, gHomeDir
8991
, gArch
92+
, gTargetOS
9093
, gBinarySuffix
9194
, gTestHaddocks
9295
, gBuildArgs
96+
, gStackArgs
9397
, gCertificateName
9498
}
9599
flags
@@ -131,13 +135,23 @@ options =
131135
g { gBuildArgs =
132136
gBuildArgs g
133137
++ [ "--flag=stack:static"
134-
, "--docker"
138+
]
139+
, gStackArgs =
140+
gStackArgs g
141+
++ [ "--docker"
135142
, "--system-ghc"
136143
, "--no-install-ghc"
137144
]
145+
, gTargetOS = Linux
138146
}
139147
)
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'."
141155
, Option "" [buildArgsOptName]
142156
( ReqArg
143157
(\v -> Right $ \g -> g{gBuildArgs = gBuildArgs g ++ words v})
@@ -184,25 +198,27 @@ rules global args = do
184198
stackExeFileName
185199
]
186200
(stackArgs global)
201+
global.gStackArgs
187202
["build"]
188203
global.gBuildArgs
189204
integrationTestFlagArgs
190205
["--pedantic", "--no-haddock-deps", "--test"]
191206
["--haddock" | global.gTestHaddocks]
192207
["stack"]
193208
() <- 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+
]
201217
copyFileChanged (releaseBinDir </> binaryName </> stackExeFileName) out
202218

203219
releaseDir </> binaryPkgZipFileName %> \out -> do
204220
stageFiles <- getBinaryPkgStageFiles
205-
putNormal $ "zip " ++ out
221+
putInfo $ "zip " ++ out
206222
liftIO $ do
207223
entries <- forM stageFiles $ \stageFile -> do
208224
Zip.readEntry
@@ -233,14 +249,23 @@ rules global args = do
233249

234250
releaseDir </> binaryExeFileName %> \out -> do
235251
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."
244269
case platformOS of
245270
Windows -> do
246271
-- Windows doesn't have or need a 'strip' command, so skip it.
@@ -336,7 +361,7 @@ rules global args = do
336361
releaseBinDir = releaseDir </> "bin"
337362

338363
binaryPkgFileNames =
339-
case platformOS of
364+
case global.gTargetOS of
340365
Windows ->
341366
[ binaryExeFileName
342367
, binaryPkgZipFileName
@@ -357,7 +382,7 @@ rules global args = do
357382
, "-"
358383
, stackVersionStr global
359384
, "-"
360-
, display platformOS
385+
, display global.gTargetOS
361386
, "-"
362387
, display global.gArch
363388
, if null global.gBinarySuffix then "" else "-" ++ global.gBinarySuffix
@@ -438,6 +463,10 @@ binaryVariantOptName = "binary-variant"
438463
noTestHaddocksOptName :: String
439464
noTestHaddocksOptName = "no-test-haddocks"
440465

466+
-- | @--stack-args@ command-line option name.
467+
stackArgsOptName :: String
468+
stackArgsOptName = "stack-args"
469+
441470
-- | @--build-args@ command-line option name.
442471
buildArgsOptName :: String
443472
buildArgsOptName = "build-args"
@@ -469,9 +498,11 @@ data Global = Global
469498
, gProjectRoot :: !FilePath
470499
, gHomeDir :: !FilePath
471500
, gArch :: !Arch
501+
, gTargetOS :: !OS
472502
, gBinarySuffix :: !String
473503
, gTestHaddocks :: !Bool
474504
, gBuildArgs :: [String]
505+
, gStackArgs :: [String]
475506
, gCertificateName :: !(Maybe String)
476507
}
477508
deriving Show

0 commit comments

Comments
 (0)
Please sign in to comment.