Skip to content

Commit

Permalink
Print info about current project file in use to stderr and ignore the…
Browse files Browse the repository at this point in the history
… imports by default (#10548)

* Print info about current project file in use to stderr (fix #10547)

* only report top-level project config files in the default verbosity

in verbose mode report imported files too

* fix tests

* don't print anything when provenance is empty

* fix tests

* Apply suggestions from code review

Co-authored-by: ffaf1 <[email protected]>

---------

Co-authored-by: ffaf1 <[email protected]>
  • Loading branch information
ulysses4ever and ffaf1 authored Nov 13, 2024
1 parent 287d347 commit 7de199a
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Distribution.Solver.Types.ProjectConfigPath

-- * Checks and Normalization
, isCyclicConfigPath
, isTopLevelConfigPath
, canonicalizeConfigPath
) where

Expand Down Expand Up @@ -138,6 +139,11 @@ nullProjectConfigPath = ProjectConfigPath $ "unused" :| []
isCyclicConfigPath :: ProjectConfigPath -> Bool
isCyclicConfigPath (ProjectConfigPath p) = length p /= length (NE.nub p)

-- | Check if the project config path is top-level, meaning it was not included by
-- some other project config.
isTopLevelConfigPath :: ProjectConfigPath -> Bool
isTopLevelConfigPath (ProjectConfigPath p) = NE.length p == 1

-- | Prepends the path of the importee to the importer path.
consProjectConfigPath :: FilePath -> ProjectConfigPath -> ProjectConfigPath
consProjectConfigPath p ps = ProjectConfigPath (p <| coerce ps)
Expand Down
7 changes: 7 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Distribution.Client.ProjectConfig
, writeProjectLocalFreezeConfig
, writeProjectConfigFile
, commandLineFlagsToProjectConfig
, onlyTopLevelProvenance

-- * Packages within projects
, ProjectPackageLocation (..)
Expand Down Expand Up @@ -1753,3 +1754,9 @@ checkBadPerPackageCompilerPaths compilerPrograms packagesConfig =
] of
[] -> return ()
ps -> throwIO (BadPerPackageCompilerPaths ps)

-- | Filter out non-top-level project configs.
onlyTopLevelProvenance :: Set ProjectConfigProvenance -> Set ProjectConfigProvenance
onlyTopLevelProvenance = Set.filter $ \case
Implicit -> False
Explicit ps -> isTopLevelConfigPath ps
15 changes: 8 additions & 7 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ import Distribution.Backpack.LinkedComponent
import Distribution.Backpack.ModuleShape

import Distribution.Simple.Utils
import Distribution.Verbosity
import Distribution.Version

import qualified Distribution.InstalledPackageInfo as IPI
Expand Down Expand Up @@ -397,13 +398,13 @@ rebuildProjectConfig
localPackages <- phaseReadLocalPackages (projectConfig <> cliConfig)
return (projectConfig, localPackages)

sequence_
[ do
notice verbosity . render . vcat $
text "Configuration is affected by the following files:"
: [text "-" <+> docProjectConfigPath path]
| Explicit path <- Set.toList $ projectConfigProvenance projectConfig
]
let configfiles =
[ text "-" <+> docProjectConfigPath path
| Explicit path <- Set.toList . (if verbosity >= verbose then id else onlyTopLevelProvenance) $ projectConfigProvenance projectConfig
]
unless (null configfiles) $
notice (verboseStderr verbosity) . render . vcat $
text "Configuration is affected by the following files:" : configfiles

