Skip to content

Commit 7bd4884

Browse files
committed
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 haskell#3552. Signed-off-by: Edward Z. Yang <[email protected]>
1 parent d357fc4 commit 7bd4884

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,13 @@ checkCabalFileBOM :: Monad m => CheckPackageContentOps m
15351535
checkCabalFileBOM ops = do
15361536
epdfile <- findPackageDesc ops
15371537
case epdfile of
1538-
Left pc -> return $ Just pc
1538+
-- MASSIVE HACK. If the Cabal file doesn't exist, that is
1539+
-- a very strange situation to be in, because the driver code
1540+
-- in 'Distribution.Setup' ought to have noticed already!
1541+
-- But this can be an issue, see #3552 and also when
1542+
-- --cabal-file is specified. So if you can't find the file,
1543+
-- just don't bother with this check.
1544+
Left _pc -> return $ Nothing
15391545
Right pdfile -> (flip check pc . startsWithBOM . fromUTF8) `liftM` (getFileContents ops pdfile)
15401546
where pc = PackageDistInexcusable $
15411547
pdfile ++ " starts with an Unicode byte order mark (BOM). This may cause problems with older cabal versions."
@@ -1566,7 +1572,7 @@ findPackageDesc ops
15661572
++ "Please create a package description file <pkgname>.cabal"
15671573

15681574
multiDesc :: [String] -> String
1569-
multiDesc l = "Multiple cabal files found.\n"
1575+
multiDesc l = "Multiple cabal files found while checking.\n"
15701576
++ "Please use only one of: "
15711577
++ intercalate ", " l
15721578

Cabal/Distribution/Simple.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ configureAction hooks flags args = do
192192
pbi <- preConf hooks args flags'
193193

194194
(mb_pd_file, pkg_descr0) <- confPkgDescr hooks verbosity
195+
(flagToMaybe (configCabalFilePath flags))
195196

196197
let epkg_descr = (pkg_descr0, pbi)
197198

@@ -211,13 +212,15 @@ configureAction hooks flags args = do
211212
where
212213
verbosity = fromFlag (configVerbosity flags)
213214

214-
confPkgDescr :: UserHooks -> Verbosity -> IO (Maybe FilePath, GenericPackageDescription)
215-
confPkgDescr hooks verbosity = do
215+
confPkgDescr :: UserHooks -> Verbosity -> Maybe FilePath -> IO (Maybe FilePath, GenericPackageDescription)
216+
confPkgDescr hooks verbosity mb_path = do
216217
mdescr <- readDesc hooks
217218
case mdescr of
218219
Just descr -> return (Nothing, descr)
219220
Nothing -> do
220-
pdfile <- defaultPackageDesc verbosity
221+
pdfile <- case mb_path of
222+
Nothing -> defaultPackageDesc verbosity
223+
Just path -> return path
221224
descr <- readPackageDescription verbosity pdfile
222225
return (Just pdfile, descr)
223226

@@ -293,7 +296,7 @@ cleanAction hooks flags args = do
293296

294297
pbi <- preClean hooks args flags'
295298

296-
(_, ppd) <- confPkgDescr hooks verbosity
299+
(_, ppd) <- confPkgDescr hooks verbosity Nothing
297300
-- It might seem like we are doing something clever here
298301
-- but we're really not: if you look at the implementation
299302
-- of 'clean' in the end all the package description is
@@ -337,7 +340,18 @@ sdistAction hooks flags args = do
337340

338341
mlbi <- maybeGetPersistBuildConfig distPref
339342

340-
(_, ppd) <- confPkgDescr hooks verbosity
343+
-- NB: It would be TOTALLY WRONG to use the 'PackageDescription'
344+
-- store in the 'LocalBuildInfo' for the rest of @sdist@, because
345+
-- that would result in only the files that would be built
346+
-- *according to the user's configure* being packaged up.
347+
-- In fact, it is not obvious why we need to read the
348+
-- 'LocalBuildInfo' in the first place, except that we want
349+
-- to do some architecture-independent preprocessing which
350+
-- needs to be configured. This is totally awful, see
351+
-- GH#130.
352+
353+
(_, ppd) <- confPkgDescr hooks verbosity Nothing
354+
341355
let pkg_descr0 = flattenPackageDescription ppd
342356
sanityCheckHookedBuildInfo pkg_descr0 pbi
343357
let pkg_descr = updatePackageDescription pbi pkg_descr0

Cabal/Distribution/Simple/Setup.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ data ConfigFlags = ConfigFlags {
393393
configIPID :: Flag String, -- ^ explicit IPID to be used
394394

395395
configDistPref :: Flag FilePath, -- ^"dist" prefix
396+
configCabalFilePath :: Flag FilePath, -- ^ Cabal file to use
396397
configVerbosity :: Flag Verbosity, -- ^verbosity level
397398
configUserInstall :: Flag Bool, -- ^The --user\/--global flag
398399
configPackageDBs :: [Maybe PackageDB], -- ^Which package DBs to use
@@ -451,6 +452,7 @@ defaultConfigFlags progConf = emptyConfigFlags {
451452
configProgPrefix = Flag (toPathTemplate ""),
452453
configProgSuffix = Flag (toPathTemplate ""),
453454
configDistPref = NoFlag,
455+
configCabalFilePath = NoFlag,
454456
configVerbosity = Flag normal,
455457
configUserInstall = Flag False, --TODO: reverse this
456458
#if defined(mingw32_HOST_OS)
@@ -517,6 +519,11 @@ configureOptions showOrParseArgs =
517519
, (Flag (HaskellSuite "haskell-suite"), ([] , ["haskell-suite"]),
518520
"compile with a haskell-suite compiler")])
519521

522+
,option "" ["cabal-file"]
523+
"use this Cabal file"
524+
configCabalFilePath (\v flags -> flags { configCabalFilePath = v })
525+
(reqArgFlag "PATH")
526+
520527
,option "w" ["with-compiler"]
521528
"give the path to a particular compiler"
522529
configHcPath (\v flags -> flags { configHcPath = v })

cabal-install/Distribution/Client/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ instance Semigroup SavedConfig where
302302
configExtraIncludeDirs = lastNonEmpty configExtraIncludeDirs,
303303
configIPID = combine configIPID,
304304
configDistPref = combine configDistPref,
305+
configCabalFilePath = combine configCabalFilePath,
305306
configVerbosity = combine configVerbosity,
306307
configUserInstall = combine configUserInstall,
307308
-- TODO: NubListify

cabal-install/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ convertToLegacyAllPackageConfig
552552
configInstallDirs = mempty,
553553
configScratchDir = mempty,
554554
configDistPref = mempty,
555+
configCabalFilePath = mempty,
555556
configVerbosity = mempty,
556557
configUserInstall = mempty, --projectConfigUserInstall,
557558
configPackageDBs = mempty, --projectConfigPackageDBs,
@@ -613,6 +614,7 @@ convertToLegacyPerPackageConfig PackageConfig {..} =
613614
configInstallDirs = mempty,
614615
configScratchDir = mempty,
615616
configDistPref = mempty,
617+
configCabalFilePath = mempty,
616618
configVerbosity = mempty,
617619
configUserInstall = mempty,
618620
configPackageDBs = mempty,

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,7 @@ setupHsConfigureFlags (ReadyPackage
19461946
(Cabal.ConfigFlags {..})
19471947
where
19481948
configDistPref = toFlag builddir
1949+
configCabalFilePath = mempty
19491950
configVerbosity = toFlag verbosity
19501951

19511952
configIPID = toFlag (display (installedUnitId pkg))

0 commit comments

Comments
 (0)