Skip to content

Commit

Permalink
Fix MacOS canonical paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Sep 1, 2024
1 parent fb21b24 commit d575fea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Cabal-tests/lib/Test/Utils/TempTestDir.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ withTestDir verbosity template action = withTestDir' verbosity defaultTempFileOp

withTestDir' :: (MonadIO m, MonadMask m) => Verbosity -> TempFileOptions -> String -> (FilePath -> m a) -> m a
withTestDir' verbosity tempFileOpts template action = do
systmpdir <- liftIO getTemporaryDirectory
systmpdir <-
-- MacOS returns /var/folders/... which is a symlink (/var -> /private/var),
-- so the test-suite struggles to make the build cwd-agnostic in particular
-- for the ShowBuildInfo tests. This canonicalizePath call makes it
-- /private/var/folders/... which will work.
liftIO $ canonicalizePath =<< getTemporaryDirectory
bracket
( do { tmpRelDir <- liftIO $ createTempDirectory systmpdir template
; return $ systmpdir </> tmpRelDir } )
Expand Down
11 changes: 6 additions & 5 deletions cabal-testsuite/src/Test/Cabal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ mkNormalizerEnv = do
tmpDir <- liftIO $ getTemporaryDirectory

canonicalizedTestTmpDir <- liftIO $ canonicalizePath (testTmpDir env)
canonicalizedGblDir <- liftIO $ canonicalizePath tmpDir

-- 'cabal' is configured in the package-db, but doesn't specify how to find the program version
-- Thus we find the program location, if it exists, and query for the program version for
Expand All @@ -642,11 +643,6 @@ mkNormalizerEnv = do
liftIO (findProgramVersion "--numeric-version" id (testVerbosity env) (programPath cabalProg))

return NormalizerEnv {
normalizerRoot
= (if buildOS == Windows
then joinDrive "\\" . dropDrive
else id)
$ addTrailingPathSeparator (testSourceDir env),
normalizerTmpDir
= (if buildOS == Windows
then joinDrive "\\" . dropDrive
Expand All @@ -662,6 +658,11 @@ mkNormalizerEnv = do
then joinDrive "\\" . dropDrive
else id)
$ addTrailingPathSeparator tmpDir,
normalizerCanonicalGblTmpDir
= (if buildOS == Windows
then joinDrive "\\" . dropDrive
else id)
$ addTrailingPathSeparator canonicalizedGblDir,
normalizerGhcVersion
= compilerVersion (testCompiler env),
normalizerGhcPath
Expand Down
14 changes: 12 additions & 2 deletions cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ normalizeOutput nenv =
-- string search-replace. Make sure we do this before backslash
-- normalization!
. resub (posixRegexEscape (normalizerGblTmpDir nenv) ++ "[a-z0-9\\.-]+") "<GBLTMPDIR>"
. resub (posixRegexEscape (normalizerCanonicalGblTmpDir nenv) ++ "[a-z0-9\\.-]+") "<GBLTMPDIR>"
-- Munge away .exe suffix on filenames (Windows)
. (if buildOS == Windows then resub "([A-Za-z0-9.-]+)\\.exe" "\\1" else id)
-- tmp/src-[0-9]+ is tmp\src-[0-9]+ in Windows
Expand Down Expand Up @@ -123,12 +124,21 @@ normalizeOutput nenv =
"\"-package-id\",\"<PACKAGEDEP>\""

data NormalizerEnv = NormalizerEnv
{ normalizerRoot :: FilePath
, normalizerTmpDir :: FilePath
{ normalizerTmpDir :: FilePath
, normalizerCanonicalTmpDir :: FilePath
-- ^ May differ from 'normalizerTmpDir', especially e.g. on macos, where
-- `/var` is a symlink for `/private/var`.
, normalizerGblTmpDir :: FilePath
-- ^ The global temp directory: @/tmp@ on Linux, @/var/folders/...@ on macos
-- and @\\msys64\\tmp@ on Windows.
--
-- Note that on windows the actual path would be @C:\\msys64\\tmp@ but we
-- drop the @C:@ prefix because this path appears sometimes
-- twice in the same path in some tests, and the second time it doesn't have a @C:@, so
-- the logic fails to catch it.
, normalizerCanonicalGblTmpDir :: FilePath
-- ^ The canonical version of 'normalizerGblTmpDir', might differ in the same
-- way as above on macos
, normalizerGhcVersion :: Version
, normalizerGhcPath :: FilePath
, normalizerKnownPackages :: [PackageId]
Expand Down

0 comments on commit d575fea

Please sign in to comment.