Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precedence for PATH for build-tools-depends #8972

Merged
merged 5 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,17 @@ mkProgramDb cfg initialProgramDb = programDb
. setProgramSearchPath searchpath
$ initialProgramDb
searchpath =
map
ProgramSearchPathDir
(fromNubList $ configProgramPathExtra cfg)
++ getProgramSearchPath initialProgramDb
getProgramSearchPath initialProgramDb
++ map
ProgramSearchPathDir
(fromNubList $ configProgramPathExtra cfg)

-- Note. We try as much as possible to _prepend_ rather than postpend the extra-prog-path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe postpend → append

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append doesn't specify to front or back

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to debate a native speaker, but “add (something) to the end of a written document.” (def).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun! I also don't like how artificial "postpend" sounds but on the other hand maybe extra clarity is justified here...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I was surprised by "append doesn't specify"; I've always understood it as meaning "to the end of".

-- so that we can override the system path. However, in a v2-build, at this point, the "system" path
-- has already been extended by both the built-tools-depends paths, as well as the program-path-extra
-- so for v2 builds adding it again is entirely unnecessary. However, it needs to get added again _anyway_
-- so as to take effect for v1 builds or standalone calls to Setup.hs
-- In this instance, the lesser evil is to not allow it to override the system path.

-- -----------------------------------------------------------------------------
-- Helper functions for configure
Expand Down
49 changes: 25 additions & 24 deletions cabal-install/src/Distribution/Client/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,35 @@ check verbosity = do

-- Poor man’s “group checks by constructor”.
groupChecks :: [PackageCheck] -> [NE.NonEmpty PackageCheck]
groupChecks ds = NE.groupBy (F.on (==) constInt)
(L.sortBy (F.on compare constInt) ds)
where
constInt :: PackageCheck -> Int
constInt (PackageBuildImpossible {}) = 0
constInt (PackageBuildWarning {}) = 1
constInt (PackageDistSuspicious {}) = 2
constInt (PackageDistSuspiciousWarn {}) = 3
constInt (PackageDistInexcusable {}) = 4
groupChecks ds =
NE.groupBy
(F.on (==) constInt)
(L.sortBy (F.on compare constInt) ds)
where
constInt :: PackageCheck -> Int
constInt (PackageBuildImpossible{}) = 0
constInt (PackageBuildWarning{}) = 1
constInt (PackageDistSuspicious{}) = 2
constInt (PackageDistSuspiciousWarn{}) = 3
constInt (PackageDistInexcusable{}) = 4

groupExplanation :: PackageCheck -> String
groupExplanation (PackageBuildImpossible {}) = "The package will not build sanely due to these errors:"
groupExplanation (PackageBuildWarning {}) = "The following errors are likely to affect your build negatively:"
groupExplanation (PackageDistSuspicious {}) = "These warnings will likely cause trouble when distributing the package:"
groupExplanation (PackageDistSuspiciousWarn {}) = "These warnings may cause trouble when distributing the package:"
groupExplanation (PackageDistInexcusable {}) = "The following errors will cause portability problems on other environments:"
groupExplanation (PackageBuildImpossible{}) = "The package will not build sanely due to these errors:"
groupExplanation (PackageBuildWarning{}) = "The following errors are likely to affect your build negatively:"
groupExplanation (PackageDistSuspicious{}) = "These warnings will likely cause trouble when distributing the package:"
groupExplanation (PackageDistSuspiciousWarn{}) = "These warnings may cause trouble when distributing the package:"
groupExplanation (PackageDistInexcusable{}) = "The following errors will cause portability problems on other environments:"

