Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions Cabal/src/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Distribution.Simple.BuildPaths
, haddockPref
, autogenPackageModulesDir
, autogenComponentModulesDir
, includeSearchDirs
, preBuildRulesCacheFile
, autogenPathsModuleName
, autogenPackageInfoModuleName
Expand Down Expand Up @@ -156,6 +157,44 @@ autogenPackageModulesDir lbi = buildDir lbi </> makeRelativePathEx "global-autog
autogenComponentModulesDir :: LocalBuildInfo -> ComponentLocalBuildInfo -> SymbolicPath Pkg (Dir Source)
autogenComponentModulesDir lbi clbi = componentBuildDir lbi clbi </> makeRelativePathEx "autogen"

-- | The directories in which to look for a header file named in @includes@ or
-- @install-includes@.
--
-- Searched directories:
--
-- - the package root
-- - the component build directory (if any)
-- - the include directories, with relative ones being interpreted relative to:
-- - the package root,
-- - the package build directory,
-- - the component build directory (if any)
includeSearchDirs
:: LocalBuildInfo
-> Maybe ComponentLocalBuildInfo
-- ^ the component being built (if any)
-> [SymbolicPath Pkg (Dir Include)]
-- ^ @include-dirs@
-> [SymbolicPath Pkg (Dir Include)]
includeSearchDirs lbi mbClbi incDirs =
ordNub $
(sameDirectory : incDirs)
++ [ componentRoot </> dir
| componentRoot <- maybeToList mbComponentRoot
, dir <- sameDirectory : relIncDirs
]
++ [ packageBuildRoot </> dir
| dir <- relIncDirs
]
where
relIncDirs :: [RelativePath Pkg (Dir Include)]
relIncDirs = mapMaybe symbolicPathRelative_maybe incDirs

packageBuildRoot :: SymbolicPath Pkg (Dir Pkg)
packageBuildRoot = coerceSymbolicPath (buildDir lbi)

mbComponentRoot :: Maybe (SymbolicPath Pkg (Dir Pkg))
mbComponentRoot = coerceSymbolicPath . componentBuildDir lbi <$> mbClbi

