Commit b74c03f3 authored by Edward Z. Yang's avatar Edward Z. Yang

Add --project-file global flag, for the name of cabal.project files.

This is a global flag, so it can only be specified prior to the
subcommand.  It controls the name of the cabal.project file which
new-build and related commands looks for.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 4c7f9356
......@@ -31,9 +31,10 @@ configureCommand = Client.installCommand {
commandUsage = usageAlternatives "new-configure" [ "[FLAGS]" ],
commandDescription = Just $ \_ -> wrapText $
"Configures a Nix-local build project, downloading source from"
++ " the network and writing out a cabal.project.local file which"
++ " saves any FLAGS, to be reapplied on subsequent invocations to "
++ "new-build.",
++ " the network and writing out a cabal.project.local file"
++ " (or $project_file.local, if --project-file is specified)"
++ " which saves any FLAGS, to be reapplied on subsequent invocations to"
++ " new-build.",
commandNotes = Just $ \pname ->
"Examples:\n"
++ " " ++ pname ++ " new-configure "
......@@ -65,7 +66,7 @@ configureAction (configFlags, configExFlags, installFlags, haddockFlags)
hookPrePlanning = \rootDir _ cliConfig ->
-- Write out the @cabal.project.local@ so it gets picked up by the
-- planning phase.
writeProjectLocalExtraConfig rootDir cliConfig,
writeProjectLocalExtraConfig installFlags rootDir cliConfig,
hookSelectPlanSubset = \buildSettings' elaboratedPlan -> do
-- Select the same subset of targets as 'CmdBuild' would
......
......@@ -11,7 +11,7 @@ import Distribution.Client.ProjectPlanning
import Distribution.Client.ProjectConfig
( ProjectConfig(..), ProjectConfigShared(..)
, commandLineFlagsToProjectConfig, writeProjectLocalFreezeConfig
, findProjectRoot )
, findProjectRoot, getProjectFileName )
import Distribution.Client.Targets
( UserConstraint(..) )
import Distribution.Solver.Types.ConstraintSource
......@@ -60,6 +60,7 @@ freezeCommand = Client.installCommand {
commandDescription = Just $ \_ -> wrapText $
"Performs dependency solving on a Nix-local build project, and"
++ " then writes out the precise dependency configuration to cabal.project.freeze"
++ " (or $project_file.freeze if --project-file is specified)"
++ " so that the plan is always used in subsequent builds.",
commandNotes = Just $ \pname ->
"Examples:\n"
......@@ -86,7 +87,7 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags)
cabalDir <- defaultCabalDir
let cabalDirLayout = defaultCabalDirLayout cabalDir
projectRootDir <- findProjectRoot
projectRootDir <- findProjectRoot installFlags
let distDirLayout = defaultDistDirLayout configFlags projectRootDir
let cliConfig = commandLineFlagsToProjectConfig
......@@ -95,14 +96,14 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags)
(_, elaboratedPlan, _, _) <-
rebuildInstallPlan verbosity
rebuildInstallPlan verbosity installFlags
projectRootDir distDirLayout cabalDirLayout
cliConfig
let freezeConfig = projectFreezeConfig elaboratedPlan
writeProjectLocalFreezeConfig projectRootDir freezeConfig
writeProjectLocalFreezeConfig installFlags projectRootDir freezeConfig
notice verbosity $
"Wrote freeze file: " ++ projectRootDir </> "cabal.project.freeze"
"Wrote freeze file: " ++ projectRootDir </> getProjectFileName installFlags <.> "freeze"
where
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
......
......@@ -260,7 +260,8 @@ instance Semigroup SavedConfig where
installNumJobs = combine installNumJobs,
installKeepGoing = combine installKeepGoing,
installRunTests = combine installRunTests,
installOfflineMode = combine installOfflineMode
installOfflineMode = combine installOfflineMode,
installProjectFileName = combine installProjectFileName
}
where
combine = combine' savedInstallFlags
......
......@@ -37,6 +37,7 @@ module Distribution.Client.ProjectConfig (
resolveSolverSettings,
BuildTimeSettings(..),
resolveBuildTimeSettings,
getProjectFileName,
-- * Checking configuration
checkBadPerPackageCompilerPaths,
......@@ -84,7 +85,7 @@ import Distribution.Simple.Setup
( Flag(Flag), toFlag, flagToMaybe, flagToList
, fromFlag, fromFlagOrDefault, AllowNewer(..), AllowOlder(..), RelaxDeps(..) )
import Distribution.Client.Setup
( defaultSolver, defaultMaxBackjumps, )
( defaultSolver, defaultMaxBackjumps, InstallFlags, installProjectFileName )
import Distribution.Simple.InstallDirs
( PathTemplate, fromPathTemplate
, toPathTemplate, substPathTemplate, initialPathTemplateEnv )
......@@ -338,14 +339,20 @@ resolveBuildTimeSettings verbosity
-- Reading and writing project config files
--
getProjectFileName :: InstallFlags -> FilePath
getProjectFileName installFlags =
fromFlagOrDefault "cabal.project" (installProjectFileName installFlags)
-- | Find the root of this project.
--
-- Searches for an explicit @cabal.project@ file, in the current directory or
-- parent directories. If no project file is found then the current dir is the
-- project root (and the project will use an implicit config).
--
findProjectRoot :: IO FilePath
findProjectRoot = do
findProjectRoot :: InstallFlags -> IO FilePath
findProjectRoot installFlags = do
let projectFileName = getProjectFileName installFlags
curdir <- getCurrentDirectory
homedir <- getHomeDirectory
......@@ -355,7 +362,7 @@ findProjectRoot = do
let probe dir | isDrive dir || dir == homedir
= return curdir -- implicit project root
probe dir = do
exists <- doesFileExist (dir </> "cabal.project")
exists <- doesFileExist (dir </> projectFileName)
if exists
then return dir -- explicit project root
else probe (takeDirectory dir)
......@@ -367,20 +374,20 @@ findProjectRoot = do
-- | Read all the config relevant for a project. This includes the project
-- file if any, plus other global config.
--
readProjectConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
readProjectConfig verbosity projectRootDir = do
global <- readGlobalConfig verbosity
local <- readProjectLocalConfig verbosity projectRootDir
freeze <- readProjectLocalFreezeConfig verbosity projectRootDir
extra <- readProjectLocalExtraConfig verbosity projectRootDir
readProjectConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig
readProjectConfig verbosity installFlags projectRootDir = do
global <- readGlobalConfig verbosity
local <- readProjectLocalConfig verbosity installFlags projectRootDir
freeze <- readProjectLocalFreezeConfig verbosity installFlags projectRootDir
extra <- readProjectLocalExtraConfig verbosity installFlags projectRootDir
return (global <> local <> freeze <> extra)
-- | Reads an explicit @cabal.project@ file in the given project root dir,
-- or returns the default project config for an implicitly defined project.
--
readProjectLocalConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
readProjectLocalConfig verbosity projectRootDir = do
readProjectLocalConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig
readProjectLocalConfig verbosity installFlags projectRootDir = do
usesExplicitProjectRoot <- liftIO $ doesFileExist projectFile
if usesExplicitProjectRoot
then do
......@@ -391,7 +398,7 @@ readProjectLocalConfig verbosity projectRootDir = do
return defaultImplicitProjectConfig
where
projectFile = projectRootDir </> "cabal.project"
projectFile = projectRootDir </> getProjectFileName installFlags
readProjectFile =
reportParseResult verbosity "project file" projectFile
. parseProjectConfig
......@@ -419,25 +426,25 @@ readProjectLocalConfig verbosity projectRootDir = do
-- or returns empty. This file gets written by @cabal configure@, or in
-- principle can be edited manually or by other tools.
--
readProjectLocalExtraConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
readProjectLocalExtraConfig verbosity =
readProjectExtensionFile verbosity "local"
readProjectLocalExtraConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig
readProjectLocalExtraConfig verbosity installFlags =
readProjectExtensionFile verbosity installFlags "local"
"project local configuration file"
-- | Reads a @cabal.project.freeze@ file in the given project root dir,
-- or returns empty. This file gets written by @cabal freeze@, or in
-- principle can be edited manually or by other tools.
--
readProjectLocalFreezeConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
readProjectLocalFreezeConfig verbosity =
readProjectExtensionFile verbosity "freeze"
readProjectLocalFreezeConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig
readProjectLocalFreezeConfig verbosity installFlags =
readProjectExtensionFile verbosity installFlags "freeze"
"project freeze file"
-- | Reads a named config file in the given project root dir, or returns empty.
--
readProjectExtensionFile :: Verbosity -> String -> FilePath
readProjectExtensionFile :: Verbosity -> InstallFlags -> String -> FilePath
-> FilePath -> Rebuild ProjectConfig
readProjectExtensionFile verbosity extensionName extensionDescription
readProjectExtensionFile verbosity installFlags extensionName extensionDescription
projectRootDir = do
exists <- liftIO $ doesFileExist extensionFile
if exists
......@@ -446,7 +453,9 @@ readProjectExtensionFile verbosity extensionName extensionDescription
else do monitorFiles [monitorNonExistentFile extensionFile]
return mempty
where
extensionFile = projectRootDir </> "cabal.project" <.> extensionName
extensionFile = projectRootDir </> projectFileName <.> extensionName
projectFileName = getProjectFileName installFlags
readExtensionFile =
reportParseResult verbosity extensionDescription extensionFile
......@@ -477,20 +486,20 @@ showProjectConfig =
-- | Write a @cabal.project.local@ file in the given project root dir.
--
writeProjectLocalExtraConfig :: FilePath -> ProjectConfig -> IO ()
writeProjectLocalExtraConfig projectRootDir =
writeProjectLocalExtraConfig :: InstallFlags -> FilePath -> ProjectConfig -> IO ()
writeProjectLocalExtraConfig installFlags projectRootDir =
writeProjectConfigFile projectExtraConfigFile
where
projectExtraConfigFile = projectRootDir </> "cabal.project.local"
projectExtraConfigFile = projectRootDir </> getProjectFileName installFlags <.> "local"
-- | Write a @cabal.project.freeze@ file in the given project root dir.
--
writeProjectLocalFreezeConfig :: FilePath -> ProjectConfig -> IO ()
writeProjectLocalFreezeConfig projectRootDir =
writeProjectLocalFreezeConfig :: InstallFlags -> FilePath -> ProjectConfig -> IO ()
writeProjectLocalFreezeConfig installFlags projectRootDir =
writeProjectConfigFile projectFreezeConfigFile
where
projectFreezeConfigFile = projectRootDir </> "cabal.project.freeze"
projectFreezeConfigFile = projectRootDir </> getProjectFileName installFlags <.> "freeze"
-- | Write in the @cabal.project@ format to the given file.
......
......@@ -515,7 +515,8 @@ convertToLegacySharedConfig
installNumJobs = projectConfigNumJobs,
installKeepGoing = projectConfigKeepGoing,
installRunTests = mempty,
installOfflineMode = projectConfigOfflineMode
installOfflineMode = projectConfigOfflineMode,
installProjectFileName = mempty
}
......
......@@ -172,7 +172,7 @@ runProjectPreBuildPhase
cabalDir <- defaultCabalDir
let cabalDirLayout = defaultCabalDirLayout cabalDir
projectRootDir <- findProjectRoot
projectRootDir <- findProjectRoot installFlags
let distDirLayout = defaultDistDirLayout configFlags projectRootDir
let cliConfig = commandLineFlagsToProjectConfig
......@@ -189,7 +189,7 @@ runProjectPreBuildPhase
-- the user has asked for.
--
(elaboratedPlan, _, elaboratedShared, projectConfig) <-
rebuildInstallPlan verbosity
rebuildInstallPlan verbosity installFlags
projectRootDir distDirLayout cabalDirLayout
cliConfig
......
......@@ -284,6 +284,7 @@ sanityCheckElaboratedPackage ElaboratedConfiguredPackage{..}
-- dependencies of executables and setup scripts.
--
rebuildInstallPlan :: Verbosity
-> InstallFlags
-> FilePath -> DistDirLayout -> CabalDirLayout
-> ProjectConfig
-> IO ( ElaboratedInstallPlan -- with store packages
......@@ -292,6 +293,7 @@ rebuildInstallPlan :: Verbosity
, ProjectConfig )
-- ^ @(improvedPlan, elaboratedPlan, _, _)@
rebuildInstallPlan verbosity
installFlags
projectRootDir
distDirLayout@DistDirLayout {
distDirectory,
......@@ -365,7 +367,7 @@ rebuildInstallPlan verbosity
createDirectoryIfMissingVerbose verbosity True distDirectory
createDirectoryIfMissingVerbose verbosity True distProjectCacheDirectory
projectConfig <- readProjectConfig verbosity projectRootDir
projectConfig <- readProjectConfig verbosity installFlags projectRootDir
-- The project config comming from the command line includes "build only"
-- flags that we don't cache persistently (because like all "build only"
......
......@@ -1250,7 +1250,15 @@ data InstallFlags = InstallFlags {
installNumJobs :: Flag (Maybe Int),
installKeepGoing :: Flag Bool,
installRunTests :: Flag Bool,
installOfflineMode :: Flag Bool
installOfflineMode :: Flag Bool,
-- | The cabal project file name; defaults to @cabal.project@.
-- Th name itself denotes the cabal project file name, but it also
-- is the base of auxiliary project files, such as
-- @cabal.project.local@ and @cabal.project.freeze@ which are also
-- read and written out in some cases. If the path is not found
-- in the current working directory, we will successively probe
-- relative to parent directories until this name is found.
installProjectFileName :: Flag FilePath
}
deriving (Eq, Generic)
......@@ -1284,7 +1292,8 @@ defaultInstallFlags = InstallFlags {
installNumJobs = mempty,
installKeepGoing = Flag False,
installRunTests = mempty,
installOfflineMode = Flag False
installOfflineMode = Flag False,
installProjectFileName = mempty
}
where
docIndexFile = toPathTemplate ("$datadir" </> "doc"
......@@ -1514,6 +1523,11 @@ installOptions showOrParseArgs =
"Don't download packages from the Internet."
installOfflineMode (\v flags -> flags { installOfflineMode = v })
(yesNoOpt showOrParseArgs)
, option [] ["project-file"]
"Set the name of the cabal.project file to search for in parent directories"
installProjectFileName (\v flags -> flags {installProjectFileName = v})
(reqArgFlag "FILE")
] ++ case showOrParseArgs of -- TODO: remove when "cabal install"
-- avoids
ParseArgs ->
......
......@@ -256,7 +256,7 @@ planProject testdir cliConfig = do
cleanProject testdir
(elaboratedPlan, _, elaboratedShared, projectConfig) <-
rebuildInstallPlan verbosity
rebuildInstallPlan verbosity mempty
projectRootDir distDirLayout cabalDirLayout
cliConfig
......
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