groupOutputFunction :: PackageCheck -> Verbosity -> String -> IO ()
groupOutputFunction (PackageBuildImpossible {}) ver = warnError ver
groupOutputFunction (PackageBuildWarning {}) ver = warnError ver
groupOutputFunction (PackageDistSuspicious {}) ver = warn ver
groupOutputFunction (PackageDistSuspiciousWarn {}) ver = warn ver
groupOutputFunction (PackageDistInexcusable {}) ver = warnError ver
groupOutputFunction (PackageBuildImpossible{}) ver = warnError ver
groupOutputFunction (PackageBuildWarning{}) ver = warnError ver
groupOutputFunction (PackageDistSuspicious{}) ver = warn ver
groupOutputFunction (PackageDistSuspiciousWarn{}) ver = warn ver
groupOutputFunction (PackageDistInexcusable{}) ver = warnError ver

outputGroupCheck :: Verbosity -> NE.NonEmpty PackageCheck -> IO ()
outputGroupCheck ver pcs = do
let hp = NE.head pcs
outf = groupOutputFunction hp ver
notice ver (groupExplanation hp)
CM.mapM_ (outf . ppPackageCheck) pcs

let hp = NE.head pcs
outf = groupOutputFunction hp ver
notice ver (groupExplanation hp)
CM.mapM_ (outf . ppPackageCheck) pcs
14 changes: 10 additions & 4 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ sanityCheckElaboratedPackage
-- readProjectConfig also loads the global configuration, which is read with
-- loadConfig and convertd to a ProjectConfig with convertLegacyGlobalConfig.
--
-- *Important*

-- * Important *

--
-- You can notice how some project config options are needed to read the
-- project config! This is evident by the fact that rebuildProjectConfig
Expand Down Expand Up @@ -539,9 +541,10 @@ configureCompiler
)
$ defaultProgramDb


------------------------------------------------------------------------------

-- * Deciding what to do: making an 'ElaboratedInstallPlan'

------------------------------------------------------------------------------

-- | Return an up-to-date elaborated install plan.
Expand Down Expand Up @@ -4009,8 +4012,11 @@ setupHsScriptOptions
, useDistPref = builddir
, useLoggingHandle = Nothing -- this gets set later
, useWorkingDir = Just srcdir
, useExtraPathEnv = elabExeDependencyPaths elab
, useExtraEnvOverrides = dataDirsEnvironmentForPlan distdir plan
, useExtraPathEnv = elabExeDependencyPaths elab ++ elabProgramPathExtra
, -- note that the above adds the extra-prog-path directly following the elaborated
-- dep paths, so that it overrides the normal path, but _not_ the elaborated extensions
-- for build-tools-depends.
useExtraEnvOverrides = dataDirsEnvironmentForPlan distdir plan
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comma goes here (for a cleaner diff), I believe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

, useWin32CleanHack = False -- TODO: [required eventually]
, forceExternalSetupMethod = isParallelBuild
, setupCacheLock = Just cacheLock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,24 @@ import Distribution.Solver.Types.PackageConstraint (PackageProperty (..))

import Data.Coerce (Coercible, coerce)
import Network.URI (URI (..), URIAuth (..), isUnreserved)
import Test.QuickCheck (Arbitrary(..), Gen, NonEmptyList(..),
arbitraryBoundedEnum, choose, elements, frequency, genericShrink,
liftArbitrary, listOf, oneof, resize, sized, shrinkBoundedEnum, suchThat, vectorOf)
import Test.QuickCheck
( Arbitrary (..)
, Gen
, NonEmptyList (..)
, arbitraryBoundedEnum
, choose
, elements
, frequency
, genericShrink
, liftArbitrary
, listOf
, oneof
, resize
, shrinkBoundedEnum
, sized
, suchThat
, vectorOf
)
import Test.QuickCheck.GenericArbitrary (genericArbitrary)
import Test.QuickCheck.Instances.Cabal ()

Expand Down
9 changes: 9 additions & 0 deletions changelog.d/pr-8972
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
synopsis: Fix precedence for PATH for build-tools-depends
packages: Cabal cabal-install
prs: #8972

description: {

- fixes a bug introduced in #8506 that caused executables in the path to take precedence over those specified in build-tools-depends.

}