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

Commit

Permalink
Fix profiled GHC
Browse files Browse the repository at this point in the history
See #239
  • Loading branch information
snowleopard committed Jan 7, 2017
1 parent 8e7685c commit 76de227
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ topLevelTargets = do
docs <- interpretInContext context $ buildHaddock flavour
need $ libs ++ [ pkgHaddockFile context | docs && stage == Stage1 ]
else do -- otherwise build a program
need =<< maybeToList <$> programPath context
need =<< maybeToList <$> programPath (programContext stage pkg)

packageRules :: Rules ()
packageRules = do
Expand All @@ -61,21 +61,22 @@ packageRules = do
let readPackageDb = [(packageDb, 1)]
writePackageDb = [(packageDb, maxConcurrentReaders)]

-- TODO: not all build rules make sense for all stage/package combinations
let contexts = liftM3 Context allStages knownPackages allWays
vanillaContexts = liftM2 vanillaContext allStages knownPackages
programContexts = liftM2 programContext allStages knownPackages

forM_ contexts $ mconcat
[ Rules.Compile.compilePackage readPackageDb
, Rules.Library.buildPackageLibrary ]

forM_ programContexts $ Rules.Program.buildProgram readPackageDb

forM_ vanillaContexts $ mconcat
[ Rules.Data.buildPackageData
, Rules.Dependencies.buildPackageDependencies readPackageDb
, Rules.Documentation.buildPackageDocumentation
, Rules.Library.buildPackageGhciLibrary
, Rules.Generate.generatePackageCode
, Rules.Program.buildProgram readPackageDb
, Rules.Register.registerPackage writePackageDb ]

buildRules :: Rules ()
Expand Down
7 changes: 3 additions & 4 deletions src/Rules/Program.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ wrappers = [ (vanillaContext Stage0 ghc , ghcWrapper )
buildProgram :: [(Resource, Int)] -> Context -> Rules ()
buildProgram rs context@Context {..} = when (isProgram package) $ do
let installStage = do
latest <- latestBuildStage package -- isJust below is safe
latest <- latestBuildStage package -- fromJust below is safe
return $ if package == ghc then stage else fromJust latest

buildPath context -/- programName context <.> exe %>
Expand Down Expand Up @@ -68,15 +68,14 @@ buildWrapper context@Context {..} wrapper wrapperPath binPath = do
quote (pkgNameString package) ++ " (" ++ show stage ++ ")."

-- TODO: Get rid of the Paths_hsc2hs.o hack.
-- TODO: Do we need to consider other ways when building programs?
buildBinary :: [(Resource, Int)] -> Context -> FilePath -> Action ()
buildBinary rs context@Context {..} bin = do
binDeps <- if stage == Stage0 && package == ghcCabal
then hsSources context
else do
ways <- interpretInContext context getLibraryWays
deps <- contextDependencies context
needContext [ dep { way = w } | dep <- deps, w <- ways ]
ways <- interpretInContext context (getLibraryWays <> getRtsWays)
needContext $ deps ++ [ rtsContext { way = w } | w <- ways ]
let path = buildPath context
cObjs <- map (objectPath context) <$> pkgDataList (CSrcs path)
hsObjs <- hsObjects context
Expand Down
7 changes: 6 additions & 1 deletion src/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Settings (
getArgs, getPackages, getLibraryWays, getRtsWays, flavour, knownPackages,
findKnownPackage, getPkgData, getPkgDataList, isLibrary, getPackagePath,
getContextDirectory, getBuildPath, stagePackages, builderPath,
getBuilderPath, isSpecified, latestBuildStage, programPath
getBuilderPath, isSpecified, latestBuildStage, programPath, programContext
) where

import Base
Expand Down Expand Up @@ -62,6 +62,11 @@ flavour = fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
flavours = hadrianFlavours ++ userFlavours
flavourName = fromMaybe "default" cmdFlavour

programContext :: Stage -> Package -> Context
programContext stage pkg
| pkg == ghc && ghcProfiled flavour = Context stage pkg profiling
| otherwise = vanillaContext stage pkg

-- TODO: switch to Set Package as the order of packages should not matter?
-- Otherwise we have to keep remembering to sort packages from time to time.
knownPackages :: [Package]
Expand Down

0 comments on commit 76de227

Please sign in to comment.