From c098f45511629b1006b96a71b7fa826365141212 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Fri, 16 Nov 2018 09:55:12 +0300 Subject: [PATCH 1/7] disable buffering for /tmp/stderr --- test/integration/lib/StackTest.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/lib/StackTest.hs b/test/integration/lib/StackTest.hs index 12daa8e280..1cd7bca05a 100644 --- a/test/integration/lib/StackTest.hs +++ b/test/integration/lib/StackTest.hs @@ -98,8 +98,10 @@ runRepl cmd args actions = do hSetBuffering rStderr NoBuffering _ <- forkIO $ withFile "/tmp/stderr" WriteMode - $ \err -> forever $ catch (hGetChar rStderr >>= hPutChar err) - $ \e -> unless (isEOFError e) $ throw e + $ \err -> do + hSetBuffering err NoBuffering + forever $ catch (hGetChar rStderr >>= hPutChar err) + $ \e -> unless (isEOFError e) $ throw e runReaderT (nextPrompt >> actions) (ReplConnection rStdin rStdout) waitForProcess ph From ca9ee4c6a5ca2474f627e814e8463bb1b9dcae94 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Fri, 16 Nov 2018 10:14:20 +0300 Subject: [PATCH 2/7] Copy .tag.gz files to prevent redownloading of Hackage index --- test/integration/IntegrationSpec.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/IntegrationSpec.hs b/test/integration/IntegrationSpec.hs index f5595e5eb8..1144347dad 100644 --- a/test/integration/IntegrationSpec.hs +++ b/test/integration/IntegrationSpec.hs @@ -139,6 +139,7 @@ toCopyRoot srcfp = any (`isSuffixOf` srcfp) -- FIXME command line parameters to control how many of these get -- copied, trade-off of runtime/bandwidth vs isolation of tests [ ".tar" + , ".tar.gz" , ".xz" -- , ".gz" , ".7z.exe" From d992a3367cb56a82eae44c18ed4a5906228692a5 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Fri, 16 Nov 2018 12:15:01 +0300 Subject: [PATCH 3/7] Use default resolver for test 4270-files-order --- test/integration/tests/4270-files-order/files/stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/tests/4270-files-order/files/stack.yaml b/test/integration/tests/4270-files-order/files/stack.yaml index c18657e207..2241b0f190 100644 --- a/test/integration/tests/4270-files-order/files/stack.yaml +++ b/test/integration/tests/4270-files-order/files/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-12.8 +resolver: lts-11.22 packages: - . From af36e049e740c2bfa8810a20d1700a849a200b11 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Fri, 16 Nov 2018 12:27:20 +0300 Subject: [PATCH 4/7] Resolve c files without resolving symbolic links Without this change `stack repl` fails to load .o files when they come from a symbolic link --- src/Stack/Package.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index b7ad44820a..ed9e099ada 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -803,12 +803,16 @@ resolveComponentFiles component build names = do -- | Get all C sources and extra source files in a build. buildOtherSources :: BuildInfo -> RIO Ctx [DotCabalPath] -buildOtherSources build = - do csources <- liftM (map DotCabalCFilePath) - (mapMaybeM resolveFileOrWarn (cSources build)) - jsources <- liftM (map DotCabalFilePath) - (mapMaybeM resolveFileOrWarn (targetJsSources build)) - return (csources <> jsources) +buildOtherSources build = do + dir <- asks (parent . ctxFile) + -- TODO: add warnMissing here too + csources <- + forMaybeM (cSources build) $ \fp -> + findCandidate [dir] (DotCabalCFile fp) + jsources <- + forMaybeM (targetJsSources build) $ \fp -> + findCandidate [dir] (DotCabalFile fp) + return (csources <> jsources) -- | Get the target's JS sources. targetJsSources :: BuildInfo -> [FilePath] From d96be328faea5b4b0b50b3e3edd6ee41157818d9 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Mon, 19 Nov 2018 12:04:57 +0300 Subject: [PATCH 5/7] More granular file resolving function, add back warnings --- src/Stack/Package.hs | 56 ++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index ed9e099ada..1f6439fcf0 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -804,14 +804,19 @@ resolveComponentFiles component build names = do -- | Get all C sources and extra source files in a build. buildOtherSources :: BuildInfo -> RIO Ctx [DotCabalPath] buildOtherSources build = do + cwd <- liftIO getCurrentDir dir <- asks (parent . ctxFile) - -- TODO: add warnMissing here too - csources <- - forMaybeM (cSources build) $ \fp -> - findCandidate [dir] (DotCabalCFile fp) - jsources <- - forMaybeM (targetJsSources build) $ \fp -> - findCandidate [dir] (DotCabalFile fp) + file <- asks ctxFile + let resolveDirFiles files toCabalPath = + forMaybeM files $ \fp -> do + result <- resolveDirFile dir fp + case result of + Nothing -> do + warnMissingFile "File" cwd fp file + return Nothing + Just p -> return $ Just (toCabalPath p) + csources <- resolveDirFiles (cSources build) DotCabalCFilePath + jsources <- resolveDirFiles (targetJsSources build) DotCabalFilePath return (csources <> jsources) -- | Get the target's JS sources. @@ -1231,14 +1236,16 @@ findCandidate dirs name = do -- Otherwise, return everything (xs, ys) -> xs ++ ys - resolveCandidate - :: (MonadIO m, MonadThrow m) - => Path Abs Dir -> FilePath.FilePath -> m [Path Abs File] - resolveCandidate x y = do - -- The standard canonicalizePath does not work for this case - p <- parseCollapsedAbsFile (toFilePath x FilePath. y) - exists <- doesFileExist p - return $ if exists then [p] else [] + resolveCandidate dir = fmap maybeToList . resolveDirFile dir + +resolveDirFile + :: (MonadIO m, MonadThrow m) + => Path Abs Dir -> FilePath.FilePath -> m (Maybe (Path Abs File)) +resolveDirFile x y = do + -- The standard canonicalizePath does not work for this case + p <- parseCollapsedAbsFile (toFilePath x FilePath. y) + exists <- doesFileExist p + return $ if exists then Just p else Nothing -- | Warn the user that multiple candidates are available for an -- entry, but that we picked one anyway and continued. @@ -1315,16 +1322,19 @@ resolveOrWarn subject resolver path = file <- asks ctxFile dir <- asks (parent . ctxFile) result <- resolver dir path - when (isNothing result) $ - prettyWarnL - [ fromString . T.unpack $ subject -- TODO: needs style? - , flow "listed in" - , maybe (pretty file) pretty (stripProperPrefix cwd file) - , flow "file does not exist:" - , style Dir . fromString $ path - ] + when (isNothing result) $ warnMissingFile subject cwd path file return result +warnMissingFile :: Text -> Path Abs Dir -> FilePath -> Path Abs File -> RIO Ctx () +warnMissingFile subject cwd path fromFile = + prettyWarnL + [ fromString . T.unpack $ subject -- TODO: needs style? + , flow "listed in" + , maybe (pretty fromFile) pretty (stripProperPrefix cwd fromFile) + , flow "file does not exist:" + , style Dir . fromString $ path + ] + -- | Resolve the file, if it can't be resolved, warn for the user -- (purely to be helpful). resolveFileOrWarn :: FilePath.FilePath From 1ea6bc57fc63b6f56bedfba0566bed7dd947be4d Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Mon, 19 Nov 2018 14:23:43 +0300 Subject: [PATCH 6/7] Update changelog --- ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index a6db22f3b9..6e7477bef6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -94,6 +94,8 @@ Bug fixes: * Fix for git packages to update submodules to the correct state. See [#4314](https://github.com/commercialhaskell/stack/pull/4314) * Add `--cabal-files` flag to `stack ide targets` command. +* Support loading in GHCi definitions from symlinked C files. See + [#4402](https://github.com/commercialhaskell/stack/pull/4402) ## v1.9.1 From f31a808267f398a703a61014748f3e755d1c0fd4 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Mon, 19 Nov 2018 15:03:45 +0300 Subject: [PATCH 7/7] More haddocks and changelog details --- ChangeLog.md | 5 ++++- src/Stack/Package.hs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 3ba29a88c0..fef5c5da00 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -97,7 +97,10 @@ Bug fixes: [#4314](https://github.com/commercialhaskell/stack/pull/4314) * Add `--cabal-files` flag to `stack ide targets` command. * Don't download ghc when using `stack clean`. -* Support loading in GHCi definitions from symlinked C files. See +* Support loading in GHCi definitions from symlinked C files. Without this + patch, Stack will try to find object files in the directory pointed to + by symlinks, while GCC will produce the object files in the original + directory. See [#4402](https://github.com/commercialhaskell/stack/pull/4402) ## v1.9.1 diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index 1f6439fcf0..542ed97f4d 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -1238,6 +1238,8 @@ findCandidate dirs name = do (xs, ys) -> xs ++ ys resolveCandidate dir = fmap maybeToList . resolveDirFile dir +-- | Resolve file as a child of a specified directory, symlinks +-- don't get followed. resolveDirFile :: (MonadIO m, MonadThrow m) => Path Abs Dir -> FilePath.FilePath -> m (Maybe (Path Abs File))