Skip to content

Commit 4d6dfd6

Browse files
committed
Fix extra-prog-path propagation in the codebase.
This allows finding system executables in: - `cabal exec` - `cabal build` (configure steps for example) - `cabal get` In particular this fixes PATH issues when running MinGW cabal in PowerShell.
1 parent 7ba955f commit 4d6dfd6

File tree

9 files changed

+89
-21
lines changed

9 files changed

+89
-21
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import Distribution.Client.NixStyleOptions
2626
, defaultNixStyleFlags
2727
, nixStyleOptions
2828
)
29+
import Distribution.Client.ProjectConfig.Types
30+
( ProjectConfig (projectConfigShared)
31+
, ProjectConfigShared (projectConfigProgPathExtra)
32+
)
2933
import Distribution.Client.ProjectFlags
3034
( removeIgnoreProjectOption
3135
)
@@ -91,6 +95,9 @@ import Distribution.Simple.Utils
9195
, withTempDirectory
9296
, wrapText
9397
)
98+
import Distribution.Utils.NubList
99+
( fromNubList
100+
)
94101
import Distribution.Verbosity
95102
( normal
96103
)
@@ -163,9 +170,15 @@ execAction flags@NixStyleFlags{..} extraArgs globalFlags = do
163170

164171
-- Some dependencies may have executables. Let's put those on the PATH.
165172
extraPaths <- pathAdditions verbosity baseCtx buildCtx
173+
let configProgPathExtras =
174+
fromNubList
175+
. projectConfigProgPathExtra
176+
. projectConfigShared
177+
. projectConfig
178+
$ baseCtx
166179
let programDb =
167180
modifyProgramSearchPath
168-
(map ProgramSearchPathDir extraPaths ++)
181+
(map ProgramSearchPathDir (configProgPathExtras ++ extraPaths) ++)
169182
. pkgConfigCompilerProgs
170183
. elaboratedShared
171184
$ buildCtx

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ import Distribution.Client.NixStyleOptions
4848
, defaultNixStyleFlags
4949
, nixStyleOptions
5050
)
51+
import Distribution.Client.ProjectConfig.Types
52+
( ProjectConfig (projectConfigShared)
53+
, ProjectConfigShared (projectConfigProgPathExtra)
54+
)
5155
import Distribution.Client.ProjectOrchestration
5256
import Distribution.Client.ProjectPlanning
5357
( ElaboratedConfiguredPackage (..)
@@ -105,6 +109,9 @@ import Distribution.Types.UnqualComponentName
105109
( UnqualComponentName
106110
, unUnqualComponentName
107111
)
112+
import Distribution.Utils.NubList
113+
( fromNubList
114+
)
108115
import Distribution.Verbosity
109116
( normal
110117
, silent
@@ -288,6 +295,13 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
288295
buildSettingDryRun (buildSettings baseCtx)
289296
|| buildSettingOnlyDownload (buildSettings baseCtx)
290297

298+
let extraPath =
299+
fromNubList
300+
. projectConfigProgPathExtra
301+
. projectConfigShared
302+
. projectConfig
303+
$ baseCtx
304+
291305
if dryRun
292306
then notice verbosity "Running of executable suppressed by flag(s)"
293307
else
@@ -300,6 +314,7 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
300314
dataDirsEnvironmentForPlan
301315
(distDirLayout baseCtx)
302316
elaboratedPlan
317+
, progInvokePathEnv = extraPath
303318
}
304319
where
305320
(targetStr, args) = splitAt 1 targetAndArgs

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,14 @@ parseConfig src initial = \str -> do
15391539
splitMultiPath
15401540
(configConfigureArgs scf)
15411541
}
1542+
, savedGlobalFlags =
1543+
let sgf = savedGlobalFlags conf
1544+
in sgf
1545+
{ globalProgPathExtra =
1546+
toNubList $
1547+
splitMultiPath
1548+
(fromNubList $ globalProgPathExtra sgf)
1549+
}
15421550
}
15431551

