Skip to content

Commit

Permalink
Use a consistent include dir for cwd (#114)
Browse files Browse the repository at this point in the history
This only matters for the DAML codebase (so I’ll add a test on that
side) where we use relative paths:

Previously, we would produce the include dir "." for moduleImportPath
"./A.daml"
and "" for moduleImportPath "./A/B.daml". This resulted in us ending
up with ./A.daml and A.daml in the Shake graph which resulted in
issues like digital-asset/daml#2929.

We should move this logic completely over to the DAML repo at some
point but I’ll leave that for a separate PR.
  • Loading branch information
cocreature authored Sep 23, 2019
1 parent 79301b4 commit dcd7cb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ upgradeWarningToError (nfp, fd) = (nfp, fd{_severity = Just DsError})

addRelativeImport :: ParsedModule -> DynFlags -> DynFlags
addRelativeImport modu dflags = dflags
{importPaths = nubOrd $ maybeToList (moduleImportPaths modu) ++ importPaths dflags}
{importPaths = nubOrd $ maybeToList (moduleImportPath modu) ++ importPaths dflags}

mkTcModuleResult
:: GhcMonad m
Expand Down
21 changes: 15 additions & 6 deletions src/Development/IDE/GHC/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Development.IDE.GHC.Util(
prettyPrint,
runGhcEnv,
textToStringBuffer,
moduleImportPaths,
moduleImportPath,
HscEnvEq, hscEnv, newHscEnvEq
) where

Expand Down Expand Up @@ -103,16 +103,25 @@ fakeDynFlags = defaultDynFlags settings mempty
, pc_WORD_SIZE=8
}

moduleImportPaths :: GHC.ParsedModule -> Maybe FilePath
moduleImportPaths pm
| rootModDir == "." = Just rootPathDir
| otherwise =
dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
moduleImportPath :: GHC.ParsedModule -> Maybe FilePath
moduleImportPath pm
| rootModDir == "." = Just rootPathDir
| otherwise = do
dir <- dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
-- For modules with more than one component, this can be empty, e.g.,
-- stripSuffix (normalise ./A) (normalise ./A) for A/B.daml.
-- We make a best effort attemp at not duplicating file paths
-- by mapping the current directory to '.' if 'rootPathDir' starts with '.' and
-- to an empty string otherwise.
pure $! if null dir then dotDir else dir
where
dotDir = if "." `isPrefixOf` rootPathDir then "." else ""
ms = GHC.pm_mod_summary pm
file = GHC.ms_hspp_file ms
mod' = GHC.ms_mod ms
-- ./src/A for file ./src/A/B.daml
rootPathDir = takeDirectory file
-- A for module A.B
rootModDir = takeDirectory . moduleNameSlashes . GHC.moduleName $ mod'

-- | An HscEnv with equality.
Expand Down

0 comments on commit dcd7cb4

Please sign in to comment.