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

Fix test 4270 #4402

Merged
merged 8 commits into from
Nov 19, 2018
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
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ 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. 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

Expand Down
60 changes: 38 additions & 22 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -803,12 +803,21 @@ 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
cwd <- liftIO getCurrentDir
dir <- asks (parent . ctxFile)
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.
targetJsSources :: BuildInfo -> [FilePath]
Expand Down Expand Up @@ -1227,14 +1236,18 @@ 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

-- | Resolve file as a child of a specified directory, symlinks
-- don't get followed.
resolveDirFile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining that symlinks will not be followed.

:: (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.
Expand Down Expand Up @@ -1311,16 +1324,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
Expand Down
1 change: 1 addition & 0 deletions test/integration/IntegrationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions test/integration/lib/StackTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/tests/4270-files-order/files/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-12.8
resolver: lts-11.22

packages:
- .