Skip to content

Commit 579de9d

Browse files
authored
Merge pull request #10800 from haskell/wip/t10772
cabal-install: Fix the directory the build folder is created in
2 parents 8a5a331 + 852430c commit 579de9d

File tree

9 files changed

+67
-6
lines changed

9 files changed

+67
-6
lines changed

cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ buildInplaceUnpackedPackage
459459
-- TODO: [code cleanup] there is duplication between the
460460
-- distdirlayout and the builddir here builddir is not
461461
-- enough, we also need the per-package cachedir
462-
createDirectoryIfMissingVerbose verbosity True $ getSymbolicPath builddir
462+
createDirectoryIfMissingVerbose verbosity True $ interpretSymbolicPath (Just srcdir) builddir
463463
createDirectoryIfMissingVerbose
464464
verbosity
465465
True

cabal-testsuite/PackageTests/HaddockKeepTmpsCustom/cabal.test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main = cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
1515
else "haddock-response*.txt"
1616

1717
-- Check that there is a response file.
18-
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
18+
responseFiles <- assertGlobMatchesTestDir testSystemTmpDir glob
1919

2020
-- Check that the matched response file is not empty, and is indeed a Haddock
2121
-- response file.

cabal-testsuite/PackageTests/HaddockKeepsTmps/cabal.test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ main =
2222
else "haddock-response*.txt"
2323

2424
-- Check that there is a response file.
25-
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
25+
responseFiles <- assertGlobMatchesTestDir testSystemTmpDir glob
2626

2727
-- Check that the matched response file is not empty, and is indeed a Haddock
2828
-- response file.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# cabal v2-run
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- fake-package-0 (exe:script-script.hs) (first run)
6+
Configuring executable 'script-script.hs' for fake-package-0...
7+
Building executable 'script-script.hs' for fake-package-0...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
-- NB: Uses cabal_raw' here to direct simulate what a user would write (#10772)
5+
res <- defaultRecordMode RecordMarked $ do
6+
recordHeader ["cabal", "v2-run"]
7+
cabal_raw' ["v2-run", "script.hs", marked_verbose] Nothing
8+
assertOutputContains "Hello World" res
9+
10+
env <- getTestEnv
11+
cacheDir <- getScriptCacheDirectory (testCurrentDir env </> "script.hs")
12+
liftIO $ print (testTmpDir env </> "build")
13+
14+
shouldExist $ cacheDir </> "fake-package.cabal"
15+
shouldExist $ cacheDir </> "scriptlocation"
16+
shouldDirectoryNotExist $ testTmpDir env </> "build"
17+
shouldDirectoryNotExist $ testTmpDir env </> "dist-newstyle"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /usr/bin/env cabal
2+
{- cabal:
3+
build-depends: base >= 4.3 && <5
4+
-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
6+
7+
import Prelude
8+
9+
main :: IO ()
10+
main = putStrLn "Hello World"
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import Test.Cabal.Prelude
22

33
main = cabalTest $ do
4-
res <- cabal' "v2-run" ["script.hs"]
4+
-- NB: Uses cabal_raw' here to direct simulate what a user would write (#10772)
5+
res <- defaultRecordMode RecordMarked $ do
6+
recordHeader ["cabal", "v2-run"]
7+
cabal_raw' ["v2-run", "script.hs", marked_verbose] Nothing
58
assertOutputContains "Hello World" res
69

710
env <- getTestEnv
811
cacheDir <- getScriptCacheDirectory (testCurrentDir env </> "script.hs")
12+
liftIO $ print (testTmpDir env </> "build")
913

1014
shouldExist $ cacheDir </> "fake-package.cabal"
1115
shouldExist $ cacheDir </> "scriptlocation"
16+
shouldDirectoryNotExist $ testTmpDir env </> "build"
17+
-- "dist-newstyle" should exist, because the folder has a cabal.project in
18+
-- so the v2-run command runs in that context.
19+
shouldDirectoryExist $ testTmpDir env </> "dist-newstyle"

cabal-testsuite/src/Test/Cabal/Monad.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Test.Cabal.Monad (
3434
testPrefixDir,
3535
testLibInstallDir,
3636
testDistDir,
37+
testSystemTmpDir,
3738
testPackageDbDir,
3839
testRepoDir,
3940
testKeysDir,
@@ -407,9 +408,9 @@ runTestM mode m =
407408
, ("CABAL_DIR", Just (testCabalDir env))
408409
, ("CABAL_CONFIG", Just (testUserCabalConfigFile env))
409410
-- Set `TMPDIR` so that temporary files aren't created in the global `TMPDIR`.
410-
, ("TMPDIR", Just tmp_dir)
411+
, ("TMPDIR", Just (testSystemTmpDir env))
411412
-- Windows uses `TMP` for the `TMPDIR`.
412-
, ("TMP", Just tmp_dir)
413+
, ("TMP", Just (testSystemTmpDir env))
413414
],
414415
testShouldFail = False,
415416
testRelativeCurrentDir = ".",
@@ -548,6 +549,7 @@ initWorkDir :: TestM ()
548549
initWorkDir = do
549550
env <- getTestEnv
550551
liftIO $ createDirectoryIfMissing True (testWorkDir env)
552+
liftIO $ createDirectoryIfMissing True (testSystemTmpDir env)
551553

552554

553555

@@ -824,6 +826,11 @@ testName env = testSubName env <.> testMode env
824826
testWorkDir :: TestEnv -> FilePath
825827
testWorkDir env = testTmpDir env </> (testName env <.> "dist")
826828

829+
-- The folder which TMPDIR is set to.
830+
-- This is different to testTmpDir, which is the folder which is the test is run from.
831+
testSystemTmpDir :: TestEnv -> FilePath
832+
testSystemTmpDir env = testWorkDir env </> "tmp"
833+
827834
-- | The absolute prefix where installs go.
828835
testPrefixDir :: TestEnv -> FilePath
829836
testPrefixDir env = testWorkDir env </> "usr"

changelog.d/pr-10800

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
synopsis: Fix regression where 'build' folder was created in CWD when running a standlone script.
2+
packages: cabal-install
3+
prs: #10800
4+
issues: #10772
5+
significance:
6+
7+
description: {
8+
9+
Fix a regression where the `build` folder was created in the current directory
10+
when running a standalone script.
11+
12+
}

0 commit comments

Comments
 (0)