Skip to content

Commit 9896af0

Browse files
mergify[bot]mpickeringMikolaj
authored
Backport haskell#10800: cabal-install: Fix the directory the build folder is created in (haskell#10888)
* testsuite: Set TMPDIR to a specific folder rather than the test root If things start getting created in the TMPDIR, then it is better to not place them directly in the project root next to the source and test files. This also makes it easier to write tests which are sensitive to what is created in the CWD. (cherry picked from commit c64a32d) # Conflicts: # cabal-testsuite/PackageTests/HaddockKeepTmpsCustom/cabal.test.hs # cabal-testsuite/PackageTests/HaddockKeepsTmps/cabal.test.hs # cabal-testsuite/src/Test/Cabal/Monad.hs * cabal-install: Fix the directory the build folder is created in Clearly this path needs to be relative to the CWD, and the correct offset is passed as the `srcdir` parameter. Fixes haskell#10772 (cherry picked from commit 85ef030) * Add tests which check build/dist-newstyle folders are not created with v2-run The existing test CmdRun/Script is modified to test the case when v2-run is executed in a project context. This test checks that a "build" folder is not created in the CWD (haskell#10772) A new test is also added which checks what happens in the "no context" case. A separate bug was fixed in this area recently but no test added which verifies the change (haskell#10686) (cherry picked from commit 852430c) * Quickfix the conflicts in tests; let's see if it works * Remove test updates for which we lack machinery * Remove the added test and all the modifications to an old test --------- Co-authored-by: Matthew Pickering <[email protected]> Co-authored-by: Mikolaj Konarski <[email protected]>
1 parent ffa5f6d commit 9896af0

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ buildInplaceUnpackedPackage
447447
-- TODO: [code cleanup] there is duplication between the
448448
-- distdirlayout and the builddir here builddir is not
449449
-- enough, we also need the per-package cachedir
450-
createDirectoryIfMissingVerbose verbosity True $ getSymbolicPath builddir
450+
createDirectoryIfMissingVerbose verbosity True $ interpretSymbolicPath (Just srcdir) builddir
451451
createDirectoryIfMissingVerbose
452452
verbosity
453453
True

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

Lines changed: 11 additions & 0 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,
@@ -406,6 +407,10 @@ runTestM mode m =
406407
-- effect on Windows.
407408
, ("CABAL_DIR", Just (testCabalDir env))
408409
, ("CABAL_CONFIG", Just (testUserCabalConfigFile env))
410+
-- Set `TMPDIR` so that temporary files aren't created in the global `TMPDIR`.
411+
, ("TMPDIR", Just (testSystemTmpDir env))
412+
-- Windows uses `TMP` for the `TMPDIR`.
413+
, ("TMP", Just (testSystemTmpDir env))
409414
],
410415
testShouldFail = False,
411416
testRelativeCurrentDir = ".",
@@ -544,6 +549,7 @@ initWorkDir :: TestM ()
544549
initWorkDir = do
545550
env <- getTestEnv
546551
liftIO $ createDirectoryIfMissing True (testWorkDir env)
552+
liftIO $ createDirectoryIfMissing True (testSystemTmpDir env)
547553

548554

549555

@@ -820,6 +826,11 @@ testName env = testSubName env <.> testMode env
820826
testWorkDir :: TestEnv -> FilePath
821827
testWorkDir env = testTmpDir env </> (testName env <.> "dist")
822828

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+
823834
-- | The absolute prefix where installs go.
824835
testPrefixDir :: TestEnv -> FilePath
825836
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)