Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more flexible da flavour #215

Merged
merged 5 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 48 additions & 61 deletions CI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Data.List.Extra
import Data.Time.Clock
import Data.Time.Calendar
import Data.Semigroup ((<>))
import qualified Data.List
import qualified Options.Applicative as Opts
import qualified System.Environment as Env
import qualified System.Exit as Exit
Expand All @@ -30,13 +31,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, daMergeBaseSha, daPatches, daFlavor, stackOptions } <- Opts.execParser opts
garyverhaegen-da marked this conversation as resolved.
Show resolved Hide resolved
version <- buildDists ghcFlavor stackOptions daMergeBaseSha daPatches daFlavor
putStrLn version

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

Expand All @@ -48,7 +51,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I'd like to see the DA specific parameters on the Da ctor as we do for the GhcMaster ctor. That String you see there is the commit SHA for GHC in the case of flavor GhcMaster XXX. Better we have one way of doing things so I'd rather see this mechanism extended if possible.

deriving (Eq, Show)

-- Last tested gitlab.haskell.org/ghc/ghc.git at
Expand All @@ -67,13 +70,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 +104,29 @@ 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-merge-base-sha"
<> Opts.help "DA flavour only. Base commit to use from the GHC repo."
<> Opts.showDefault
<> Opts.value "ghc-8.8.1-release"
garyverhaegen-da marked this conversation as resolved.
Show resolved Hide resolved
)
<*> (Opts.some
(Opts.strOption
( Opts.long "da-patch"
<> Opts.help "DA flavour only. Commits to merge in from the DA GHC fork, referenced as 'upstream'. Can be specified multiple times. If no patch is specified, default will be equivalent to `--da-patch upstream/da-master-8.8.1 --da-patch upstream/da-unit-ids-8.8.1`. Specifying any patch will overwrite the default (i.e. replace, not add)."
)
)
Opts.<|> pure ["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 +135,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 +162,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}
daMergeBaseSha
daPatches
daFlavor
=
do
let stackConfig = fromMaybe "stack.yaml" stackYaml

Expand Down Expand Up @@ -210,12 +197,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 " <> daMergeBaseSha
-- 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 " <> Data.List.intercalate " " daPatches
GhcMaster hash -> cmd $ "cd ghc && git checkout " ++ hash
cmd "cd ghc && git submodule update --init --recursive"

Expand Down Expand Up @@ -249,7 +236,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 +247,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 +278,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 +317,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
6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ strategy:
# +---------+-----------------+------------+
linux-da-ghc-8.8.1-8.8.1:
image: "Ubuntu 16.04"
ghc-flavor: "da-ghc-8.8.1"
ghc-flavor: "da"
resolver: "nightly-2019-09-26"
stack-yaml: "stack.yaml"
windows-da-ghc-8.8.1-8.8.1:
image: "vs2017-win2016"
ghc-flavor: "da-ghc-8.8.1"
ghc-flavor: "da"
resolver: "nightly-2019-09-26"
stack-yaml: "stack.yaml"
mac-da-ghc-8.8.1-8.8.1:
image: "macOS-10.14"
ghc-flavor: "da-ghc-8.8.1"
ghc-flavor: "da"
resolver: "nightly-2019-09-26"
stack-yaml: "stack.yaml"

Expand Down