Skip to content

Commit

Permalink
more flexible da flavour
Browse files Browse the repository at this point in the history
This PR updates the `CI.hs` script to make the DAML-specific build more
flexible. The motivation for this change is to set up a fully auditable
CI process for the DAML repo, i.e. one in which we can specify (and
track) exactly which commits were involved in creating the version of
ghc-lib used by the DAML compiler.
  • Loading branch information
garyverhaegen-da committed Jun 2, 2020
1 parent 5eb84d1 commit 9529115
Showing 1 changed file with 46 additions and 61 deletions.
107 changes: 46 additions & 61 deletions CI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ main = do
<> Opts.progDesc "Build (and possibly upload) ghc-lib and ghc-lib-parser tarballs."
<> Opts.header "CI - CI script for ghc-lib"
)
Options { upload, ghcFlavor, stackOptions } <- Opts.execParser opts
version <- buildDists ghcFlavor stackOptions
when upload $ bintrayUpload version
Options { ghcFlavor, daBaseSha, daPatches, daFlavor, stackOptions } <- Opts.execParser opts
version <- buildDists ghcFlavor stackOptions daBaseSha daPatches daFlavor
putStrLn version

data Options = Options
{ upload :: Bool
, ghcFlavor :: GhcFlavor
{ ghcFlavor :: GhcFlavor
, daBaseSha :: String
, daPatches :: String
, daFlavor :: String
, stackOptions :: StackOptions
} deriving (Show)

Expand All @@ -48,7 +50,7 @@ data StackOptions = StackOptions
, ghcOptions :: Maybe String -- If 'Just _', pass '--ghc-options="xxx"' to 'stack build' (for ghc verbose, try 'v3').
} deriving (Show)

data GhcFlavor = Ghc8101 | Ghc881 | Ghc882 | Ghc883 | DaGhc881 | GhcMaster String
data GhcFlavor = Ghc8101 | Ghc881 | Ghc882 | Ghc883 | Da | GhcMaster String
deriving (Eq, Show)

-- Last tested gitlab.haskell.org/ghc/ghc.git at
Expand All @@ -67,13 +69,13 @@ stackResolverOpt = \case
Just resolver -> "--resolver " ++ resolver
Nothing -> ""

ghcFlavorOpt :: GhcFlavor -> String
ghcFlavorOpt = \case
ghcFlavorOpt :: String -> GhcFlavor -> String
ghcFlavorOpt daFlavor = \case
Ghc8101 -> "--ghc-flavor ghc-8.10.1"
Ghc881 -> "--ghc-flavor ghc-8.8.1"
Ghc882 -> "--ghc-flavor ghc-8.8.2"
Ghc883 -> "--ghc-flavor ghc-8.8.3"
DaGhc881 -> "--ghc-flavor da-ghc-8.8.1"
Da -> "--ghc-flavor " <> daFlavor
GhcMaster _hash -> "--ghc-flavor ghc-master"
-- The git SHA1 hash is not passed to ghc-lib-gen at this time.

Expand Down Expand Up @@ -101,13 +103,28 @@ genVersionStr = \case

parseOptions :: Opts.Parser Options
parseOptions = Options
<$> Opts.switch
( Opts.long "upload-to-bintray"
<> Opts.help "If specified, will try uploading the sdists to Bintray, using credentials in BINTRAY_BASIC_AUTH env var.")
<*> Opts.option readFlavor
<$> Opts.option readFlavor
( Opts.long "ghc-flavor"
<> Opts.help "The ghc-flavor to test against"
)
<*> Opts.strOption
( Opts.long "da-base-sha"
<> Opts.help "DA flavour only. Base commit to use from the GHC repo."
<> Opts.showDefault
<> Opts.value "ghc-8.8.1-release"
)
<*> Opts.strOption
( Opts.long "da-patches"
<> Opts.help "DA flavour only. Commits to merge in from the DA GHC fork, referenced as 'upstream'. Space-separated."
<> Opts.showDefault
<> Opts.value "upstream/da-master-8.8.1 upstream/da-unit-ids-8.8.1"
)
<*> Opts.strOption
( Opts.long "da-gen-flavor"
<> Opts.help "DA flavor only. Flavor to pass on to ghc-lib-gen."
<> Opts.showDefault
<> Opts.value "da-ghc-8.8.1"
)
<*> parseStackOptions
where
readFlavor :: Opts.ReadM GhcFlavor
Expand All @@ -116,7 +133,7 @@ parseOptions = Options
"ghc-8.8.1" -> Right Ghc881
"ghc-8.8.2" -> Right Ghc882
"ghc-8.8.3" -> Right Ghc883
"da-ghc-8.8.1" -> Right DaGhc881
"da" -> Right Da
"ghc-master" -> Right (GhcMaster current)
hash -> Right (GhcMaster hash)

Expand All @@ -143,46 +160,14 @@ parseStackOptions = StackOptions
<> Opts.help "If specified, pass '--ghc-options=\"xxx\"' to stack"
))

