Skip to content

Commit

Permalink
New approach using --with-prog-name
Browse files Browse the repository at this point in the history
  • Loading branch information
mpickering committed Jan 13, 2025
1 parent ea2f922 commit 2869160
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/CmdRun.hs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
| otherwise =
[]
extraPath =
elabExeDependencyPaths pkg
map snd (elabExeDependencyPaths pkg)
++ ( fromNubList
. projectConfigProgPathExtra
. projectConfigShared
Expand Down
25 changes: 21 additions & 4 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildWay
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import Distribution.Simple.Program
import Distribution.Simple.Program.Types
import Distribution.Simple.Program.Db
import Distribution.Simple.Program.Find
import Distribution.System
Expand Down Expand Up @@ -1811,9 +1812,11 @@ elaborateInstallPlan
annotatedIdToConfiguredId
(cc_exe_deps cc0)
compExeDependencyPaths =
[ (annotatedIdToConfiguredId aid', path)
[ (annotatedIdToConfiguredId aid', (unUnqualComponentName cn, path))
| aid' <- cc_exe_deps cc0
, Just paths <- [Map.lookup (ann_id aid') exe_map1]
-- cc_exe_deps all must depend on executables.
, CExeName cn <- [ann_cname aid']
, path <- paths
]
elab_comp = ElaboratedComponent{..}
Expand Down Expand Up @@ -3817,11 +3820,11 @@ setupHsScriptOptions
]
, useDependenciesExclusive = True
, useVersionMacros = elabSetupScriptStyle == SetupCustomExplicitDeps
, useProgramDb = pkgConfigCompilerProgs
, useProgramDb = programDbWithBuildTools
, useDistPref = builddir
, useLoggingHandle = Nothing -- this gets set later
, useWorkingDir = Just srcdir
, useExtraPathEnv = elabExeDependencyPaths elab ++ elabProgramPathExtra
, useExtraPathEnv = map snd (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.
Expand All @@ -3831,6 +3834,13 @@ setupHsScriptOptions
, setupCacheLock = Just cacheLock
, isInteractive = False
}
where
-- Using simpleConfiguredProgram here is fine because the ProgramDb is
-- only used to pass --with-prog-name args to ./Setup commands.
programDbWithBuildTools =
foldr (\(name, path) -> updateProgram (simpleConfiguredProgram name (UserSpecified $ path </> name)))
pkgConfigCompilerProgs (elabExeDependencyPaths elab)


-- | To be used for the input for elaborateInstallPlan.
--
Expand Down Expand Up @@ -3985,7 +3995,14 @@ setupHsConfigureFlags
ElabPackage _ -> mempty
ElabComponent _ -> toFlag elabComponentId

configProgramPaths = Map.toList elabProgramPaths
buildToolDependsPaths = [(name, path </> name) | (name, path) <- elabExeDependencyPaths elab]

-- right-biased union
combineProgramPaths = Map.unionWith (\_ b -> b)

configProgramPaths =
-- Map wrangling to remove duplicates and prefer build-tool-depends paths.
Map.toList (elabProgramPaths `combineProgramPaths` Map.fromList buildToolDependsPaths)
configProgramArgs
| {- elabSetupScriptCliVersion < mkVersion [1,24,3] -} True =
-- workaround for <https://github.com/haskell/cabal/issues/4010>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ elabExeDependencies elab = map confInstId $
-- must add these paths to PATH before invoking the setup script.
-- (This is usually what you want, not 'elabExeDependencies', if you
-- actually want to build something.)
elabExeDependencyPaths :: ElaboratedConfiguredPackage -> [FilePath]
elabExeDependencyPaths :: ElaboratedConfiguredPackage -> [(String, FilePath)]
elabExeDependencyPaths elab =
case elabPkgOrComp elab of
ElabPackage pkg -> map snd $ CD.nonSetupDeps (pkgExeDependencyPaths pkg)
Expand Down Expand Up @@ -687,8 +687,8 @@ data ElaboratedComponent = ElaboratedComponent
-- internal executables).
, compPkgConfigDependencies :: [(PkgconfigName, Maybe PkgconfigVersion)]
-- ^ The @pkg-config@ dependencies of the component
, compExeDependencyPaths :: [(ConfiguredId, FilePath)]
-- ^ The paths all our executable dependencies will be installed
, compExeDependencyPaths :: [(ConfiguredId, (String, FilePath))]
-- ^ The path and name of all our executable dependencies will be installed
-- to once they are installed.
, compOrderLibDependencies :: [UnitId]
-- ^ The UnitIds of the libraries (identifying elaborated packages/
Expand Down Expand Up @@ -726,7 +726,7 @@ data ElaboratedPackage = ElaboratedPackage
-- a library registration
, pkgExeDependencies :: ComponentDeps [ConfiguredId]
-- ^ Dependencies on executable packages.
, pkgExeDependencyPaths :: ComponentDeps [(ConfiguredId, FilePath)]
, pkgExeDependencyPaths :: ComponentDeps [(ConfiguredId, (String, FilePath))]
-- ^ Paths where executable dependencies live.
, pkgPkgConfigDependencies :: [(PkgconfigName, Maybe PkgconfigVersion)]
-- ^ Dependencies on @pkg-config@ packages.
Expand Down

0 comments on commit 2869160

Please sign in to comment.