-- | The path to the pre-build rules cache file for a component, used to
-- compute rule staleness across runs.
preBuildRulesCacheFile
Expand Down Expand Up @@ -249,7 +288,7 @@ getExeSourceFiles
-> IO [(ModuleName.ModuleName, SymbolicPath Pkg 'File)]
getExeSourceFiles verbosity lbi exe clbi = do
moduleFiles <- getSourceFiles verbosity mbWorkDir searchpaths modules
srcMainPath <- findFileCwd verbosity mbWorkDir (hsSourceDirs bi) (modulePath exe)
srcMainPath <- findFileCwd verbosity FindHaskellSourceFile mbWorkDir (hsSourceDirs bi) (modulePath exe)
return ((ModuleName.main, srcMainPath) : moduleFiles)
where
mbWorkDir = mbWorkDirLBI lbi
Expand All @@ -269,7 +308,7 @@ getTestSourceFiles
-> IO [(ModuleName.ModuleName, SymbolicPath Pkg 'File)]
getTestSourceFiles verbosity lbi test@TestSuite{testInterface = TestSuiteExeV10 _ path} clbi = do
moduleFiles <- getSourceFiles verbosity mbWorkDir searchpaths modules
srcMainPath <- findFileCwd verbosity mbWorkDir (hsSourceDirs bi) path
srcMainPath <- findFileCwd verbosity FindHaskellSourceFile mbWorkDir (hsSourceDirs bi) path
return ((ModuleName.main, srcMainPath) : moduleFiles)
where
mbWorkDir = mbWorkDirLBI lbi
Expand All @@ -290,7 +329,7 @@ getBenchmarkSourceFiles
-> IO [(ModuleName.ModuleName, SymbolicPath Pkg 'File)]
getBenchmarkSourceFiles verbosity lbi bench@Benchmark{benchmarkInterface = BenchmarkExeV10 _ path} clbi = do
moduleFiles <- getSourceFiles verbosity mbWorkDir searchpaths modules
srcMainPath <- findFileCwd verbosity mbWorkDir (hsSourceDirs bi) path
srcMainPath <- findFileCwd verbosity FindHaskellSourceFile mbWorkDir (hsSourceDirs bi) path
return ((ModuleName.main, srcMainPath) : moduleFiles)
where
mbWorkDir = mbWorkDirLBI lbi
Expand Down
33 changes: 12 additions & 21 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import Distribution.PackageDescription
import Distribution.PackageDescription.Check hiding (doesFileExist, listDirectory)
import Distribution.PackageDescription.Configuration
import Distribution.PackageDescription.PrettyPrint
import Distribution.Simple.BuildPaths (includeSearchDirs)
import Distribution.Simple.BuildTarget
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.BuildWay
Expand Down Expand Up @@ -1371,12 +1372,15 @@ finalCheckPackage
do
let common = configCommonFlags cfg
verbosity = mkVerbosity verbHandles (fromFlag $ setupVerbosity common)
cabalFileDir = packageRoot common
pkgRoot =
interpretSymbolicPath
(flagToMaybe $ setupWorkingDir common)
(sameDirectory :: SymbolicPath Pkg (Dir Pkg))

checkCompilerProblems verbosity comp pkg_descr enabled
checkPackageProblems
verbosity
cabalFileDir
pkgRoot
g_pkg_descr
(updatePackageDescription hookedBuildInfo pkg_descr)
-- NB: we apply the HookedBuildInfo to check it is valid,
Expand Down Expand Up @@ -2777,14 +2781,14 @@ checkForeignDeps pkg lbi verbosity =
<$> listDirectory (i (buildDir lbi) </> dir) `catchIO` (\_ -> return [])
srcHeaders <- for relIncDirs $ \dir ->
fmap (dir </>) . filter isHeader
<$> listDirectory (baseDir </> dir) `catchIO` (\_ -> return [])
<$> listDirectory (pkgRoot </> dir) `catchIO` (\_ -> return [])
let commonHeaders = concat genHeaders `intersect` concat srcHeaders
for_ commonHeaders $ \hdr -> do
warn verbosity $
"Duplicate header found in "
++ (getSymbolicPath (buildDir lbi) </> hdr)
++ " and "
++ (baseDir </> hdr)
++ (pkgRoot </> hdr)
++ ". Which one the C compiler will use is unspecified."

findOffendingHdr =
Expand Down Expand Up @@ -2820,12 +2824,10 @@ checkForeignDeps pkg lbi verbosity =

libExists lib = builds (makeProgram []) (makeLdArgs [lib])

common = configCommonFlags $ configFlags lbi
baseDir = packageRoot common

-- See Note [Symbolic paths] in Distribution.Utils.Path
i = interpretSymbolicPathLBI lbi
mbWorkDir = mbWorkDirLBI lbi
pkgRoot = i (sameDirectory :: SymbolicPath Pkg (Dir Pkg))

commonCppArgs =
platformDefines lbi
Expand All @@ -2834,20 +2836,9 @@ checkForeignDeps pkg lbi verbosity =
-- PER-component (c.f. the "I'm Feeling Lucky"; we
-- should NOT be glomming everything together.)
++ ["-I" ++ i (buildDir lbi </> makeRelativePathEx "autogen")]
-- `configure' may generate headers in the build directory
++ [ "-I" ++ i (buildDir lbi </> unsafeCoerceSymbolicPath dir)
| dir <- mapMaybe symbolicPathRelative_maybe $ ordNub (collectField includeDirs)
]
-- we might also reference headers from the
-- packages directory.
++ [ "-I" ++ baseDir </> getSymbolicPath dir
| dir <- mapMaybe symbolicPathRelative_maybe $ ordNub (collectField includeDirs)
]
++ [ "-I" ++ dir
| dir <- ordNub (collectField (fmap getSymbolicPath . includeDirs))
, isAbsolute dir
++ [ "-I" ++ i dir
| dir <- includeSearchDirs lbi Nothing $ ordNub (collectField includeDirs)
]
++ ["-I" ++ baseDir]
++ collectField cppOptions
++ collectField ccOptions
++ [ "-I" ++ dir
Expand Down Expand Up @@ -2937,7 +2928,7 @@ checkForeignDeps pkg lbi verbosity =
checkPackageProblems
:: Verbosity
-> FilePath
-- ^ Path to the @.cabal@ file's directory
-- ^ Path to the package root
-> GenericPackageDescription
-> PackageDescription
-> IO ()
Expand Down
5 changes: 3 additions & 2 deletions Cabal/src/Distribution/Simple/ConfigureScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Distribution.PackageDescription
import Distribution.Pretty
import Distribution.Simple.Configure (findDistPrefOrDefault)
import Distribution.Simple.Errors
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Simple.Program.Db
import Distribution.Simple.Setup.Common
Expand Down Expand Up @@ -59,7 +58,9 @@ runConfigureScript verbHandles cfg flags programDb hp = do
dist_dir <- findDistPrefOrDefault $ setupDistPref commonCfg
let build_dir = dist_dir </> makeRelativePathEx "build"
mbWorkDir = flagToMaybe $ setupWorkingDir commonCfg
configureScriptPath = packageRoot commonCfg </> "configure"
configureScriptPath =
interpretSymbolicPath mbWorkDir $
makeRelativePathEx @Pkg "configure"
confExists <- doesFileExist configureScriptPath
unless confExists $
dieWithException verbosity (ConfigureScriptNotFound configureScriptPath)
Expand Down
35 changes: 27 additions & 8 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE LambdaCase #-}

-----------------------------------------------------------------------------

-- Module : Distribution.Simple.Errors
Expand All @@ -11,6 +13,7 @@
module Distribution.Simple.Errors
( CabalException (..)
, FailedDependency (..)
, WhatToFind (..)
, exceptionCode
, exceptionMessage
) where
Expand Down Expand Up @@ -49,10 +52,8 @@ data CabalException
| -- | @NoLibraryFound@ has been downgraded to a warning, and is therefore no longer emitted.
NoLibraryFound
| CompilerNotInstalled CompilerFlavor
| CantFindIncludeFile String [String]
| UnsupportedTestSuite String
| UnsupportedBenchMark String
| NoIncludeFileFound String [String]
| NoModuleFound ModuleName [Suffix]
| RegMultipleInstancePkg
| SuppressingChecksOnFile
Expand Down Expand Up @@ -148,7 +149,7 @@ data CabalException
| Couldn'tFindTestProgLibV09 FilePath
| TestCoverageSupportLibV09
| RawSystemStdout String
| FindFile FilePath
| FindFile WhatToFind FilePath [FilePath]
| FindModuleFileEx ModuleName [Suffix] [FilePath]
| MultipleFilesWithExtension String
| NoDesc
Expand All @@ -172,6 +173,20 @@ data CabalException
| StandaloneBytecodeNotSupportedYet
deriving (Show)

data WhatToFind
= FindIncludeFile
| FindHaskellSourceFile
| FindModuleDefFile
| FindOtherFile -- generic fallback
deriving (Show, Eq)

whatToFind :: WhatToFind -> String
whatToFind = \case
FindIncludeFile -> "include file"
FindHaskellSourceFile -> "Haskell source file"
FindModuleDefFile -> "module definition file"
FindOtherFile -> "file"

exceptionCode :: CabalException -> Int
exceptionCode e = case e of
NoBenchMarkProgram{} -> 1678
Expand All @@ -180,10 +195,10 @@ exceptionCode e = case e of
NoBenchMark{} -> 1654
NoLibraryFound -> 2546
CompilerNotInstalled{} -> 7465
CantFindIncludeFile{} -> 3876
-- Retired: CantFindIncludeFile{} -> 3876
UnsupportedTestSuite{} -> 3245
UnsupportedBenchMark{} -> 9123
NoIncludeFileFound{} -> 2987
-- Retired: NoIncludeFileFound{} -> 2987
NoModuleFound{} -> 6421
RegMultipleInstancePkg{} -> 3421
SuppressingChecksOnFile{} -> 5436
Expand Down Expand Up @@ -319,10 +334,8 @@ exceptionMessage e = case e of
NoBenchMark bmName -> "no such benchmark: " ++ bmName
NoLibraryFound -> "No executables and no library found. Nothing to do."
CompilerNotInstalled compilerFlavor -> "installing with " ++ prettyShow compilerFlavor ++ "is not implemented"
CantFindIncludeFile file sd -> "can't find include file " ++ file ++ " in any of the search dirs " ++ intercalate ", " sd
UnsupportedTestSuite test_type -> "Unsupported test suite type: " ++ test_type
UnsupportedBenchMark benchMarkType -> "Unsupported benchmark type: " ++ benchMarkType
NoIncludeFileFound f sd -> "can't find include file " ++ f ++ " in any of the search dirs " ++ intercalate ", " sd
NoModuleFound m suffixes ->
"Could not find module: "
++ prettyShow m
Expand Down Expand Up @@ -720,7 +733,13 @@ exceptionMessage e = case e of
++ "\". Did you build the package first?"
TestCoverageSupportLibV09 -> "Test coverage is only supported for packages with a library component."
RawSystemStdout errors -> errors
FindFile fileName -> fileName ++ " doesn't exist"
FindFile what fileName searchDirs ->
"Could not find "
++ whatToFind what
++ " "
++ fileName
++ " in any of the search dirs: "
++ intercalate ", " searchDirs
FindModuleFileEx mod_name extensions searchPath ->
"Could not find module: "
++ prettyShow mod_name
Expand Down
8 changes: 7 additions & 1 deletion Cabal/src/Distribution/Simple/GHC/Build/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Distribution.PackageDescription.Utils (cabalBug)
import Distribution.Simple.BuildPaths
import Distribution.Simple.BuildWay
import Distribution.Simple.Compiler
import Distribution.Simple.Errors (WhatToFind (..))
import qualified Distribution.Simple.GHC.Internal as Internal
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup.Common
Expand All @@ -40,7 +41,12 @@ findExecutableMain
-> IO (SymbolicPath Pkg File)
-- ^ The path to the main source file.
findExecutableMain verbosity mbWorkDir buildDir (bnfo, modPath) =
findFileCwd verbosity mbWorkDir (coerceSymbolicPath buildDir : hsSourceDirs bnfo) modPath
findFileCwd
verbosity
FindHaskellSourceFile
mbWorkDir
(coerceSymbolicPath buildDir : hsSourceDirs bnfo)
modPath

-- | Does this compiler support the @-dynamic-too@ option
supportsDynamicToo :: Compiler -> Bool
Expand Down
8 changes: 1 addition & 7 deletions Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,7 @@ includePaths lbi bi clbi odir =
, coerceSymbolicPath $ autogenPackageModulesDir lbi
, coerceSymbolicPath odir
]
-- includes relative to the package
++ includeDirs bi
-- potential includes generated by `configure'
-- in the build directory
++ [ buildDir lbi </> dir
| dir <- mapMaybe (symbolicPathRelative_maybe . unsafeCoerceSymbolicPath) $ includeDirs bi
]
++ includeSearchDirs lbi (Just clbi) (includeDirs bi)

data SplitSource = CcProgram | CxxProgram

Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/GHCJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ gbuildSources verbosity mbWorkDir pkgId specVer tmpDir bm =
where
exeSources :: Executable -> IO BuildSources
exeSources exe@Executable{buildInfo = bnfo, modulePath = modPath} = do
main <- findFileCwd verbosity mbWorkDir (tmpDir : hsSourceDirs bnfo) modPath
main <- findFileCwd verbosity FindHaskellSourceFile mbWorkDir (tmpDir : hsSourceDirs bnfo) modPath
let mainModName = fromMaybe ModuleName.main $ exeMainModuleName exe
otherModNames = exeModules exe
haskellMain = isHaskell (getSymbolicPath main)
Expand Down
Loading
Loading