From fe761f9b0c6703bf4b6c8b27c56692963cb63dcb Mon Sep 17 00:00:00 2001 From: Maciej Bielecki Date: Wed, 27 Oct 2021 12:23:09 +0000 Subject: [PATCH] Make test-ghc-env files unique across parallel jobs Since the build temporary directory is shared between jobs, we can't use the same file name for the `test-ghc-env` for all of them. Fixes https://github.com/commercialhaskell/stack/issues/5024 --- package.yaml | 1 + src/Stack/Build/Execute.hs | 4 +++- stack.cabal | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.yaml b/package.yaml index a70d058dce..9c5822f95c 100644 --- a/package.yaml +++ b/package.yaml @@ -104,6 +104,7 @@ dependencies: - primitive - process - project-template +- random - retry - rio >= 0.1.21.0 - rio-prettyprint >= 0.1.1.0 diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 8fbf4489cd..394ef2cc08 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -93,6 +93,7 @@ import System.PosixCompat.Files (createLink, modificationTime, getFile import RIO.PrettyPrint import RIO.Process import Pantry.Internal.Companion +import System.Random (randomIO) -- | Has an executable been built or not? data ExecutableBuildStatus @@ -1918,10 +1919,11 @@ singleTest topts testsToRun ac ee task installedMap = do -- see e.g. https://github.com/doctest/issues/119 -- also we set HASKELL_DIST_DIR to a package dist directory so -- doctest will be able to load modules autogenerated by Cabal + ghcEnvRandomId <- liftIO (randomIO :: IO Int) let setEnv f pc = modifyEnvVars pc $ \envVars -> Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePath buildDir) $ Map.insert "GHC_ENVIRONMENT" (T.pack f) envVars - fp = toFilePath $ eeTempDir ee testGhcEnvRelFile + fp = toFilePath (eeTempDir ee testGhcEnvRelFile) <> show ghcEnvRandomId snapDBPath = toFilePathNoTrailingSep (bcoSnapDB $ eeBaseConfigOpts ee) localDBPath = toFilePathNoTrailingSep (bcoLocalDB $ eeBaseConfigOpts ee) ghcEnv = diff --git a/stack.cabal b/stack.cabal index 423971375b..b483a19edd 100644 --- a/stack.cabal +++ b/stack.cabal @@ -282,6 +282,7 @@ library , primitive , process , project-template + , random , retry , rio >=0.1.21.0 , rio-prettyprint >=0.1.1.0 @@ -405,6 +406,7 @@ executable stack , primitive , process , project-template + , random , retry , rio >=0.1.21.0 , rio-prettyprint >=0.1.1.0 @@ -527,6 +529,7 @@ executable stack-integration-test , primitive , process , project-template + , random , retry , rio >=0.1.21.0 , rio-prettyprint >=0.1.1.0 @@ -654,6 +657,7 @@ test-suite stack-test , primitive , process , project-template + , random , raw-strings-qq , retry , rio >=0.1.21.0