Skip to content

Commit 74601f4

Browse files
Append paths in global config to progdb in configureCompiler v2 (#10826)
* Append paths in global config to progdb in `configureCompiler` * Add test to check global extra-prog-path is used in `configureCompiler` We add a new PackageTest for cabal-install, which makes sure that the extra-prog-path in the global config is used when resolving pkg-config instead of anything already on PATH. We do this by specifying a "bad" pkg-config to extra-prog-path that returns exit code 1. On Windows, Cabal logs are identical in the following two cases: - the override didn't work, and pkg-config was not found on the system - the override did work, and querying it failed (expectedly) To work around this, we add a "good" pkg-config script to PATH before- hand, so that cabal succeeds in the first case and the logs differ. This test is a stripped down reproduction of what happens when a user on Windows adds MSYS2 paths to extra-prog-path but not the system PATH. This is a reasonable setup (often, adding MSYS2 to system PATH is not good practice), and is even created automatically by GHCup. * Refactor `configureCompiler` path addition for cleaner variable names * Remove unnecessary build target from ExtraProgPathGlobal test command * Fix ExtraProgPathGlobal test failing on Mac/Unix for missing +x perms * Rename pr-10790 changelog to pr-10826 as it superceded * Add hashtag before PR/issue numbers in changelog for 10826 --------- Co-authored-by: Javier Sagredo <[email protected]>
1 parent c0d52b2 commit 74601f4

File tree

13 files changed

+174
-7
lines changed

13 files changed

+174
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ configureCompiler
476476
{ projectConfigHcFlavor
477477
, projectConfigHcPath
478478
, projectConfigHcPkg
479+
, projectConfigProgPathExtra
479480
}
480481
, projectConfigLocalPackages =
481482
PackageConfig
@@ -499,25 +500,28 @@ configureCompiler
499500
)
500501
$ do
501502
liftIO $ info verbosity "Compiler settings changed, reconfiguring..."
502-
let extraPath = fromNubList packageConfigProgramPathExtra
503-
progdb <- liftIO $ prependProgramSearchPath verbosity extraPath [] defaultProgramDb
504-
let progdb' = userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths)) progdb
505-
result@(_, _, progdb'') <-
503+
progdb <-
504+
liftIO $
505+
-- Add paths in the global config
506+
prependProgramSearchPath verbosity (fromNubList projectConfigProgPathExtra) [] defaultProgramDb
507+
-- Add paths in the local config
508+
>>= prependProgramSearchPath verbosity (fromNubList packageConfigProgramPathExtra) []
509+
>>= pure . userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths))
510+
result@(_, _, progdb') <-
506511
liftIO $
507512
Cabal.configCompilerEx
508513
hcFlavor
509514
hcPath
510515
hcPkg
511-
progdb'
516+
progdb
512517
verbosity
513-
514518
-- Note that we added the user-supplied program locations and args
515519
-- for /all/ programs, not just those for the compiler prog and
516520
-- compiler-related utils. In principle we don't know which programs
517521
-- the compiler will configure (and it does vary between compilers).
518522
-- We do know however that the compiler will only configure the
519523
-- programs it cares about, and those are the ones we monitor here.
520-
monitorFiles (programsMonitorFiles progdb'')
524+
monitorFiles (programsMonitorFiles progdb')
521525

522526
-- Note: There is currently a bug here: we are dropping unconfigured
523527
-- programs from the 'ProgramDb' when we re-use the cache created by
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module MyLibrary () where
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: *.cabal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CheckExtraProgPathGlobal
2+
version: 0.1
3+
license: BSD3
4+
license-file: LICENSE
5+
author: Yuto Takano
6+
maintainer: Yuto Takano
7+
synopsis: Check Extra Prog Path Global
8+
category: PackageTests
9+
build-type: Simple
10+
cabal-version: 2.0
11+
12+
description:
13+
Check that Cabal recognizes an override of the prog path.
14+
15+
Library
16+
pkgconfig-depends: zlib
17+
default-language: Haskell2010
18+
build-depends: base <5.0
19+
exposed-modules:
20+
MyLibrary
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
# ugly, but "good enough" for this test
6+
# This will need to be updated whenever cabal invokes pkg-config
7+
# in new ways
8+
case "$*" in
9+
'--version')
10+
echo 2.1.0 # whatever
11+
;;
12+
13+
'--variable pc_path pkg-config')
14+
echo '.'
15+
;;
16+
17+
'--list-all')
18+
printf 'zlib zlib - zlib compression library\n'
19+
# \256 = \xAE is the iso-8859-1 (latin-1) encoded version of U+00AE,
20+
# i.e. the "registered sign": ®
21+
# This resulted in problems, see #9608
22+
printf 'vpl Intel\256 Video Processing Library - Accelerated video decode, encode, and frame processing capabilities on Intel\256 GPUs\n'
23+
# \360 = \xF0 is latin-1 for ð; this is orð, Icelandic for "word"/"words".
24+
printf 'or\360 Icelandic characters\n'
25+
;;
26+
27+
'--modversion '*)
28+
shift # drop the --modversion
29+
for arg; do
30+
case "$arg" in
31+
zlib) echo 1.3; ;; # whatever
32+
vpl) echo 2.10; ;; # whatever
33+
# No entry for orð here; let's not even try to match on that
34+
*)
35+
echo >&2 "Package $arg was not found in the pkg-config search path."
36+
exit 1
37+
esac
38+
done
39+
;;
40+
41+
# Ignore some stuff we're not implementing
42+
'--cflags '*) ;;
43+
'--libs '*) ;;
44+
45+
*)
46+
echo >&2 "pkg-config: unrecognised arguments $* (this is an incomplete shim)"
47+
exit 1
48+
;;
49+
esac
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
path = "FINDSH/sh.exe"
2+
args = "SCRIPTSWINPATHDIR/pkg-config"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exit 1;
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
path = "FINDSH/sh.exe"
2+
args = "SCRIPTSDIR/pkg-config"

0 commit comments

Comments
 (0)