Skip to content

Commit 8b82837

Browse files
committed
Fix TH dependent file detection for absolute paths and special characters (#105)
1 parent f976929 commit 8b82837

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Stack/Package.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,21 +769,24 @@ resolveFilesAndDeps ty buildComponentDir dirs names0 exts = do
769769
thDeps =
770770
case ty of
771771
AllFiles ->
772+
-- The dependent file path is surrounded by quotes but is not escaped.
773+
-- It can be an absolute or relative path.
772774
mapMaybe
773-
(fmap (dir </>) .
774-
parseRelFile .
775-
T.unpack .
776-
decodeUtf8 .
777-
C8.takeWhile (/= '"') .
778-
C8.dropWhile (== '"') . C8.dropWhile (/= '"')) $
775+
(parseAbsOrRelFile dir <=<
776+
(fmap T.unpack .
777+
(T.stripSuffix "\"" <=< T.stripPrefix "\"") .
778+
decodeUtf8 . C8.dropWhile (/= '"'))) $
779779
filter ("addDependentFile \"" `C8.isPrefixOf`) dumpHI
780780
Modules -> []
781781
--liftIO $ putStrLn $ "XXX dumpHI " ++ show dumpHIPath ++ "\n XXX moduleDeps=" ++ show moduleDeps ++ "\n XXX thDeps=" ++ show thDeps
782-
return
783-
(moduleDeps, thDeps)
782+
return (moduleDeps, thDeps)
784783
getHIDir = do
785784
bld <- asks snd
786785
return $ maybe bld (bld </>) buildComponentDir
786+
parseAbsOrRelFile dir fp =
787+
case parseRelFile fp of
788+
Just rel -> Just (dir </> rel)
789+
Nothing -> parseAbsFile fp
787790

788791
-- | Try to resolve the list of base names in the given directory by
789792
-- looking for unique instances of base names applied with the given

0 commit comments

Comments
 (0)