Skip to content
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

cabal-install: Fix the directory the build folder is created in #10800

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ buildInplaceUnpackedPackage
-- TODO: [code cleanup] there is duplication between the
-- distdirlayout and the builddir here builddir is not
-- enough, we also need the per-package cachedir
createDirectoryIfMissingVerbose verbosity True $ getSymbolicPath builddir
createDirectoryIfMissingVerbose verbosity True $ interpretSymbolicPath (Just srcdir) builddir
createDirectoryIfMissingVerbose
verbosity
True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main = cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
else "haddock-response*.txt"

-- Check that there is a response file.
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
responseFiles <- assertGlobMatchesTestDir testSystemTmpDir glob

-- Check that the matched response file is not empty, and is indeed a Haddock
-- response file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ main =
else "haddock-response*.txt"

-- Check that there is a response file.
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
responseFiles <- assertGlobMatchesTestDir testSystemTmpDir glob

-- Check that the matched response file is not empty, and is indeed a Haddock
-- response file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- fake-package-0 (exe:script-script.hs) (first run)
Configuring executable 'script-script.hs' for fake-package-0...
Building executable 'script-script.hs' for fake-package-0...
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Test.Cabal.Prelude

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

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

shouldExist $ cacheDir </> "fake-package.cabal"
shouldExist $ cacheDir </> "scriptlocation"
shouldDirectoryNotExist $ testTmpDir env </> "build"
shouldDirectoryNotExist $ testTmpDir env </> "dist-newstyle"
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/NewBuild/CmdRun/NoContext/script.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /usr/bin/env cabal
{- cabal:
build-depends: base >= 4.3 && <5
-}
{-# LANGUAGE ScopedTypeVariables #-}

import Prelude

main :: IO ()
main = putStrLn "Hello World"
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import Test.Cabal.Prelude

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

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

shouldExist $ cacheDir </> "fake-package.cabal"
shouldExist $ cacheDir </> "scriptlocation"
shouldDirectoryNotExist $ testTmpDir env </> "build"
-- "dist-newstyle" should exist, because the folder has a cabal.project in
-- so the v2-run command runs in that context.
shouldDirectoryExist $ testTmpDir env </> "dist-newstyle"
11 changes: 9 additions & 2 deletions cabal-testsuite/src/Test/Cabal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Test.Cabal.Monad (
testPrefixDir,
testLibInstallDir,
testDistDir,
testSystemTmpDir,
testPackageDbDir,
testRepoDir,
testKeysDir,
Expand Down Expand Up @@ -407,9 +408,9 @@ runTestM mode m =
, ("CABAL_DIR", Just (testCabalDir env))
, ("CABAL_CONFIG", Just (testUserCabalConfigFile env))
-- Set `TMPDIR` so that temporary files aren't created in the global `TMPDIR`.
, ("TMPDIR", Just tmp_dir)
, ("TMPDIR", Just (testSystemTmpDir env))
-- Windows uses `TMP` for the `TMPDIR`.
, ("TMP", Just tmp_dir)
, ("TMP", Just (testSystemTmpDir env))
],
testShouldFail = False,
testRelativeCurrentDir = ".",
Expand Down Expand Up @@ -548,6 +549,7 @@ initWorkDir :: TestM ()
initWorkDir = do
env <- getTestEnv
liftIO $ createDirectoryIfMissing True (testWorkDir env)
liftIO $ createDirectoryIfMissing True (testSystemTmpDir env)



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

-- The folder which TMPDIR is set to.
-- This is different to testTmpDir, which is the folder which is the test is run from.
testSystemTmpDir :: TestEnv -> FilePath
testSystemTmpDir env = testWorkDir env </> "tmp"

-- | The absolute prefix where installs go.
testPrefixDir :: TestEnv -> FilePath
testPrefixDir env = testWorkDir env </> "usr"
Expand Down
12 changes: 12 additions & 0 deletions changelog.d/pr-10800
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
synopsis: Fix regression where 'build' folder was created in CWD when running a standlone script.
packages: cabal-install
prs: #10800
issues: #10772
significance:

description: {

Fix a regression where the `build` folder was created in the current directory
when running a standalone script.

}
Loading