diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/cabal.project b/cabal-testsuite/PackageTests/ExtraProgPathLocal/cabal.project new file mode 100644 index 00000000000..7c64e37f6d3 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/cabal.project @@ -0,0 +1 @@ +packages: client diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/client/Hello.x b/cabal-testsuite/PackageTests/ExtraProgPathLocal/client/Hello.x new file mode 100644 index 00000000000..9f36e8f8813 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/client/Hello.x @@ -0,0 +1,3 @@ +This file is deliberately an invalid .x file, +to ensure that we pick up the local alex script rather than +any system-wide alex executable. diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/client/client.cabal b/cabal-testsuite/PackageTests/ExtraProgPathLocal/client/client.cabal new file mode 100644 index 00000000000..825fb893922 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/client/client.cabal @@ -0,0 +1,12 @@ +name: client +version: 0.1.0.0 +synopsis: Checks build-tool-depends are put in PATH +license: BSD3 +category: Testing +build-type: Simple +cabal-version: >=1.10 + +executable hello-world + main-is: Hello.hs + build-depends: base + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex new file mode 100755 index 00000000000..5fd07c9795b --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +echo "I am not the alex you are looking for" diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex.exe b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex.exe differ diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex.shim b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex.shim new file mode 100644 index 00000000000..1b827e8f883 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts/alex.shim @@ -0,0 +1,2 @@ +path = "FINDSH/sh.exe" +args = "SCRIPTSDIR/alex" diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex new file mode 100755 index 00000000000..671539c560e --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex @@ -0,0 +1,4 @@ +#! /usr/bin/env bash + +echo "I am the alex you are looking for" +echo "module Main where main = print ()" > $3 diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex.exe b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex.exe differ diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex.shim b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex.shim new file mode 100644 index 00000000000..0ab606d997a --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/scripts2/alex.shim @@ -0,0 +1,2 @@ +path = "FINDSH/sh.exe" +args = "SCRIPTS2DIR/alex" diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/setup.out b/cabal-testsuite/PackageTests/ExtraProgPathLocal/setup.out new file mode 100644 index 00000000000..8bcc416af16 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/setup.out @@ -0,0 +1,10 @@ +# cabal v2-build +Configuration is affected by the following files: +- cabal.project +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - client-0.1.0.0 (exe:hello-world) (first run) +Configuring executable 'hello-world' for client-0.1.0.0... +Preprocessing executable 'hello-world' for client-0.1.0.0... +Building executable 'hello-world' for client-0.1.0.0... diff --git a/cabal-testsuite/PackageTests/ExtraProgPathLocal/setup.test.hs b/cabal-testsuite/PackageTests/ExtraProgPathLocal/setup.test.hs new file mode 100644 index 00000000000..496d5822dd1 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraProgPathLocal/setup.test.hs @@ -0,0 +1,39 @@ +import Test.Cabal.Prelude +import System.Directory + +-- Test package-local extra-prog-path works. +main = cabalTest $ do + env <- getTestEnv + let + testDir = testCurrentDir env + tmpDir = testTmpDir env + scripts1 = tmpDir "scripts" + scripts2 = tmpDir "scripts2" + + ------------------------- + -- Workaround for the fact that, on Windows, Cabal will only look for + -- .exe files to satisfy executable dependencs. So we have to create + -- shim alex.exe files (the good one in 'scripts2', the bad one in 'scripts') + -- with the logic below. + 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 (scripts1 "alex.shim"), escape (scripts2 "alex.shim") ] + void $ shell "sed" [ "-i", "-e", "s/SCRIPTSDIR/" <> escape scripts1 <> "/g", escape (scripts1 "alex.shim") ] + void $ shell "sed" [ "-i", "-e", "s/SCRIPTS2DIR/" <> escape scripts2 <> "/g", escape (scripts2 "alex.shim") ] + + -- End of Windows workarounds + ------------------------------ + + -- Add the 'scripts' directory to PATH, and add the 'scripts2' directory + -- to extra-prog-path. + -- + -- This checks that the executables in extra-prog-path take priority over + -- those in PATH: 'scripts/alex' will fail, while 'scripts2/alex' will succeed. + + liftIO $ appendFile (testDir "cabal.project") $ + "\npackage client\n extra-prog-path:" ++ scripts2 + addToPath scripts1 $ cabal "v2-build" ["client"]