Commit 6305156f authored by Edward Z. Yang's avatar Edward Z. Yang Committed by GitHub
Browse files

Merge pull request #3607 from ezyang/pr/autogen

Restore autogenModulesDir to BC-compatible signature
parents a300cb2b ff6aa2f0
......@@ -576,11 +576,11 @@ writeAutogenFiles :: Verbosity
-> ComponentLocalBuildInfo
-> IO ()
writeAutogenFiles verbosity pkg lbi clbi = do
createDirectoryIfMissingVerbose verbosity True (autogenModulesDir lbi clbi)
createDirectoryIfMissingVerbose verbosity True (autogenComponentModulesDir lbi clbi)
let pathsModulePath = autogenModulesDir lbi clbi
let pathsModulePath = autogenComponentModulesDir lbi clbi
</> ModuleName.toFilePath (autogenModuleName pkg) <.> "hs"
rewriteFile pathsModulePath (Build.PathsModule.generate pkg lbi clbi)
let cppHeaderPath = autogenModulesDir lbi clbi </> cppHeaderName
let cppHeaderPath = autogenComponentModulesDir lbi clbi </> cppHeaderName
rewriteFile cppHeaderPath (Build.Macros.generate pkg lbi clbi)
......@@ -15,6 +15,8 @@ module Distribution.Simple.BuildPaths (
defaultDistPref, srcPref,
haddockDirName, hscolourPref, haddockPref,
autogenModulesDir,
autogenPackageModulesDir,
autogenComponentModulesDir,
autogenModuleName,
cppHeaderName,
......@@ -62,9 +64,21 @@ haddockPref :: HaddockTarget -> FilePath -> PackageDescription -> FilePath
haddockPref haddockTarget distPref pkg_descr
= distPref </> "doc" </> "html" </> haddockDirName haddockTarget pkg_descr
-- |The directory in which we put auto-generated modules
autogenModulesDir :: LocalBuildInfo -> ComponentLocalBuildInfo -> String
autogenModulesDir lbi clbi = componentBuildDir lbi clbi </> "autogen"
-- | The directory in which we put auto-generated modules for EVERY
-- component in the package. See deprecation notice.
{-# DEPRECATED autogenModulesDir "If you can, use 'autogenComponentModulesDir' instead, but if you really wanted package-global generated modules, use 'autogenPackageModulesDir'. In Cabal 2.0, we avoid using autogenerated files which apply to all components, because the information you often want in these files, e.g., dependency information, is best specified per component, so that reconfiguring a different component (e.g., enabling tests) doesn't force the entire to be rebuilt. 'autogenPackageModulesDir' still provides a place to put files you want to apply to the entire package, but most users of 'autogenModulesDir' should seriously consider 'autogenComponentModulesDir' if you really wanted the module to apply to one component." #-}
autogenModulesDir :: LocalBuildInfo -> String
autogenModulesDir = autogenPackageModulesDir
-- | The directory in which we put auto-generated modules for EVERY
-- component in the package.
autogenPackageModulesDir :: LocalBuildInfo -> String
autogenPackageModulesDir lbi = buildDir lbi </> "global-autogen"
-- | The directory in which we put auto-generated modules for a
-- particular component.
autogenComponentModulesDir :: LocalBuildInfo -> ComponentLocalBuildInfo -> String
autogenComponentModulesDir lbi clbi = componentBuildDir lbi clbi </> "autogen"
-- NB: Look at 'checkForeignDeps' for where a simplified version of this
-- has been copy-pasted.
......
......@@ -249,7 +249,9 @@ componentCcGhcOptions _verbosity _implInfo lbi bi clbi odir filename =
ghcOptMode = toFlag GhcModeCompile,
ghcOptInputFiles = toNubListR [filename],
ghcOptCppIncludePath = toNubListR $ [autogenModulesDir lbi clbi, odir]
ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi
,odir]
++ PD.includeDirs bi,
ghcOptPackageDBs = withPackageDB lbi,
ghcOptPackages = toNubListR $ mkGhcOptPackages clbi,
......@@ -284,12 +286,15 @@ componentGhcOptions _verbosity lbi bi clbi odir =
ghcOptSplitObjs = toFlag (splitObjs lbi),
ghcOptSourcePathClear = toFlag True,
ghcOptSourcePath = toNubListR $ [odir] ++ (hsSourceDirs bi)
++ [autogenModulesDir lbi clbi],
ghcOptCppIncludePath = toNubListR $ [autogenModulesDir lbi clbi, odir]
++ [autogenComponentModulesDir lbi clbi]
++ [autogenPackageModulesDir lbi],
ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi
,odir]
++ PD.includeDirs bi,
ghcOptCppOptions = toNubListR $ cppOptions bi,
ghcOptCppIncludes = toNubListR $
[autogenModulesDir lbi clbi </> cppHeaderName],
[autogenComponentModulesDir lbi clbi </> cppHeaderName],
ghcOptFfiIncludes = toNubListR $ PD.includes bi,
ghcOptObjDir = toFlag odir,
ghcOptHiDir = toFlag odir,
......
......@@ -730,7 +730,9 @@ getLibSourceFiles lbi lib clbi = getSourceFiles searchpaths modules
where
bi = libBuildInfo lib
modules = PD.exposedModules lib ++ otherModules bi
searchpaths = autogenModulesDir lbi clbi : buildDir lbi : hsSourceDirs bi
searchpaths = autogenComponentModulesDir lbi clbi
: autogenPackageModulesDir lbi
: buildDir lbi : hsSourceDirs bi
getExeSourceFiles :: LocalBuildInfo
-> Executable
......@@ -743,7 +745,9 @@ getExeSourceFiles lbi exe clbi = do
where
bi = buildInfo exe
modules = otherModules bi
searchpaths = autogenModulesDir lbi clbi : exeBuildDir lbi exe : hsSourceDirs bi
searchpaths = autogenComponentModulesDir lbi clbi
: autogenPackageModulesDir lbi
: exeBuildDir lbi exe : hsSourceDirs bi
getSourceFiles :: [FilePath]
-> [ModuleName.ModuleName]
......
......@@ -165,7 +165,9 @@ 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 clbi, odir] ++ includeDirs bi ] ++
concat [ ["-I", d] | d <- [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi
,odir] ++ includeDirs bi ] ++
[ packageDbOpt pkgDb | pkgDb <- dbStack ] ++
[ "--package-name", display pkgid ] ++
concat [ ["--package-id", display ipkgid ]
......
......@@ -143,7 +143,8 @@ constructJHCCmdLine lbi bi clbi _odir verbosity =
++ extensionsToFlags (compiler lbi) (usedExtensions bi)
++ ["--noauto","-i-"]
++ concat [["-i", l] | l <- nub (hsSourceDirs bi)]
++ ["-i", autogenModulesDir lbi clbi]
++ ["-i", autogenComponentModulesDir lbi clbi]
++ ["-i", autogenPackageModulesDir lbi]
++ ["-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.
......
......@@ -578,12 +578,14 @@ ghcOptions lbi bi clbi odir
++ ["-i"]
++ ["-i" ++ odir]
++ ["-i" ++ l | l <- nub (hsSourceDirs bi)]
++ ["-i" ++ autogenModulesDir lbi clbi]
++ ["-I" ++ autogenModulesDir lbi clbi]
++ ["-i" ++ autogenComponentModulesDir lbi clbi]
++ ["-i" ++ autogenPackageModulesDir lbi]
++ ["-I" ++ autogenComponentModulesDir lbi clbi]
++ ["-I" ++ autogenPackageModulesDir lbi]
++ ["-I" ++ odir]
++ ["-I" ++ dir | dir <- PD.includeDirs bi]
++ ["-optP" ++ opt | opt <- cppOptions bi]
++ [ "-optP-include", "-optP"++ (autogenModulesDir lbi clbi </> cppHeaderName) ]
++ [ "-optP-include", "-optP"++ (autogenComponentModulesDir lbi clbi </> cppHeaderName) ]
++ [ "-#include \"" ++ inc ++ "\"" | inc <- PD.includes bi ]
++ [ "-odir", odir, "-hidir", odir ]
++ (if compilerVersion c >= Version [6,8] []
......
......@@ -146,13 +146,15 @@ preprocessComponent :: PackageDescription
-> IO ()
preprocessComponent pd comp lbi clbi isSrcDist verbosity handlers = case comp of
(CLib lib@Library{ libBuildInfo = bi }) -> do
let dirs = hsSourceDirs bi ++ [autogenModulesDir lbi clbi]
let dirs = hsSourceDirs bi ++ [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi]
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 clbi]
dirs = hsSourceDirs bi ++ [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi]
setupMessage verbosity ("Preprocessing executable '" ++ nm ++ "' for") (packageId pd)
forM_ (map ModuleName.toFilePath $ otherModules bi) $
pre dirs exeDir (localHandlers bi)
......@@ -192,7 +194,8 @@ preprocessComponent pd comp lbi clbi isSrcDist verbosity handlers = case comp of
(benchmarkModules bm)
preProcessComponent bi modules exePath dir = do
let biHandlers = localHandlers bi
sourceDirs = hsSourceDirs bi ++ [ autogenModulesDir lbi clbi ]
sourceDirs = hsSourceDirs bi ++ [ autogenComponentModulesDir lbi clbi
, autogenPackageModulesDir lbi ]
sequence_ [ preprocessFile sourceDirs dir isSrcDist
(ModuleName.toFilePath modu) verbosity builtinSuffixes
biHandlers
......@@ -343,7 +346,7 @@ ppGhcCpp program xHs extraArgs _bi lbi clbi =
-- 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 clbi </> cppHeaderName) ]
++ [ "-optP-include", "-optP"++ (autogenComponentModulesDir lbi clbi </> cppHeaderName) ]
++ ["-o", outFile, inFile]
++ extraArgs
}
......@@ -359,7 +362,7 @@ ppCpphs extraArgs _bi lbi clbi =
("-O" ++ outFile) : inFile
: "--noline" : "--strip"
: (if cpphsVersion >= Version [1,6] []
then ["--include="++ (autogenModulesDir lbi clbi </> cppHeaderName)]
then ["--include="++ (autogenComponentModulesDir lbi clbi </> cppHeaderName)]
else [])
++ extraArgs
}
......@@ -402,8 +405,9 @@ ppHsc2hs bi lbi clbi =
++ [ "--cflag=" ++ opt | opt <- PD.ccOptions bi
++ PD.cppOptions bi ]
++ [ "--cflag=" ++ opt | opt <-
[ "-I" ++ autogenModulesDir lbi clbi,
"-include", autogenModulesDir lbi clbi </> cppHeaderName ] ]
[ "-I" ++ autogenComponentModulesDir lbi clbi,
"-I" ++ autogenPackageModulesDir lbi,
"-include", autogenComponentModulesDir lbi clbi </> cppHeaderName ] ]
++ [ "--lflag=-L" ++ opt | opt <- PD.extraLibDirs bi ]
++ [ "--lflag=-Wl,-R," ++ opt | isELF
, opt <- PD.extraLibDirs bi ]
......@@ -467,7 +471,7 @@ ppC2hs bi lbi clbi =
-- Options from the current package:
[ "--cpp=" ++ programPath gccProg, "--cppopts=-E" ]
++ [ "--cppopts=" ++ opt | opt <- getCppOptions bi lbi ]
++ [ "--cppopts=-include" ++ (autogenModulesDir lbi clbi </> cppHeaderName) ]
++ [ "--cppopts=-include" ++ (autogenComponentModulesDir lbi clbi </> cppHeaderName) ]
++ [ "--include=" ++ outBaseDir ]
-- Options from dependent packages
......
......@@ -223,7 +223,8 @@ constructUHCCmdLine user system lbi bi clbi odir verbosity =
-- search paths
++ ["-i" ++ odir]
++ ["-i" ++ l | l <- nub (hsSourceDirs bi)]
++ ["-i" ++ autogenModulesDir lbi clbi]
++ ["-i" ++ autogenComponentModulesDir lbi clbi]
++ ["-i" ++ autogenPackageModulesDir lbi]
-- cpp options
++ ["--optP=" ++ opt | opt <- cppOptions bi]
-- output path
......
......@@ -19,7 +19,8 @@
only the macros for the library, and is not generated if a
package has no library; to find the macros for an executable
named 'foobar', look in 'dist/build/foobar/autogen/cabal_macros.h'.
Similarly, 'autogenModulesDir' now requires a
Similarly, if you used 'autogenModulesDir' you should now
use 'autogenComponentModulesDir', which now requires a
'ComponentLocalBuildInfo' argument as well in order to
disambiguate which component the autogenerated files are for.
* Backwards incompatible change to 'Component': 'TestSuite' and
......
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