15441552
parse =

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ import Distribution.Solver.Types.SourcePackage
7878
import Control.Monad (mapM_)
7979
import qualified Data.Map as Map
8080
import Distribution.Client.Errors
81+
import Distribution.Utils.NubList
82+
( fromNubList
83+
)
8184
import System.Directory
8285
( createDirectoryIfMissing
8386
, doesDirectoryExist
@@ -99,7 +102,7 @@ get
99102
-> IO ()
100103
get verbosity _ _ _ [] =
101104
notice verbosity "No packages requested. Nothing to do."
102-
get verbosity repoCtxt _ getFlags userTargets = do
105+
get verbosity repoCtxt globalFlags getFlags userTargets = do
103106
let useSourceRepo = case getSourceRepository getFlags of
104107
NoFlag -> False
105108
_ -> True
@@ -154,7 +157,7 @@ get verbosity repoCtxt _ getFlags userTargets = do
154157

155158
clone :: [UnresolvedSourcePackage] -> IO ()
156159
clone =
157-
clonePackagesFromSourceRepo verbosity prefix kind
160+
clonePackagesFromSourceRepo verbosity prefix kind (fromNubList $ globalProgPathExtra globalFlags)
158161
. map (\pkg -> (packageId pkg, packageSourceRepos pkg))
159162
where
160163
kind :: Maybe RepoKind
@@ -337,6 +340,8 @@ clonePackagesFromSourceRepo
337340
-- ^ destination dir prefix
338341
-> Maybe RepoKind
339342
-- ^ preferred 'RepoKind'
343+
-> [FilePath]
344+
-- ^ Extra prog paths
340345
-> [(PackageId, [PD.SourceRepo])]
341346
-- ^ the packages and their
342347
-- available 'SourceRepo's
@@ -345,13 +350,15 @@ clonePackagesFromSourceRepo
345350
verbosity
346351
destDirPrefix
347352
preferredRepoKind
353+
progPaths
348354
pkgrepos = do
349355
-- Do a bunch of checks and collect the required info
350356
pkgrepos' <- traverse preCloneChecks pkgrepos
351357

352358
-- Configure the VCS drivers for all the repository types we may need
353359
vcss <-
354-
configureVCSs verbosity $
360+
-- TODO: the empty list below should have the config prog paths
361+
configureVCSs verbosity progPaths $
355362
Map.fromList
356363
[ (vcsRepoType vcs, vcs)
357364
| (_, _, vcs, _) <- pkgrepos'

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,10 @@ syncAndReadSourcePackagesRemoteRepos
13511351
| (repo, rloc, rtype, vcs) <- repos'
13521352
]
13531353

1354-
-- TODO: pass progPathExtra on to 'configureVCS'
1355-
let _progPathExtra = fromNubList projectConfigProgPathExtra
1354+
let progPathExtra = fromNubList projectConfigProgPathExtra
13561355
getConfiguredVCS <- delayInitSharedResources $ \repoType ->
13571356
let vcs = Map.findWithDefault (error $ "Unknown VCS: " ++ prettyShow repoType) repoType knownVCSs
1358-
in configureVCS verbosity {-progPathExtra-} vcs
1357+
in configureVCS verbosity progPathExtra vcs
13591358

13601359
concat
13611360
<$> sequenceA

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ import Distribution.Simple.Program
6161
, runProgramInvocation
6262
, simpleProgram
6363
)
64+
import Distribution.Simple.Program.Db
65+
( modifyProgramSearchPath
66+
)
67+
import Distribution.Simple.Program.Find
68+
( ProgramSearchPathEntry (ProgramSearchPathDir)
69+
)
6470
import Distribution.Types.SourceRepo
6571
( KnownRepoType (..)
6672
, RepoType (..)
@@ -198,18 +204,22 @@ validateSourceRepos rs =
198204

199205
configureVCS
200206
:: Verbosity
207+
-> [FilePath]
201208
-> VCS Program
209+
-- ^ Extra prog paths
202210
-> IO (VCS ConfiguredProgram)
203-
configureVCS verbosity vcs@VCS{vcsProgram = prog} =
204-
asVcsConfigured <$> requireProgram verbosity prog emptyProgramDb
211+
configureVCS verbosity progPaths vcs@VCS{vcsProgram = prog} =
212+
asVcsConfigured <$> requireProgram verbosity prog (modifyProgramSearchPath (map ProgramSearchPathDir progPaths ++) emptyProgramDb)
205213
where
206214
asVcsConfigured (prog', _) = vcs{vcsProgram = prog'}
207215

208216
configureVCSs
209217
:: Verbosity
218+
-> [FilePath]
210219
-> Map RepoType (VCS Program)
220+
-- ^ Extra prog paths
211221
-> IO (Map RepoType (VCS ConfiguredProgram))
212-
configureVCSs verbosity = traverse (configureVCS verbosity)
222+
configureVCSs verbosity progPaths = traverse (configureVCS verbosity progPaths)
213223

214224
-- ------------------------------------------------------------
215225

cabal-install/tests/UnitTests/Distribution/Client/Get.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ testNoRepos :: Assertion
6464
testNoRepos = do
6565
e <-
6666
assertException $
67-
clonePackagesFromSourceRepo verbosity "." Nothing pkgrepos
67+
clonePackagesFromSourceRepo verbosity "." Nothing [] pkgrepos
6868
e @?= ClonePackageNoSourceRepos pkgidfoo
6969
where
7070
pkgrepos = [(pkgidfoo, [])]
@@ -73,7 +73,7 @@ testNoReposOfKind :: Assertion
7373
testNoReposOfKind = do
7474
e <-
7575
assertException $
76-
clonePackagesFromSourceRepo verbosity "." repokind pkgrepos
76+
clonePackagesFromSourceRepo verbosity "." repokind [] pkgrepos
7777
e @?= ClonePackageNoSourceReposOfKind pkgidfoo repokind
7878
where
7979
pkgrepos = [(pkgidfoo, [repo])]
@@ -84,7 +84,7 @@ testNoRepoType :: Assertion
8484
testNoRepoType = do
8585
e <-
8686
assertException $
87-
clonePackagesFromSourceRepo verbosity "." Nothing pkgrepos
87+
clonePackagesFromSourceRepo verbosity "." Nothing [] pkgrepos
8888
e @?= ClonePackageNoRepoType pkgidfoo repo
8989
where
9090
pkgrepos = [(pkgidfoo, [repo])]
@@ -94,7 +94,7 @@ testUnsupportedRepoType :: Assertion
9494
testUnsupportedRepoType = do
9595
e <-
9696
assertException $
97-
clonePackagesFromSourceRepo verbosity "." Nothing pkgrepos
97+
clonePackagesFromSourceRepo verbosity "." Nothing [] pkgrepos
9898
e @?= ClonePackageUnsupportedRepoType pkgidfoo repo' repotype
9999
where
100100
pkgrepos = [(pkgidfoo, [repo])]
@@ -118,7 +118,7 @@ testNoRepoLocation :: Assertion
118118
testNoRepoLocation = do
119119
e <-
120120
assertException $
121-
clonePackagesFromSourceRepo verbosity "." Nothing pkgrepos
121+
clonePackagesFromSourceRepo verbosity "." Nothing [] pkgrepos
122122
e @?= ClonePackageNoRepoLocation pkgidfoo repo
123123
where
124124
pkgrepos = [(pkgidfoo, [repo])]
@@ -139,7 +139,7 @@ testSelectRepoKind =
139139
e' @?= ClonePackageNoRepoType pkgidfoo expectedRepo
140140
| let test rt rs =
141141
assertException $
142-
clonePackagesFromSourceRepo verbosity "." rt rs
142+
clonePackagesFromSourceRepo verbosity "." rt [] rs
143143
, (requestedRepoType, expectedRepo) <- cases
144144
]
145145
where
@@ -161,14 +161,14 @@ testRepoDestinationExists =
161161
createDirectory pkgdir
162162
e1 <-
163163
assertException $
164-
clonePackagesFromSourceRepo verbosity tmpdir Nothing pkgrepos
164+
clonePackagesFromSourceRepo verbosity tmpdir Nothing [] pkgrepos
165165
e1 @?= ClonePackageDestinationExists pkgidfoo pkgdir True {- isdir -}
166166
removeDirectory pkgdir
167167

