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 43a5047

Browse files
committedMar 26, 2024
Fix #6531 Allow cross-operating system release.hs
1 parent c55283b commit 43a5047

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed
 

‎etc/scripts/release.hs

+40-10
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})
@@ -180,9 +194,13 @@ rules global args = do
180194
, show dirty
181195
]
182196
() <- cmd
197+
stackProgName
198+
global.gStackArgs
199+
["exec"]
183200
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
184201
stackExeFileName
185202
]
203+
["--"]
186204
(stackArgs global)
187205
["build"]
188206
global.gBuildArgs
@@ -191,9 +209,8 @@ rules global args = do
191209
["--haddock" | global.gTestHaddocks]
192210
["stack"]
193211
() <- cmd
194-
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
195-
stackExeFileName
196-
]
212+
stackProgName
213+
global.gStackArgs
197214
["exec"]
198215
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
199216
"stack-integration-test"
@@ -202,7 +219,7 @@ rules global args = do
202219

203220
releaseDir </> binaryPkgZipFileName %> \out -> do
204221
stageFiles <- getBinaryPkgStageFiles
205-
putNormal $ "zip " ++ out
222+
putInfo $ "zip " ++ out
206223
liftIO $ do
207224
entries <- forM stageFiles $ \stageFile -> do
208225
Zip.readEntry
@@ -234,7 +251,13 @@ rules global args = do
234251
releaseDir </> binaryExeFileName %> \out -> do
235252
need [releaseBinDir </> binaryName </> stackExeFileName]
236253
(Stdout versionOut) <-
237-
cmd (releaseBinDir </> binaryName </> stackExeFileName) "--version"
254+
cmd
255+
stackProgName
256+
global.gStackArgs
257+
["exec"]
258+
(releaseBinDir </> binaryName </> stackExeFileName)
259+
["--"]
260+
["--version"]
238261
when (not global.gAllowDirty && "dirty" `isInfixOf` lower versionOut) $
239262
error
240263
( "Refusing continue because 'stack --version' reports dirty. Use --"
@@ -298,6 +321,7 @@ rules global args = do
298321
( cmd stackProgName
299322
(stackArgs global)
300323
["--local-bin-path=" ++ takeDirectory out]
324+
global.gStackArgs
301325
"install"
302326
global.gBuildArgs
303327
integrationTestFlagArgs
@@ -336,7 +360,7 @@ rules global args = do
336360
releaseBinDir = releaseDir </> "bin"
337361

338362
binaryPkgFileNames =
339-
case platformOS of
363+
case global.gTargetOS of
340364
Windows ->
341365
[ binaryExeFileName
342366
, binaryPkgZipFileName
@@ -357,7 +381,7 @@ rules global args = do
357381
, "-"
358382
, stackVersionStr global
359383
, "-"
360-
, display platformOS
384+
, display global.gTargetOS
361385
, "-"
362386
, display global.gArch
363387
, if null global.gBinarySuffix then "" else "-" ++ global.gBinarySuffix
@@ -438,6 +462,10 @@ binaryVariantOptName = "binary-variant"
438462
noTestHaddocksOptName :: String
439463
noTestHaddocksOptName = "no-test-haddocks"
440464

465+
-- | @--stack-args@ command-line option name.
466+
stackArgsOptName :: String
467+
stackArgsOptName = "stack-args"
468+
441469
-- | @--build-args@ command-line option name.
442470
buildArgsOptName :: String
443471
buildArgsOptName = "build-args"
@@ -469,9 +497,11 @@ data Global = Global
469497
, gProjectRoot :: !FilePath
470498
, gHomeDir :: !FilePath
471499
, gArch :: !Arch
500+
, gTargetOS :: !OS
472501
, gBinarySuffix :: !String
473502
, gTestHaddocks :: !Bool
474503
, gBuildArgs :: [String]
504+
, gStackArgs :: [String]
475505
, gCertificateName :: !(Maybe String)
476506
}
477507
deriving Show

0 commit comments

Comments
 (0)