Skip to content

Commit

Permalink
Implement --cabal-file, allows multiple Cabal files in directory
Browse files Browse the repository at this point in the history
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: Edward Z. Yang <ezyang@cs.stanford.edu>
  • Loading branch information
ezyang committed Jul 24, 2016
1 parent e95266f commit e507ca8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
10 changes: 8 additions & 2 deletions Cabal/Distribution/PackageDescription/Check.hs
Expand Up @@ -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 $
Expand Down Expand Up @@ -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

Expand Down
24 changes: 19 additions & 5 deletions Cabal/Distribution/Simple.hs
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Cabal/Distribution/Simple/Setup.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 })
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/Config.hs
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/Distribution/Client/ProjectConfig/Legacy.hs
Expand Up @@ -554,6 +554,7 @@ convertToLegacyAllPackageConfig
configInstallDirs = mempty,
configScratchDir = mempty,
configDistPref = mempty,
configCabalFilePath = mempty,
configVerbosity = mempty,
configUserInstall = mempty, --projectConfigUserInstall,
configPackageDBs = mempty, --projectConfigPackageDBs,
Expand Down Expand Up @@ -616,6 +617,7 @@ convertToLegacyPerPackageConfig PackageConfig {..} =
configInstallDirs = mempty,
configScratchDir = mempty,
configDistPref = mempty,
configCabalFilePath = mempty,
configVerbosity = mempty,
configUserInstall = mempty,
configPackageDBs = mempty,
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Expand Up @@ -1947,6 +1947,7 @@ setupHsConfigureFlags (ReadyPackage
(Cabal.ConfigFlags {..})
where
configDistPref = toFlag builddir
configCabalFilePath = mempty
configVerbosity = toFlag verbosity

configIPID = toFlag (display (installedUnitId pkg))
Expand Down

0 comments on commit e507ca8

Please sign in to comment.