168168
writeFile pkgdir ""
169169
e2 <-
170170
assertException $
171-
clonePackagesFromSourceRepo verbosity tmpdir Nothing pkgrepos
171+
clonePackagesFromSourceRepo verbosity tmpdir Nothing [] pkgrepos
172172
e2 @?= ClonePackageDestinationExists pkgidfoo pkgdir False {- isfile -}
173173
where
174174
pkgrepos = [(pkgidfoo, [repo])]
@@ -199,7 +199,7 @@ testGitFetchFailed =
199199
pkgrepos = [(pkgidfoo, [repo])]
200200
e1 <-
201201
assertException $
202-
clonePackagesFromSourceRepo verbosity tmpdir Nothing pkgrepos
202+
clonePackagesFromSourceRepo verbosity tmpdir Nothing [] pkgrepos
203203
e1 @?= ClonePackageFailedWithExitCode pkgidfoo repo' "git" (ExitFailure 128)
204204

205205
testNetworkGitClone :: Assertion
@@ -214,6 +214,7 @@ testNetworkGitClone =
214214
verbosity
215215
tmpdir
216216
Nothing
217+
[]
217218
[(mkpkgid "zlib1", [repo1])]
218219
assertFileContains (tmpdir </> "zlib1/zlib.cabal") ["name:", "zlib"]
219220

