Repository navigation
List each search path entry once in mkProgramDb - #12551
ulysses4ever wants to merge 2 commits into
Conversation
mkProgramDb puts the initial search path, which has the directories of the build-tool-depends executables, in front of the search path that prependProgramSearchPath made from it, so since haskell#9762 that path appears twice. Every search for a program that is not installed went through PATH twice, and every configured program, ghc included, ran with a PATH that listed each directory twice. Keep the first occurrence of each entry, so that lookups find the same programs in the same order. Found while looking into haskell#12544. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0176vAefrw8jPKXdh9h1wKuj
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0176vAefrw8jPKXdh9h1wKuj
|
84c30c2 made it so that There are three components to the program search paths: build-tool-depends directories ( I think we should more deliberately pass these search paths in this order, both in-library and for the external Setup method, in a way where we don't create duplicates in the first place. I think the code today is so confused/confusing that it needs to be tidied up first. |
|
I'm working on another PR to solve this in a more principled way. Here's the note I am drafting to finally bring a bit of clarity to this area of the codebase: {- Note [Program search paths]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Within Cabal, configuration (of a package or of a single component within a
package) produces a program search path (see 'progSearchPath'). It is used:
1. When configuring a program, to find its location
(see 'configureUnconfiguredProgram').
2. When running a program: 'programOverrideEnv' modifies the environment a
program runs in so that it gets a PATH that reflects the search path we
used to locate the program when we configured it.
Program lookup proceeds as follows:
O. Use the explicit override, if there was one (e.g. "--with-happy=<path>").
The override is given by 'configProgramPaths' (one entry per --with-PROG flag)
and recorded in the 'ProgramDb' by 'userSpecifyPaths'.
C. If the program comes bundled with the compiler, then use the location of
the compiler to find it (e.g. find `ghc-pkg` next to where we found `ghc`).
See 'guessToolFromGhcPath'.
If none of these cases above apply, we fall back to the program search path,
which must respect the following order:
B. Build tools specified in 'build-tool-depends'. This includes both
internal and external build tools.
E. Search paths given with --extra-prog-path, e.g. '--extra-prog-path=/opt/llvm/bin'.
P. The PATH environment variable.
We arrange this as follows:
1. Cabal puts internal build tools at the front, with 'addInternalBuildTools'.
(This is a bit of a special case, as it happens when building, not at
configure time.)
2. The rest of B & E is seen by Cabal as a single list that it gets given
(see 'configProgramPathExtra').
It is the responsibility of callers (e.g. cabal-install) to construct this
list in a way that respects the order above, for example by putting the
directories of external build tools first in this list.
3. Cabal falls back to P when lookup in 'configProgramPathExtra' fails.
B takes precedence over both E and P to ensure that build tools that were solved
for are used (e.g. to ensure the build tool has the exact version requested by
the user, as in #9756).
E takes precedence over P to allow users to customise program locations.
-} |
|
I put up my attempt in #12556. |
|
Closing in favour of #12556, which stops the search path from being duplicated in the first place ( |
configuresearches each directory of the program search path once again, and the programs it configures get aPATHthat lists each directory once. For #12544. Below is the longer story from your friendly AI engine (Opus 5.5).Since #9762 (Cabal 3.14),
mkProgramDbputs the initial search path, which has the directories of thebuild-tool-dependsexecutables, in front of the search path thatprependProgramSearchPathmade from it, so that path appears twice:[ProgramSearchPathDefault, ProgramSearchPathDefault]when there are no extra directories. This has two effects:PATHtwice.configuredoes several of those in every component, for the builtin programs that are not installed (Programs are configured needlessly often #12544).PATHthat lists each directory twice. Incabal repl,getEnv "PATH"has 88 entries for aPATHof 44.This keeps the first occurrence of each entry, so lookups find the same programs in the same order.
Reconfiguring the 41 components of a package of one-module sublibraries after a change to
PATH(on Linux, GHC 9.10.3):PATHof 44 entriesPATHof 444 entriessetup-configfiles, 444 entriesTesting
PathNoDuplicatesputs a directory in front ofPATHand checks thatcabal replsees it once; with master's cabal, it sees it twice. The tests about build tools andextra-prog-pathpass locally:BuildToolDepends,BuildToolDependsExternal,BuildToolDependsInternalMissing,BuildTools/*,ExtraProgPath,ExtraProgPathGlobal,ExtraProgPathLocal,IgnoreBuildTools,MultiRepl/BuildToolDependsandPathRecomp.significance: significantin the changelog file.QA Notes
Put a directory in front of
PATH, startcabal replin a package, and evaluateSystem.Environment.getEnv "PATH": the directory appears once. Since cabal 3.14 it has appeared twice (checked with 3.16.0.0).🤖 Generated with Claude Code
https://claude.ai/code/session_0176vAefrw8jPKXdh9h1wKuj