Skip to content

Commit eaa38b6

Browse files
authored
Warn if builddir is going to be ignored (#8949)
* Unify the default project with the implicit one Passing --ignore-project made cabal use `defaultProject` which is not quite identical to the one used when cabal.project is missing (`defaultImplifictProjectConfig`). There is no reason the two should be different. * Warn if builddir is going to be ignored. builddir can only be specified from the command line. Closes: #7941 * Clarify which project option can only be passed from the command line * Add note about reading the project configuration
1 parent 4a99076 commit eaa38b6

File tree

8 files changed

+105
-39
lines changed

8 files changed

+105
-39
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,15 @@ readProjectConfig
664664
-> Flag FilePath
665665
-> DistDirLayout
666666
-> Rebuild ProjectConfigSkeleton
667-
readProjectConfig verbosity httpTransport ignoreProjectFlag configFileFlag distDirLayout = do
668-
let defaultProject =
669-
mempty
670-
{ projectPackages = ["./"]
671-
}
667+
readProjectConfig verbosity _ (Flag True) configFileFlag _ = do
668+
global <- singletonProjectConfigSkeleton <$> readGlobalConfig verbosity configFileFlag
669+
return (global <> singletonProjectConfigSkeleton defaultImplicitProjectConfig)
670+
readProjectConfig verbosity httpTransport _ configFileFlag distDirLayout = do
672671
global <- singletonProjectConfigSkeleton <$> readGlobalConfig verbosity configFileFlag
673672
local <- readProjectLocalConfigOrDefault verbosity httpTransport distDirLayout
674673
freeze <- readProjectLocalFreezeConfig verbosity httpTransport distDirLayout
675674
extra <- readProjectLocalExtraConfig verbosity httpTransport distDirLayout
676-
if ignoreProjectFlag == Flag True
677-
then return (global <> singletonProjectConfigSkeleton defaultProject)
678-
else return (global <> local <> freeze <> extra)
675+
return (global <> local <> freeze <> extra)
679676

680677
-- | Reads an explicit @cabal.project@ file in the given project root dir,
681678
-- or returns the default project config for an implicitly defined project.
@@ -687,19 +684,21 @@ readProjectLocalConfigOrDefault
687684
readProjectLocalConfigOrDefault verbosity httpTransport distDirLayout = do
688685
let projectFile = distProjectFile distDirLayout ""
689686
usesExplicitProjectRoot <- liftIO $ doesFileExist projectFile
690-
let defaultImplicitProjectConfig =
691-
mempty
692-
{ -- We expect a package in the current directory.
693-
projectPackages = ["./*.cabal"]
694-
, projectConfigProvenance = Set.singleton Implicit
695-
}
696687
if usesExplicitProjectRoot
697688
then do
698689
readProjectFileSkeleton verbosity httpTransport distDirLayout "" "project file"
699690
else do
700691
monitorFiles [monitorNonExistentFile projectFile]
701692
return (singletonProjectConfigSkeleton defaultImplicitProjectConfig)
702693

694+
defaultImplicitProjectConfig :: ProjectConfig
695+
defaultImplicitProjectConfig =
696+
mempty
697+
{ -- We expect a package in the current directory.
698+
projectPackages = ["./*.cabal"]
699+
, projectConfigProvenance = Set.singleton Implicit
700+
}
701+
703702
-- | Reads a @cabal.project.local@ file in the given project root dir,
704703
-- or returns empty. This file gets written by @cabal configure@, or in
705704
-- principle can be edited manually or by other tools.

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,37 @@ sanityCheckElaboratedPackage
331331
`optStanzaSetIsSubset` pkgStanzasEnabled
332332
)
333333

334-
------------------------------------------------------------------------------
335-
336-
-- * Deciding what to do: making an 'ElaboratedInstallPlan'
337-
338-
------------------------------------------------------------------------------
334+
-- Note [reading project configuration]
335+
--
336+
-- The project configuration is assembled into a ProjectConfig as follows:
337+
--
338+
-- CLI arguments are converted using commandLineFlagsToProjectConfig in the
339+
-- v2 command entrypoints and passed to establishProjectBaseContext which
340+
-- then calls rebuildProjectConfig.
341+
--
342+
-- rebuildProjectConfig then calls readProjectConfig to read the project
343+
-- files. Because of conditionals, this output is in the form of a
344+
-- ProjectConfigSkeleton and will be resolved by rebuildProjectConfig using
345+
-- instantiateProjectConfigSkeletonFetchingCompiler.
346+
--
347+
-- readProjectConfig also loads the global configuration, which is read with
348+
-- loadConfig and convertd to a ProjectConfig with convertLegacyGlobalConfig.
349+
--
350+
-- *Important*
351+
--
352+
-- You can notice how some project config options are needed to read the
353+
-- project config! This is evident by the fact that rebuildProjectConfig
354+
-- takes HttpTransport and DistDirLayout as parameters. Two arguments are
355+
-- infact determined from the CLI alone (in establishProjectBaseContext).
356+
-- Consequently, project files (including global configuration) cannot
357+
-- affect those parameters.
358+
--
359+
-- Furthermore, the project configuration can specify a compiler to use,
360+
-- which we need to resolve the conditionals in the project configuration!
361+
-- To solve this, we configure the compiler from what is obtained by applying
362+
-- the CLI configuration over the the configuration obtained by "flattening"
363+
-- ProjectConfigSkeleton. This means collapsing all conditionals by taking
364+
-- both branches.
339365

340366
-- | Return the up-to-date project config and information about the local
341367
-- packages within the project.
@@ -390,6 +416,9 @@ rebuildProjectConfig
390416
pure (os, arch, compilerInfo compiler)
391417