return (projectConfig <> cliConfig, localPackages)
where
Expand Down
48 changes: 0 additions & 48 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Downloading the latest package list from test-local-repo
# cabal v2-run
Configuration is affected by the following files:
- cabal.project
Configuration is affected by the following files:
- extra.project
imported by: cabal.project
Resolving dependencies...
Expand Down Expand Up @@ -70,9 +69,7 @@ cyclical import of cyclical-2-out-out-self-b.config;
Configuration is affected by the following files:
- noncyclical-same-filename-a.config
imported by: noncyclical-same-filename-a.project
Configuration is affected by the following files:
- noncyclical-same-filename-a.project
Configuration is affected by the following files:
- same-filename/noncyclical-same-filename-a.config
imported by: noncyclical-same-filename-a.config
imported by: noncyclical-same-filename-a.project
Expand All @@ -89,9 +86,7 @@ Configuration is affected by the following files:
- noncyclical-same-filename-b.config
imported by: same-filename/noncyclical-same-filename-b.config
imported by: noncyclical-same-filename-b.project
Configuration is affected by the following files:
- noncyclical-same-filename-b.project
Configuration is affected by the following files:
- same-filename/noncyclical-same-filename-b.config
imported by: noncyclical-same-filename-b.project
Up to date
Expand Down Expand Up @@ -126,25 +121,21 @@ cyclical import of cyclical-same-filename-out-out-back.config;
# cabal v2-build
Configuration is affected by the following files:
- hops-0.project
Configuration is affected by the following files:
- hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops-4.config
imported by: hops/hops-3.config
imported by: hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops-6.config
imported by: hops/hops-5.config
imported by: hops-4.config
imported by: hops/hops-3.config
imported by: hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops-8.config
imported by: hops/hops-7.config
imported by: hops-6.config
Expand All @@ -154,22 +145,18 @@ Configuration is affected by the following files:
imported by: hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops/hops-3.config
imported by: hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops/hops-5.config
imported by: hops-4.config
imported by: hops/hops-3.config
imported by: hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops/hops-7.config
imported by: hops-6.config
imported by: hops/hops-5.config
Expand All @@ -178,7 +165,6 @@ Configuration is affected by the following files:
imported by: hops-2.config
imported by: hops/hops-1.config
imported by: hops-0.project
Configuration is affected by the following files:
- hops/hops-9.config
imported by: hops-8.config
imported by: hops/hops-7.config
Expand All @@ -194,25 +180,21 @@ Up to date
# cabal v2-build
Configuration is affected by the following files:
- oops-0.project
Configuration is affected by the following files:
- oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops-4.config
imported by: oops/oops-3.config
imported by: oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops-6.config
imported by: oops/oops-5.config
imported by: oops-4.config
imported by: oops/oops-3.config
imported by: oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops-8.config
imported by: oops/oops-7.config
imported by: oops-6.config
Expand All @@ -222,22 +204,18 @@ Configuration is affected by the following files:
imported by: oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops/oops-3.config
imported by: oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops/oops-5.config
imported by: oops-4.config
imported by: oops/oops-3.config
imported by: oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops/oops-7.config
imported by: oops-6.config
imported by: oops/oops-5.config
Expand All @@ -246,7 +224,6 @@ Configuration is affected by the following files:
imported by: oops-2.config
imported by: oops/oops-1.config
imported by: oops-0.project
Configuration is affected by the following files:
- oops/oops-9.config
imported by: oops-8.config
imported by: oops/oops-7.config
Expand Down Expand Up @@ -281,57 +258,47 @@ After searching the rest of the dependency tree exhaustively, these were the goa
# cabal v2-build
Configuration is affected by the following files:
- yops-0.project
Configuration is affected by the following files:
- yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-4.config
imported by: yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-4.config
imported by: yops/yops-3.config
imported by: yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-6.config
imported by: yops/yops-5.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-6.config
imported by: yops/yops-5.config
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-6.config
imported by: yops/yops-5.config
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-8.config
imported by: yops/yops-7.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-8.config
imported by: yops/yops-7.config
imported by: yops-6.config
imported by: yops/yops-5.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-8.config
imported by: yops/yops-7.config
imported by: yops-6.config
imported by: yops/yops-5.config
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops-8.config
imported by: yops/yops-7.config
imported by: yops-6.config
Expand All @@ -341,48 +308,38 @@ Configuration is affected by the following files:
imported by: yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-3.config
imported by: yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-5.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-5.config
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-5.config
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-7.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-7.config
imported by: yops-6.config
imported by: yops/yops-5.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-7.config
imported by: yops-6.config
imported by: yops/yops-5.config
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-7.config
imported by: yops-6.config
imported by: yops/yops-5.config
Expand All @@ -391,22 +348,18 @@ Configuration is affected by the following files:
imported by: yops-2.config
imported by: yops/yops-1.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-9.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-9.config
imported by: yops-8.config
imported by: yops/yops-7.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-9.config
imported by: yops-8.config
imported by: yops/yops-7.config
imported by: yops-6.config
imported by: yops/yops-5.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-9.config
imported by: yops-8.config
imported by: yops/yops-7.config
Expand All @@ -415,7 +368,6 @@ Configuration is affected by the following files:
imported by: yops-4.config
imported by: yops/yops-3.config
imported by: yops-0.project
Configuration is affected by the following files:
- yops/yops-9.config
imported by: yops-8.config
imported by: yops/yops-7.config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# cabal v2-configure
Configuration is affected by the following files:
- cabal.project
Configuration is affected by the following files:
- cabal.project.local
'cabal.project.local' already exists, backing it up to 'cabal.project.local~'.
# cabal v2-configure
Configuration is affected by the following files:
- foo.project
Configuration is affected by the following files:
- foo.project.local
'foo.project.local' already exists, backing it up to 'foo.project.local~'.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Wrote freeze file: <ROOT>/cabal.project.freeze
# cabal v2-build
Configuration is affected by the following files:
- cabal.project
Configuration is affected by the following files:
- cabal.project.freeze
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Wrote freeze file: <ROOT>/cabal.project.freeze
# cabal v2-build
Configuration is affected by the following files:
- cabal.project
Configuration is affected by the following files:
- cabal.project.freeze
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Wrote freeze file: <ROOT>/cabal.project.freeze
# cabal v2-build
Configuration is affected by the following files:
- cabal.project
Configuration is affected by the following files:
- cabal.project.freeze
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
Expand All @@ -41,7 +40,6 @@ Building executable 'my-exe' for my-local-package-1.0...
# cabal v2-freeze
Configuration is affected by the following files:
- cabal.project
Configuration is affected by the following files:
- cabal.project.freeze
Wrote freeze file: <ROOT>/cabal.project.freeze
# cabal v2-build
Expand Down
Loading

0 comments on commit 7de199a

Please sign in to comment.