Skip to content

Commit

Permalink
More granular file resolving function, add back warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
qrilka committed Nov 19, 2018
1 parent af36e04 commit 7117686
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,17 @@ 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
file <- asks ctxFile
csources <-
forMaybeM (cSources build) $ \fp ->
findCandidate [dir] (DotCabalCFile fp)
forMaybeM (cSources build) $ \fp -> do
result <- resolveDirFile dir fp
case result of
Nothing -> do
warnMissingFile "File" cwd fp file
return Nothing
Just p -> return $ Just (DotCabalCFilePath p)
jsources <-
forMaybeM (targetJsSources build) $ \fp ->
findCandidate [dir] (DotCabalFile fp)
Expand Down Expand Up @@ -1231,14 +1237,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.
Expand Down Expand Up @@ -1315,16 +1323,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

0 comments on commit 7117686

Please sign in to comment.