From 9637b6fb7f919a81595bc5db03e5d6e0678a7a76 Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sun, 18 Mar 2018 00:33:39 -0700 Subject: [PATCH] Work around issue #4515 in several new-build integration tests. This commit uses a temporary directory for the nix store in several of the new-build tests in cabal-testsuite. The directory is given a very short path on Windows in order to avoid issues with long store paths. --- .../use-local-package-as-setup-dep.test.hs | 27 +++--- ...ld-local-package-with-custom-setup.test.hs | 15 +-- ...ackage-from-repo-with-custom-setup.test.hs | 23 ++--- .../PackageTests/NewBuild/T4375/cabal.test.hs | 5 +- .../NewFreeze/FreezeFile/new_freeze.test.hs | 91 ++++++++++--------- cabal-testsuite/Test/Cabal/Prelude.hs | 14 ++- 6 files changed, 96 insertions(+), 79 deletions(-) diff --git a/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.test.hs b/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.test.hs index b8822ebfdad..6db060469a8 100644 --- a/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.test.hs +++ b/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.test.hs @@ -10,16 +10,17 @@ import Test.Cabal.Prelude -- qualifier as pkg, even though they are both build targets of the project. -- The solution must use --independent-goals to give pkg and setup-dep different -- qualifiers. -main = cabalTest $ do - skipUnless =<< hasNewBuildCompatBootCabal - withRepo "repo" $ do - fails $ cabal "new-build" ["pkg:my-exe", "--dry-run"] - -- Disabled recording because whether or not we get - -- detailed information for the build of my-exe depends - -- on whether or not the Cabal library version is recent - -- enough - r1 <- recordMode DoNotRecord $ cabal' "new-build" ["pkg:my-exe", "--independent-goals"] - assertOutputContains "Setup.hs: setup-dep from project" r1 - withPlan $ do - r2 <- runPlanExe' "pkg" "my-exe" [] - assertOutputContains "Main.hs: setup-dep from repo" r2 +main = withShorterPathForNewBuildStore $ \storeDir -> + cabalTest $ do + skipUnless =<< hasNewBuildCompatBootCabal + withRepo "repo" $ do + fails $ cabalG ["--store-dir=" ++ storeDir] "new-build" ["pkg:my-exe", "--dry-run"] + -- Disabled recording because whether or not we get + -- detailed information for the build of my-exe depends + -- on whether or not the Cabal library version is recent + -- enough + r1 <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "new-build" ["pkg:my-exe", "--independent-goals"] + assertOutputContains "Setup.hs: setup-dep from project" r1 + withPlan $ do + r2 <- runPlanExe' "pkg" "my-exe" [] + assertOutputContains "Main.hs: setup-dep from repo" r2 diff --git a/cabal-testsuite/PackageTests/NewBuild/CustomSetup/LocalPackageWithCustomSetup/build-local-package-with-custom-setup.test.hs b/cabal-testsuite/PackageTests/NewBuild/CustomSetup/LocalPackageWithCustomSetup/build-local-package-with-custom-setup.test.hs index a39ff4bce73..792695ce8eb 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CustomSetup/LocalPackageWithCustomSetup/build-local-package-with-custom-setup.test.hs +++ b/cabal-testsuite/PackageTests/NewBuild/CustomSetup/LocalPackageWithCustomSetup/build-local-package-with-custom-setup.test.hs @@ -2,10 +2,11 @@ import Test.Cabal.Prelude -- The one local package, pkg, has a setup dependency on setup-dep-2.0, which is -- in the repository. -main = cabalTest $ do - skipUnless =<< hasNewBuildCompatBootCabal - withRepo "repo" $ do - r <- recordMode DoNotRecord $ cabal' "new-build" ["pkg"] - -- pkg's setup script should print out a message that it imported from - -- setup-dep: - assertOutputContains "pkg Setup.hs: setup-dep-2.0" r +main = withShorterPathForNewBuildStore $ \storeDir -> + cabalTest $ do + skipUnless =<< hasNewBuildCompatBootCabal + withRepo "repo" $ do + r <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "new-build" ["pkg"] + -- pkg's setup script should print out a message that it imported from + -- setup-dep: + assertOutputContains "pkg Setup.hs: setup-dep-2.0" r diff --git a/cabal-testsuite/PackageTests/NewBuild/CustomSetup/RemotePackageWithCustomSetup/build-package-from-repo-with-custom-setup.test.hs b/cabal-testsuite/PackageTests/NewBuild/CustomSetup/RemotePackageWithCustomSetup/build-package-from-repo-with-custom-setup.test.hs index d21e4fc8e49..fbd0bc11681 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CustomSetup/RemotePackageWithCustomSetup/build-package-from-repo-with-custom-setup.test.hs +++ b/cabal-testsuite/PackageTests/NewBuild/CustomSetup/RemotePackageWithCustomSetup/build-package-from-repo-with-custom-setup.test.hs @@ -2,14 +2,15 @@ import Test.Cabal.Prelude -- The one local package, pkg, has a dependency on remote-pkg-2.0, which has a -- setup dependency on remote-setup-dep-3.0. -main = cabalTest $ do - skipUnless =<< hasNewBuildCompatBootCabal - withRepo "repo" $ do - r1 <- recordMode DoNotRecord $ cabal' "new-build" ["pkg:my-exe"] - -- remote-pkg's setup script should print out a message that it imported from - -- remote-setup-dep: - assertOutputContains "remote-pkg Setup.hs: remote-setup-dep-3.0" r1 - withPlan $ do - r2 <- runPlanExe' "pkg" "my-exe" [] - -- pkg's executable should print a message that it imported from remote-pkg: - assertOutputContains "pkg Main.hs: remote-pkg-2.0" r2 +main = withShorterPathForNewBuildStore $ \storeDir -> + cabalTest $ do + skipUnless =<< hasNewBuildCompatBootCabal + withRepo "repo" $ do + r1 <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "new-build" ["pkg:my-exe"] + -- remote-pkg's setup script should print out a message that it imported from + -- remote-setup-dep: + assertOutputContains "remote-pkg Setup.hs: remote-setup-dep-3.0" r1 + withPlan $ do + r2 <- runPlanExe' "pkg" "my-exe" [] + -- pkg's executable should print a message that it imported from remote-pkg: + assertOutputContains "pkg Main.hs: remote-pkg-2.0" r2 diff --git a/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.test.hs b/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.test.hs index f6684ff352d..ec12a08f137 100644 --- a/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.test.hs +++ b/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.test.hs @@ -1,5 +1,6 @@ import Test.Cabal.Prelude -main = cabalTest $ do +main = withShorterPathForNewBuildStore $ \storeDir -> + cabalTest $ do -- Don't run this test unless the GHC is sufficiently recent -- to not ship boot old-time/old-locale skipUnless =<< ghcVersionIs (>= mkVersion [7,11]) @@ -8,4 +9,4 @@ main = cabalTest $ do -- we had the full Hackage index, we'd try it.) skipUnless =<< ghcVersionIs (< mkVersion [8,1]) withRepo "repo" $ do - cabal "new-build" ["a"] + cabalG ["--store-dir=" ++ storeDir] "new-build" ["a"] diff --git a/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs b/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs index de914a226a2..8a50ae4f097 100644 --- a/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs +++ b/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs @@ -5,48 +5,49 @@ import System.Directory -- Test for 'cabal new-freeze' with only a single library dependency. -- my-local-package depends on my-library-dep, which has versions 1.0 and 2.0. -main = cabalTest $ withSourceCopy $ - withRepo "repo" $ do - cwd <- fmap testCurrentDir getTestEnv - let freezeFile = cwd "cabal.project.freeze" - - shouldNotExist freezeFile - - -- new-build should choose the latest version for the dependency. - cabal' "new-build" ["--dry-run"] >>= assertUsesLatestDependency - - -- Freeze a dependency on the older version. - cabal "new-freeze" ["--constraint=my-library-dep==1.0"] - - -- The file should constrain the dependency, but not the local package. - shouldExist freezeFile - assertFileDoesContain freezeFile "any.my-library-dep ==1.0" - assertFileDoesNotContain freezeFile "my-local-package" - - -- cabal should be able to build the package using the constraint from the - -- freeze file. - cabal' "new-build" [] >>= assertDoesNotUseLatestDependency - - -- Re-running new-freeze should not change the constraints, because cabal - -- should use the existing freeze file when choosing the new install plan. - cabal "new-freeze" [] - assertFileDoesContain freezeFile "any.my-library-dep ==1.0" - - -- cabal should choose the latest version again after the freeze file is - -- removed. - liftIO $ removeFile freezeFile - cabal' "new-build" ["--dry-run"] >>= assertUsesLatestDependency - - -- Re-running new-freeze with no constraints or freeze file should constrain - -- the dependency to the latest version. - cabal "new-freeze" [] - assertFileDoesContain freezeFile "any.my-library-dep ==2.0" - assertFileDoesNotContain freezeFile "my-local-package" - where - assertUsesLatestDependency out = do - assertOutputContains "my-library-dep-2.0 (lib)" out - assertOutputDoesNotContain "my-library-dep-1.0" out - - assertDoesNotUseLatestDependency out = do - assertOutputContains "my-library-dep-1.0 (lib)" out - assertOutputDoesNotContain "my-library-dep-2.0" out +main = withShorterPathForNewBuildStore $ \storeDir -> + cabalTest $ withSourceCopy $ + withRepo "repo" $ do + cwd <- fmap testCurrentDir getTestEnv + let freezeFile = cwd "cabal.project.freeze" + + shouldNotExist freezeFile + + -- new-build should choose the latest version for the dependency. + cabalG' ["--store-dir=" ++ storeDir] "new-build" ["--dry-run"] >>= assertUsesLatestDependency + + -- Freeze a dependency on the older version. + cabalG ["--store-dir=" ++ storeDir] "new-freeze" ["--constraint=my-library-dep==1.0"] + + -- The file should constrain the dependency, but not the local package. + shouldExist freezeFile + assertFileDoesContain freezeFile "any.my-library-dep ==1.0" + assertFileDoesNotContain freezeFile "my-local-package" + + -- cabal should be able to build the package using the constraint from the + -- freeze file. + cabalG' ["--store-dir=" ++ storeDir] "new-build" [] >>= assertDoesNotUseLatestDependency + + -- Re-running new-freeze should not change the constraints, because cabal + -- should use the existing freeze file when choosing the new install plan. + cabalG ["--store-dir=" ++ storeDir] "new-freeze" [] + assertFileDoesContain freezeFile "any.my-library-dep ==1.0" + + -- cabal should choose the latest version again after the freeze file is + -- removed. + liftIO $ removeFile freezeFile + cabalG' ["--store-dir=" ++ storeDir] "new-build" ["--dry-run"] >>= assertUsesLatestDependency + + -- Re-running new-freeze with no constraints or freeze file should constrain + -- the dependency to the latest version. + cabalG ["--store-dir=" ++ storeDir] "new-freeze" [] + assertFileDoesContain freezeFile "any.my-library-dep ==2.0" + assertFileDoesNotContain freezeFile "my-local-package" + where + assertUsesLatestDependency out = do + assertOutputContains "my-library-dep-2.0 (lib)" out + assertOutputDoesNotContain "my-library-dep-1.0" out + + assertDoesNotUseLatestDependency out = do + assertOutputContains "my-library-dep-1.0 (lib)" out + assertOutputDoesNotContain "my-library-dep-2.0" out diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 950ae2c17c7..9de245ef468 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -27,7 +27,7 @@ import Distribution.Simple.Program.Db import Distribution.Simple.Program import Distribution.System (OS(Windows,Linux,OSX), buildOS) import Distribution.Simple.Utils - ( withFileContents, tryFindPackageDesc ) + ( withFileContents, withTempDirectory, tryFindPackageDesc ) import Distribution.Simple.Configure ( getPersistBuildConfig ) import Distribution.Version @@ -36,6 +36,7 @@ import Distribution.Types.UnqualComponentName import Distribution.Types.LocalBuildInfo import Distribution.PackageDescription import Distribution.PackageDescription.Parsec +import Distribution.Verbosity (normal) import Distribution.Compat.Stack @@ -930,3 +931,14 @@ isTestFile f = ".test.hs" -> True ".multitest.hs" -> True _ -> False + +-- | Work around issue #4515 (store paths exceeding the Windows path length +-- limit) by creating a temporary directory for the new-build store. This +-- function creates a directory immediately under the current drive on Windows. +-- The directory must be passed to new- commands with --store-dir. +withShorterPathForNewBuildStore :: (FilePath -> IO a) -> IO a +withShorterPathForNewBuildStore test = do + tempDir <- if buildOS == Windows + then takeDrive `fmap` getCurrentDirectory + else getTemporaryDirectory + withTempDirectory normal tempDir "cabal-test-store" test