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 43a5047
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 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,12 @@ 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 = []
gCertificateName = Nothing
global0 = foldl
(flip id)
Expand All @@ -87,9 +89,11 @@ main = shakeArgsWith
, gProjectRoot
, gHomeDir
, gArch
, gTargetOS
, gBinarySuffix
, gTestHaddocks
, gBuildArgs
, gStackArgs
, gCertificateName
}
flags
Expand Down Expand Up @@ -131,13 +135,23 @@ options =
g { gBuildArgs =
gBuildArgs g
++ [ "--flag=stack:static"
, "--docker"
]
, gStackArgs =
gStackArgs g
++ [ "--docker"
, "--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,9 +194,13 @@ rules global args = do
, show dirty
]
() <- cmd
stackProgName
global.gStackArgs
["exec"]
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
stackExeFileName
]
["--"]
(stackArgs global)
["build"]
global.gBuildArgs
Expand All @@ -191,9 +209,8 @@ rules global args = do
["--haddock" | global.gTestHaddocks]
["stack"]
() <- cmd
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
stackExeFileName
]
stackProgName
global.gStackArgs
["exec"]
[ global.gProjectRoot </> releaseBinDir </> binaryName </>
"stack-integration-test"
Expand All @@ -202,7 +219,7 @@ rules global args = do

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 +251,13 @@ rules global args = do
releaseDir </> binaryExeFileName %> \out -> do
need [releaseBinDir </> binaryName </> stackExeFileName]
(Stdout versionOut) <-
cmd (releaseBinDir </> binaryName </> stackExeFileName) "--version"
cmd
stackProgName
global.gStackArgs
["exec"]
(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 @@ -298,6 +321,7 @@ rules global args = do
( cmd stackProgName
(stackArgs global)
["--local-bin-path=" ++ takeDirectory out]
global.gStackArgs
"install"
global.gBuildArgs
integrationTestFlagArgs
Expand Down Expand Up @@ -336,7 +360,7 @@ rules global args = do
releaseBinDir = releaseDir </> "bin"

binaryPkgFileNames =
case platformOS of
case global.gTargetOS of
Windows ->
[ binaryExeFileName
, binaryPkgZipFileName
Expand All @@ -357,7 +381,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 +462,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 +497,11 @@ data Global = Global
, gProjectRoot :: !FilePath
, gHomeDir :: !FilePath
, gArch :: !Arch
, gTargetOS :: !OS
, gBinarySuffix :: !String
, gTestHaddocks :: !Bool
, gBuildArgs :: [String]
, gStackArgs :: [String]
, gCertificateName :: !(Maybe String)
}
deriving Show

0 comments on commit 43a5047

Please sign in to comment.