From 5b5caaced60cb809bde281c40b5380c154e727e2 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 11 Jan 2016 15:58:10 -0800 Subject: [PATCH] Per-component cabal_macros.h (#1893) and install paths This commit is a number of refactorings that I needed to do while fixing bugs with internal libraries support. - With internal libraries, it becomes especially clear that cabal_macros.h and Paths_foo.hs need to be done per-component. It is done! This change breaks BC in an important way: the preprocessor interface now takes a ComponentLocalBuildInfo along with the BuildInfo and LocalBuildInfo. This means that if you implemented a custom preprocessor, or called 'preprocessComponent' in a custom Setup, you will have to make sure you pass the right ComponentLocalBuildInfo. Some sub-notes: - While I was mucking about cabal_macros.h, I updated it to have two new macros: CURRENT_COMPONENT_ID (an alias for CURRENT_PACKAGE_KEY, but using modern terminology) and LOCAL_COMPONENT_ID (which refers to the public library; we use this in Cabal's test suite but it's unclear what the general utility of this is. See the TODO.) - checkForeignDeps has a hack where we hardcode the cabal_macros.h of the main library. If we did the foreign dep check for every component individually that would be better, but I didn't want to roll it into this patch. - The other piece I needed for internal libraries was per-component install directories; otherwise, internal libraries clobber each other. absoluteInstallDirs now takes a ComponentId, which is used to determine what '$libname' expands to. Generally, InstallPaths must be computed per component, c.f. #2836. We're not TRULY per-component install paths, since some files are installed for the "per-package" InstallPaths (the one we computed for the library as a whole), but for libraries we have to compute InstallPaths for each one. - While doing this, ComponentLocalBuildInfo grew a new 'componentId' field for non-library things. This lets us treat InstallPaths expansion uniformly. Signed-off-by: Edward Z. Yang --- Cabal/Distribution/Simple/Build.hs | 76 +++++----- Cabal/Distribution/Simple/Build/Macros.hs | 51 +++---- .../Distribution/Simple/Build/PathsModule.hs | 10 +- Cabal/Distribution/Simple/BuildPaths.hs | 6 +- Cabal/Distribution/Simple/Configure.hs | 26 +++- Cabal/Distribution/Simple/GHC.hs | 2 +- Cabal/Distribution/Simple/GHC/Internal.hs | 8 +- Cabal/Distribution/Simple/Haddock.hs | 36 ++--- Cabal/Distribution/Simple/HaskellSuite.hs | 2 +- Cabal/Distribution/Simple/Install.hs | 136 ++++++++++-------- Cabal/Distribution/Simple/JHC.hs | 2 +- Cabal/Distribution/Simple/LHC.hs | 6 +- Cabal/Distribution/Simple/LocalBuildInfo.hs | 30 ++-- Cabal/Distribution/Simple/PreProcess.hs | 69 ++++----- Cabal/Distribution/Simple/Register.hs | 6 +- Cabal/Distribution/Simple/SrcDist.hs | 4 +- Cabal/Distribution/Simple/UHC.hs | 2 +- cabal-install/Setup.hs | 5 +- 18 files changed, 262 insertions(+), 215 deletions(-) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 2ebb6c11b49..bba103c3bcf 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -87,22 +87,22 @@ build pkg_descr lbi flags suffixes = do info verbosity $ "Component build order: " ++ intercalate ", " (map showComponentName componentsToBuild) - initialBuildSteps distPref pkg_descr lbi verbosity when (null targets) $ -- Only bother with this message if we're building the whole package setupMessage verbosity "Building" (packageId pkg_descr) internalPackageDB <- createInternalPackageDB verbosity lbi distPref - withComponentsInBuildOrder pkg_descr lbi componentsToBuild $ \comp clbi -> + withComponentsInBuildOrder pkg_descr lbi componentsToBuild $ \comp clbi -> do + initialBuildSteps distPref pkg_descr lbi clbi verbosity let bi = componentBuildInfo comp progs' = addInternalBuildTools pkg_descr lbi bi (withPrograms lbi) lbi' = lbi { withPrograms = progs', withPackageDB = withPackageDB lbi ++ [internalPackageDB] } - in buildComponent verbosity (buildNumJobs flags) pkg_descr - lbi' suffixes comp clbi distPref + buildComponent verbosity (buildNumJobs flags) pkg_descr + lbi' suffixes comp clbi distPref repl :: PackageDescription -- ^ Mostly information from the .cabal file @@ -127,8 +127,6 @@ repl pkg_descr lbi flags suffixes args = do ++ intercalate ", " [ showComponentName c | (c,_) <- componentsToBuild ] - initialBuildSteps distPref pkg_descr lbi verbosity - internalPackageDB <- createInternalPackageDB verbosity lbi distPref let lbiForComponent comp lbi' = @@ -140,17 +138,19 @@ repl pkg_descr lbi flags suffixes args = do -- build any dependent components sequence_ - [ let comp = getComponent pkg_descr cname - lbi' = lbiForComponent comp lbi - in buildComponent verbosity NoFlag - pkg_descr lbi' suffixes comp clbi distPref + [ do let comp = getComponent pkg_descr cname + lbi' = lbiForComponent comp lbi + initialBuildSteps distPref pkg_descr lbi clbi verbosity + buildComponent verbosity NoFlag + pkg_descr lbi' suffixes comp clbi distPref | (cname, clbi) <- init componentsToBuild ] -- REPL for target components let (cname, clbi) = componentForRepl comp = getComponent pkg_descr cname lbi' = lbiForComponent comp lbi - in replComponent verbosity pkg_descr lbi' suffixes comp clbi distPref + initialBuildSteps distPref pkg_descr lbi clbi verbosity + replComponent verbosity pkg_descr lbi' suffixes comp clbi distPref -- | Start an interpreter without loading any package files. @@ -173,7 +173,7 @@ buildComponent :: Verbosity -> IO () buildComponent verbosity numJobs pkg_descr lbi suffixes comp@(CLib lib) clbi distPref = do - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi info verbosity $ "Building library " ++ libName lib ++ "..." let libbi = libBuildInfo lib @@ -192,7 +192,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes buildComponent verbosity numJobs pkg_descr lbi suffixes comp@(CExe exe) clbi _ = do - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi info verbosity $ "Building executable " ++ exeName exe ++ "..." let ebi = buildInfo exe @@ -204,7 +204,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes comp@(CTest test@TestSuite { testInterface = TestSuiteExeV10{} }) clbi _distPref = do let exe = testSuiteExeV10AsExe test - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi info verbosity $ "Building test suite " ++ testName test ++ "..." let ebi = buildInfo exe @@ -224,7 +224,7 @@ buildComponent verbosity numJobs pkg_descr lbi0 suffixes pwd <- getCurrentDirectory let (pkg, lib, libClbi, lbi, ipi, exe, exeClbi) = testSuiteLibV09AsLibAndExe pkg_descr test clbi lbi0 distPref pwd - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi info verbosity $ "Building test suite " ++ testName test ++ "..." buildLib verbosity numJobs pkg lbi lib libClbi @@ -248,7 +248,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes comp@(CBench bm@Benchmark { benchmarkInterface = BenchmarkExeV10 {} }) clbi _ = do let (exe, exeClbi) = benchmarkExeV10asExe bm clbi - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi info verbosity $ "Building benchmark " ++ benchmarkName bm ++ "..." let ebi = buildInfo exe @@ -281,7 +281,7 @@ replComponent :: Verbosity -> IO () replComponent verbosity pkg_descr lbi suffixes comp@(CLib lib) clbi _ = do - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi let libbi = libBuildInfo lib lib' = lib { libBuildInfo = libbi { cSources = cSources libbi ++ extras } } @@ -289,7 +289,7 @@ replComponent verbosity pkg_descr lbi suffixes replComponent verbosity pkg_descr lbi suffixes comp@(CExe exe) clbi _ = do - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi let ebi = buildInfo exe exe' = exe { buildInfo = ebi { cSources = cSources ebi ++ extras } } @@ -300,7 +300,7 @@ replComponent verbosity pkg_descr lbi suffixes comp@(CTest test@TestSuite { testInterface = TestSuiteExeV10{} }) clbi _distPref = do let exe = testSuiteExeV10AsExe test - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi let ebi = buildInfo exe exe' = exe { buildInfo = ebi { cSources = cSources ebi ++ extras } } @@ -314,7 +314,7 @@ replComponent verbosity pkg_descr lbi0 suffixes pwd <- getCurrentDirectory let (pkg, lib, libClbi, lbi, _, _, _) = testSuiteLibV09AsLibAndExe pkg_descr test clbi lbi0 distPref pwd - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi let libbi = libBuildInfo lib lib' = lib { libBuildInfo = libbi { cSources = cSources libbi ++ extras } } @@ -331,7 +331,7 @@ replComponent verbosity pkg_descr lbi suffixes comp@(CBench bm@Benchmark { benchmarkInterface = BenchmarkExeV10 {} }) clbi _ = do let (exe, exeClbi) = benchmarkExeV10asExe bm clbi - preprocessComponent pkg_descr comp lbi False verbosity suffixes + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes extras <- preprocessExtras comp lbi let ebi = buildInfo exe exe' = exe { buildInfo = ebi { cSources = cSources ebi ++ extras } } @@ -384,21 +384,13 @@ testSuiteLibV09AsLibAndExe pkg_descr libExposed = True, libBuildInfo = bi } - -- NB: temporary hack; I have a refactor which solves this - cid = computeComponentId NoFlag - (package pkg_descr) - (CTestName (testName test)) - (map ((\(SimpleUnitId cid0) -> cid0) . fst) - (componentPackageDeps clbi)) - (flagAssignment lbi) - uid = SimpleUnitId cid (compat_name, compat_key) = computeCompatPackageKey (compiler lbi) (package pkg_descr) - (CTestName (testName test)) uid + (CTestName (testName test)) (componentUnitId clbi) libClbi = LibComponentLocalBuildInfo { componentPackageDeps = componentPackageDeps clbi , componentPackageRenaming = componentPackageRenaming clbi - , componentUnitId = uid + , componentUnitId = componentUnitId clbi , componentCompatPackageName = compat_name , componentCompatPackageKey = compat_key , componentExposedModules = [IPI.ExposedModule m Nothing] @@ -427,6 +419,9 @@ testSuiteLibV09AsLibAndExe pkg_descr -- | The stub executable needs a new 'ComponentLocalBuildInfo' -- that exposes the relevant test suite library. exeClbi = ExeComponentLocalBuildInfo { + -- TODO: this is a hack, but as long as this is unique + -- (doesn't clobber something) we won't run into trouble + componentUnitId = mkUnitId (stubName test), componentPackageDeps = (IPI.installedUnitId ipi, packageId ipi) : (filter (\(_, x) -> let PackageName name = pkgName x @@ -450,6 +445,7 @@ benchmarkExeV10asExe bm@Benchmark { benchmarkInterface = BenchmarkExeV10 _ f } buildInfo = benchmarkBuildInfo bm } exeClbi = ExeComponentLocalBuildInfo { + componentUnitId = componentUnitId clbi, componentPackageDeps = componentPackageDeps clbi, componentPackageRenaming = componentPackageRenaming clbi } @@ -534,9 +530,10 @@ replExe verbosity pkg_descr lbi exe clbi = initialBuildSteps :: FilePath -- ^"dist" prefix -> PackageDescription -- ^mostly information from the .cabal file -> LocalBuildInfo -- ^Configuration information + -> ComponentLocalBuildInfo -> Verbosity -- ^The verbosity to use -> IO () -initialBuildSteps _distPref pkg_descr lbi verbosity = do +initialBuildSteps _distPref pkg_descr lbi clbi verbosity = do -- check that there's something to build unless (not . null $ allBuildInfo pkg_descr) $ do let name = display (packageId pkg_descr) @@ -545,23 +542,24 @@ initialBuildSteps _distPref pkg_descr lbi verbosity = do createDirectoryIfMissingVerbose verbosity True (buildDir lbi) - writeAutogenFiles verbosity pkg_descr lbi + writeAutogenFiles verbosity pkg_descr lbi clbi -- | Generate and write out the Paths_.hs and cabal_macros.h files -- writeAutogenFiles :: Verbosity -> PackageDescription -> LocalBuildInfo + -> ComponentLocalBuildInfo -> IO () -writeAutogenFiles verbosity pkg lbi = do - createDirectoryIfMissingVerbose verbosity True (autogenModulesDir lbi) +writeAutogenFiles verbosity pkg lbi clbi = do + createDirectoryIfMissingVerbose verbosity True (autogenModulesDir lbi clbi) - let pathsModulePath = autogenModulesDir lbi + let pathsModulePath = autogenModulesDir lbi clbi ModuleName.toFilePath (autogenModuleName pkg) <.> "hs" - rewriteFile pathsModulePath (Build.PathsModule.generate pkg lbi) + rewriteFile pathsModulePath (Build.PathsModule.generate pkg lbi clbi) - let cppHeaderPath = autogenModulesDir lbi cppHeaderName - rewriteFile cppHeaderPath (Build.Macros.generate pkg lbi) + let cppHeaderPath = autogenModulesDir lbi clbi cppHeaderName + rewriteFile cppHeaderPath (Build.Macros.generate pkg lbi clbi) -- | Check that the given build targets are valid in the current context. -- diff --git a/Cabal/Distribution/Simple/Build/Macros.hs b/Cabal/Distribution/Simple/Build/Macros.hs index 528c394b614..9ca6a406938 100644 --- a/Cabal/Distribution/Simple/Build/Macros.hs +++ b/Cabal/Distribution/Simple/Build/Macros.hs @@ -22,23 +22,17 @@ module Distribution.Simple.Build.Macros ( generatePackageVersionMacros, ) where -import Data.Maybe - ( isJust ) import Distribution.Package - ( PackageIdentifier(PackageIdentifier) ) import Distribution.Version - ( Version(versionBranch) ) import Distribution.PackageDescription - ( PackageDescription ( package ) ) +import Distribution.Simple.Compiler import Distribution.Simple.LocalBuildInfo - ( LocalBuildInfo(withPrograms), externalPackageDeps - , localComponentId, localCompatPackageKey ) import Distribution.Simple.Program.Db - ( configuredPrograms ) import Distribution.Simple.Program.Types - ( ConfiguredProgram(programId, programVersion) ) import Distribution.Text - ( display ) + +import Data.Maybe + ( isJust ) -- ------------------------------------------------------------ -- * Generate cabal_macros.h @@ -46,13 +40,13 @@ import Distribution.Text -- | The contents of the @cabal_macros.h@ for the given configured package. -- -generate :: PackageDescription -> LocalBuildInfo -> String -generate pkg_descr lbi = +generate :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> String +generate pkg_descr lbi clbi = "/* DO NOT EDIT: This file is automatically generated by Cabal */\n\n" ++ generatePackageVersionMacros - (package pkg_descr : map snd (externalPackageDeps lbi)) ++ + (package pkg_descr : map snd (componentPackageDeps clbi)) ++ generateToolVersionMacros (configuredPrograms . withPrograms $ lbi) ++ - generateComponentIdMacro lbi + generateComponentIdMacro lbi clbi -- | Helper function that generates just the @VERSION_pkg@ and @MIN_VERSION_pkg@ -- macros for a list of package ids (usually used with the specific deps of @@ -84,10 +78,10 @@ generateToolVersionMacros progs = concat -- 'generateToolVersionMacros'. -- generateMacros :: String -> String -> Version -> String -generateMacros prefix name version = +generateMacros macro_prefix name version = concat - ["#define ", prefix, "VERSION_",name," ",show (display version),"\n" - ,"#define MIN_", prefix, "VERSION_",name,"(major1,major2,minor) (\\\n" + ["#define ", macro_prefix, "VERSION_",name," ",show (display version),"\n" + ,"#define MIN_", macro_prefix, "VERSION_",name,"(major1,major2,minor) (\\\n" ," (major1) < ",major1," || \\\n" ," (major1) == ",major1," && (major2) < ",major2," || \\\n" ," (major1) == ",major1," && (major2) == ",major2," && (minor) <= ",minor,")" @@ -96,14 +90,21 @@ generateMacros prefix name version = where (major1:major2:minor:_) = map show (versionBranch version ++ repeat 0) --- | Generate the @CURRENT_COMPONENT_ID@ definition for the component ID --- of the current package. -generateComponentIdMacro :: LocalBuildInfo -> String -generateComponentIdMacro lbi = - concat - [ "#define CURRENT_COMPONENT_ID \"" ++ display (localComponentId lbi) ++ "\"\n\n" - , "#define CURRENT_PACKAGE_KEY \"" ++ localCompatPackageKey lbi ++ "\"\n\n" - ] +-- | Generate the @CURRENT_PACKAGE_KEY@ definition for the package key +-- of the current package, if supported by the compiler. +-- NB: this only makes sense for definite packages. +generateComponentIdMacro :: LocalBuildInfo -> ComponentLocalBuildInfo -> String +generateComponentIdMacro lbi clbi + | packageKeySupported (compiler lbi) = + concat + -- Has to be the local one, since it's not guaranteed to be + -- present for non-libraries (TODO: maybe we should store those?) + ["#define CURRENT_PACKAGE_KEY \"" ++ localCompatPackageKey lbi ++ "\"\n" + ,"#define CURRENT_COMPONENT_ID \"" ++ display (componentComponentId clbi) ++ "\"\n" + -- TODO: maybe just give component IDs for all dependents? Hmm... + ,"#define LOCAL_COMPONENT_ID \"" ++ display (localComponentId lbi) ++ "\"\n" + ,"\n"] + | otherwise = "" fixchar :: Char -> Char fixchar '-' = '_' diff --git a/Cabal/Distribution/Simple/Build/PathsModule.hs b/Cabal/Distribution/Simple/Build/PathsModule.hs index c70f34ad1a9..79e1853a194 100644 --- a/Cabal/Distribution/Simple/Build/PathsModule.hs +++ b/Cabal/Distribution/Simple/Build/PathsModule.hs @@ -37,8 +37,8 @@ import Data.Maybe -- * Building Paths_.hs -- ------------------------------------------------------------ -generate :: PackageDescription -> LocalBuildInfo -> String -generate pkg_descr lbi = +generate :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> String +generate pkg_descr lbi clbi = let pragmas = cpp_pragma ++ ffi_pragmas ++ warning_pragmas cpp_pragma | supports_cpp = "{-# LANGUAGE CPP #-}\n" @@ -169,6 +169,8 @@ generate pkg_descr lbi = in header++body where + cid = componentUnitId clbi + InstallDirs { prefix = flat_prefix, bindir = flat_bindir, @@ -176,14 +178,14 @@ generate pkg_descr lbi = datadir = flat_datadir, libexecdir = flat_libexecdir, sysconfdir = flat_sysconfdir - } = absoluteInstallDirs pkg_descr lbi NoCopyDest + } = absoluteInstallDirs pkg_descr lbi cid NoCopyDest InstallDirs { bindir = flat_bindirrel, libdir = flat_libdirrel, datadir = flat_datadirrel, libexecdir = flat_libexecdirrel, sysconfdir = flat_sysconfdirrel - } = prefixRelativeInstallDirs (packageId pkg_descr) lbi + } = prefixRelativeInstallDirs (packageId pkg_descr) lbi cid flat_bindirreloc = shortRelativePath flat_prefix flat_bindir flat_libdirreloc = shortRelativePath flat_prefix flat_libdir diff --git a/Cabal/Distribution/Simple/BuildPaths.hs b/Cabal/Distribution/Simple/BuildPaths.hs index f9df7b5b5dc..babba025f5f 100644 --- a/Cabal/Distribution/Simple/BuildPaths.hs +++ b/Cabal/Distribution/Simple/BuildPaths.hs @@ -56,8 +56,10 @@ haddockPref distPref pkg_descr = distPref "doc" "html" display (packageName pkg_descr) -- |The directory in which we put auto-generated modules -autogenModulesDir :: LocalBuildInfo -> String -autogenModulesDir lbi = buildDir lbi "autogen" +autogenModulesDir :: LocalBuildInfo -> ComponentLocalBuildInfo -> String +autogenModulesDir lbi clbi = libBuildDir lbi clbi "autogen" +-- NB: Look at 'checkForeignDeps' for where a simplified version of this +-- has been copy-pasted. cppHeaderName :: String cppHeaderName = "cabal_macros.h" diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 06276e634c3..830a6f5160a 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -70,7 +70,6 @@ import Distribution.Simple.Program import Distribution.Simple.Setup as Setup import qualified Distribution.Simple.InstallDirs as InstallDirs import Distribution.Simple.LocalBuildInfo -import Distribution.Simple.BuildPaths import Distribution.Simple.Utils import Distribution.System import Distribution.Version @@ -647,8 +646,10 @@ configure (pkg_descr0', pbi) cfg = do when reloc (checkRelocatable verbosity pkg_descr lbi) - let dirs = absoluteInstallDirs pkg_descr lbi NoCopyDest - relative = prefixRelativeInstallDirs (packageId pkg_descr) lbi + -- TODO: This is not entirely correct, because the dirs may vary + -- across libraries/executables + let dirs = absoluteInstallDirs pkg_descr lbi (localUnitId lbi) NoCopyDest + relative = prefixRelativeInstallDirs (packageId pkg_descr) lbi (localUnitId lbi) unless (isAbsolute (prefix dirs)) $ die $ "expected an absolute directory name for --prefix: " ++ prefix dirs @@ -1622,16 +1623,19 @@ mkComponentsLocalBuildInfo cfg comp installedPackages pkg_descr } CExe _ -> return ExeComponentLocalBuildInfo { + componentUnitId = uid, componentPackageDeps = cpds, componentPackageRenaming = cprns } CTest _ -> return TestComponentLocalBuildInfo { + componentUnitId = uid, componentPackageDeps = cpds, componentPackageRenaming = cprns } CBench _ -> return BenchComponentLocalBuildInfo { + componentUnitId = uid, componentPackageDeps = cpds, componentPackageRenaming = cprns } @@ -1858,7 +1862,11 @@ checkForeignDeps pkg lbi verbosity = do libExists lib = builds (makeProgram []) (makeLdArgs [lib]) commonCppArgs = platformDefines lbi - ++ [ "-I" ++ autogenModulesDir lbi ] + -- TODO: This is a massive hack, to work around the + -- fact that the test performed here should be + -- PER-component (c.f. the "I'm Feeling Lucky"; we + -- should NOT be glomming everything together.) + ++ [ "-I" ++ buildDir lbi "autogen" ] ++ [ "-I" ++ dir | dir <- collectField PD.includeDirs ] ++ ["-I."] ++ collectField PD.cppOptions @@ -2018,7 +2026,10 @@ checkRelocatable verbosity pkg lbi $ die $ "Installation directories are not prefix_relative:\n" ++ show installDirs where - installDirs = absoluteInstallDirs pkg lbi NoCopyDest + -- NB: should be good enough to check this against the default + -- component ID, but if we wanted to be strictly correct we'd + -- check for each ComponentId. + installDirs = absoluteInstallDirs pkg lbi (localUnitId lbi) NoCopyDest p = prefix installDirs relativeInstallDirs (InstallDirs {..}) = all isJust @@ -2039,7 +2050,10 @@ checkRelocatable verbosity pkg lbi (Installed.libraryDirs ipkg) | otherwise = return () - installDirs = absoluteInstallDirs pkg lbi NoCopyDest + -- NB: should be good enough to check this against the default + -- component ID, but if we wanted to be strictly correct we'd + -- check for each ComponentId. + installDirs = absoluteInstallDirs pkg lbi (localUnitId lbi) NoCopyDest p = prefix installDirs ipkgs = PackageIndex.allPackages (installedPkgs lbi) msg l = "Library directory of a dependency: " ++ show l ++ diff --git a/Cabal/Distribution/Simple/GHC.hs b/Cabal/Distribution/Simple/GHC.hs index 07061f9f115..c2122726871 100644 --- a/Cabal/Distribution/Simple/GHC.hs +++ b/Cabal/Distribution/Simple/GHC.hs @@ -651,7 +651,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do profileLibFilePath = libTargetDir mkProfLibName uid sharedLibFilePath = libTargetDir mkSharedLibName compiler_id uid ghciLibFilePath = libTargetDir Internal.mkGHCiLibName uid - libInstallPath = libdir $ absoluteInstallDirs pkg_descr lbi NoCopyDest + libInstallPath = libdir $ absoluteInstallDirs pkg_descr lbi uid NoCopyDest sharedLibInstallPath = libInstallPath mkSharedLibName compiler_id uid stubObjs <- catMaybes <$> sequence diff --git a/Cabal/Distribution/Simple/GHC/Internal.hs b/Cabal/Distribution/Simple/GHC/Internal.hs index a9bfc6eb396..acc5257656b 100644 --- a/Cabal/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/Distribution/Simple/GHC/Internal.hs @@ -246,7 +246,7 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename = ghcOptMode = toFlag GhcModeCompile, ghcOptInputFiles = toNubListR [filename], - ghcOptCppIncludePath = toNubListR $ [autogenModulesDir lbi, odir] + ghcOptCppIncludePath = toNubListR $ [autogenModulesDir lbi clbi, odir] ++ PD.includeDirs bi, ghcOptPackageDBs = withPackageDB lbi, ghcOptPackages = toNubListR $ mkGhcOptPackages clbi, @@ -280,12 +280,12 @@ componentGhcOptions verbosity lbi bi clbi odir = ghcOptSplitObjs = toFlag (splitObjs lbi), ghcOptSourcePathClear = toFlag True, ghcOptSourcePath = toNubListR $ [odir] ++ (hsSourceDirs bi) - ++ [autogenModulesDir lbi], - ghcOptCppIncludePath = toNubListR $ [autogenModulesDir lbi, odir] + ++ [autogenModulesDir lbi clbi], + ghcOptCppIncludePath = toNubListR $ [autogenModulesDir lbi clbi, odir] ++ PD.includeDirs bi, ghcOptCppOptions = toNubListR $ cppOptions bi, ghcOptCppIncludes = toNubListR $ - [autogenModulesDir lbi cppHeaderName], + [autogenModulesDir lbi clbi cppHeaderName], ghcOptFfiIncludes = toNubListR $ PD.includes bi, ghcOptObjDir = toFlag odir, ghcOptHiDir = toFlag odir, diff --git a/Cabal/Distribution/Simple/Haddock.hs b/Cabal/Distribution/Simple/Haddock.hs index ab06b052590..94c2851a095 100644 --- a/Cabal/Distribution/Simple/Haddock.hs +++ b/Cabal/Distribution/Simple/Haddock.hs @@ -177,8 +177,6 @@ haddock pkg_descr lbi suffixes flags' = do -- the tools match the requests, we can proceed - initialBuildSteps (flag haddockDistPref) pkg_descr lbi verbosity - when (flag haddockHscolour) $ hscolour' (warn verbosity) pkg_descr lbi suffixes (defaultHscolourFlags `mappend` haddockToHscolour flags) @@ -190,9 +188,9 @@ haddock pkg_descr lbi suffixes flags' = do , fromPackageDescription forDist pkg_descr ] forDist = fromFlagOrDefault False (haddockForHackage flags) - let pre c = preprocessComponent pkg_descr c lbi False verbosity suffixes withAllComponentsInBuildOrder pkg_descr lbi $ \component clbi -> do - pre component + initialBuildSteps (flag haddockDistPref) pkg_descr lbi clbi verbosity + preprocessComponent pkg_descr component lbi clbi False verbosity suffixes let doExe com = case (compToExe com) of Just exe -> do @@ -286,7 +284,7 @@ fromLibrary :: Verbosity -> Version -> IO HaddockArgs fromLibrary verbosity tmp lbi lib clbi htmlTemplate haddockVersion = do - inFiles <- map snd `fmap` getLibSourceFiles lbi lib + inFiles <- map snd `fmap` getLibSourceFiles lbi lib clbi ifaceArgs <- getInterfaces verbosity lbi clbi htmlTemplate let vanillaOpts = (componentGhcOptions normal lbi bi clbi (buildDir lbi)) { -- Noooooooooo!!!!!111 @@ -331,7 +329,7 @@ fromExecutable :: Verbosity -> Version -> IO HaddockArgs fromExecutable verbosity tmp lbi exe clbi htmlTemplate haddockVersion = do - inFiles <- map snd `fmap` getExeSourceFiles lbi exe + inFiles <- map snd `fmap` getExeSourceFiles lbi exe clbi ifaceArgs <- getInterfaces verbosity lbi clbi htmlTemplate let vanillaOpts = (componentGhcOptions normal lbi bi clbi (buildDir lbi)) { -- Noooooooooo!!!!!111 @@ -645,13 +643,7 @@ hscolour :: PackageDescription -> HscolourFlags -> IO () hscolour pkg_descr lbi suffixes flags = do - -- we preprocess even if hscolour won't be found on the machine - -- will this upset someone? - initialBuildSteps distPref pkg_descr lbi verbosity hscolour' die pkg_descr lbi suffixes flags - where - verbosity = fromFlag (hscolourVerbosity flags) - distPref = fromFlag $ hscolourDistPref flags hscolour' :: (String -> IO ()) -- ^ Called when the 'hscolour' exe is not found. -> PackageDescription @@ -670,15 +662,15 @@ hscolour' onNoHsColour pkg_descr lbi suffixes flags = createDirectoryIfMissingVerbose verbosity True $ hscolourPref distPref pkg_descr - let pre c = preprocessComponent pkg_descr c lbi False verbosity suffixes - withAllComponentsInBuildOrder pkg_descr lbi $ \comp _ -> do - pre comp + withAllComponentsInBuildOrder pkg_descr lbi $ \comp clbi -> do + initialBuildSteps distPref pkg_descr lbi clbi verbosity + preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes let doExe com = case (compToExe com) of Just exe -> do let outputDir = hscolourPref distPref pkg_descr exeName exe "src" - runHsColour hscolourProg outputDir =<< getExeSourceFiles lbi exe + runHsColour hscolourProg outputDir =<< getExeSourceFiles lbi exe clbi Nothing -> do warn (fromFlag $ hscolourVerbosity flags) "Unsupported component, skipping..." @@ -686,7 +678,7 @@ hscolour' onNoHsColour pkg_descr lbi suffixes flags = case comp of CLib lib -> do let outputDir = hscolourPref distPref pkg_descr "src" - runHsColour hscolourProg outputDir =<< getLibSourceFiles lbi lib + runHsColour hscolourProg outputDir =<< getLibSourceFiles lbi lib clbi CExe _ -> when (fromFlag (hscolourExecutables flags)) $ doExe comp CTest _ -> when (fromFlag (hscolourTestSuites flags)) $ doExe comp CBench _ -> when (fromFlag (hscolourBenchmarks flags)) $ doExe comp @@ -728,24 +720,26 @@ haddockToHscolour flags = getLibSourceFiles :: LocalBuildInfo -> Library + -> ComponentLocalBuildInfo -> IO [(ModuleName.ModuleName, FilePath)] -getLibSourceFiles lbi lib = getSourceFiles searchpaths modules +getLibSourceFiles lbi lib clbi = getSourceFiles searchpaths modules where bi = libBuildInfo lib modules = PD.exposedModules lib ++ otherModules bi - searchpaths = autogenModulesDir lbi : buildDir lbi : hsSourceDirs bi + searchpaths = autogenModulesDir lbi clbi : buildDir lbi : hsSourceDirs bi getExeSourceFiles :: LocalBuildInfo -> Executable + -> ComponentLocalBuildInfo -> IO [(ModuleName.ModuleName, FilePath)] -getExeSourceFiles lbi exe = do +getExeSourceFiles lbi exe clbi = do moduleFiles <- getSourceFiles searchpaths modules srcMainPath <- findFile (hsSourceDirs bi) (modulePath exe) return ((ModuleName.main, srcMainPath) : moduleFiles) where bi = buildInfo exe modules = otherModules bi - searchpaths = autogenModulesDir lbi : exeBuildDir lbi exe : hsSourceDirs bi + searchpaths = autogenModulesDir lbi clbi : exeBuildDir lbi exe : hsSourceDirs bi getSourceFiles :: [FilePath] -> [ModuleName.ModuleName] diff --git a/Cabal/Distribution/Simple/HaskellSuite.hs b/Cabal/Distribution/Simple/HaskellSuite.hs index 7301ccb925b..280b30c3db3 100644 --- a/Cabal/Distribution/Simple/HaskellSuite.hs +++ b/Cabal/Distribution/Simple/HaskellSuite.hs @@ -165,7 +165,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do runDbProgram verbosity haskellSuiteProgram conf $ [ "compile", "--build-dir", odir ] ++ concat [ ["-i", d] | d <- srcDirs ] ++ - concat [ ["-I", d] | d <- [autogenModulesDir lbi, odir] ++ includeDirs bi ] ++ + concat [ ["-I", d] | d <- [autogenModulesDir lbi clbi, odir] ++ includeDirs bi ] ++ [ packageDbOpt pkgDb | pkgDb <- dbStack ] ++ [ "--package-name", display pkgid ] ++ concat [ ["--package-id", display ipkgid ] diff --git a/Cabal/Distribution/Simple/Install.hs b/Cabal/Distribution/Simple/Install.hs index 20ba705307a..1012fa9ee4f 100644 --- a/Cabal/Distribution/Simple/Install.hs +++ b/Cabal/Distribution/Simple/Install.hs @@ -47,6 +47,9 @@ import Distribution.Text -- |Perform the \"@.\/setup install@\" and \"@.\/setup copy@\" -- actions. Move files into place based on the prefix argument. +-- +-- This does NOT register libraries, you should call 'register' +-- to do that. install :: PackageDescription -- ^information from the .cabal file -> LocalBuildInfo -- ^information from the configure step @@ -56,35 +59,36 @@ install pkg_descr lbi flags = do let distPref = fromFlag (copyDistPref flags) verbosity = fromFlag (copyVerbosity flags) copydest = fromFlag (copyDest flags) - installDirs@(InstallDirs { - bindir = binPref, - libdir = libPref, --- dynlibdir = dynlibPref, --see TODO below + -- This is a bit of a hack, to handle files which are not + -- per-component (data files and Haddock files.) + InstallDirs { datadir = dataPref, + -- NB: The situation with Haddock is a bit delicate. On the + -- one hand, the easiest to understand Haddock documentation + -- path is pkgname-0.1, which means it's per-package (not + -- per-component). But this means that it's impossible to + -- install Haddock documentation for internal libraries. We'll + -- keep this constraint for now; this means you can't use + -- Cabal to Haddock internal libraries. This does not seem + -- like a big problem. docdir = docPref, htmldir = htmlPref, - haddockdir = interfacePref, - includedir = incPref}) - -- Using the library clbi for binPref is a hack; - -- binPref should be computed per executable - = absoluteInstallDirs pkg_descr lbi copydest - - --TODO: decide if we need the user to be able to control the libdir - -- for shared libs independently of the one for static libs. If so - -- it should also have a flag in the command line UI - -- For the moment use dynlibdir = libdir - dynlibPref = libPref - progPrefixPref = substPathTemplate (packageId pkg_descr) lbi (progPrefix lbi) - progSuffixPref = substPathTemplate (packageId pkg_descr) lbi (progSuffix lbi) + haddockdir = interfacePref} + -- Notice use of localComponentId. This means for + -- non-library packages we'll just pick a nondescriptive foo-0.1 + = absoluteInstallDirs pkg_descr lbi (localUnitId lbi) copydest unless (hasLibs pkg_descr || hasExes pkg_descr) $ die "No executables and no library found. Nothing to do." + + -- Install (package-global) data files + installDataFiles verbosity pkg_descr dataPref + + -- Install (package-global) Haddock files docExists <- doesDirectoryExist $ haddockPref distPref pkg_descr info verbosity ("directory " ++ haddockPref distPref pkg_descr ++ " does exist: " ++ show docExists) - installDataFiles verbosity pkg_descr dataPref - when docExists $ do createDirectoryIfMissingVerbose verbosity True htmlPref installDirectoryContents verbosity @@ -112,46 +116,63 @@ install pkg_descr lbi flags = do [ installOrdinaryFile verbosity lfile (docPref takeFileName lfile) | lfile <- lfiles ] - let buildPref = buildDir lbi - when (hasLibs pkg_descr) $ - notice verbosity ("Installing library in " ++ libPref) - when (hasExes pkg_descr) $ do - notice verbosity ("Installing executable(s) in " ++ binPref) + withLibLBI pkg_descr lbi $ \lib clbi -> do + let InstallDirs{ + libdir = libPref, + includedir = incPref + } = absoluteInstallDirs pkg_descr lbi (componentUnitId clbi) copydest + buildPref = libBuildDir lbi clbi + -- TODO: decide if we need the user to be able to control the libdir + -- for shared libs independently of the one for static libs. If so + -- it should also have a flag in the command line UI + -- For the moment use dynlibdir = libdir + dynlibPref = libPref + + if componentUnitId clbi == localUnitId lbi + then notice verbosity ("Installing library in " ++ libPref) + else notice verbosity ("Installing internal library " ++ libName lib ++ " in " ++ libPref) + + -- install include files for all compilers - they may be needed to compile + -- haskell files (using the CPP extension) + installIncludeFiles verbosity lib incPref + + case compilerFlavor (compiler lbi) of + GHC -> GHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr lib clbi + GHCJS -> GHCJS.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr lib clbi + LHC -> LHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr lib clbi + JHC -> JHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr lib clbi + UHC -> UHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr lib clbi + HaskellSuite _ -> HaskellSuite.installLib + verbosity lbi libPref dynlibPref buildPref pkg_descr lib clbi + _ -> die $ "installing with " + ++ display (compilerFlavor (compiler lbi)) + ++ " is not implemented" + + withExeLBI pkg_descr lbi $ \exe clbi -> do + let installDirs@InstallDirs { + bindir = binPref + } = absoluteInstallDirs pkg_descr lbi (componentUnitId clbi) copydest + -- the installers know how to find the actual location of the + -- binaries + buildPref = buildDir lbi + uid = componentUnitId clbi + progPrefixPref = substPathTemplate (packageId pkg_descr) lbi uid (progPrefix lbi) + progSuffixPref = substPathTemplate (packageId pkg_descr) lbi uid (progSuffix lbi) + notice verbosity ("Installing executable " ++ exeName exe ++ " in " ++ binPref) inPath <- isInSearchPath binPref when (not inPath) $ warn verbosity ("The directory " ++ binPref ++ " is not in the system search path.") - - -- install include files for all compilers - they may be needed to compile - -- haskell files (using the CPP extension) - -- - when (hasLibs pkg_descr) $ installIncludeFiles verbosity pkg_descr incPref - - withLibLBI pkg_descr lbi $ - case compilerFlavor (compiler lbi) of - GHC -> GHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr - GHCJS -> GHCJS.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr - LHC -> LHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr - JHC -> JHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr - UHC -> UHC.installLib verbosity lbi libPref dynlibPref buildPref pkg_descr - HaskellSuite _ -> HaskellSuite.installLib - verbosity lbi libPref dynlibPref buildPref pkg_descr - _ -> \_ _ -> die $ "installing with " - ++ display (compilerFlavor (compiler lbi)) - ++ " is not implemented" - - withExe pkg_descr $ case compilerFlavor (compiler lbi) of - GHC -> GHC.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr - GHCJS -> GHCJS.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr - LHC -> LHC.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr - JHC -> JHC.installExe verbosity binPref buildPref (progPrefixPref, progSuffixPref) pkg_descr - UHC -> \_ -> return () - HaskellSuite {} -> \_ -> return () - _ -> \_ -> die $ "installing with " - ++ display (compilerFlavor (compiler lbi)) - ++ " is not implemented" - -- register step should be performed by caller. + GHC -> GHC.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr exe + GHCJS -> GHCJS.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr exe + LHC -> LHC.installExe verbosity lbi installDirs buildPref (progPrefixPref, progSuffixPref) pkg_descr exe + JHC -> JHC.installExe verbosity binPref buildPref (progPrefixPref, progSuffixPref) pkg_descr exe + UHC -> return () + HaskellSuite {} -> return () + _ -> die $ "installing with " + ++ display (compilerFlavor (compiler lbi)) + ++ " is not implemented" -- | Install the files listed in data-files -- @@ -166,11 +187,10 @@ installDataFiles verbosity pkg_descr destDataDir = (destDataDir file') | file' <- files ] --- | Install the files listed in install-includes +-- | Install the files listed in install-includes for a library -- -installIncludeFiles :: Verbosity -> PackageDescription -> FilePath -> IO () -installIncludeFiles verbosity pkg destIncludeDir = do - withLib pkg $ \lib -> do +installIncludeFiles :: Verbosity -> Library -> FilePath -> IO () +installIncludeFiles verbosity lib destIncludeDir = do let relincdirs = "." : filter (not.isAbsolute) (includeDirs lbi) lbi = libBuildInfo lib incs <- mapM (findInc relincdirs) (installIncludes lbi) diff --git a/Cabal/Distribution/Simple/JHC.hs b/Cabal/Distribution/Simple/JHC.hs index 3c6e8b4c2eb..dbdb3234f59 100644 --- a/Cabal/Distribution/Simple/JHC.hs +++ b/Cabal/Distribution/Simple/JHC.hs @@ -143,7 +143,7 @@ constructJHCCmdLine lbi bi clbi _odir verbosity = ++ extensionsToFlags (compiler lbi) (usedExtensions bi) ++ ["--noauto","-i-"] ++ concat [["-i", l] | l <- nub (hsSourceDirs bi)] - ++ ["-i", autogenModulesDir lbi] + ++ ["-i", autogenModulesDir lbi clbi] ++ ["-optc" ++ opt | opt <- PD.ccOptions bi] -- It would be better if JHC would accept package names with versions, -- but JHC-0.7.2 doesn't accept this. diff --git a/Cabal/Distribution/Simple/LHC.hs b/Cabal/Distribution/Simple/LHC.hs index fe988988583..795592bd97f 100644 --- a/Cabal/Distribution/Simple/LHC.hs +++ b/Cabal/Distribution/Simple/LHC.hs @@ -578,12 +578,12 @@ ghcOptions lbi bi clbi odir ++ ["-i"] ++ ["-i" ++ odir] ++ ["-i" ++ l | l <- nub (hsSourceDirs bi)] - ++ ["-i" ++ autogenModulesDir lbi] - ++ ["-I" ++ autogenModulesDir lbi] + ++ ["-i" ++ autogenModulesDir lbi clbi] + ++ ["-I" ++ autogenModulesDir lbi clbi] ++ ["-I" ++ odir] ++ ["-I" ++ dir | dir <- PD.includeDirs bi] ++ ["-optP" ++ opt | opt <- cppOptions bi] - ++ [ "-optP-include", "-optP"++ (autogenModulesDir lbi cppHeaderName) ] + ++ [ "-optP-include", "-optP"++ (autogenModulesDir lbi clbi cppHeaderName) ] ++ [ "-#include \"" ++ inc ++ "\"" | inc <- PD.includes bi ] ++ [ "-odir", odir, "-hidir", odir ] ++ (if compilerVersion c >= Version [6,8] [] diff --git a/Cabal/Distribution/Simple/LocalBuildInfo.hs b/Cabal/Distribution/Simple/LocalBuildInfo.hs index 665a913be33..689e1abecce 100644 --- a/Cabal/Distribution/Simple/LocalBuildInfo.hs +++ b/Cabal/Distribution/Simple/LocalBuildInfo.hs @@ -31,6 +31,7 @@ module Distribution.Simple.LocalBuildInfo ( showComponentName, ComponentLocalBuildInfo(..), libBuildDir, + componentComponentId, foldComponent, componentName, componentBuildInfo, @@ -227,14 +228,17 @@ data ComponentLocalBuildInfo componentPackageRenaming :: Map PackageName ModuleRenaming } | ExeComponentLocalBuildInfo { + componentUnitId :: UnitId, componentPackageDeps :: [(UnitId, PackageId)], componentPackageRenaming :: Map PackageName ModuleRenaming } | TestComponentLocalBuildInfo { + componentUnitId :: UnitId, componentPackageDeps :: [(UnitId, PackageId)], componentPackageRenaming :: Map PackageName ModuleRenaming } | BenchComponentLocalBuildInfo { + componentUnitId :: UnitId, componentPackageDeps :: [(UnitId, PackageId)], componentPackageRenaming :: Map PackageName ModuleRenaming } @@ -247,6 +251,10 @@ libBuildDir lbi clbi | componentUnitId clbi == localUnitId lbi = buildDir lbi | otherwise = buildDir lbi display (componentUnitId clbi) +componentComponentId :: ComponentLocalBuildInfo -> ComponentId +componentComponentId clbi = case componentUnitId clbi of + SimpleUnitId cid -> cid + foldComponent :: (Library -> a) -> (Executable -> a) -> (TestSuite -> a) @@ -454,7 +462,7 @@ depLibraryPaths :: Bool -- ^ Building for inplace? -> IO [FilePath] depLibraryPaths inplace relative lbi clbi = do let pkgDescr = localPkgDescr lbi - installDirs = absoluteInstallDirs pkgDescr lbi NoCopyDest + installDirs = absoluteInstallDirs pkgDescr lbi (componentUnitId clbi) NoCopyDest executable = case clbi of ExeComponentLocalBuildInfo {} -> True _ -> False @@ -504,12 +512,14 @@ depLibraryPaths inplace relative lbi clbi = do -- Wrappers for a couple functions from InstallDirs -- |See 'InstallDirs.absoluteInstallDirs' -absoluteInstallDirs :: PackageDescription -> LocalBuildInfo -> CopyDest +absoluteInstallDirs :: PackageDescription -> LocalBuildInfo + -> UnitId + -> CopyDest -> InstallDirs FilePath -absoluteInstallDirs pkg lbi copydest = +absoluteInstallDirs pkg lbi uid copydest = InstallDirs.absoluteInstallDirs (packageId pkg) - (localUnitId lbi) + uid (compilerInfo (compiler lbi)) copydest (hostPlatform lbi) @@ -517,21 +527,23 @@ absoluteInstallDirs pkg lbi copydest = -- |See 'InstallDirs.prefixRelativeInstallDirs' prefixRelativeInstallDirs :: PackageId -> LocalBuildInfo + -> UnitId -> InstallDirs (Maybe FilePath) -prefixRelativeInstallDirs pkg_descr lbi = +prefixRelativeInstallDirs pkg_descr lbi uid = InstallDirs.prefixRelativeInstallDirs (packageId pkg_descr) - (localUnitId lbi) + uid (compilerInfo (compiler lbi)) (hostPlatform lbi) (installDirTemplates lbi) substPathTemplate :: PackageId -> LocalBuildInfo + -> UnitId -> PathTemplate -> FilePath -substPathTemplate pkgid lbi = fromPathTemplate - . ( InstallDirs.substPathTemplate env ) +substPathTemplate pkgid lbi uid = fromPathTemplate + . ( InstallDirs.substPathTemplate env ) where env = initialPathTemplateEnv pkgid - (localUnitId lbi) + uid (compilerInfo (compiler lbi)) (hostPlatform lbi) diff --git a/Cabal/Distribution/Simple/PreProcess.hs b/Cabal/Distribution/Simple/PreProcess.hs index 1f2fb5914d3..bc76e38fbf2 100644 --- a/Cabal/Distribution/Simple/PreProcess.hs +++ b/Cabal/Distribution/Simple/PreProcess.hs @@ -132,26 +132,27 @@ runSimplePreProcessor pp inFile outFile verbosity = -- |A preprocessor for turning non-Haskell files with the given extension -- into plain Haskell source files. type PPSuffixHandler - = (String, BuildInfo -> LocalBuildInfo -> PreProcessor) + = (String, BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor) -- | Apply preprocessors to the sources from 'hsSourceDirs' for a given -- component (lib, exe, or test suite). preprocessComponent :: PackageDescription -> Component -> LocalBuildInfo + -> ComponentLocalBuildInfo -> Bool -> Verbosity -> [PPSuffixHandler] -> IO () -preprocessComponent pd comp lbi isSrcDist verbosity handlers = case comp of +preprocessComponent pd comp lbi clbi isSrcDist verbosity handlers = case comp of (CLib lib@Library{ libBuildInfo = bi }) -> do - let dirs = hsSourceDirs bi ++ [autogenModulesDir lbi] + let dirs = hsSourceDirs bi ++ [autogenModulesDir lbi clbi] setupMessage verbosity "Preprocessing library" (packageId pd) forM_ (map ModuleName.toFilePath $ libModules lib) $ pre dirs (buildDir lbi) (localHandlers bi) (CExe exe@Executable { buildInfo = bi, exeName = nm }) -> do let exeDir = buildDir lbi nm nm ++ "-tmp" - dirs = hsSourceDirs bi ++ [autogenModulesDir lbi] + dirs = hsSourceDirs bi ++ [autogenModulesDir lbi clbi] setupMessage verbosity ("Preprocessing executable '" ++ nm ++ "' for") (packageId pd) forM_ (map ModuleName.toFilePath $ otherModules bi) $ pre dirs exeDir (localHandlers bi) @@ -182,7 +183,7 @@ preprocessComponent pd comp lbi isSrcDist verbosity handlers = case comp of builtinHaskellSuffixes = ["hs", "lhs", "hsig", "lhsig"] builtinCSuffixes = cSourceExtensions builtinSuffixes = builtinHaskellSuffixes ++ builtinCSuffixes - localHandlers bi = [(ext, h bi lbi) | (ext, h) <- handlers] + localHandlers bi = [(ext, h bi lbi clbi) | (ext, h) <- handlers] pre dirs dir lhndlrs fp = preprocessFile dirs dir isSrcDist fp verbosity builtinSuffixes lhndlrs preProcessTest test = preProcessComponent (testBuildInfo test) @@ -191,7 +192,7 @@ preprocessComponent pd comp lbi isSrcDist verbosity handlers = case comp of (benchmarkModules bm) preProcessComponent bi modules exePath dir = do let biHandlers = localHandlers bi - sourceDirs = hsSourceDirs bi ++ [ autogenModulesDir lbi ] + sourceDirs = hsSourceDirs bi ++ [ autogenModulesDir lbi clbi ] sequence_ [ preprocessFile sourceDirs dir isSrcDist (ModuleName.toFilePath modu) verbosity builtinSuffixes biHandlers @@ -294,8 +295,8 @@ preprocessFile searchLoc buildLoc forSDist baseFile verbosity builtinSuffixes ha -- * known preprocessors -- ------------------------------------------------------------ -ppGreenCard :: BuildInfo -> LocalBuildInfo -> PreProcessor -ppGreenCard _ lbi +ppGreenCard :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppGreenCard _ lbi _ = PreProcessor { platformIndependent = False, runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> @@ -314,21 +315,21 @@ ppUnlit = either (writeUTF8File outFile) die (unlit inFile contents) } -ppCpp :: BuildInfo -> LocalBuildInfo -> PreProcessor +ppCpp :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor ppCpp = ppCpp' [] -ppCpp' :: [String] -> BuildInfo -> LocalBuildInfo -> PreProcessor -ppCpp' extraArgs bi lbi = +ppCpp' :: [String] -> BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppCpp' extraArgs bi lbi clbi = case compilerFlavor (compiler lbi) of - GHC -> ppGhcCpp ghcProgram (>= Version [6,6] []) args bi lbi - GHCJS -> ppGhcCpp ghcjsProgram (const True) args bi lbi - _ -> ppCpphs args bi lbi + GHC -> ppGhcCpp ghcProgram (>= Version [6,6] []) args bi lbi clbi + GHCJS -> ppGhcCpp ghcjsProgram (const True) args bi lbi clbi + _ -> ppCpphs args bi lbi clbi where cppArgs = getCppOptions bi lbi args = cppArgs ++ extraArgs ppGhcCpp :: Program -> (Version -> Bool) - -> [String] -> BuildInfo -> LocalBuildInfo -> PreProcessor -ppGhcCpp program xHs extraArgs _bi lbi = + -> [String] -> BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppGhcCpp program xHs extraArgs _bi lbi clbi = PreProcessor { platformIndependent = False, runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> do @@ -342,13 +343,13 @@ ppGhcCpp program xHs extraArgs _bi lbi = -- double-unlitted. In the future we might switch to -- using cpphs --unlit instead. ++ (if xHs version then ["-x", "hs"] else []) - ++ [ "-optP-include", "-optP"++ (autogenModulesDir lbi cppHeaderName) ] + ++ [ "-optP-include", "-optP"++ (autogenModulesDir lbi clbi cppHeaderName) ] ++ ["-o", outFile, inFile] ++ extraArgs } -ppCpphs :: [String] -> BuildInfo -> LocalBuildInfo -> PreProcessor -ppCpphs extraArgs _bi lbi = +ppCpphs :: [String] -> BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppCpphs extraArgs _bi lbi clbi = PreProcessor { platformIndependent = False, runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> do @@ -358,13 +359,13 @@ ppCpphs extraArgs _bi lbi = ("-O" ++ outFile) : inFile : "--noline" : "--strip" : (if cpphsVersion >= Version [1,6] [] - then ["--include="++ (autogenModulesDir lbi cppHeaderName)] + then ["--include="++ (autogenModulesDir lbi clbi cppHeaderName)] else []) ++ extraArgs } -ppHsc2hs :: BuildInfo -> LocalBuildInfo -> PreProcessor -ppHsc2hs bi lbi = +ppHsc2hs :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppHsc2hs bi lbi clbi = PreProcessor { platformIndependent = False, runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> do @@ -401,8 +402,8 @@ ppHsc2hs bi lbi = ++ [ "--cflag=" ++ opt | opt <- PD.ccOptions bi ++ PD.cppOptions bi ] ++ [ "--cflag=" ++ opt | opt <- - [ "-I" ++ autogenModulesDir lbi, - "-include", autogenModulesDir lbi cppHeaderName ] ] + [ "-I" ++ autogenModulesDir lbi clbi, + "-include", autogenModulesDir lbi clbi cppHeaderName ] ] ++ [ "--lflag=-L" ++ opt | opt <- PD.extraLibDirs bi ] ++ [ "--lflag=-Wl,-R," ++ opt | isELF , opt <- PD.extraLibDirs bi ] @@ -427,9 +428,9 @@ ppHsc2hs bi lbi = -- TODO: installedPkgs contains ALL dependencies associated with -- the package, but we really only want to look at packages for the -- *current* dependency. We should use PackageIndex.dependencyClosure - -- on the direct depends of the component. Can't easily do that, - -- because the signature of this function is wrong. Tracked with - -- #2971 (which has a test case.) + -- on the direct depends of the component. The signature of this + -- function was recently refactored, so this should be fixable + -- now. Tracked with #2971 (which has a test case.) pkgs = PackageIndex.topologicalOrder (packageHacks (installedPkgs lbi)) isOSX = case buildOS of OSX -> True; _ -> False isELF = case buildOS of OSX -> False; Windows -> False; AIX -> False; _ -> True; @@ -451,8 +452,8 @@ ppHsc2hsExtras :: PreProcessorExtras ppHsc2hsExtras buildBaseDir = filter ("_hsc.c" `isSuffixOf`) `fmap` getDirectoryContentsRecursive buildBaseDir -ppC2hs :: BuildInfo -> LocalBuildInfo -> PreProcessor -ppC2hs bi lbi = +ppC2hs :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppC2hs bi lbi clbi = PreProcessor { platformIndependent = False, runPreProcessor = \(inBaseDir, inRelativeFile) @@ -466,7 +467,7 @@ ppC2hs bi lbi = -- Options from the current package: [ "--cpp=" ++ programPath gccProg, "--cppopts=-E" ] ++ [ "--cppopts=" ++ opt | opt <- getCppOptions bi lbi ] - ++ [ "--cppopts=-include" ++ (autogenModulesDir lbi cppHeaderName) ] + ++ [ "--cppopts=-include" ++ (autogenModulesDir lbi clbi cppHeaderName) ] ++ [ "--include=" ++ outBaseDir ] -- Options from dependent packages @@ -580,16 +581,16 @@ platformDefines lbi = JavaScript -> ["javascript"] OtherArch _ -> [] -ppHappy :: BuildInfo -> LocalBuildInfo -> PreProcessor -ppHappy _ lbi = pp { platformIndependent = True } +ppHappy :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppHappy _ lbi _ = pp { platformIndependent = True } where pp = standardPP lbi happyProgram (hcFlags hc) hc = compilerFlavor (compiler lbi) hcFlags GHC = ["-agc"] hcFlags GHCJS = ["-agc"] hcFlags _ = [] -ppAlex :: BuildInfo -> LocalBuildInfo -> PreProcessor -ppAlex _ lbi = pp { platformIndependent = True } +ppAlex :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor +ppAlex _ lbi _ = pp { platformIndependent = True } where pp = standardPP lbi alexProgram (hcFlags hc) hc = compilerFlavor (compiler lbi) hcFlags GHC = ["-g"] diff --git a/Cabal/Distribution/Simple/Register.hs b/Cabal/Distribution/Simple/Register.hs index 01e27b693cd..1ac011dcac2 100644 --- a/Cabal/Distribution/Simple/Register.hs +++ b/Cabal/Distribution/Simple/Register.hs @@ -377,7 +377,7 @@ inplaceInstalledPackageInfo inplaceDir distPref pkg abi_hash lib lbi clbi = adjustRelativeIncludeDirs = map (inplaceDir ) libTargetDir = libBuildDir lbi clbi installDirs = - (absoluteInstallDirs pkg lbi NoCopyDest) { + (absoluteInstallDirs pkg lbi (componentUnitId clbi) NoCopyDest) { libdir = inplaceDir libTargetDir, datadir = inplaceDir dataDir pkg, docdir = inplaceDocdir, @@ -409,7 +409,7 @@ absoluteInstalledPackageInfo pkg abi_hash lib lbi clbi = | null (installIncludes bi) = [] | otherwise = [includedir installDirs] bi = libBuildInfo lib - installDirs = absoluteInstallDirs pkg lbi NoCopyDest + installDirs = absoluteInstallDirs pkg lbi (componentUnitId clbi) NoCopyDest relocatableInstalledPackageInfo :: PackageDescription @@ -431,7 +431,7 @@ relocatableInstalledPackageInfo pkg abi_hash lib lbi clbi pkgroot = bi = libBuildInfo lib installDirs = fmap (("${pkgroot}" ) . shortRelativePath pkgroot) - $ absoluteInstallDirs pkg lbi NoCopyDest + $ absoluteInstallDirs pkg lbi (componentUnitId clbi) NoCopyDest -- ----------------------------------------------------------------------------- -- Unregistration diff --git a/Cabal/Distribution/Simple/SrcDist.hs b/Cabal/Distribution/Simple/SrcDist.hs index 9e13cac7d59..c0eea1d7ca5 100644 --- a/Cabal/Distribution/Simple/SrcDist.hs +++ b/Cabal/Distribution/Simple/SrcDist.hs @@ -249,8 +249,8 @@ prepareTree verbosity pkg_descr0 mb_lbi targetDir pps = do case mb_lbi of Just lbi | not (null pps) -> do let lbi' = lbi{ buildDir = targetDir buildDir lbi } - withAllComponentsInBuildOrder pkg_descr lbi' $ \c _ -> - preprocessComponent pkg_descr c lbi' True verbosity pps + withAllComponentsInBuildOrder pkg_descr lbi' $ \c clbi -> + preprocessComponent pkg_descr c lbi' clbi True verbosity pps _ -> return () (ordinary, mExecutable) <- listPackageSources verbosity pkg_descr0 pps diff --git a/Cabal/Distribution/Simple/UHC.hs b/Cabal/Distribution/Simple/UHC.hs index dd2dc7411a3..2fbcfafadc0 100644 --- a/Cabal/Distribution/Simple/UHC.hs +++ b/Cabal/Distribution/Simple/UHC.hs @@ -223,7 +223,7 @@ constructUHCCmdLine user system lbi bi clbi odir verbosity = -- search paths ++ ["-i" ++ odir] ++ ["-i" ++ l | l <- nub (hsSourceDirs bi)] - ++ ["-i" ++ autogenModulesDir lbi] + ++ ["-i" ++ autogenModulesDir lbi clbi] -- cpp options ++ ["--optP=" ++ opt | opt <- cppOptions bi] -- output path diff --git a/cabal-install/Setup.hs b/cabal-install/Setup.hs index a997cdb390f..92a77b061f5 100644 --- a/cabal-install/Setup.hs +++ b/cabal-install/Setup.hs @@ -10,6 +10,7 @@ import Distribution.Simple.InstallDirs ( mandir ) import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) , absoluteInstallDirs + , localUnitId ) import Distribution.Simple.Utils ( copyFiles , notice ) @@ -49,5 +50,7 @@ buildManpage lbi verbosity = do installManpage :: PackageDescription -> LocalBuildInfo -> Verbosity -> CopyDest -> IO () installManpage pkg lbi verbosity copy = do - let destDir = mandir (absoluteInstallDirs pkg lbi copy) "man1" + -- NB: no library here, let's just use the default unit ID + -- (it shouldn't make a difference) + let destDir = mandir (absoluteInstallDirs pkg lbi (localUnitId lbi) copy) "man1" copyFiles verbosity destDir [(buildDir lbi "cabal", "cabal.1")]