Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Improve naming convention for build directories: always use stageN.
Browse files Browse the repository at this point in the history
  • Loading branch information
snowleopard committed Dec 22, 2015
1 parent 3d90d06 commit 52ecf6c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 50 deletions.
18 changes: 2 additions & 16 deletions src/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,15 @@ xhtml = library "xhtml"
-- * build/ : contains compiled object code
-- * doc/ : produced by haddock
-- * package-data.mk : contains output of ghc-cabal applied to pkgCabal
-- TODO: simplify to just 'show stage'?
-- TODO: we divert from the previous convention for ghc-cabal and ghc-pkg,
-- which used to store stage 0 build results in 'dist' folder
-- On top of that, mkUserGuidePart used dist for stage 1 for some reason.
defaultTargetDirectory :: Stage -> Package -> FilePath
defaultTargetDirectory stage pkg
| pkg == compiler = "stage" ++ show (fromEnum stage + 1)
| pkg == ghc = "stage" ++ show (fromEnum stage + 1)
| stage == Stage0 = "dist-boot"
| otherwise = "dist-install"
defaultTargetDirectory stage _ = "stage" ++ show (fromEnum stage)

-- TODO: simplify
-- TODO: haddock and ghtTags should be built in stage2 only
-- | Returns a relative path to the program executable
defaultProgramPath :: Stage -> Package -> Maybe FilePath
defaultProgramPath stage pkg
| pkg == ghc = Just . inplaceProgram $ "ghc-stage" ++ show (fromEnum stage + 1)
| pkg == haddock = case stage of
Stage1 -> Just . inplaceProgram $ pkgName pkg
Stage2 -> Just . inplaceProgram $ pkgName pkg
_ -> Nothing
| pkg == ghcTags = case stage of
Stage1 -> Just . inplaceProgram $ pkgName pkg
| pkg == haddock || pkg == ghcTags = case stage of
Stage2 -> Just . inplaceProgram $ pkgName pkg
_ -> Nothing
| isProgram pkg = case stage of
Expand Down
3 changes: 1 addition & 2 deletions src/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ generateTargets = action $ do
return $ libTargets ++ programTargets
need targets