@@ -226,6 +227,7 @@ testNetworkGitClone =
226227
verbosity
227228
tmpdir
228229
Nothing
230+
[]
229231
[(mkpkgid "zlib2", [repo2])]
230232
assertFileContains (tmpdir </> "zlib2/zlib.cabal") ["name:", "zlib"]
231233

@@ -239,6 +241,7 @@ testNetworkGitClone =
239241
verbosity
240242
tmpdir
241243
Nothing
244+
[]
242245
[(mkpkgid "zlib3", [repo3])]
243246
assertFileContains (tmpdir </> "zlib3/zlib.cabal") ["version:", "0.5.0.0"]
244247
where

cabal-install/tests/UnitTests/Distribution/Client/VCS.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ tests :: MTimeChange -> [TestTree]
5757
tests mtimeChange =
5858
map
5959
(localOption $ QuickCheckTests 10)
60-
[ ignoreInWindows "See issue #8048" $
60+
[ ignoreInWindows "See issue #8048 and #9519" $
6161
testGroup
6262
"git"
6363
[ testProperty "check VCS test framework" prop_framework_git
@@ -227,7 +227,7 @@ testSetup
227227
-> IO a
228228
testSetup vcs mkVCSTestDriver repoRecipe theTest = do
229229
-- test setup
230-
vcs' <- configureVCS verbosity vcs
230+
vcs' <- configureVCS verbosity [] vcs
231231
withTestDir verbosity "vcstest" $ \tmpdir -> do
232232
let srcRepoPath = tmpdir </> "src"
233233
submodulesPath = tmpdir </> "submodules"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
synopsis: Fix extra-prog-path propagation
2+
packages: cabal-install
3+
prs: #9527
4+
issues: #7649 #9519
5+
6+
description: {
7+
8+
- extra-prog-paths are now propagated to all commands. This in particular helps
9+
when running a MinGW cabal in the PowerShell, where the MSYS2 paths are
10+
usually not available in the PowerShell PATH. GHCup already sets them up for
11+
us but they were not being propagated properly.
12+
13+
}

0 commit comments

Comments
 (0)