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

Implement --cabal-file, allows multiple Cabal files in directory



This is primarily intended for use with the Cabal test suite (allowing
us to easily specify multiple Cabal packages for the same Haskell source
files), but maybe some end-users will find it useful as well.  If there
are multiple Cabal files in the current working directory, --cabal-file
(for configure) allows you to disambiguate which one to build with.

There's a big hack to handle the BOM check, as it is inconvenient to
plumb the flag value all the way to the check code.  Some bigger
refactoring needed, see #3552.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent e95266f3
......@@ -1563,7 +1563,13 @@ checkCabalFileBOM :: Monad m => CheckPackageContentOps m
checkCabalFileBOM ops = do
epdfile <- findPackageDesc ops
case epdfile of
Left pc -> return $ Just pc
-- MASSIVE HACK. If the Cabal file doesn't exist, that is
-- a very strange situation to be in, because the driver code
-- in 'Distribution.Setup' ought to have noticed already!
-- But this can be an issue, see #3552 and also when
-- --cabal-file is specified. So if you can't find the file,
-- just don't bother with this check.
Left _ -> return $ Nothing
Right pdfile -> (flip check pc . startsWithBOM . fromUTF8)
`liftM` (getFileContents ops pdfile)
where pc = PackageDistInexcusable $
......@@ -1597,7 +1603,7 @@ findPackageDesc ops
++ "Please create a package description file <pkgname>.cabal"
multiDesc :: [String] -> String
multiDesc l = "Multiple cabal files found.\n"
multiDesc l = "Multiple cabal files found while checking.\n"
++ "Please use only one of: "
++ intercalate ", " l
......
......@@ -192,6 +192,7 @@ configureAction hooks flags args = do
pbi <- preConf hooks args flags'
(mb_pd_file, pkg_descr0) <- confPkgDescr hooks verbosity
(flagToMaybe (configCabalFilePath flags))
let epkg_descr = (pkg_descr0, pbi)
......@@ -211,13 +212,15 @@ configureAction hooks flags args = do
where
verbosity = fromFlag (configVerbosity flags)
confPkgDescr :: UserHooks -> Verbosity -> IO (Maybe FilePath, GenericPackageDescription)
confPkgDescr hooks verbosity = do
confPkgDescr :: UserHooks -> Verbosity -> Maybe FilePath -> IO (Maybe FilePath, GenericPackageDescription)
confPkgDescr hooks verbosity mb_path = do
mdescr <- readDesc hooks
case mdescr of
Just descr -> return (Nothing, descr)
Nothing -> do
pdfile <- defaultPackageDesc verbosity
pdfile <- case mb_path of
Nothing -> defaultPackageDesc verbosity
Just path -> return path
descr <- readPackageDescription verbosity pdfile
return (Just pdfile, descr)
......@@ -293,7 +296,7 @@ cleanAction hooks flags args = do
pbi <- preClean hooks args flags'
(_, ppd) <- confPkgDescr hooks verbosity
(_, ppd) <- confPkgDescr hooks verbosity Nothing
-- It might seem like we are doing something clever here
-- but we're really not: if you look at the implementation
-- of 'clean' in the end all the package description is
......@@ -337,7 +340,18 @@ sdistAction hooks flags args = do
mlbi <- maybeGetPersistBuildConfig distPref
(_, ppd) <- confPkgDescr hooks verbosity
-- NB: It would be TOTALLY WRONG to use the 'PackageDescription'
-- store in the 'LocalBuildInfo' for the rest of @sdist@, because
-- that would result in only the files that would be built
-- according to the user's configure being packaged up.
-- In fact, it is not obvious why we need to read the
-- 'LocalBuildInfo' in the first place, except that we want
-- to do some architecture-independent preprocessing which
-- needs to be configured. This is totally awful, see
-- GH#130.
(_, ppd) <- confPkgDescr hooks verbosity Nothing
let pkg_descr0 = flattenPackageDescription ppd
sanityCheckHookedBuildInfo pkg_descr0 pbi
let pkg_descr = updatePackageDescription pbi pkg_descr0
......
......@@ -393,6 +393,7 @@ data ConfigFlags = ConfigFlags {
configIPID :: Flag String, -- ^ explicit IPID to be used
configDistPref :: Flag FilePath, -- ^"dist" prefix
configCabalFilePath :: Flag FilePath, -- ^ Cabal file to use
configVerbosity :: Flag Verbosity, -- ^verbosity level
configUserInstall :: Flag Bool, -- ^The --user\/--global flag
configPackageDBs :: [Maybe PackageDB], -- ^Which package DBs to use
......@@ -452,6 +453,7 @@ defaultConfigFlags progConf = emptyConfigFlags {
configProgPrefix = Flag (toPathTemplate ""),
configProgSuffix = Flag (toPathTemplate ""),
configDistPref = NoFlag,
configCabalFilePath = NoFlag,
configVerbosity = Flag normal,
configUserInstall = Flag False, --TODO: reverse this
#if defined(mingw32_HOST_OS)
......@@ -518,6 +520,11 @@ configureOptions showOrParseArgs =
, (Flag (HaskellSuite "haskell-suite"), ([] , ["haskell-suite"]),
"compile with a haskell-suite compiler")])
,option "" ["cabal-file"]
"use this Cabal file"
configCabalFilePath (\v flags -> flags { configCabalFilePath = v })
(reqArgFlag "PATH")
,option "w" ["with-compiler"]
"give the path to a particular compiler"
configHcPath (\v flags -> flags { configHcPath = v })
......
......@@ -302,6 +302,7 @@ instance Semigroup SavedConfig where
configExtraIncludeDirs = lastNonEmpty configExtraIncludeDirs,
configIPID = combine configIPID,
configDistPref = combine configDistPref,
configCabalFilePath = combine configCabalFilePath,
configVerbosity = combine configVerbosity,
configUserInstall = combine configUserInstall,
-- TODO: NubListify
......
......@@ -554,6 +554,7 @@ convertToLegacyAllPackageConfig
configInstallDirs = mempty,
configScratchDir = mempty,
configDistPref = mempty,
configCabalFilePath = mempty,
configVerbosity = mempty,
configUserInstall = mempty, --projectConfigUserInstall,
configPackageDBs = mempty, --projectConfigPackageDBs,
......@@ -616,6 +617,7 @@ convertToLegacyPerPackageConfig PackageConfig {..} =
configInstallDirs = mempty,
configScratchDir = mempty,
configDistPref = mempty,
configCabalFilePath = mempty,
configVerbosity = mempty,
configUserInstall = mempty,
configPackageDBs = mempty,
......
......@@ -1947,6 +1947,7 @@ setupHsConfigureFlags (ReadyPackage
(Cabal.ConfigFlags {..})
where
configDistPref = toFlag builddir
configCabalFilePath = mempty
configVerbosity = toFlag verbosity
configIPID = toFlag (display (installedUnitId pkg))
......
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