Skip to content

Commit e788d37

Browse files
ulysses4evermergify[bot]
authored andcommitted
Print info about current project file in use to stderr and ignore the 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]> (cherry picked from commit 7de199a) # Conflicts: # cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out
1 parent 9b26613 commit e788d37

File tree

14 files changed

+149
-62
lines changed

14 files changed

+149
-62
lines changed

cabal-install-solver/src/Distribution/Solver/Types/ProjectConfigPath.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Distribution.Solver.Types.ProjectConfigPath
1616

1717
-- * Checks and Normalization
1818
, isCyclicConfigPath
19+
, isTopLevelConfigPath
1920
, canonicalizeConfigPath
2021
) where
2122

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

142+
-- | Check if the project config path is top-level, meaning it was not included by
143+
-- some other project config.
144+
isTopLevelConfigPath :: ProjectConfigPath -> Bool
145+
isTopLevelConfigPath (ProjectConfigPath p) = NE.length p == 1
146+
141147
-- | Prepends the path of the importee to the importer path.
142148
consProjectConfigPath :: FilePath -> ProjectConfigPath -> ProjectConfigPath
143149
consProjectConfigPath p ps = ProjectConfigPath (p <| coerce ps)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Distribution.Client.ProjectConfig
3737
, writeProjectLocalFreezeConfig
3838
, writeProjectConfigFile
3939
, commandLineFlagsToProjectConfig
40+
, onlyTopLevelProvenance
4041

4142
-- * Packages within projects
4243
, ProjectPackageLocation (..)
@@ -1753,3 +1754,9 @@ checkBadPerPackageCompilerPaths compilerPrograms packagesConfig =
17531754
] of
17541755
[] -> return ()
17551756
ps -> throwIO (BadPerPackageCompilerPaths ps)
1757+
1758+
-- | Filter out non-top-level project configs.
1759+
onlyTopLevelProvenance :: Set ProjectConfigProvenance -> Set ProjectConfigProvenance
1760+
onlyTopLevelProvenance = Set.filter $ \case
1761+
Implicit -> False
1762+
Explicit ps -> isTopLevelConfigPath ps

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ import Distribution.Backpack.LinkedComponent
192192
import Distribution.Backpack.ModuleShape
193193

194194
import Distribution.Simple.Utils
195+
import Distribution.Verbosity
195196
import Distribution.Version
196197

197198
import qualified Distribution.InstalledPackageInfo as IPI
@@ -394,13 +395,13 @@ rebuildProjectConfig
394395
localPackages <- phaseReadLocalPackages (projectConfig <> cliConfig)
395396
return (projectConfig, localPackages)
396397

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

405406
return (projectConfig <> cliConfig, localPackages)
406407
where

cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out

