-
Notifications
You must be signed in to change notification settings - Fork 714
Append paths in global config to progdb in configureCompiler v2 #10826
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
697a808
Append paths in global config to progdb in `configureCompiler`
jasagredo d9fb984
Add test to check global extra-prog-path is used in `configureCompiler`
yutotakano 29c2498
Refactor `configureCompiler` path addition for cleaner variable names
yutotakano b112c7a
Remove unnecessary build target from ExtraProgPathGlobal test command
yutotakano 7c9ab29
Fix ExtraProgPathGlobal test failing on Mac/Unix for missing +x perms
yutotakano dacc3d7
Rename pr-10790 changelog to pr-10826 as it superceded
yutotakano 860dfab
Add hashtag before PR/issue numbers in changelog for 10826
yutotakano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module MyLibrary () where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: *.cabal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: CheckExtraProgPathGlobal | ||
version: 0.1 | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: Yuto Takano | ||
maintainer: Yuto Takano | ||
synopsis: Check Extra Prog Path Global | ||
category: PackageTests | ||
build-type: Simple | ||
cabal-version: 2.0 | ||
|
||
description: | ||
Check that Cabal recognizes an override of the prog path. | ||
|
||
Library | ||
pkgconfig-depends: zlib | ||
default-language: Haskell2010 | ||
build-depends: base <5.0 | ||
exposed-modules: | ||
MyLibrary |
49 changes: 49 additions & 0 deletions
49
cabal-testsuite/PackageTests/ExtraProgPathGlobal/scripts-winpath/pkg-config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
# ugly, but "good enough" for this test | ||
# This will need to be updated whenever cabal invokes pkg-config | ||
# in new ways | ||
case "$*" in | ||
'--version') | ||
echo 2.1.0 # whatever | ||
;; | ||
|
||
'--variable pc_path pkg-config') | ||
echo '.' | ||
;; | ||
|
||
'--list-all') | ||
printf 'zlib zlib - zlib compression library\n' | ||
# \256 = \xAE is the iso-8859-1 (latin-1) encoded version of U+00AE, | ||
# i.e. the "registered sign": ® | ||
# This resulted in problems, see #9608 | ||
printf 'vpl Intel\256 Video Processing Library - Accelerated video decode, encode, and frame processing capabilities on Intel\256 GPUs\n' | ||
# \360 = \xF0 is latin-1 for ð; this is orð, Icelandic for "word"/"words". | ||
printf 'or\360 Icelandic characters\n' | ||
;; | ||
|
||
'--modversion '*) | ||
shift # drop the --modversion | ||
for arg; do | ||
case "$arg" in | ||
zlib) echo 1.3; ;; # whatever | ||
vpl) echo 2.10; ;; # whatever | ||
# No entry for orð here; let's not even try to match on that | ||
*) | ||
echo >&2 "Package $arg was not found in the pkg-config search path." | ||
exit 1 | ||
esac | ||
done | ||
;; | ||
|
||
# Ignore some stuff we're not implementing | ||
'--cflags '*) ;; | ||
'--libs '*) ;; | ||
|
||
*) | ||
echo >&2 "pkg-config: unrecognised arguments $* (this is an incomplete shim)" | ||
exit 1 | ||
;; | ||
esac |
Binary file added
BIN
+113 KB
cabal-testsuite/PackageTests/ExtraProgPathGlobal/scripts-winpath/pkg-config.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
cabal-testsuite/PackageTests/ExtraProgPathGlobal/scripts-winpath/pkg-config.shim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
path = "FINDSH/sh.exe" | ||
args = "SCRIPTSWINPATHDIR/pkg-config" |
3 changes: 3 additions & 0 deletions
3
cabal-testsuite/PackageTests/ExtraProgPathGlobal/scripts/pkg-config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
exit 1; |
Binary file added
BIN
+113 KB
cabal-testsuite/PackageTests/ExtraProgPathGlobal/scripts/pkg-config.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
cabal-testsuite/PackageTests/ExtraProgPathGlobal/scripts/pkg-config.shim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
path = "FINDSH/sh.exe" | ||
args = "SCRIPTSDIR/pkg-config" |
14 changes: 14 additions & 0 deletions
14
cabal-testsuite/PackageTests/ExtraProgPathGlobal/setup.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# cabal v2-build | ||
Configuration is affected by the following files: | ||
- cabal.project | ||
Warning: cannot determine version of <ROOT>/scripts/pkg-config : | ||
"" | ||
Warning: cannot determine version of <ROOT>/scripts/pkg-config : | ||
"" | ||
Resolving dependencies... | ||
Error: [Cabal-7107] | ||
Could not resolve dependencies: | ||
[__0] next goal: CheckExtraProgPathGlobal (user goal) | ||
[__0] rejecting: CheckExtraProgPathGlobal-0.1 (pkg-config package zlib-any is needed but no pkg-config executable was found or querying it failed) | ||
[__0] fail (backjumping, conflict set: CheckExtraProgPathGlobal) | ||
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: CheckExtraProgPathGlobal (2) |
60 changes: 60 additions & 0 deletions
60
cabal-testsuite/PackageTests/ExtraProgPathGlobal/setup.test.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Test.Cabal.Prelude | ||
import System.Directory | ||
|
||
-- Test that extra-prog-path in the global cabal config (~/.cabal/config) | ||
-- overrides the path for pkg-config while resolving a dependency on zlib. | ||
-- Specifically, this test emulates the scenario on Windows where pkg-config | ||
-- doesn't exist natively and must be provided via extra-prog-path. | ||
main = cabalTest $ do | ||
env <- getTestEnv | ||
let | ||
testDir = testCurrentDir env | ||
tmpDir = testTmpDir env | ||
-- Scripts is where we put a bad pkg-config | ||
scripts = tmpDir </> "scripts" | ||
-- Scripts-Winpath contains a mock pkg-config that returns good results. | ||
-- We add this to PATH on Windows before executing the test so we can tell | ||
-- apart when Cabal uses the override or not. | ||
scripts_winpath = tmpDir </> "scripts-winpath" | ||
|
||
------------------------- | ||
-- Workaround for the fact that, on Windows, Cabal will only look for | ||
-- .exe files to satisfy executable dependencies. So we have to create a | ||
-- shim pkg-config.exe file in 'script'. This is a thin wrapper (which is | ||
-- explicitly added to Git) that calls whatever is defined in the .shim | ||
-- file. In our case, we rewrite the .shim file as below so that the | ||
-- pkg-config script is executed using sh. | ||
when isWindows $ do | ||
mb_sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") | ||
case mb_sh of | ||
Nothing -> skip "no sh" | ||
Just sh -> do | ||
let escape = concatMap (\c -> case c of '\\' -> "\\\\\\\\"; x -> [x]) | ||
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> escape sh <> "/g", escape (scripts </> "pkg-config.shim"), escape (scripts_winpath </> "pkg-config.shim") ] | ||
void $ shell "sed" [ "-i", "-e", "s/SCRIPTSDIR/" <> escape scripts <> "/g", escape (scripts </> "pkg-config.shim") ] | ||
void $ shell "sed" [ "-i", "-e", "s/SCRIPTSWINPATHDIR/" <> escape scripts_winpath <> "/g", escape (scripts_winpath </> "pkg-config.shim") ] | ||
|
||
-- End of Windows workaround | ||
------------------------------ | ||
|
||
-- On Windows, we want it to find the "scripts/pkg-config" (which will | ||
-- return exit code 1), instead of what we add to the path | ||
-- ("scripts-winpath/pkg-config", which will return exit code 0). This is | ||
-- because Windows doesn't have a system pkg-config by default. If we didn't | ||
-- add a known-to-be-good mock pkg-config in the path, we wouldn't be able | ||
-- to tell apart from Cabal logs whether it wasn't able to find pkg-config | ||
-- at all (test fail) or whether the override worked and it found the bad | ||
-- one but couldn't query it (test success). | ||
-- | ||
-- On other systems, we want it to find "scripts/pkg-config" (exit code 1) | ||
-- instead of the system pkg-config (success). | ||
let wrap_test = if isWindows then addToPath scripts_winpath else id | ||
|
||
-- Add global config override in ~/.cabal/config (in the test environment). | ||
liftIO $ appendFile (testUserCabalConfigFile env) $ | ||
"\nextra-prog-path: " ++ scripts | ||
liftIO $ putStrLn $ testUserCabalConfigFile env | ||
|
||
-- On correct behaviour, cabal should fail because it found our exit-code-1 | ||
-- pkg-config through the global extra-prog-path. | ||
fails $ wrap_test $ cabal "v2-build" [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
synopsis: Prepend the global extra paths to the `ProgramDb` sooner | ||
packages: cabal-install | ||
prs: #10826 | ||
issues: #9800 | ||
significance: significant | ||
|
||
description: { | ||
|
||
- The initial configuration of programs was done without the `extra-prog-path` from the global cabal configuration. This meant that in some cases, some executables were not found. In particular this manifested as Windows users who didn't add the MSYS2 paths to the global PATH couldn't make use of `pkg-config`. | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.