Skip to content

Commit

Permalink
Fix #6531 Allow cross-operating system release.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Mar 26, 2024
1 parent c55283b commit a088e79
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ jobs:
# (Note that the online documentation for '--docker-stack-exe image'
# specifies that the host Stack and image Stack must have the same
# version number.)
/usr/local/bin/stack etc/scripts/release.hs build --alpine --build-args --docker-stack-exe=image
/usr/local/bin/stack etc/scripts/release.hs build --alpine --stack-args --docker-stack-exe=image
- name: Upload bindist
if: needs.configuration.outputs.test-arm64 == 'true'
Expand Down
68 changes: 54 additions & 14 deletions etc/scripts/release.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Development.Shake
( Action, Change (..), pattern Chatty, CmdOption (..), Rules
, ShakeOptions (..), Stdout (..), (%>), actionOnException
, alwaysRerun, cmd, command_, copyFileChanged
, getDirectoryFiles, liftIO, need, phony, putNormal
, getDirectoryFiles, liftIO, need, phony, putInfo
, removeFilesAfter, shakeArgsWith, shakeOptions, want
)
import Development.Shake.FilePath
Expand Down Expand Up @@ -72,10 +72,13 @@ main = shakeArgsWith
let gAllowDirty = False
Platform arch _ = buildPlatform
gArch = arch
gTargetOS = platformOS
gBinarySuffix = ""
gTestHaddocks = True
gProjectRoot = "" -- Set to real value below.
gBuildArgs = ["--flag", "stack:-developer-mode"]
gStackArgs = []
gCheckStackArgs = []
gCertificateName = Nothing
global0 = foldl
(flip id)
Expand All @@ -87,9 +90,12 @@ main = shakeArgsWith
, gProjectRoot
, gHomeDir
, gArch
, gTargetOS
, gBinarySuffix
, gTestHaddocks
, gBuildArgs
, gStackArgs
, gCheckStackArgs
, gCertificateName
}
flags
Expand Down Expand Up @@ -131,13 +137,28 @@ options =
g { gBuildArgs =
gBuildArgs g
++ [ "--flag=stack:static"
, "--docker"
]
, gStackArgs =
gStackArgs g
++ [ "--docker"
, "--system-ghc"
, "--no-install-ghc"
]
, gCheckStackArgs =
gCheckStackArgs g
++ [ "--system-ghc"
, "--no-install-ghc"
]
, gTargetOS = Linux
}
)
"Build a statically linked binary using an Alpine Docker image."
"Build a statically-linked binary using an Alpine Linux Docker image."
, Option "" [stackArgsOptName]
( ReqArg
(\v -> Right $ \g -> g{gStackArgs = gStackArgs g ++ words v})
"\"ARG1 ARG2 ...\""
)
"Additional arguments to pass to 'stack'."
, Option "" [buildArgsOptName]
( ReqArg
(\v -> Right $ \g -> g{gBuildArgs = gBuildArgs g ++ words v})
Expand Down Expand Up @@ -180,29 +201,33 @@ rules global args = do
, show dirty
]
() <- cmd
stackProgName -- Use the platform's Stack
global.gStackArgs -- Possibly to set up a Docker container
["exec"] -- To execute the target Stack
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
stackExeFileName
]
["--"]
(stackArgs global)
["build"]
global.gCheckStackArgs -- Possible use the Docker image's GHC
["build"] -- To build the target Stack (Stack builds Stack)
global.gBuildArgs
integrationTestFlagArgs
["--pedantic", "--no-haddock-deps", "--test"]
["--haddock" | global.gTestHaddocks]
["stack"]
() <- cmd
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
stackExeFileName
]
["exec"]
stackProgName -- Use the platform's Stack
global.gStackArgs -- Possibiy to set up a Docker container
["exec"] -- To execute the target stack-integration-test
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
"stack-integration-test"
]
copyFileChanged (releaseBinDir </> binaryName </> stackExeFileName) out

releaseDir </> binaryPkgZipFileName %> \out -> do
stageFiles <- getBinaryPkgStageFiles
putNormal $ "zip " ++ out
putInfo $ "zip " ++ out
liftIO $ do
entries <- forM stageFiles $ \stageFile -> do
Zip.readEntry
Expand Down Expand Up @@ -234,7 +259,13 @@ rules global args = do
releaseDir </> binaryExeFileName %> \out -> do
need [releaseBinDir </> binaryName </> stackExeFileName]
(Stdout versionOut) <-
cmd (releaseBinDir </> binaryName </> stackExeFileName) "--version"
cmd
stackProgName -- Use the platform's Stack
global.gStackArgs -- Possibly to set up a Docker container
["exec"] -- To execute the target Stack and get its version info
(releaseBinDir </> binaryName </> stackExeFileName)
["--"]
["--version"]
when (not global.gAllowDirty && "dirty" `isInfixOf` lower versionOut) $
error
( "Refusing continue because 'stack --version' reports dirty. Use --"
Expand Down Expand Up @@ -295,10 +326,12 @@ rules global args = do
releaseBinDir </> binaryName </> stackExeFileName %> \out -> do
alwaysRerun
actionOnException
( cmd stackProgName
( cmd
stackProgName -- Use the platform's Stack
(stackArgs global)
["--local-bin-path=" ++ takeDirectory out]
"install"
global.gStackArgs -- Possibly to set up a Docker container
"install" -- To build and install Stack to that local bin path
global.gBuildArgs
integrationTestFlagArgs
"--pedantic"
Expand Down Expand Up @@ -336,7 +369,7 @@ rules global args = do
releaseBinDir = releaseDir </> "bin"

binaryPkgFileNames =
case platformOS of
case global.gTargetOS of
Windows ->
[ binaryExeFileName
, binaryPkgZipFileName
Expand All @@ -357,7 +390,7 @@ rules global args = do
, "-"
, stackVersionStr global
, "-"
, display platformOS
, display global.gTargetOS
, "-"
, display global.gArch
, if null global.gBinarySuffix then "" else "-" ++ global.gBinarySuffix
Expand Down Expand Up @@ -438,6 +471,10 @@ binaryVariantOptName = "binary-variant"
noTestHaddocksOptName :: String
noTestHaddocksOptName = "no-test-haddocks"

-- | @--stack-args@ command-line option name.
stackArgsOptName :: String
stackArgsOptName = "stack-args"

-- | @--build-args@ command-line option name.
buildArgsOptName :: String
buildArgsOptName = "build-args"
Expand Down Expand Up @@ -469,9 +506,12 @@ data Global = Global
, gProjectRoot :: !FilePath
, gHomeDir :: !FilePath
, gArch :: !Arch
, gTargetOS :: !OS
, gBinarySuffix :: !String
, gTestHaddocks :: !Bool
, gBuildArgs :: [String]
, gStackArgs :: [String]
, gCheckStackArgs :: [String]
, gCertificateName :: !(Maybe String)
}
deriving Show

0 comments on commit a088e79

Please sign in to comment.