-- TODO: use stage 2 compiler for building stage 2 packages (instead of stage 1)
packageRules :: Rules ()
packageRules = do
resources <- resourceRules
forM_ [Stage0, Stage1] $ \stage ->
forM_ [Stage0 ..] $ \stage ->
forM_ knownPackages $ \pkg ->
buildPackage resources $ PartialTarget stage pkg
20 changes: 10 additions & 10 deletions src/Rules/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
, "Axes.c", "Dimensions.c", "Key.c", "PsFile.c"
, "Shade.c", "Utilities.c" ]
contents = unlines
[ "utils_hp2ps_dist-boot_PROGNAME = hp2ps"
, "utils_hp2ps_dist-boot_C_SRCS = " ++ unwords cSrcs
, "utils_hp2ps_dist-boot_INSTALL = YES"
, "utils_hp2ps_dist-boot_INSTALL_INPLACE = YES"
, "utils_hp2ps_dist-boot_DEP_EXTRA_LIBS = m"
, "utils_hp2ps_dist-boot_CC_OPTS = "
[ "utils_hp2ps_stage0_PROGNAME = hp2ps"
, "utils_hp2ps_stage0_C_SRCS = " ++ unwords cSrcs
, "utils_hp2ps_stage0_INSTALL = YES"
, "utils_hp2ps_stage0_INSTALL_INPLACE = YES"
, "utils_hp2ps_stage0_DEP_EXTRA_LIBS = m"
, "utils_hp2ps_stage0_CC_OPTS = "
++ unwords (map ("-I"++) ghcIncludeDirs) ]
writeFileChanged mk contents
putBuild $ "| Successfully generated '" ++ mk ++ "'."
Expand All @@ -65,10 +65,10 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
-- by running by running `ghcCabal`, because it has not yet been built.
when (pkg == ghcCabal && stage == Stage0) $ dataFile %> \mk -> do
let contents = unlines
[ "utils_ghc-cabal_dist-boot_PROGNAME = ghc-cabal"
, "utils_ghc-cabal_dist-boot_MODULES = Main"
, "utils_ghc-cabal_dist-boot_SYNOPSIS = Bootstrapped ghc-cabal utility."
, "utils_ghc-cabal_dist-boot_HS_SRC_DIRS = ." ]
[ "utils_ghc-cabal_stage0_PROGNAME = ghc-cabal"
, "utils_ghc-cabal_stage0_MODULES = Main"
, "utils_ghc-cabal_stage0_SYNOPSIS = Bootstrapped ghc-cabal utility."
, "utils_ghc-cabal_stage0_HS_SRC_DIRS = ." ]
writeFileChanged mk contents
putBuild $ "| Successfully generated '" ++ mk ++ "'."

Expand Down
18 changes: 10 additions & 8 deletions src/Rules/Program.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ buildProgram _ target @ (PartialTarget stage pkg) = do
++ [ buildPath -/- "Paths_hsc2hs.o" | pkg == hsc2hs ]
++ [ buildPath -/- "Paths_haddock.o" | pkg == haddock ]
objs = cObjs ++ hObjs
pkgs <- interpretPartial target getPackages
ways <- interpretPartial target getWays
depNames <- interpretPartial target $ getPkgDataList TransitiveDepNames
ghciFlag <- interpretPartial target $ getPkgData BuildGhciLib
let libStage = min stage Stage1 -- libraries are built only in Stage0/1
libTarget = PartialTarget libStage pkg
pkgs <- interpretPartial libTarget getPackages
ghciFlag <- interpretPartial libTarget $ getPkgData BuildGhciLib
let deps = matchPackageNames (sort pkgs) (sort depNames)
ghci = ghciFlag == "YES" && stage == Stage1
libs <- fmap concat . forM deps $ \dep -> do
let depTarget = PartialTarget stage dep
let depTarget = PartialTarget libStage dep
compId <- interpretPartial depTarget $ getPkgData ComponentId
libFiles <- fmap concat . forM ways $ \way -> do
libFile <- pkgLibraryFile stage dep compId way
lib0File <- pkgLibraryFile stage dep (compId ++ "-0") way
dll0 <- needDll0 stage dep
libFile <- pkgLibraryFile libStage dep compId way
lib0File <- pkgLibraryFile libStage dep (compId ++ "-0") way
dll0 <- needDll0 libStage dep
return $ [ libFile ] ++ [ lib0File | dll0 ]
return $ libFiles ++ [ pkgGhciLibraryFile stage dep compId | ghci ]
return $ libFiles ++ [ pkgGhciLibraryFile libStage dep compId | ghci ]
let binDeps = if pkg == ghcCabal && stage == Stage0
then [ pkgPath pkg -/- src <.> "hs" | src <- hSrcs ]
else objs
Expand All @@ -50,6 +52,6 @@ buildProgram _ target @ (PartialTarget stage pkg) = do
synopsis <- interpretPartial target $ getPkgData Synopsis
putSuccess $ renderBox
[ "Successfully built program '"
++ pkgName pkg ++ "' (stage " ++ show stage ++ ")."
++ pkgName pkg ++ "' (" ++ show stage ++ ")."
, "Executable: " ++ bin
, "Package synopsis: " ++ dropWhileEnd isPunctuation synopsis ++ "." ]
2 changes: 2 additions & 0 deletions src/Settings/Builders/Ghc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ includeGhcArgs = do
, arg $ "-I" ++ autogenPath
, append [ "-i" ++ pkgPath pkg -/- dir | dir <- srcDirs ]
, append [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
, (pkg == compiler || pkg == ghc) ?
arg ("-I" ++ pkgPath compiler -/- "stage" ++ show (fromEnum stage))
, not (pkg == hp2ps || pkg == ghcCabal && stage == Stage0) ?
append [ "-optP-include"
, "-optP" ++ autogenPath -/- "cabal_macros.h" ] ]
Expand Down
23 changes: 10 additions & 13 deletions src/Settings/Builders/GhcCabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ccArgs = validating ? ccWarnings
ccWarnings :: Args
ccWarnings = do
let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
mconcat [ arg "-Werror"
mconcat [ turnWarningsIntoErrors ? arg "-Werror"
, arg "-Wall"
, flag GccIsClang ? arg "-Wno-unknown-pragmas"
, gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
Expand All @@ -120,8 +120,8 @@ cppArgs = append $ map ("-I" ++) ghcIncludeDirs
-- TODO: move this somewhere
customPackageArgs :: Args
customPackageArgs = do
nextStage <- fmap succ getStage
rtsWays <- getRtsWays
stage <- getStage
rtsWays <- getRtsWays
mconcat
[ package integerGmp ?
mconcat [ windowsHost ? builder GhcCabal ?
Expand All @@ -137,8 +137,7 @@ customPackageArgs = do

, package compiler ?
builder GhcCabal ?
mconcat [ arg $ "--ghc-option=-DSTAGE=" ++ show nextStage
, arg $ "--flags=stage" ++ show nextStage
mconcat [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
, arg "--disable-library-for-ghci"
, anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
, flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
Expand All @@ -157,17 +156,15 @@ customPackageArgs = do
ghciWithDebugger ?
notStage0 ? arg "--ghc-option=-DDEBUGGER"
, ghcProfiled ?
notStage0 ? arg "--ghc-pkg-option=--force"
]
notStage0 ? arg "--ghc-pkg-option=--force" ]

, package ghc ?
builder GhcCabal ?
mconcat [ arg $ "--flags=stage" ++ show nextStage
, ghcWithInterpreter ?
notStage0 ? arg "--flags=ghci"
]
mconcat [ ghcWithInterpreter ?
notStage0 ? arg "--flags=ghci" ]

, package haddock ?
builder GhcCabal ? append ["--flag", "in-ghc-tree"]
]
builder GhcCabal ? append ["--flag", "in-ghc-tree"] ]

withBuilderKey :: Builder -> String
withBuilderKey b = case b of
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/Builders/HsCpp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ hsCppArgs = builder HsCpp ? do
mconcat [ append =<< getSettingList HsCppArgs
, arg "-P"
, cppArgs
, arg $ "-Icompiler/stage" ++ show (succ stage)
, arg $ "-Icompiler/stage" ++ show (fromEnum stage)
, arg "-x"
, arg "c"
, arg =<< getInput ]
2 changes: 2 additions & 0 deletions src/Settings/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ packagesStage1 = mconcat
, notM windowsHost ? append [iservBin]
, buildHaddock ? append [xhtml] ]

-- TODO: currently there is an unchecked assumption that we only build programs
-- in Stage2 and Stage3. Can we check this in compile time?
packagesStage2 :: Packages
packagesStage2 = mconcat
[ append [ghcTags]
Expand Down

0 comments on commit 52ecf6c

Please sign in to comment.