392418
projectConfig <- instantiateProjectConfigSkeletonFetchingCompiler fetchCompiler mempty projectConfigSkeleton
419+
when (projectConfigDistDir (projectConfigShared $ projectConfig) /= NoFlag) $
420+
liftIO $
421+
warn verbosity "The builddir option is not supported in project and config files. It will be ignored."
393422
localPackages <- phaseReadLocalPackages (projectConfig <> cliConfig)
394423
return (projectConfig, localPackages)
395424

@@ -510,6 +539,11 @@ configureCompiler
510539
)
511540
$ defaultProgramDb
512541

542+
543+
------------------------------------------------------------------------------
544+
-- * Deciding what to do: making an 'ElaboratedInstallPlan'
545+
------------------------------------------------------------------------------
546+
513547
-- | Return an up-to-date elaborated install plan.
514548
--
515549
-- Two variants of the install plan are returned: with and without packages
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# cabal v2-build
2+
Warning: The builddir option is not supported in project and config files. It will be ignored.
3+
Resolving dependencies...
4+
Build profile: -w ghc-<GHCVER> -O1
5+
In order, the following would be built:
6+
- main-0.1 (lib) (first run)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: .
2+
builddir: something
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
cabal "v2-build" ["--dry-run", "all"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cabal-version: 3.0
2+
3+
name: main
4+
version: 0.1
5+
build-type: Simple
6+
category: Test
7+
maintainer: Joe
8+
synopsis: Test input
9+
description: Test input
10+
license: BSD-3-Clause
11+
12+
library
13+
build-depends: base
14+
default-language: Haskell2010

changelog.d/pr-8949

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
synopsis: Warn when project configuration options are going to be ignored.
2+
packages: cabal-install
3+
prs: #8949
4+
5+
description: {
6+
7+
Some project configuration options can only be specified from the command line.
8+
If the user specified those options from a project file, cabal-install would
9+
silently ignore them. Now cabal-install will emit a warning.
10+
11+
}

doc/cabal-project.rst

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ package, and thus apply globally:
288288
to the root of the project (i.e., where the ``cabal.project``
289289
file lives.)
290290

291-
This option cannot be specified via a ``cabal.project`` file.
291+
This option can only be specified from the command line.
292292

293293
.. _cmdoption-project-dir:
294294
.. option:: --project-dir=DIR
@@ -297,9 +297,9 @@ package, and thus apply globally:
297297
:ref:`project-file<cmdoption-project-file>` path is also specified,
298298
it will be resolved relative to this directory.
299299

300-
The project directory need not contain a ``cabal.project`` file.
300+
The project directory does not need to contain a ``cabal.project`` file.
301301

302-
This option cannot be specified via a ``cabal.project`` file.
302+
This option can only be specified from the command line.
303303

304304
.. _cmdoption-project-file:
305305
.. option:: --project-file=FILE
@@ -318,7 +318,7 @@ package, and thus apply globally:
318318
and then for the parent directory, until the project file is
319319
found or we have hit the top of the user's home directory.
320320

321-
This option cannot be specified via a ``cabal.project`` file.
321+
This option can only be specified from the command line.
322322

323323
.. option:: --ignore-project
324324

@@ -880,21 +880,7 @@ feature was added.
880880
The command line variant of this flag is ``--enable-benchmarks`` and
881881
``--disable-benchmarks``.
882882

883-
.. cfg-field:: multi-repl: boolean
884-
--enable-multi-repl
885-
--disable-multi-repl
886-
:synopsis: Enable starting a repl with multiple targets.
887-
888-
:default: ``False``
889-
890-
Allow starting GHCi with multiple targets. This requires GHC with multiple
891-
home unit support (GHC-9.4+).
892-
893-
The closure of required components will be loaded.
894-
895-
The command line variant of this flag is ``--enable-multi-repl`` and
896-
``--disable-multi-repl``.
897-
883+
.. _cmdoption-extra-prog-path:
898884
.. cfg-field:: extra-prog-path: paths (newline or comma separated)
899885
--extra-prog-path=PATH
900886
:synopsis: Add directories to program search path.
@@ -909,6 +895,10 @@ feature was added.
909895
The command line variant of this flag is ``--extra-prog-path=PATH``,
910896
which can be specified multiple times.
911897

898+
When specifying :ref:`--http-transport<cmdoption-http-transport>` from the
899+
command line, only extra-prog-path from the command line are added to the
900+
program search path.
901+
912902
.. cfg-field:: run-tests: boolean
913903
--run-tests
914904
:synopsis: Run package test suite upon installation.
@@ -1587,7 +1577,7 @@ Advanced global configuration options
15871577
The format and fields of the generated build information is currently experimental,
15881578
in the future we might add or remove fields, depending on the needs of other tooling.
15891579

1590-
1580+
.. _cmdoption-http-transport:
15911581
.. cfg-field:: http-transport: curl, wget, powershell, or plain-http
15921582
--http-transport=transport
15931583
:synopsis: Transport to use with http(s) requests.
@@ -1598,6 +1588,12 @@ Advanced global configuration options
15981588

15991589
The command line variant of this field is ``--http-transport=curl``.
16001590

1591+
If the project configuration imports remote urls, the user can only specify
1592+
the http-transport option from the command line.
1593+
1594+
When specifying the http-transport from the command line, the program
1595+
search path can only be influenced using :ref:`--extra-prog-path<cmdoption-extra-prog-path>`.
1596+
16011597
.. cfg-field:: ignore-expiry: boolean
16021598
--ignore-expiry
16031599
:synopsis: Ignore Hackage expiration dates.

0 commit comments

Comments
 (0)