Skip to content

Commit 91d07f1

Browse files
authored
Merge pull request #3553 from ezyang/configure-cabal-file
Implement --cabal-file, allows multiple Cabal files in directory
2 parents e95266f + e507ca8 commit 91d07f1

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
@@ -1563,7 +1563,13 @@ checkCabalFileBOM :: Monad m => CheckPackageContentOps m
15631563
checkCabalFileBOM ops = do
15641564
epdfile <- findPackageDesc ops
15651565
case epdfile of
1566-
Left pc -> return $ Just pc
1566+
-- MASSIVE HACK. If the Cabal file doesn't exist, that is
1567+
-- a very strange situation to be in, because the driver code
1568+
-- in 'Distribution.Setup' ought to have noticed already!
1569+
-- But this can be an issue, see #3552 and also when
1570+
-- --cabal-file is specified. So if you can't find the file,
1571+
-- just don't bother with this check.
1572+
Left _ -> return $ Nothing
15671573
Right pdfile -> (flip check pc . startsWithBOM . fromUTF8)
15681574
`liftM` (getFileContents ops pdfile)
15691575
where pc = PackageDistInexcusable $
@@ -1597,7 +1603,7 @@ findPackageDesc ops
15971603
++ "Please create a package description file <pkgname>.cabal"
15981604

15991605
multiDesc :: [String] -> String
1600-
multiDesc l = "Multiple cabal files found.\n"
1606+
multiDesc l = "Multiple cabal files found while checking.\n"
16011607
++ "Please use only one of: "
16021608
++ intercalate ", " l
16031609

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
@@ -452,6 +453,7 @@ defaultConfigFlags progConf = emptyConfigFlags {
452453
configProgPrefix = Flag (toPathTemplate ""),
453454
configProgSuffix = Flag (toPathTemplate ""),
454455
configDistPref = NoFlag,
456+
configCabalFilePath = NoFlag,
455457
configVerbosity = Flag normal,
456458
configUserInstall = Flag False, --TODO: reverse this
457459
#if defined(mingw32_HOST_OS)
@@ -518,6 +520,11 @@ configureOptions showOrParseArgs =
518520
, (Flag (HaskellSuite "haskell-suite"), ([] , ["haskell-suite"]),
519521
"compile with a haskell-suite compiler")])
520522

523+
,option "" ["cabal-file"]
524+
"use this Cabal file"
525+
configCabalFilePath (\v flags -> flags { configCabalFilePath = v })
526+
(reqArgFlag "PATH")
527+
521528
,option "w" ["with-compiler"]
522529
"give the path to a particular compiler"
523530
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
@@ -554,6 +554,7 @@ convertToLegacyAllPackageConfig
554554
configInstallDirs = mempty,
555555
configScratchDir = mempty,
556556
configDistPref = mempty,
557+
configCabalFilePath = mempty,
557558
configVerbosity = mempty,
558559
configUserInstall = mempty, --projectConfigUserInstall,
559560
configPackageDBs = mempty, --projectConfigPackageDBs,
@@ -616,6 +617,7 @@ convertToLegacyPerPackageConfig PackageConfig {..} =
616617
configInstallDirs = mempty,
617618
configScratchDir = mempty,
618619
configDistPref = mempty,
620+
configCabalFilePath = mempty,
619621
configVerbosity = mempty,
620622
configUserInstall = mempty,
621623
configPackageDBs = mempty,

cabal-install/Distribution/Client/ProjectPlanning.hs

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

19521953
configIPID = toFlag (display (installedUnitId pkg))

0 commit comments

Comments
 (0)