Unverified Commit 9dd7ad2a authored by Andrey Mokhov's avatar Andrey Mokhov Committed by GitHub

Fix dependencies (#477)

See #464

* Drop non-source dependencies during compilation

* Drop duplicated dependencies on package configuration

* Compute transitive closure of context dependencies

* Don't depend on a temporary file
parent 49718439
...@@ -22,8 +22,6 @@ compilePackage rs context@Context {..} = do ...@@ -22,8 +22,6 @@ compilePackage rs context@Context {..} = do
path <- buildPath context path <- buildPath context
(src, deps) <- lookupDependencies (path -/- ".dependencies") obj (src, deps) <- lookupDependencies (path -/- ".dependencies") obj
need $ src : deps need $ src : deps
when (isLibrary package) $ need =<< return <$> pkgConfFile context
needLibrary =<< contextDependencies context
buildWithResources rs $ target context (Ghc CompileHs stage) [src] [obj] buildWithResources rs $ target context (Ghc CompileHs stage) [src] [obj]
priority 2.0 $ do priority 2.0 $ do
......
...@@ -19,11 +19,11 @@ buildPackageDependencies rs context@Context {..} = ...@@ -19,11 +19,11 @@ buildPackageDependencies rs context@Context {..} =
orderOnly =<< interpretInContext context generatedDependencies orderOnly =<< interpretInContext context generatedDependencies
let mk = deps <.> "mk" let mk = deps <.> "mk"
if null srcs if null srcs
then writeFileChanged mk "" then writeFile' mk ""
else buildWithResources rs $ else buildWithResources rs $
target context (Ghc FindHsDependencies stage) srcs [mk] target context (Ghc FindHsDependencies stage) srcs [mk]
removeFile $ mk <.> "bak" removeFile $ mk <.> "bak"
mkDeps <- readFile' mk mkDeps <- liftIO $ readFile mk
writeFileChanged deps . unlines writeFileChanged deps . unlines
. map (\(src, deps) -> unwords $ src : deps) . map (\(src, deps) -> unwords $ src : deps)
. map (bimap unifyPath (map unifyPath)) . map (bimap unifyPath (map unifyPath))
......
...@@ -87,10 +87,10 @@ haddockGhcArgs = mconcat [ commonGhcArgs, getPkgDataList HsArgs ] ...@@ -87,10 +87,10 @@ haddockGhcArgs = mconcat [ commonGhcArgs, getPkgDataList HsArgs ]
-- Used in ghcBuilderArgs, ghcCBuilderArgs, ghcMBuilderArgs and haddockGhcArgs. -- Used in ghcBuilderArgs, ghcCBuilderArgs, ghcMBuilderArgs and haddockGhcArgs.
commonGhcArgs :: Args commonGhcArgs :: Args
commonGhcArgs = do commonGhcArgs = do
way <- getWay way <- getWay
path <- getBuildPath path <- getBuildPath
pkg <- getPackage pkg <- getPackage
when (isLibrary pkg) $ do when (pkg == rts) $ do
context <- getContext context <- getContext
conf <- expr $ pkgConfFile context conf <- expr $ pkgConfFile context
expr $ need [conf] expr $ need [conf]
......
...@@ -8,10 +8,11 @@ import Utilities ...@@ -8,10 +8,11 @@ import Utilities
ghcCabalPackageArgs :: Args ghcCabalPackageArgs :: Args
ghcCabalPackageArgs = stage0 ? package ghcCabal ? builder Ghc ? do ghcCabalPackageArgs = stage0 ? package ghcCabal ? builder Ghc ? do
cabalDeps <- expr $ stage1Dependencies cabal cabalDeps <- expr $ stage1Dependencies cabal
let bootDeps = cabalDeps \\ [integerGmp, integerSimple, mtl, parsec, text]
cabalVersion <- expr $ pkgVersion (unsafePkgCabalFile cabal) -- TODO: improve cabalVersion <- expr $ pkgVersion (unsafePkgCabalFile cabal) -- TODO: improve
mconcat mconcat
[ pure [ "-package " ++ pkgName pkg | pkg <- cabalDeps \\ [parsec, mtl] ] [ pure [ "-package " ++ pkgName pkg | pkg <- bootDeps ]
, arg "--make" , arg "--make"
, arg "-j" , arg "-j"
, pure ["-Wall", "-fno-warn-unused-imports", "-fno-warn-warnings-deprecations"] , pure ["-Wall", "-fno-warn-unused-imports", "-fno-warn-warnings-deprecations"]
......
...@@ -24,21 +24,29 @@ buildWithResources rs target = H.buildWithResources rs target getArgs ...@@ -24,21 +24,29 @@ buildWithResources rs target = H.buildWithResources rs target getArgs
buildWithCmdOptions :: [CmdOption] -> Target -> Action () buildWithCmdOptions :: [CmdOption] -> Target -> Action ()
buildWithCmdOptions opts target = H.buildWithCmdOptions opts target getArgs buildWithCmdOptions opts target = H.buildWithCmdOptions opts target getArgs
-- | Given a 'Context' this 'Action' look up the package dependencies and wrap -- TODO: Cache the computation.
-- | Given a 'Context' this 'Action' looks up the package dependencies and wraps
-- the results in appropriate contexts. The only subtlety here is that we never -- the results in appropriate contexts. The only subtlety here is that we never
-- depend on packages built in 'Stage2' or later, therefore the stage of the -- depend on packages built in 'Stage2' or later, therefore the stage of the
-- resulting dependencies is bounded from above at 'Stage1'. To compute package -- resulting dependencies is bounded from above at 'Stage1'. To compute package
-- dependencies we scan package @.cabal@ files, see 'pkgDependencies' defined -- dependencies we transitively scan @.cabal@ files using 'pkgDependencies'
-- in "Hadrian.Haskell.Cabal". -- defined in "Hadrian.Haskell.Cabal".
contextDependencies :: Context -> Action [Context] contextDependencies :: Context -> Action [Context]
contextDependencies Context {..} = case pkgCabalFile package of contextDependencies Context {..} = do
Nothing -> return [] -- Non-Cabal packages have no dependencies. depPkgs <- go [package]
Just cabalFile -> do return [ Context depStage pkg way | pkg <- depPkgs, pkg /= package ]
let depStage = min stage Stage1 where
depContext = \pkg -> Context depStage pkg way depStage = min stage Stage1
deps <- pkgDependencies cabalFile go pkgs = do
pkgs <- sort <$> stagePackages depStage deps <- concatMapM step pkgs
return . map depContext $ intersectOrd (compare . pkgName) pkgs deps let newPkgs = nubOrd $ sort (deps ++ pkgs)
if pkgs == newPkgs then return pkgs else go newPkgs
step pkg = case pkgCabalFile pkg of
Nothing -> return [] -- Non-Cabal packages have no dependencies.
Just cabalFile -> do
deps <- pkgDependencies cabalFile
active <- sort <$> stagePackages depStage
return $ intersectOrd (compare . pkgName) active deps
-- | Lookup dependencies of a 'Package' in the vanilla Stage1 context. -- | Lookup dependencies of a 'Package' in the vanilla Stage1 context.
stage1Dependencies :: Package -> Action [Package] stage1Dependencies :: Package -> Action [Package]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment