-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
basedir #4874
Merged
Merged
basedir #4874
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d88dd9
Adds tryGetBuildInfo
angerman af49513
Read basedir from cabal-file, and thread it through apropriately.
angerman 3a9830b
Check for duplicate files generated by `configure` and shipped with t…
angerman 767efff
Cleanup directory compat
angerman 3ebb984
Move compat bits for 'directory' to D.Compat.Directory.
23Skidoo f69ef8d
Comments only.
23Skidoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,14 +100,31 @@ import System.Environment (getArgs, getProgName) | |
import System.Directory (removeFile, doesFileExist | ||
,doesDirectoryExist, removeDirectoryRecursive) | ||
import System.Exit (exitWith,ExitCode(..)) | ||
import System.FilePath (searchPathSeparator) | ||
import System.FilePath (searchPathSeparator, takeDirectory, (</>)) | ||
import Distribution.Compat.Environment (getEnvironment) | ||
import Distribution.Compat.GetShortPathName (getShortPathName) | ||
|
||
import Data.List (unionBy, (\\)) | ||
|
||
import Distribution.PackageDescription.Parsec | ||
|
||
#if MIN_VERSION_directory(1,2,2) | ||
import System.Directory | ||
(makeAbsolute) | ||
#else | ||
import System.Directory | ||
(getCurrentDirectory) | ||
import System.FilePath | ||
(isAbsolute) | ||
|
||
makeAbsolute :: FilePath -> IO FilePath | ||
makeAbsolute p | isAbsolute p = return p | ||
| otherwise = do | ||
cwd <- getCurrentDirectory | ||
return $ cwd </> p | ||
#endif | ||
|
||
|
||
-- | A simple implementation of @main@ for a Cabal setup script. | ||
-- It reads the package description file using IO, and performs the | ||
-- action specified on the command line. | ||
|
@@ -249,9 +266,10 @@ buildAction :: UserHooks -> BuildFlags -> Args -> IO () | |
buildAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (buildDistPref flags) | ||
let verbosity = fromFlag $ buildVerbosity flags | ||
flags' = flags { buildDistPref = toFlag distPref } | ||
|
||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { buildDistPref = toFlag distPref | ||
, buildCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
|
||
progs <- reconfigurePrograms verbosity | ||
(buildProgramPaths flags') | ||
(buildProgramArgs flags') | ||
|
@@ -289,7 +307,10 @@ hscolourAction :: UserHooks -> HscolourFlags -> Args -> IO () | |
hscolourAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (hscolourDistPref flags) | ||
let verbosity = fromFlag $ hscolourVerbosity flags | ||
flags' = flags { hscolourDistPref = toFlag distPref } | ||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { hscolourDistPref = toFlag distPref | ||
, hscolourCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
|
||
hookedAction preHscolour hscolourHook postHscolour | ||
(getBuildConfig hooks verbosity distPref) | ||
hooks flags' args | ||
|
@@ -314,9 +335,10 @@ haddockAction :: UserHooks -> HaddockFlags -> Args -> IO () | |
haddockAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (haddockDistPref flags) | ||
let verbosity = fromFlag $ haddockVerbosity flags | ||
flags' = flags { haddockDistPref = toFlag distPref } | ||
|
||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { haddockDistPref = toFlag distPref | ||
, haddockCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
|
||
progs <- reconfigurePrograms verbosity | ||
(haddockProgramPaths flags') | ||
(haddockProgramArgs flags') | ||
|
@@ -360,7 +382,9 @@ copyAction :: UserHooks -> CopyFlags -> Args -> IO () | |
copyAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (copyDistPref flags) | ||
let verbosity = fromFlag $ copyVerbosity flags | ||
flags' = flags { copyDistPref = toFlag distPref } | ||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { copyDistPref = toFlag distPref | ||
, copyCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
hookedAction preCopy copyHook postCopy | ||
(getBuildConfig hooks verbosity distPref) | ||
hooks flags' { copyArgs = args } args | ||
|
@@ -369,7 +393,9 @@ installAction :: UserHooks -> InstallFlags -> Args -> IO () | |
installAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (installDistPref flags) | ||
let verbosity = fromFlag $ installVerbosity flags | ||
flags' = flags { installDistPref = toFlag distPref } | ||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { installDistPref = toFlag distPref | ||
, installCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
hookedAction preInst instHook postInst | ||
(getBuildConfig hooks verbosity distPref) | ||
hooks flags' args | ||
|
@@ -433,7 +459,9 @@ registerAction :: UserHooks -> RegisterFlags -> Args -> IO () | |
registerAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (regDistPref flags) | ||
let verbosity = fromFlag $ regVerbosity flags | ||
flags' = flags { regDistPref = toFlag distPref } | ||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { regDistPref = toFlag distPref | ||
, regCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
hookedAction preReg regHook postReg | ||
(getBuildConfig hooks verbosity distPref) | ||
hooks flags' { regArgs = args } args | ||
|
@@ -442,7 +470,9 @@ unregisterAction :: UserHooks -> RegisterFlags -> Args -> IO () | |
unregisterAction hooks flags args = do | ||
distPref <- findDistPrefOrDefault (regDistPref flags) | ||
let verbosity = fromFlag $ regVerbosity flags | ||
flags' = flags { regDistPref = toFlag distPref } | ||
lbi <- getBuildConfig hooks verbosity distPref | ||
let flags' = flags { regDistPref = toFlag distPref | ||
, regCabalFilePath = maybeToFlag (cabalFilePath lbi)} | ||
hookedAction preUnreg unregHook postUnreg | ||
(getBuildConfig hooks verbosity distPref) | ||
hooks flags' args | ||
|
@@ -630,12 +660,14 @@ defaultUserHooks = autoconfUserHooks { | |
-- https://github.com/haskell/cabal/issues/158 | ||
where oldCompatPostConf args flags pkg_descr lbi | ||
= do let verbosity = fromFlag (configVerbosity flags) | ||
confExists <- doesFileExist "configure" | ||
baseDir lbi' = fromMaybe "" (takeDirectory <$> cabalFilePath lbi') | ||
|
||
confExists <- doesFileExist $ (baseDir lbi) </> "configure" | ||
when confExists $ | ||
runConfigureScript verbosity | ||
backwardsCompatHack flags lbi | ||
|
||
pbi <- getHookedBuildInfo verbosity | ||
pbi <- getHookedBuildInfo (buildDir lbi) verbosity | ||
sanityCheckHookedBuildInfo pkg_descr pbi | ||
let pkg_descr' = updatePackageDescription pbi pkg_descr | ||
lbi' = lbi { localPkgDescr = pkg_descr' } | ||
|
@@ -648,44 +680,51 @@ autoconfUserHooks | |
= simpleUserHooks | ||
{ | ||
postConf = defaultPostConf, | ||
preBuild = readHookWithArgs buildVerbosity, | ||
preCopy = readHookWithArgs copyVerbosity, | ||
preClean = readHook cleanVerbosity, | ||
preInst = readHook installVerbosity, | ||
preHscolour = readHook hscolourVerbosity, | ||
preHaddock = readHook haddockVerbosity, | ||
preReg = readHook regVerbosity, | ||
preUnreg = readHook regVerbosity | ||
preBuild = readHookWithArgs buildVerbosity buildDistPref, -- buildCabalFilePath, | ||
preCopy = readHookWithArgs copyVerbosity copyDistPref, | ||
preClean = readHook cleanVerbosity cleanDistPref, | ||
preInst = readHook installVerbosity installDistPref, | ||
preHscolour = readHook hscolourVerbosity hscolourDistPref, | ||
preHaddock = readHook haddockVerbosity haddockDistPref, | ||
preReg = readHook regVerbosity regDistPref, | ||
preUnreg = readHook regVerbosity regDistPref | ||
} | ||
where defaultPostConf :: Args -> ConfigFlags -> PackageDescription | ||
-> LocalBuildInfo -> IO () | ||
defaultPostConf args flags pkg_descr lbi | ||
= do let verbosity = fromFlag (configVerbosity flags) | ||
confExists <- doesFileExist "configure" | ||
baseDir lbi' = fromMaybe "" (takeDirectory <$> cabalFilePath lbi') | ||
confExists <- doesFileExist $ (baseDir lbi) </> "configure" | ||
if confExists | ||
then runConfigureScript verbosity | ||
backwardsCompatHack flags lbi | ||
else die "configure script not found." | ||
|
||
pbi <- getHookedBuildInfo verbosity | ||
pbi <- getHookedBuildInfo (buildDir lbi) verbosity | ||
sanityCheckHookedBuildInfo pkg_descr pbi | ||
let pkg_descr' = updatePackageDescription pbi pkg_descr | ||
lbi' = lbi { localPkgDescr = pkg_descr' } | ||
postConf simpleUserHooks args flags pkg_descr' lbi' | ||
|
||
backwardsCompatHack = False | ||
|
||
readHookWithArgs :: (a -> Flag Verbosity) -> Args -> a | ||
readHookWithArgs :: (a -> Flag Verbosity) | ||
-> (a -> Flag FilePath) | ||
-> Args -> a | ||
-> IO HookedBuildInfo | ||
readHookWithArgs get_verbosity _ flags = do | ||
getHookedBuildInfo verbosity | ||
readHookWithArgs get_verbosity get_dist_pref _ flags = do | ||
dist_dir <- findDistPrefOrDefault (get_dist_pref flags) | ||
getHookedBuildInfo (dist_dir </> "build") verbosity | ||
where | ||
verbosity = fromFlag (get_verbosity flags) | ||
|
||
readHook :: (a -> Flag Verbosity) -> Args -> a -> IO HookedBuildInfo | ||
readHook get_verbosity a flags = do | ||
readHook :: (a -> Flag Verbosity) | ||
-> (a -> Flag FilePath) | ||
-> Args -> a -> IO HookedBuildInfo | ||
readHook get_verbosity get_dist_pref a flags = do | ||
noExtraFlags a | ||
getHookedBuildInfo verbosity | ||
dist_dir <- findDistPrefOrDefault (get_dist_pref flags) | ||
getHookedBuildInfo (dist_dir </> "build") verbosity | ||
where | ||
verbosity = fromFlag (get_verbosity flags) | ||
|
||
|
@@ -702,6 +741,8 @@ runConfigureScript verbosity backwardsCompatHack flags lbi = do | |
-- to ccFlags | ||
-- We don't try and tell configure which ld to use, as we don't have | ||
-- a way to pass its flags too | ||
configureFile <- makeAbsolute $ | ||
fromMaybe "." (takeDirectory <$> cabalFilePath lbi) </> "configure" | ||
let extraPath = fromNubList $ configProgramPathExtra flags | ||
let cflagsEnv = maybe (unwords ccFlags) (++ (" " ++ unwords ccFlags)) | ||
$ lookup "CFLAGS" env | ||
|
@@ -710,29 +751,30 @@ runConfigureScript verbosity backwardsCompatHack flags lbi = do | |
((intercalate spSep extraPath ++ spSep)++) $ lookup "PATH" env | ||
overEnv = ("CFLAGS", Just cflagsEnv) : | ||
[("PATH", Just pathEnv) | not (null extraPath)] | ||
args' = args ++ ["CC=" ++ ccProgShort] | ||
args' = configureFile:args ++ ["CC=" ++ ccProgShort] | ||
shProg = simpleProgram "sh" | ||
progDb = modifyProgramSearchPath | ||
(\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb | ||
shConfiguredProg <- lookupProgram shProg | ||
`fmap` configureProgram verbosity shProg progDb | ||
case shConfiguredProg of | ||
Just sh -> runProgramInvocation verbosity | ||
Just sh -> runProgramInvocation verbosity $ | ||
(programInvocation (sh {programOverrideEnv = overEnv}) args') | ||
{ progInvokeCwd = Just (buildDir lbi) } | ||
Nothing -> die notFoundMsg | ||
|
||
where | ||
args = "./configure" : configureArgs backwardsCompatHack flags | ||
args = configureArgs backwardsCompatHack flags | ||
|
||
notFoundMsg = "The package has a './configure' script. " | ||
++ "If you are on Windows, This requires a " | ||
++ "Unix compatibility toolchain such as MinGW+MSYS or Cygwin. " | ||
++ "If you are not on Windows, ensure that an 'sh' command " | ||
++ "is discoverable in your path." | ||
|
||
getHookedBuildInfo :: Verbosity -> IO HookedBuildInfo | ||
getHookedBuildInfo verbosity = do | ||
maybe_infoFile <- defaultHookedPackageDesc | ||
getHookedBuildInfo :: FilePath -> Verbosity -> IO HookedBuildInfo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should mention in the changelog/migration guide that this function has changed type. |
||
getHookedBuildInfo build_dir verbosity = do | ||
maybe_infoFile <- findHookedPackageDesc build_dir | ||
case maybe_infoFile of | ||
Nothing -> return emptyHookedBuildInfo | ||
Just infoFile -> do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,8 +107,8 @@ configureToolchain _implInfo ghcProg ghcInfo = | |
} | ||
where | ||
compilerDir = takeDirectory (programPath ghcProg) | ||
baseDir = takeDirectory compilerDir | ||
mingwBinDir = baseDir </> "mingw" </> "bin" | ||
base_dir = takeDirectory compilerDir | ||
mingwBinDir = base_dir </> "mingw" </> "bin" | ||
isWindows = case buildOS of Windows -> True; _ -> False | ||
binPrefix = "" | ||
|
||
|
@@ -276,7 +276,11 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename = | |
ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi clbi | ||
,autogenPackageModulesDir lbi | ||
,odir] | ||
++ PD.includeDirs bi, | ||
-- includes relative to the package | ||
++ PD.includeDirs bi | ||
-- potential includes generated by `configure' | ||
-- in the build directory | ||
++ [buildDir lbi </> dir | dir <- PD.includeDirs bi], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you need to filter out absolute paths here as well? |
||
ghcOptHideAllPackages= toFlag True, | ||
ghcOptPackageDBs = withPackageDB lbi, | ||
ghcOptPackages = toNubListR $ mkGhcOptPackages clbi, | ||
|
@@ -309,7 +313,11 @@ componentCxxGhcOptions verbosity _implInfo lbi bi cxxlbi odir filename = | |
ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi cxxlbi | ||
,autogenPackageModulesDir lbi | ||
,odir] | ||
++ PD.includeDirs bi, | ||
-- includes relative to the package | ||
++ PD.includeDirs bi | ||
-- potential includes generated by `configure' | ||
-- in the build directory | ||
++ [buildDir lbi </> dir | dir <- PD.includeDirs bi], | ||
ghcOptHideAllPackages= toFlag True, | ||
ghcOptPackageDBs = withPackageDB lbi, | ||
ghcOptPackages = toNubListR $ mkGhcOptPackages cxxlbi, | ||
|
@@ -365,7 +373,11 @@ componentGhcOptions verbosity implInfo lbi bi clbi odir = | |
ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi clbi | ||
,autogenPackageModulesDir lbi | ||
,odir] | ||
++ PD.includeDirs bi, | ||
-- includes relative to the package | ||
++ PD.includeDirs bi | ||
-- potential includes generated by `configure' | ||
-- in the build directory | ||
++ [buildDir lbi </> dir | dir <- PD.includeDirs bi], | ||
ghcOptCppOptions = toNubListR $ cppOptions bi, | ||
ghcOptCppIncludes = toNubListR $ | ||
[autogenComponentModulesDir lbi clbi </> cppHeaderName], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally keen on the fact that we're hardcoding
"build"
everywhere. This works withnew-build
directory structure, right?