on master help sign in
Use a consistent include dir for cwd (#114)

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 https://github.com/digital-asset/daml/issues/2929. We should move this logic completely over to the DAML repo at some point but I’ll leave that for a separate PR.

commitdcd7cb499e33273e1d5835ea1e69907e8224e483 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateMon 23 Sep 2019, 14:38 (7 years ago) parent79301b4
2 files changed+16−7
src/Development/IDE/Core/Compile.hs+1−1 src/Development/IDE/GHC/Util.hs+15−6
src/Development/IDE/Core/Compile.hs+1−1
@@ -158,7 +158,7 @@ upgradeWarningToError (nfp, fd) = (nfp, fd{_severity = Just DsError})
158158
159159addRelativeImport :: ParsedModule -> DynFlags -> DynFlags
160160addRelativeImport modu dflags = dflags
161− {importPaths = nubOrd $ maybeToList (moduleImportPaths modu) ++ importPaths dflags}
161+ {importPaths = nubOrd $ maybeToList (moduleImportPath modu) ++ importPaths dflags}
162162
163163mkTcModuleResult
164164 :: GhcMonad m
src/Development/IDE/GHC/Util.hs+15−6
@@ -17,7 +17,7 @@ module Development.IDE.GHC.Util(
1717 prettyPrint,
1818 runGhcEnv,
1919 textToStringBuffer,
20− moduleImportPaths,
20+ moduleImportPath,
2121 HscEnvEq, hscEnv, newHscEnvEq
2222 ) where
2323
@@ -103,16 +103,25 @@ fakeDynFlags = defaultDynFlags settings mempty
103103 , pc_WORD_SIZE=8
104104 }
105105
106−moduleImportPaths :: GHC.ParsedModule -> Maybe FilePath
107−moduleImportPaths pm
108− | rootModDir == "." = Just rootPathDir
109− | otherwise =
110− dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
106+moduleImportPath :: GHC.ParsedModule -> Maybe FilePath
107+moduleImportPath pm
108+ | rootModDir == "." = Just rootPathDir
109+ | otherwise = do
110+ dir <- dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
111+ -- For modules with more than one component, this can be empty, e.g.,
112+ -- stripSuffix (normalise ./A) (normalise ./A) for A/B.daml.
113+ -- We make a best effort attemp at not duplicating file paths
114+ -- by mapping the current directory to '.' if 'rootPathDir' starts with '.' and
115+ -- to an empty string otherwise.
116+ pure $! if null dir then dotDir else dir
111117 where
118+ dotDir = if "." `isPrefixOf` rootPathDir then "." else ""
112119 ms = GHC.pm_mod_summary pm
113120 file = GHC.ms_hspp_file ms
114121 mod' = GHC.ms_mod ms
122+ -- ./src/A for file ./src/A/B.daml
115123 rootPathDir = takeDirectory file
124+ -- A for module A.B
116125 rootModDir = takeDirectory . moduleNameSlashes . GHC.moduleName $ mod'
117126
118127-- | An HscEnv with equality.