bintrayUpload :: String -> IO ()
bintrayUpload version = do
credentials <- Env.lookupEnv "BINTRAY_BASIC_AUTH"
case credentials of
Nothing ->
Exit.die $ unlines [
"Error: Cannot upload without BINTRAY_BASIC_AUTH.",
"To set the environment variable, run:",
" BINTRAY_BASIC_AUTH=<creds> ./CI.hs --upload-to-bintray",
"where <creds> should be of the form:",
" fname.lname@digitalassetsdk:0123456789abcdef0123456789abcdef01234567",
"You can find your API key (the part after the colon) at:",
" https://bintray.com/profile/edit",
"after logging in. (The username is also displayed on that page.)"]
Just creds -> do
cmd $ concat [
"curl -T ./ghc-lib-parser-", version, ".tar.gz",
" -u", creds,
" https://api.bintray.com/content/digitalassetsdk/ghc-lib/da-ghc-lib/", version, "/ghc-lib-parser-", version, ".tar.gz"]
cmd $ concat [
"curl -T ./ghc-lib-", version, ".tar.gz",
" -u", creds,
" https://api.bintray.com/content/digitalassetsdk/ghc-lib/da-ghc-lib/", version, "/ghc-lib-", version, ".tar.gz"]
cmd $ concat [
"curl -X POST",
" -u", creds,
" https://api.bintray.com/content/digitalassetsdk/ghc-lib/da-ghc-lib/", version, "/publish"]
where
cmd :: String -> IO ()
cmd x = do
let c = replace creds "***:***" x
putStrLn $ "\n\n# Running: " ++ c
hFlush stdout
(t, _) <- duration $ callCommand x
putStrLn $ "# Completed in " ++ showDuration t ++ ": " ++ c ++ "\n"
hFlush stdout

buildDists :: GhcFlavor -> StackOptions -> IO String
buildDists ghcFlavor
StackOptions {stackYaml, resolver, verbosity, cabalVerbose, ghcOptions} =
buildDists :: GhcFlavor -> StackOptions -> String -> String -> String -> IO String
buildDists
ghcFlavor
StackOptions {stackYaml, resolver, verbosity, cabalVerbose, ghcOptions}
daBaseSha
daPatches
daFlavor
=
do
let stackConfig = fromMaybe "stack.yaml" stackYaml

Expand Down Expand Up @@ -210,12 +195,12 @@ buildDists ghcFlavor
Ghc881 -> cmd "cd ghc && git fetch --tags && git checkout ghc-8.8.1-release"
Ghc882 -> cmd "cd ghc && git fetch --tags && git checkout ghc-8.8.2-release"
Ghc883 -> cmd "cd ghc && git fetch --tags && git checkout ghc-8.8.3-release"
DaGhc881 -> do
cmd "cd ghc && git fetch --tags && git checkout ghc-8.8.1-release"
Da -> do
cmd $ "cd ghc && git fetch --tags && git checkout " <> daBaseSha
-- Apply Digital Asset extensions.
cmd "cd ghc && git remote add upstream https://github.com/digital-asset/ghc.git"
cmd "cd ghc && git fetch upstream"
cmd "cd ghc && git -c \"user.name=Cookie Monster\" -c \"user.email=cookie.monster@seasame-street.com\" merge --no-edit upstream/da-master-8.8.1 upstream/da-unit-ids-8.8.1"
cmd $ "cd ghc && git -c user.name='Cookie Monster' -c user.email=cookie.monster@seasame-street.com merge --no-edit " <> daPatches
GhcMaster hash -> cmd $ "cd ghc && git checkout " ++ hash
cmd "cd ghc && git submodule update --init --recursive"

Expand Down Expand Up @@ -249,7 +234,7 @@ buildDists ghcFlavor
_ -> pure ()

-- Feedback on the compiler used for ghc-lib-gen.
stack $ "exec -- ghc-lib-gen ghc --ghc-lib-parser " ++ ghcFlavorOpt ghcFlavor
stack $ "exec -- ghc-lib-gen ghc --ghc-lib-parser " ++ ghcFlavorOpt daFlavor ghcFlavor
patchVersion version "ghc/ghc-lib-parser.cabal"
mkTarball pkg_ghclib_parser
renameDirectory pkg_ghclib_parser "ghc-lib-parser"
Expand All @@ -260,7 +245,7 @@ buildDists ghcFlavor
cmd "cd ghc && git checkout ."
appendFile "ghc/hadrian/stack.yaml" $ unlines ["ghc-options:"," \"$everything\": -O0 -j"]
-- Feedback on the compiler used for ghc-lib-gen.
stack $ "exec -- ghc-lib-gen ghc --ghc-lib " ++ ghcFlavorOpt ghcFlavor
stack $ "exec -- ghc-lib-gen ghc --ghc-lib " ++ ghcFlavorOpt daFlavor ghcFlavor
patchVersion version "ghc/ghc-lib.cabal"
patchConstraint version "ghc/ghc-lib.cabal"
mkTarball pkg_ghclib
Expand Down Expand Up @@ -291,7 +276,7 @@ buildDists ghcFlavor
-- explanation)
unlines ["extra-deps: [transformers-0.5.6.2]"]
#endif
DaGhc881 ->
Da ->
unlines ["flags: {mini-compile: {daml-unit-ids: true}}"]
_ -> ""

Expand Down Expand Up @@ -330,7 +315,7 @@ buildDists ghcFlavor
#endif

-- Something like, "8.8.1.20190828".
tag -- The return value of type 'IO string'.
tag -- The return value of type 'IO string'.

where
stack :: String -> IO ()
Expand Down

0 comments on commit 9529115

Please sign in to comment.