Commit 70196d50 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Fix for intra-package build-tools dependencies

parent 7d904e9b
......@@ -64,7 +64,7 @@ import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule
import Distribution.Package
( Package(..), PackageName(..), PackageIdentifier(..)
, thisPackageVersion )
, Dependency(..), thisPackageVersion )
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor, PackageDB(..) )
import Distribution.PackageDescription
......@@ -78,11 +78,13 @@ import Distribution.Simple.Setup
import Distribution.Simple.PreProcess
( preprocessComponent, PPSuffixHandler )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(compiler, buildDir, withPackageDB)
( LocalBuildInfo(compiler, buildDir, withPackageDB, withPrograms)
, Component(..), ComponentLocalBuildInfo(..), withComponentsLBI
, inplacePackageId )
import Distribution.Simple.Program.Types
import Distribution.Simple.Program.Db
import Distribution.Simple.BuildPaths
( autogenModulesDir, autogenModuleName, cppHeaderName )
( autogenModulesDir, autogenModuleName, cppHeaderName, exeExtension )
import Distribution.Simple.Register
( registerPackage, inplaceInstalledPackageInfo )
import Distribution.Simple.Test ( stubFilePath, stubName )
......@@ -97,6 +99,8 @@ import Distribution.Text
import Data.Maybe
( maybeToList )
import Data.List
( intersect )
import Control.Monad
( unless )
import System.FilePath
......@@ -120,15 +124,16 @@ build pkg_descr lbi flags suffixes = do
internalPackageDB <- createInternalPackageDB distPref
let pre c = preprocessComponent pkg_descr c lbi False verbosity suffixes
lbi' = lbi {withPackageDB = withPackageDB lbi ++ [internalPackageDB]}
-- Use the internal package DB for the exes.
withComponentsLBI pkg_descr lbi $ \comp clbi -> do
pre comp
let pre c lbi' = preprocessComponent pkg_descr c lbi' False verbosity suffixes
withComponentsLBI pkg_descr lbi $ \comp clbi ->
case comp of
CLib lib -> do
let bi = libBuildInfo lib
progs' = addInternalBuildTools pkg_descr lbi bi (withPrograms lbi)
lbi' = lbi { withPrograms = progs' }
pre comp lbi'
info verbosity "Building library..."
buildLib verbosity pkg_descr lbi lib clbi
buildLib verbosity pkg_descr lbi' lib clbi
-- Register the library in-place, so exes can depend
-- on internally defined libraries.
......@@ -144,25 +149,40 @@ build pkg_descr lbi flags suffixes = do
(withPackageDB lbi ++ [internalPackageDB])
CExe exe -> do
let bi = buildInfo exe
progs' = addInternalBuildTools pkg_descr lbi bi (withPrograms lbi)
lbi' = lbi {
withPrograms = progs',
withPackageDB = withPackageDB lbi ++ [internalPackageDB]
}
pre comp lbi'
info verbosity $ "Building executable " ++ exeName exe ++ "..."
buildExe verbosity pkg_descr lbi' exe clbi
CTest test -> do
case testInterface test of
TestSuiteExeV10 _ f -> do
let exe = Executable
let bi = testBuildInfo test
exe = Executable
{ exeName = testName test
, modulePath = f
, buildInfo = testBuildInfo test
, buildInfo = bi
}
progs' = addInternalBuildTools pkg_descr lbi bi (withPrograms lbi)
lbi' = lbi {
withPrograms = progs',
withPackageDB = withPackageDB lbi ++ [internalPackageDB]
}
pre comp lbi'
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildExe verbosity pkg_descr lbi' exe clbi
TestSuiteLibV09 _ m -> do
pwd <- getCurrentDirectory
let lib = Library
let bi = testBuildInfo test
lib = Library
{ exposedModules = [ m ]
, libExposed = True
, libBuildInfo = testBuildInfo test
, libBuildInfo = bi
}
pkg = pkg_descr
{ package = (package pkg_descr)
......@@ -197,6 +217,13 @@ build pkg_descr lbi flags suffixes = do
: (filter (\(_, x) -> let PackageName name = pkgName x in name == "Cabal" || name == "base")
$ componentPackageDeps clbi)
}
progs' = addInternalBuildTools pkg_descr lbi bi (withPrograms lbi)
lbi' = lbi {
withPrograms = progs',
withPackageDB = withPackageDB lbi ++ [internalPackageDB]
}
pre comp lbi'
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildLib verbosity pkg lbi' lib clbi
registerPackage verbosity ipi pkg lbi' True $ withPackageDB lbi'
......@@ -213,6 +240,22 @@ createInternalPackageDB distPref = do
writeFile dbFile "[]"
return packageDB
addInternalBuildTools :: PackageDescription -> LocalBuildInfo -> BuildInfo
-> ProgramDb -> ProgramDb
addInternalBuildTools pkg lbi bi progs =
foldr updateProgram progs internalBuildTools
where
internalBuildTools =
[ simpleConfiguredProgram toolName (FoundOnSystem toolLocation)
| toolName <- toolNames
, let toolLocation = buildDir lbi </> toolName </> toolName <.> exeExtension ]
toolNames = intersect buildToolNames internalExeNames
internalExeNames = map exeName (executables pkg)
buildToolNames = map buildToolName (buildTools bi)
where
buildToolName (Dependency (PackageName name) _ ) = name
-- TODO: build separate libs in separate dirs so that we can build
-- multiple libs, e.g. for 'LibTest' library-style testsuites
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
......
......@@ -91,7 +91,7 @@ import Distribution.Simple.Hpc ( enableCoverage )
import Distribution.Simple.Program
( Program(..), ProgramLocation(..), ConfiguredProgram(..)
, ProgramConfiguration, defaultProgramConfiguration
, configureAllKnownPrograms, knownPrograms, lookupKnownProgram, addKnownProgram
, configureAllKnownPrograms, knownPrograms, lookupKnownProgram
, userSpecifyArgss, userSpecifyPaths
, requireProgram, requireProgramVersion
, pkgConfigProgram, gccProgram, rawSystemProgramStdoutConf )
......@@ -429,21 +429,26 @@ configure (pkg_descr0, pbi) cfg
++ "supported by " ++ display (compilerId comp) ++ ": "
++ intercalate ", " (map display exts)
-- configured known/required programs & build tools
let requiredBuildTools = concatMap buildTools (allBuildInfo pkg_descr)
-- add all exes built by this package ("internal exes") to the program
-- conf; this makes the namespace of build-tools include intrapackage
-- references to executables
let programsConfig'' = foldr (addInternalExe buildDir') programsConfig'
(executables pkg_descr)
programsConfig''' <-
configureAllKnownPrograms (lessVerbose verbosity) programsConfig''
-- configured known/required programs & external build tools
-- exclude build-tool deps on "internal" exes in the same package
let requiredBuildTools =
[ buildTool
| let exeNames = map exeName (executables pkg_descr)
, bi <- allBuildInfo pkg_descr
, buildTool@(Dependency (PackageName toolName) reqVer) <- buildTools bi
, let isInternal =
toolName `elem` exeNames
-- we assume all internal build-tools are
-- versioned with the package:
&& packageVersion pkg_descr `withinRange` reqVer
, not isInternal ]
programsConfig'' <-
configureAllKnownPrograms (lessVerbose verbosity) programsConfig'
>>= configureRequiredPrograms verbosity requiredBuildTools
(pkg_descr', programsConfig'''') <-
configurePkgconfigPackages verbosity pkg_descr programsConfig'''
(pkg_descr', programsConfig''') <-
configurePkgconfigPackages verbosity pkg_descr programsConfig''
split_objs <-
if not (fromFlag $ configSplitObjs cfg)
......@@ -529,7 +534,7 @@ configure (pkg_descr0, pbi) cfg
installedPkgs = packageDependsIndex,
pkgDescrFile = Nothing,
localPkgDescr = pkg_descr',
withPrograms = programsConfig'''',
withPrograms = programsConfig''',
withVanillaLib = fromFlag $ configVanillaLib cfg,
withProfLib = fromFlag $ configProfLib cfg,
withSharedLib = fromFlag $ configSharedLib cfg,
......@@ -570,20 +575,11 @@ configure (pkg_descr0, pbi) cfg
dirinfo "Documentation" (docdir dirs) (docdir relative)
sequence_ [ reportProgram verbosity prog configuredProg
| (prog, configuredProg) <- knownPrograms programsConfig'''' ]
| (prog, configuredProg) <- knownPrograms programsConfig''' ]
return lbi
where
addInternalExe bd exe =
let nm = exeName exe in
addKnownProgram Program {
programName = nm,
programFindLocation = \_ -> return $ Just $ bd </> nm </> nm,
programFindVersion = \_ _ -> return Nothing,
programPostConf = \_ _ -> return []
}
addExtraIncludeLibDirs pkg_descr =
let extraBi = mempty { extraLibDirs = configExtraLibDirs cfg
, PD.includeDirs = configExtraIncludeDirs cfg}
......
......@@ -17,7 +17,6 @@
module Distribution.Simple.Program.Types (
-- * Program and functions for constructing them
Program(..),
internalProgram,
simpleProgram,
-- * Configured program and related functions
......@@ -25,19 +24,21 @@ module Distribution.Simple.Program.Types (
programPath,
ProgArg,
ProgramLocation(..),
simpleConfiguredProgram,
) where
import Data.List (nub)
import System.FilePath ((</>))
import Distribution.Simple.Utils
( findProgramLocation, findFirstFile )
( findProgramLocation )
import Distribution.Version
( Version )
import Distribution.Verbosity
( Verbosity )
-- | Represents a program which can be configured.
--
-- Note: rather than constructing this directly, start with 'simpleProgram' and
-- override any extra fields.
--
data Program = Program {
-- | The simple name of the program, eg. ghc
programName :: String,
......@@ -59,6 +60,12 @@ data Program = Program {
type ProgArg = String
-- | Represents a program which has been configured and is thus ready to be run.
--
-- These are usually made by configuring a 'Program', but if you have to
-- construct one directly then start with 'simpleConfiguredProgram' and
-- override any extra fields.
--
data ConfiguredProgram = ConfiguredProgram {
-- | Just the name again
programId :: String,
......@@ -87,7 +94,7 @@ data ProgramLocation
-- ^The user gave the path to this program,
-- eg. --ghc-path=\/usr\/bin\/ghc-6.6
| FoundOnSystem { locationPath :: FilePath }
-- ^The location of the program, as located by searching PATH.
-- ^The program was found automatically.
deriving (Read, Show, Eq)
-- | The full path of a configured program.
......@@ -109,14 +116,15 @@ simpleProgram name = Program {
programPostConf = \_ _ -> return []
}
-- | Make a simple 'internal' program; that is, one that was built as an
-- executable already and is expected to be found in the build directory
internalProgram :: [FilePath] -> String -> Program
internalProgram paths name = Program {
programName = name,
programFindLocation = \_v ->
findFirstFile id [ path </> name | path <- nub paths ],
programFindVersion = \_ _ -> return Nothing,
programPostConf = \_ _ -> return []
-- | Make a simple 'ConfiguredProgram'.
--
-- > simpleConfiguredProgram "foo" (FoundOnSystem path)
--
simpleConfiguredProgram :: String -> ProgramLocation -> ConfiguredProgram
simpleConfiguredProgram name loc = ConfiguredProgram {
programId = name,
programVersion = Nothing,
programDefaultArgs = [],
programOverrideArgs = [],
programLocation = loc
}
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