Zubin pushed to branch wip/hadrian-target at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • hadrian/src/Rules.hs
    ... ... @@ -10,6 +10,7 @@ import qualified Hadrian.Oracles.Path
    10 10
     import qualified Hadrian.Oracles.TextFile
    
    11 11
     import qualified Hadrian.Haskell.Hash
    
    12 12
     
    
    13
    +import BindistConfig
    
    13 14
     import Expression
    
    14 15
     import qualified Oracles.Flavour
    
    15 16
     import qualified Oracles.ModuleFiles
    
    ... ... @@ -32,17 +33,49 @@ import Settings.Program (programContext)
    32 33
     import Target
    
    33 34
     import UserSettings
    
    34 35
     
    
    35
    --- | This rule defines what the default build configuration is when no targets
    
    36
    --- are selected.
    
    36
    +-- | This rule calls 'need' on all top-level build targets that Hadrian builds
    
    37
    +-- by default, respecting the 'finalStage' flag.
    
    37 38
     topLevelTargets :: Rules ()
    
    38 39
     topLevelTargets = action $ do
    
    39
    -    let targets = ["binary-dist-dir"]
    
    40
    +    verbosity <- getVerbosity
    
    41
    +    forM_ [ Stage1, Stage2, Stage3] $ \stage -> do
    
    42
    +      when (verbosity >= Verbose) $ do
    
    43
    +        (libraries, programs) <- partition isLibrary <$> stagePackages stage
    
    44
    +        libNames <- mapM (name stage) libraries
    
    45
    +        pgmNames <- mapM (name stage) programs
    
    46
    +        let stageHeader t ps =
    
    47
    +              "| Building " ++ show stage ++ " "
    
    48
    +                            ++ t ++ ": " ++ intercalate ", " ps
    
    49
    +        putInfo . unlines $
    
    50
    +            [ stageHeader "libraries" libNames
    
    51
    +            , stageHeader "programs" pgmNames ]
    
    52
    +    let buildStages = [ s | s <- allStages, s < finalStage ]
    
    53
    +    targets <- concatForM buildStages $ \stage -> do
    
    54
    +        packages <- stagePackages stage
    
    55
    +        mapM (path stage) packages
    
    56
    +
    
    57
    +    -- For cross compilers, also build the target (stage 2) libraries.
    
    58
    +    cfg <- implicitBindistConfig
    
    59
    +    lib_targets <- if executable_stage cfg < finalStage
    
    60
    +        then map snd . fst <$> Rules.BinaryDist.bindistPackageTargets cfg
    
    61
    +        else return []
    
    40 62
     
    
    41 63
         -- Why we need wrappers: https://gitlab.haskell.org/ghc/ghc/issues/16534.
    
    42 64
         root <- buildRoot
    
    43 65
         let wrappers = [ root -/- ("ghc-" ++ stageString s) | s <- [Stage1, Stage2, Stage3]
    
    44 66
                                                             , s < finalStage ]
    
    45
    -    need (targets ++ wrappers)
    
    67
    +    need (targets ++ lib_targets ++ wrappers)
    
    68
    +  where
    
    69
    +    -- either the package database config file for libraries or
    
    70
    +    -- the programPath for programs. However this still does
    
    71
    +    -- not support multiple targets, where a cabal package has
    
    72
    +    -- a library /and/ a program.
    
    73
    +    path :: Stage -> Package -> Action FilePath
    
    74
    +    path stage pkg | isLibrary pkg = pkgConfFile (vanillaContext stage pkg)
    
    75
    +                   | otherwise     = programPath =<< programContext stage pkg
    
    76
    +    name :: Stage -> Package -> Action String
    
    77
    +    name stage pkg | isLibrary pkg = return (pkgName pkg)
    
    78
    +                   | otherwise     = programName (vanillaContext stage pkg)
    
    46 79
     
    
    47 80
     -- | Return the list of targets associated with a given 'Stage' and 'Package'.
    
    48 81
     packageTargets :: Stage -> Package -> Action [FilePath]
    

  • hadrian/src/Rules/BinaryDist.hs
    ... ... @@ -124,11 +124,8 @@ installTo relocatable prefix = do
    124 124
         runBuilderWithCmdOptions env (Make bindistFilesDir) ["install"] [] []
    
    125 125
     
    
    126 126
     
    
    127
    -buildBinDistDir :: FilePath -> BindistConfig -> Action ()
    
    128
    -buildBinDistDir root conf@BindistConfig{..} = do
    
    129
    -
    
    130
    -    verbosity <- getVerbosity
    
    131
    -    -- We 'need' all binaries and libraries
    
    127
    +bindistPackageTargets :: BindistConfig -> Action ([(Package, FilePath)], [(Package, FilePath)])
    
    128
    +bindistPackageTargets conf@BindistConfig{..} = do
    
    132 129
         lib_pkgs <- stagePackages library_stage
    
    133 130
         (lib_targets, _) <- partitionEithers <$> mapM (pkgTarget conf) lib_pkgs
    
    134 131
     
    
    ... ... @@ -137,6 +134,14 @@ buildBinDistDir root conf@BindistConfig{..} = do
    137 134
         let excluded_packages = [ genapply ]
    
    138 135
             bin_pkgs = filter (`notElem` excluded_packages) bin_pkgs_all
    
    139 136
         (_, bin_targets) <- partitionEithers <$> mapM (pkgTarget conf) bin_pkgs
    
    137
    +    return (lib_targets, bin_targets)
    
    138
    +
    
    139
    +buildBinDistDir :: FilePath -> BindistConfig -> Action ()
    
    140
    +buildBinDistDir root conf@BindistConfig{..} = do
    
    141
    +
    
    142
    +    verbosity <- getVerbosity
    
    143
    +    -- We 'need' all binaries and libraries
    
    144
    +    (lib_targets, bin_targets) <- bindistPackageTargets conf
    
    140 145
     
    
    141 146
         when (verbosity >= Verbose) $ do
    
    142 147
           let libNames = map (pkgName . fst) lib_targets