Lines changed: 128 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Downloading the latest package list from test-local-repo
33
# cabal v2-run
44
Configuration is affected by the following files:
55
- cabal.project
6-
Configuration is affected by the following files:
76
- extra.project
87
imported by: cabal.project
98
Resolving dependencies...
@@ -70,9 +69,7 @@ cyclical import of cyclical-2-out-out-self-b.config;
7069
Configuration is affected by the following files:
7170
- noncyclical-same-filename-a.config
7271
imported by: noncyclical-same-filename-a.project
73-
Configuration is affected by the following files:
7472
- noncyclical-same-filename-a.project
75-
Configuration is affected by the following files:
7673
- same-filename/noncyclical-same-filename-a.config
7774
imported by: noncyclical-same-filename-a.config
7875
imported by: noncyclical-same-filename-a.project
@@ -89,9 +86,7 @@ Configuration is affected by the following files:
8986
- noncyclical-same-filename-b.config
9087
imported by: same-filename/noncyclical-same-filename-b.config
9188
imported by: noncyclical-same-filename-b.project
92-
Configuration is affected by the following files:
9389
- noncyclical-same-filename-b.project
94-
Configuration is affected by the following files:
9590
- same-filename/noncyclical-same-filename-b.config
9691
imported by: noncyclical-same-filename-b.project
9792
Up to date
@@ -126,25 +121,21 @@ cyclical import of cyclical-same-filename-out-out-back.config;
126121
# cabal v2-build
127122
Configuration is affected by the following files:
128123
- hops-0.project
129-
Configuration is affected by the following files:
130124
- hops-2.config
131125
imported by: hops/hops-1.config
132126
imported by: hops-0.project
133-
Configuration is affected by the following files:
134127
- hops-4.config
135128
imported by: hops/hops-3.config
136129
imported by: hops-2.config
137130
imported by: hops/hops-1.config
138131
imported by: hops-0.project
139-
Configuration is affected by the following files:
140132
- hops-6.config
141133
imported by: hops/hops-5.config
142134
imported by: hops-4.config
143135
imported by: hops/hops-3.config
144136
imported by: hops-2.config
145137
imported by: hops/hops-1.config
146138
imported by: hops-0.project
147-
Configuration is affected by the following files:
148139
- hops-8.config
149140
imported by: hops/hops-7.config
150141
imported by: hops-6.config
@@ -154,22 +145,18 @@ Configuration is affected by the following files:
154145
imported by: hops-2.config
155146
imported by: hops/hops-1.config
156147
imported by: hops-0.project
157-
Configuration is affected by the following files:
158148
- hops/hops-1.config
159149
imported by: hops-0.project
160-
Configuration is affected by the following files:
161150
- hops/hops-3.config
162151
imported by: hops-2.config
163152
imported by: hops/hops-1.config
164153
imported by: hops-0.project
165-
Configuration is affected by the following files:
166154
- hops/hops-5.config
167155
imported by: hops-4.config
168156
imported by: hops/hops-3.config
169157
imported by: hops-2.config
170158
imported by: hops/hops-1.config
171159
imported by: hops-0.project
172-
Configuration is affected by the following files:
173160
- hops/hops-7.config
174161
imported by: hops-6.config
175162
imported by: hops/hops-5.config
@@ -178,7 +165,6 @@ Configuration is affected by the following files:
178165
imported by: hops-2.config
179166
imported by: hops/hops-1.config
180167
imported by: hops-0.project
181-
Configuration is affected by the following files:
182168
- hops/hops-9.config
183169
imported by: hops-8.config
184170
imported by: hops/hops-7.config
@@ -194,25 +180,21 @@ Up to date
194180
# cabal v2-build
195181
Configuration is affected by the following files:
196182
- oops-0.project
197-
Configuration is affected by the following files:
198183
- oops-2.config
199184
imported by: oops/oops-1.config
200185
imported by: oops-0.project
201-
Configuration is affected by the following files:
202186
- oops-4.config
203187
imported by: oops/oops-3.config
204188
imported by: oops-2.config
205189
imported by: oops/oops-1.config
206190
imported by: oops-0.project
207-
Configuration is affected by the following files:
208191
- oops-6.config
209192
imported by: oops/oops-5.config
210193
imported by: oops-4.config
211194
imported by: oops/oops-3.config
212195
imported by: oops-2.config
213196
imported by: oops/oops-1.config
214197
imported by: oops-0.project
215-
Configuration is affected by the following files:
216198
- oops-8.config
217199
imported by: oops/oops-7.config
218200
imported by: oops-6.config
@@ -222,22 +204,18 @@ Configuration is affected by the following files:
222204
imported by: oops-2.config
223205
imported by: oops/oops-1.config
224206
imported by: oops-0.project
225-
Configuration is affected by the following files:
226207
- oops/oops-1.config
227208
imported by: oops-0.project
228-
Configuration is affected by the following files:
229209
- oops/oops-3.config
230210
imported by: oops-2.config
231211
imported by: oops/oops-1.config
232212
imported by: oops-0.project
233-
Configuration is affected by the following files:
234213
- oops/oops-5.config
235214
imported by: oops-4.config
236215
imported by: oops/oops-3.config
237216
imported by: oops-2.config
238217
imported by: oops/oops-1.config
239218
imported by: oops-0.project
240-
Configuration is affected by the following files:
241219
- oops/oops-7.config
242220
imported by: oops-6.config
243221
imported by: oops/oops-5.config
@@ -246,7 +224,6 @@ Configuration is affected by the following files:
246224
imported by: oops-2.config
247225
imported by: oops/oops-1.config
248226
imported by: oops-0.project
249-
Configuration is affected by the following files:
250227
- oops/oops-9.config
251228
imported by: oops-8.config
252229
imported by: oops/oops-7.config
@@ -277,6 +254,134 @@ Could not resolve dependencies:
277254
(constraint from oops-0.project requires ==1.4.3.0)
278255
[__1] fail (backjumping, conflict set: hashable, oops)
279256
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), oops (2)
257+
<<<<<<< HEAD
258+
=======
259+
# checking if we detect when the same config is imported via many different paths (we don't)
260+
# cabal v2-build
261+
Configuration is affected by the following files:
262+
- yops-0.project
263+
- yops-2.config
264+
imported by: yops/yops-1.config
265+
imported by: yops-0.project
266+
- yops-4.config
267+
imported by: yops/yops-3.config
268+
imported by: yops-0.project
269+
- yops-4.config
270+
imported by: yops/yops-3.config
271+
imported by: yops-2.config
272+
imported by: yops/yops-1.config
273+
imported by: yops-0.project
274+
- yops-6.config
275+
imported by: yops/yops-5.config
276+
imported by: yops-0.project
277+
- yops-6.config
278+
imported by: yops/yops-5.config
279+
imported by: yops-4.config
280+
imported by: yops/yops-3.config
281+
imported by: yops-0.project
282+
- yops-6.config
283+
imported by: yops/yops-5.config
284+
imported by: yops-4.config
285+
imported by: yops/yops-3.config
286+
imported by: yops-2.config
287+
imported by: yops/yops-1.config
288+
imported by: yops-0.project
289+
- yops-8.config
290+
imported by: yops/yops-7.config
291+
imported by: yops-0.project
292+
- yops-8.config
293+
imported by: yops/yops-7.config
294+
imported by: yops-6.config
295+
imported by: yops/yops-5.config
296+
imported by: yops-0.project
297+
- yops-8.config
298+
imported by: yops/yops-7.config
299+
imported by: yops-6.config
300+
imported by: yops/yops-5.config
301+
imported by: yops-4.config
302+
imported by: yops/yops-3.config
303+
imported by: yops-0.project
304+
- yops-8.config
305+
imported by: yops/yops-7.config
306+
imported by: yops-6.config
307+
imported by: yops/yops-5.config
308+
imported by: yops-4.config
309+
imported by: yops/yops-3.config
310+
imported by: yops-2.config
311+
imported by: yops/yops-1.config
312+
imported by: yops-0.project
313+
- yops/yops-1.config
314+
imported by: yops-0.project
315+
- yops/yops-3.config
316+
imported by: yops-0.project
317+
- yops/yops-3.config
318+
imported by: yops-2.config
319+
imported by: yops/yops-1.config
320+
imported by: yops-0.project
321+
- yops/yops-5.config
322+
imported by: yops-0.project
323+
- yops/yops-5.config
324+
imported by: yops-4.config
325+
imported by: yops/yops-3.config
326+
imported by: yops-0.project
327+
- yops/yops-5.config
328+
imported by: yops-4.config
329+
imported by: yops/yops-3.config
330+
imported by: yops-2.config
331+
imported by: yops/yops-1.config
332+
imported by: yops-0.project
333+
- yops/yops-7.config
334+
imported by: yops-0.project
335+
- yops/yops-7.config
336+
imported by: yops-6.config
337+
imported by: yops/yops-5.config
338+
imported by: yops-0.project
339+
- yops/yops-7.config
340+
imported by: yops-6.config
341+
imported by: yops/yops-5.config
342+
imported by: yops-4.config
343+
imported by: yops/yops-3.config
344+
imported by: yops-0.project
345+
- yops/yops-7.config
346+
imported by: yops-6.config
347+
imported by: yops/yops-5.config
348+
imported by: yops-4.config
349+
imported by: yops/yops-3.config
350+
imported by: yops-2.config
351+
imported by: yops/yops-1.config
352+
imported by: yops-0.project
353+
- yops/yops-9.config
354+
imported by: yops-0.project
355+
- yops/yops-9.config
356+
imported by: yops-8.config
357+
imported by: yops/yops-7.config
358+
imported by: yops-0.project
359+
- yops/yops-9.config
360+
imported by: yops-8.config
361+
imported by: yops/yops-7.config
362+
imported by: yops-6.config
363+
imported by: yops/yops-5.config
364+
imported by: yops-0.project
365+
- yops/yops-9.config
366+
imported by: yops-8.config
367+
imported by: yops/yops-7.config
368+
imported by: yops-6.config
369+
imported by: yops/yops-5.config
370+
imported by: yops-4.config
371+
imported by: yops/yops-3.config
372+
imported by: yops-0.project
373+
- yops/yops-9.config
374+
imported by: yops-8.config
375+
imported by: yops/yops-7.config
376+
imported by: yops-6.config
377+
imported by: yops/yops-5.config
378+
imported by: yops-4.config
379+
imported by: yops/yops-3.config
380+
imported by: yops-2.config
381+
imported by: yops/yops-1.config
382+
imported by: yops-0.project
383+
Up to date
384+
>>>>>>> 7de199ad5 (Print info about current project file in use to stderr and ignore the imports by default (#10548))
280385
# checking bad conditional
281386
# cabal v2-build
282387
Error: [Cabal-7090]
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# cabal v2-configure
22
Configuration is affected by the following files:
33
- cabal.project
4-
Configuration is affected by the following files:
54
- cabal.project.local
65
'cabal.project.local' already exists, backing it up to 'cabal.project.local~'.
76
# cabal v2-configure
87
Configuration is affected by the following files:
98
- foo.project
10-
Configuration is affected by the following files:
119
- foo.project.local
1210
'foo.project.local' already exists, backing it up to 'foo.project.local~'.

cabal-testsuite/PackageTests/NewFreeze/BuildTools/new_freeze.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Wrote freeze file: <ROOT>/cabal.project.freeze
1818
# cabal v2-build
1919
Configuration is affected by the following files:
2020
- cabal.project
21-
Configuration is affected by the following files:
2221
- cabal.project.freeze
2322
Resolving dependencies...
2423
Build profile: -w ghc-<GHCVER> -O1

cabal-testsuite/PackageTests/NewFreeze/Flags/new_freeze.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Wrote freeze file: <ROOT>/cabal.project.freeze
1717
# cabal v2-build
1818
Configuration is affected by the following files:
1919
- cabal.project
20-
Configuration is affected by the following files:
2120
- cabal.project.freeze
2221
Resolving dependencies...
2322
Build profile: -w ghc-<GHCVER> -O1

cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Wrote freeze file: <ROOT>/cabal.project.freeze
2424
# cabal v2-build
2525
Configuration is affected by the following files:
2626
- cabal.project
27-
Configuration is affected by the following files:
2827
- cabal.project.freeze
2928
Resolving dependencies...
3029
Build profile: -w ghc-<GHCVER> -O1
@@ -41,7 +40,6 @@ Building executable 'my-exe' for my-local-package-1.0...
4140
# cabal v2-freeze
4241
Configuration is affected by the following files:
4342
- cabal.project
44-
Configuration is affected by the following files:
4543
- cabal.project.freeze
4644
Wrote freeze file: <ROOT>/cabal.project.freeze
4745
# cabal v2-build

0 commit comments

Comments
 (0)