Commit a642a28b authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Refactor libModules in to explicitLibModules and allLibModules.


Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 6059c6b3
......@@ -35,7 +35,7 @@ module Distribution.PackageDescription (
withLib,
hasPublicLib,
hasLibs,
libModules,
explicitLibModules,
libModulesAutogen,
-- ** Executables
......
......@@ -233,7 +233,8 @@ checkLibrary pkg lib =
"Duplicate modules in library: "
++ commaSep (map display moduleDuplicates)
, check (null (libModules lib) && null (reexportedModules lib)) $
-- TODO: This check is bogus if a required-signature was passed through
, check (null (explicitLibModules lib) && null (reexportedModules lib)) $
PackageDistSuspiciousWarn $
"Library " ++ (case libName lib of
Nothing -> ""
......@@ -248,7 +249,7 @@ checkLibrary pkg lib =
-- check that all autogen-modules appear on other-modules or exposed-modules
, check
(not $ and $ map (flip elem (libModules lib)) (libModulesAutogen lib)) $
(not $ and $ map (flip elem (explicitLibModules lib)) (libModulesAutogen lib)) $
PackageBuildImpossible $
"An 'autogen-module' is neither on 'exposed-modules' or "
++ "'other-modules'."
......@@ -261,7 +262,8 @@ checkLibrary pkg lib =
| specVersion pkg >= mkVersion ver = Nothing
| otherwise = check cond pc
moduleDuplicates = dups (libModules lib ++
-- TODO: not sure if this check is always right in Backpack
moduleDuplicates = dups (explicitLibModules lib ++
map moduleReexportName (reexportedModules lib))
checkExecutable :: PackageDescription -> Executable -> [PackageCheck]
......@@ -1342,7 +1344,7 @@ checkCabalVersion pkg =
allModuleNames =
(case library pkg of
Nothing -> []
(Just lib) -> libModules lib
(Just lib) -> explicitLibModules lib
)
++ concatMap otherModules (allBuildInfo pkg)
......
......@@ -479,7 +479,14 @@ componentStringName _ (CTestName name) = name
componentStringName _ (CBenchName name) = name
componentModules :: Component -> [ModuleName]
componentModules (CLib lib) = libModules lib
-- TODO: Use of 'explicitLibModules' here is a bit wrong:
-- a user could very well ask to build a specific signature
-- that was inherited from other packages. To fix this
-- we have to plumb 'LocalBuildInfo' through this code.
-- Fortunately, this is only used by 'pkgComponentInfo'
-- Please don't export this function unless you plan on fixing
-- this.
componentModules (CLib lib) = explicitLibModules lib
componentModules (CExe exe) = exeModules exe
componentModules (CTest test) = testModules test
componentModules (CBench bench) = benchmarkModules bench
......
......@@ -528,7 +528,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
vanillaOpts = baseOpts `mappend` mempty {
ghcOptMode = toFlag GhcModeMake,
ghcOptNumJobs = numJobs,
ghcOptInputModules = toNubListR $ libModules lib,
ghcOptInputModules = toNubListR $ allLibModules lib clbi,
ghcOptHPCDir = hpcdir Hpc.Vanilla
}
......@@ -580,7 +580,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptHPCDir = hpcdir Hpc.Dyn
}
unless (forRepl || null (libModules lib)) $
unless (forRepl || null (allLibModules lib clbi)) $
do let vanilla = whenVanillaLib forceVanillaLib (runGhcProg vanillaOpts)
shared = whenSharedLib forceSharedLib (runGhcProg sharedOpts)
useDynToo = dynamicTooSupported &&
......@@ -641,7 +641,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
-- exports.
ifReplLib $ do
when (null (libModules lib)) $ warn verbosity "No exposed modules"
when (null (allLibModules lib clbi)) $ warn verbosity "No exposed modules"
ifReplLib (runGhcProg replOpts)
-- link:
......@@ -663,17 +663,17 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
[ findFileWithExtension [objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| ghcVersion < mkVersion [7,2] -- ghc-7.2+ does not make _stub.o files
, x <- libModules lib ]
, x <- allLibModules lib clbi ]
stubProfObjs <- catMaybes <$> sequenceA
[ findFileWithExtension ["p_" ++ objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| ghcVersion < mkVersion [7,2] -- ghc-7.2+ does not make _stub.o files
, x <- libModules lib ]
, x <- allLibModules lib clbi ]
stubSharedObjs <- catMaybes <$> sequenceA
[ findFileWithExtension ["dyn_" ++ objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| ghcVersion < mkVersion [7,2] -- ghc-7.2+ does not make _stub.o files
, x <- libModules lib ]
, x <- allLibModules lib clbi ]
hObjs <- Internal.getHaskellObjects implInfo lib lbi
libTargetDir objExtension True
......@@ -1169,7 +1169,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
installShared = install True
copyModuleFiles ext =
findModuleFiles [builtDir] [ext] (libModules lib)
findModuleFiles [builtDir] [ext] (allLibModules lib clbi)
>>= installOrdinaryFiles verbosity targetDir
compiler_id = compilerId (compiler lbi)
......@@ -1179,7 +1179,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
ghciLibName = Internal.mkGHCiLibName uid
sharedLibName = (mkSharedLibName compiler_id) uid
hasLib = not $ null (libModules lib)
hasLib = not $ null (allLibModules lib clbi)
&& null (cSources (libBuildInfo lib))
whenVanilla = when (hasLib && withVanillaLib lbi)
whenProf = when (hasLib && withProfLib lbi)
......
......@@ -361,7 +361,7 @@ getHaskellObjects _implInfo lib lbi pref wanted_obj_ext allow_split_objs
| splitObjs lbi && allow_split_objs = do
let splitSuffix = "_" ++ wanted_obj_ext ++ "_split"
dirs = [ pref </> (ModuleName.toFilePath x ++ splitSuffix)
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
objss <- traverse getDirectoryContents dirs
let objs = [ dir </> obj
| (objs',dir) <- zip objss dirs, obj <- objs',
......@@ -370,7 +370,9 @@ getHaskellObjects _implInfo lib lbi pref wanted_obj_ext allow_split_objs
return objs
| otherwise =
return [ pref </> ModuleName.toFilePath x <.> wanted_obj_ext
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
where
clbi = getComponentLocalBuildInfo lbi CLibName
mkGhcOptPackages :: ComponentLocalBuildInfo
-> [(UnitId, ModuleRenaming)]
......
......@@ -317,7 +317,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
vanillaOptsNoJsLib = baseOpts `mappend` mempty {
ghcOptMode = toFlag GhcModeMake,
ghcOptNumJobs = numJobs,
ghcOptInputModules = toNubListR $ libModules lib,
ghcOptInputModules = toNubListR $ allLibModules lib clbi,
ghcOptHPCDir = hpcdir Hpc.Vanilla
}
vanillaOpts = vanillaOptsNoJsLib `mappend` linkJsLibOpts
......@@ -363,7 +363,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptHPCDir = hpcdir Hpc.Dyn
}
unless (forRepl || (null (libModules lib) && null jsSrcs && null cObjs)) $
unless (forRepl || (null (allLibModules lib clbi) && null jsSrcs && null cObjs)) $
do let vanilla = whenVanillaLib forceVanillaLib (runGhcjsProg vanillaOpts)
shared = whenSharedLib forceSharedLib (runGhcjsProg sharedOpts)
useDynToo = dynamicTooSupported &&
......@@ -414,7 +414,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
-- TODO: problem here is we need the .c files built first, so we can load them
-- with ghci, but .c files can depend on .h files generated by ghc by ffi
-- exports.
unless (null (libModules lib)) $
unless (null (allLibModules lib clbi)) $
ifReplLib (runGhcjsProg replOpts)
-- link:
......@@ -726,7 +726,7 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
installSharedNative = install True False
copyModuleFiles ext =
findModuleFiles [builtDir] [ext] (libModules lib)
findModuleFiles [builtDir] [ext] (allLibModules lib clbi)
>>= installOrdinaryFiles verbosity targetDir
compiler_id = compilerId (compiler lbi)
......@@ -736,7 +736,7 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
ghciLibName = Internal.mkGHCiLibName uid
sharedLibName = (mkSharedLibName compiler_id) uid
hasLib = not $ null (libModules lib)
hasLib = not $ null (allLibModules lib clbi)
&& null (cSources (libBuildInfo lib))
whenVanilla = when (hasLib && withVanillaLib lbi)
whenProf = when (hasLib && withProfLib lbi)
......
......@@ -179,7 +179,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
["-G", display language] ++
concat [ ["-X", display ex] | ex <- usedExtensions bi ] ++
cppOptions (libBuildInfo lib) ++
[ display modu | modu <- libModules lib ]
[ display modu | modu <- allLibModules lib clbi ]
......@@ -193,7 +193,7 @@ installLib
-> Library
-> ComponentLocalBuildInfo
-> IO ()
installLib verbosity lbi targetDir dynlibTargetDir builtDir pkg lib _clbi = do
installLib verbosity lbi targetDir dynlibTargetDir builtDir pkg lib clbi = do
let progdb = withPrograms lbi
runDbProgram verbosity haskellSuitePkgProgram progdb $
[ "install-library"
......@@ -201,7 +201,7 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir pkg lib _clbi = do
, "--target-dir", targetDir
, "--dynlib-target-dir", dynlibTargetDir
, "--package-id", display $ packageId pkg
] ++ map display (libModules lib)
] ++ map display (allLibModules lib clbi)
registerPackage
:: Verbosity
......
......@@ -125,7 +125,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
writeFileAtomic pfile . BS.Char8.pack $ jhcPkgConf pkg_descr
runProgram verbosity jhcProg $
["--build-hl="++pfile, "-o", hlfile] ++
args ++ map display (libModules lib)
args ++ map display (allLibModules lib clbi)
-- | Building an executable for JHC.
-- Currently C source files are not supported.
......
......@@ -312,7 +312,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
let ghcArgs =
["-package-name", display pkgid ]
++ constructGHCCmdLine lbi libBi clbi libTargetDir verbosity
++ map display (libModules lib)
++ map display (allLibModules lib clbi)
lhcWrap x = ["--build-library", "--ghc-opts=" ++ unwords x]
ghcArgsProf = ghcArgs
++ ["-prof",
......@@ -326,7 +326,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
"-osuf", "dyn_o", "-fPIC"
]
++ hcSharedOptions GHC libBi
unless (null (libModules lib)) $
unless (null (allLibModules lib clbi)) $
do ifVanillaLib forceVanillaLib (runGhcProg $ lhcWrap ghcArgs)
ifProfLib (runGhcProg $ lhcWrap ghcArgsProf)
ifSharedLib (runGhcProg $ lhcWrap ghcArgsShared)
......@@ -354,15 +354,15 @@ buildLib verbosity pkg_descr lbi lib clbi = do
stubObjs <- fmap catMaybes $ sequenceA
[ findFileWithExtension [objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
stubProfObjs <- fmap catMaybes $ sequenceA
[ findFileWithExtension ["p_" ++ objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
stubSharedObjs <- fmap catMaybes $ sequenceA
[ findFileWithExtension ["dyn_" ++ objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
hObjs <- getHaskellObjects lib lbi
pref objExtension True
......@@ -540,7 +540,7 @@ getHaskellObjects :: Library -> LocalBuildInfo
getHaskellObjects lib lbi pref wanted_obj_ext allow_split_objs
| splitObjs lbi && allow_split_objs = do
let dirs = [ pref </> (ModuleName.toFilePath x ++ "_split")
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
objss <- traverse getDirectoryContents dirs
let objs = [ dir </> obj
| (objs',dir) <- zip objss dirs, obj <- objs',
......@@ -549,7 +549,9 @@ getHaskellObjects lib lbi pref wanted_obj_ext allow_split_objs
return objs
| otherwise =
return [ pref </> ModuleName.toFilePath x <.> wanted_obj_ext
| x <- libModules lib ]
| x <- allLibModules lib clbi ]
where
clbi = getComponentLocalBuildInfo lbi CLibName
constructGHCCmdLine
......@@ -717,11 +719,11 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
createDirectoryIfMissingVerbose verbosity True dst
installOrdinaryFile verbosity (src </> n) (dst </> n)
copyModuleFiles ext =
findModuleFiles [builtDir] [ext] (libModules lib)
findModuleFiles [builtDir] [ext] (allLibModules lib clbi)
>>= installOrdinaryFiles verbosity targetDir
ifVanilla $ copyModuleFiles "hi"
ifProf $ copyModuleFiles "p_hi"
hcrFiles <- findModuleFiles (builtDir : hsSourceDirs (libBuildInfo lib)) ["hcr"] (libModules lib)
hcrFiles <- findModuleFiles (builtDir : hsSourceDirs (libBuildInfo lib)) ["hcr"] (allLibModules lib clbi)
flip traverse_ hcrFiles $ \(srcBase, srcFile) -> runLhc ["--install-library", srcBase </> srcFile]
-- copy the built library files over:
......@@ -738,7 +740,7 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
ghciLibName = mkGHCiLibName lib_name
sharedLibName = mkSharedLibName cid lib_name
hasLib = not $ null (libModules lib)
hasLib = not $ null (allLibModules lib clbi)
&& null (cSources (libBuildInfo lib))
ifVanilla = when (hasLib && withVanillaLib lbi)
ifProf = when (hasLib && withProfLib lbi)
......
......@@ -47,6 +47,7 @@ module Distribution.Simple.LocalBuildInfo (
allComponentsInBuildOrder,
componentsInBuildOrder,
depLibraryPaths,
allLibModules,
withAllComponentsInBuildOrder,
withComponentsInBuildOrder,
......@@ -82,6 +83,7 @@ import qualified Distribution.Simple.InstallDirs as InstallDirs
import Distribution.PackageDescription
import qualified Distribution.InstalledPackageInfo as Installed
import Distribution.Package
import Distribution.ModuleName
import Distribution.Simple.Compiler
import Distribution.Simple.PackageIndex
import Distribution.Simple.Utils
......@@ -287,6 +289,11 @@ depLibraryPaths inplace relative lbi clbi = do
then canonicalizePath p
else return p
-- TODO: doc
allLibModules :: Library -> ComponentLocalBuildInfo -> [ModuleName]
allLibModules lib clbi =
explicitLibModules lib
-- TODO: add more stuff
-- -----------------------------------------------------------------------------
-- Wrappers for a couple functions from InstallDirs
......
......@@ -152,7 +152,7 @@ preprocessComponent pd comp lbi clbi isSrcDist verbosity handlers = case comp of
let dirs = hsSourceDirs bi ++ [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi]
setupMessage verbosity "Preprocessing library" (packageId pd)
for_ (map ModuleName.toFilePath $ libModules lib) $
for_ (map ModuleName.toFilePath $ allLibModules lib clbi) $
pre dirs (componentBuildDir lbi clbi) (localHandlers bi)
(CExe exe@Executable { buildInfo = bi, exeName = nm }) -> do
let exeDir = buildDir lbi </> nm </> nm ++ "-tmp"
......
......@@ -433,7 +433,7 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
where
bi = libBuildInfo lib
(absinc, relinc) = partition isAbsolute (includeDirs bi)
hasModules = not $ null (libModules lib)
hasModules = not $ null (allLibModules lib clbi)
hasLibrary = hasModules || not (null (cSources bi))
|| (not (null (jsSources bi)) &&
compilerFlavor (compiler lbi) == GHCJS)
......
......@@ -185,7 +185,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
-- suboptimal: UHC does not understand module names, so
-- we replace periods by path separators
++ map (map (\ c -> if c == '.' then pathSeparator else c))
(map display (libModules lib))
(map display (allLibModules lib clbi))
runUhcProg uhcArgs
......
......@@ -4,7 +4,7 @@
module Distribution.Types.Library (
Library(..),
emptyLibrary,
libModules,
explicitLibModules,
libModulesAutogen
) where
......@@ -54,9 +54,10 @@ emptyLibrary = mempty
-- | Get all the module names from the library (exposed and internal modules)
-- which need to be compiled. (This does not include reexports, which
-- do not need to be compiled.)
libModules :: Library -> [ModuleName]
libModules lib = exposedModules lib
-- do not need to be compiled.) This may not include all modules for which
-- GHC generated interface files (i.e., implicit modules.)
explicitLibModules :: Library -> [ModuleName]
explicitLibModules lib = exposedModules lib
++ otherModules (libBuildInfo lib)
++ requiredSignatures lib
......
......@@ -51,7 +51,7 @@ import Distribution.PackageDescription
, Executable(..)
, TestSuite(..), TestSuiteInterface(..), testModules
, Benchmark(..), BenchmarkInterface(..), benchmarkModules
, BuildInfo(..), libModules, exeModules )
, BuildInfo(..), explicitLibModules, exeModules )
import Distribution.ModuleName
( ModuleName, toFilePath )
import Distribution.Simple.LocalBuildInfo
......@@ -1100,7 +1100,9 @@ componentStringName _ (CTestName name) = name
componentStringName _ (CBenchName name) = name
componentModules :: Component -> [ModuleName]
componentModules (CLib lib) = libModules lib
-- I think it's unlikely users will ask to build a requirement
-- which is not mentioned locally.
componentModules (CLib lib) = explicitLibModules lib
componentModules (CExe exe) = exeModules exe
componentModules (CTest test) = testModules test
componentModules (CBench bench) = benchmarkModules bench
......
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