Skip to content

Commit 2c19bf3

Browse files
mpickeringMikolaj
authored andcommitted
Add a test to check that extra-prog-path is honoured for local packages
Whilst fixing #10692, I realised there was also this bug where extra-prog-path would not be honoured for specific packages. The idea behind extra-prog-path is that each local package can use a different version of a preprocessor if desired.
1 parent 24f8395 commit 2c19bf3

File tree

11 files changed

+76
-0
lines changed

11 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: client
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is deliberately an invalid .x file,
2+
to ensure that we pick up the local alex script rather than
3+
any system-wide alex executable.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: client
2+
version: 0.1.0.0
3+
synopsis: Checks build-tool-depends are put in PATH
4+
license: BSD3
5+
category: Testing
6+
build-type: Simple
7+
cabal-version: >=1.10
8+
9+
executable hello-world
10+
main-is: Hello.hs
11+
build-depends: base
12+
default-language: Haskell2010
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /usr/bin/env bash
2+
3+
echo "I am not the alex you are looking for"
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
path = "FINDSH/sh.exe"
2+
args = "SCRIPTSDIR/alex"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /usr/bin/env bash
2+
3+
echo "I am the alex you are looking for"
4+
echo "module Main where main = print ()" > $3
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
path = "FINDSH/sh.exe"
2+
args = "SCRIPTS2DIR/alex"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# cabal v2-build
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- client-0.1.0.0 (exe:hello-world) (first run)
8+
Configuring executable 'hello-world' for client-0.1.0.0...
9+
Preprocessing executable 'hello-world' for client-0.1.0.0...
10+
Building executable 'hello-world' for client-0.1.0.0...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Test.Cabal.Prelude
2+
import System.Directory
3+
4+
-- Test package-local extra-prog-path works.
5+
main = cabalTest $ do
6+
env <- getTestEnv
7+
let
8+
testDir = testCurrentDir env
9+
tmpDir = testTmpDir env
10+
scripts1 = tmpDir </> "scripts"
11+
scripts2 = tmpDir </> "scripts2"
12+
13+
-------------------------
14+
-- Workaround for the fact that, on Windows, Cabal will only look for
15+
-- .exe files to satisfy executable dependencs. So we have to create
16+
-- shim alex.exe files (the good one in 'scripts2', the bad one in 'scripts')
17+
-- with the logic below.
18+
when isWindows $ do
19+
mb_sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
20+
case mb_sh of
21+
Nothing -> skip "no sh"
22+
Just sh -> do
23+
let escape = concatMap (\c -> case c of '\\' -> "\\\\\\\\"; x -> [x])
24+
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> escape sh <> "/g", escape (scripts1 </> "alex.shim"), escape (scripts2 </> "alex.shim") ]
25+
void $ shell "sed" [ "-i", "-e", "s/SCRIPTSDIR/" <> escape scripts1 <> "/g", escape (scripts1 </> "alex.shim") ]
26+
void $ shell "sed" [ "-i", "-e", "s/SCRIPTS2DIR/" <> escape scripts2 <> "/g", escape (scripts2 </> "alex.shim") ]
27+
28+
-- End of Windows workarounds
29+
------------------------------
30+
31+
-- Add the 'scripts' directory to PATH, and add the 'scripts2' directory
32+
-- to extra-prog-path.
33+
--
34+
-- This checks that the executables in extra-prog-path take priority over
35+
-- those in PATH: 'scripts/alex' will fail, while 'scripts2/alex' will succeed.
36+
37+
liftIO $ appendFile (testDir </> "cabal.project") $
38+
"\npackage client\n extra-prog-path:" ++ scripts2
39+
addToPath scripts1 $ cabal "v2-build" ["client"]

0 commit comments

Comments
 (0)