diff options
| author | Sylvain Henry <sylvain@haskus.fr> | 2021-01-22 18:20:15 +0100 |
|---|---|---|
| committer | Ben Gamari <ben@smart-cactus.org> | 2021-04-07 15:04:04 -0400 |
| commit | fc1a91acde94eda66bfd106e4438ce5f7cbe4e27 (patch) | |
| tree | d928e5a1a5b1eb6f7caa9b5968e333025a787704 | |
| parent | 216a59c0b1eecd5542339de847c9573822189d49 (diff) | |
| download | haskell-fc1a91acde94eda66bfd106e4438ce5f7cbe4e27.tar.gz | |
Add missing .hi-boot dependencies with ghc -M (#14482)
(cherry picked from commit 18e106a8dfdae50c3078558382209f53794a8c97)
| -rw-r--r-- | compiler/basicTypes/Module.hs | 8 | ||||
| -rw-r--r-- | compiler/main/DriverMkDepend.hs | 12 | ||||
| -rw-r--r-- | hadrian/src/Hadrian/Oracles/TextFile.hs | 10 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/A.hs | 5 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/B.hs | 3 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/B.hs-boot | 3 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/C.hs | 10 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/Makefile | 8 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/T14482.stdout | 14 | ||||
| -rw-r--r-- | testsuite/tests/driver/T14482/all.T | 1 |
10 files changed, 71 insertions, 3 deletions
diff --git a/compiler/basicTypes/Module.hs b/compiler/basicTypes/Module.hs index e46d4a55b1..6b770d84e8 100644 --- a/compiler/basicTypes/Module.hs +++ b/compiler/basicTypes/Module.hs @@ -112,7 +112,7 @@ module Module -- * The ModuleLocation type ModLocation(..), - addBootSuffix, addBootSuffix_maybe, + addBootSuffix, removeBootSuffix, addBootSuffix_maybe, addBootSuffixLocn, addBootSuffixLocnOut, -- * Module mappings @@ -293,6 +293,12 @@ addBootSuffix :: FilePath -> FilePath -- ^ Add the @-boot@ suffix to .hs, .hi and .o files addBootSuffix path = path ++ "-boot" +-- | Remove the @-boot@ suffix to .hs, .hi and .o files +removeBootSuffix :: FilePath -> FilePath +removeBootSuffix "-boot" = [] +removeBootSuffix (x:xs) = x : removeBootSuffix xs +removeBootSuffix [] = error "removeBootSuffix: no -boot suffix" + addBootSuffix_maybe :: Bool -> FilePath -> FilePath -- ^ Add the @-boot@ suffix if the @Bool@ argument is @True@ addBootSuffix_maybe is_boot path diff --git a/compiler/main/DriverMkDepend.hs b/compiler/main/DriverMkDepend.hs index 6368d8c785..87466b268f 100644 --- a/compiler/main/DriverMkDepend.hs +++ b/compiler/main/DriverMkDepend.hs @@ -39,7 +39,7 @@ import System.Directory import System.FilePath import System.IO import System.IO.Error ( isEOFError ) -import Control.Monad ( when ) +import Control.Monad ( when, forM_ ) import Data.Maybe ( isJust ) import Data.IORef @@ -225,6 +225,16 @@ processDeps dflags hsc_env excl_mods root hdl (AcyclicSCC node) -- Something like A.o : A.hs ; writeDependency root hdl obj_files src_file + -- add dependency between objects and their corresponding .hi-boot + -- files if the module has a corresponding .hs-boot file (#14482) + ; when (isBootSummary node) $ do + let hi_boot = msHiFilePath node + let obj = removeBootSuffix (msObjFilePath node) + forM_ extra_suffixes $ \suff -> do + let way_obj = insertSuffixes obj [suff] + let way_hi_boot = insertSuffixes hi_boot [suff] + mapM_ (writeDependency root hdl way_obj) way_hi_boot + -- Emit a dependency for each CPP import ; when (depIncludeCppDeps dflags) $ do -- CPP deps are descovered in the module parsing phase by parsing diff --git a/hadrian/src/Hadrian/Oracles/TextFile.hs b/hadrian/src/Hadrian/Oracles/TextFile.hs index aef553f70d..9cf678a37a 100644 --- a/hadrian/src/Hadrian/Oracles/TextFile.hs +++ b/hadrian/src/Hadrian/Oracles/TextFile.hs @@ -18,6 +18,7 @@ module Hadrian.Oracles.TextFile ( import Control.Monad import qualified Data.HashMap.Strict as Map import Data.Maybe +import Data.List import Development.Shake import Development.Shake.Classes import Development.Shake.Config @@ -60,7 +61,14 @@ lookupValuesOrError file key = fromMaybe (error msg) <$> lookupValues file key -- compiling @source@, which in turn also depends on a number of other @files@. lookupDependencies :: FilePath -> FilePath -> Action (FilePath, [FilePath]) lookupDependencies depFile file = do - deps <- lookupValues depFile file + let -- .hs needs to come before .hi-boot deps added to fix #14482. + -- This is still a bit fragile: we have no order guaranty from the input + -- file. Let's hope we don't have two different .hs source files (e.g. + -- one included into the other)... + weigh p + | ".hs" `isSuffixOf` p = 0 :: Int + | otherwise = 1 + deps <- fmap (sortOn weigh) <$> lookupValues depFile file case deps of Nothing -> error $ "No dependencies found for file " ++ quote file Just [] -> error $ "No source file found for file " ++ quote file diff --git a/testsuite/tests/driver/T14482/A.hs b/testsuite/tests/driver/T14482/A.hs new file mode 100644 index 0000000000..fc453a5094 --- /dev/null +++ b/testsuite/tests/driver/T14482/A.hs @@ -0,0 +1,5 @@ +module A where + +import {-# SOURCE #-} B + +data A = A B diff --git a/testsuite/tests/driver/T14482/B.hs b/testsuite/tests/driver/T14482/B.hs new file mode 100644 index 0000000000..64e74c695a --- /dev/null +++ b/testsuite/tests/driver/T14482/B.hs @@ -0,0 +1,3 @@ +module B where + +data B = B diff --git a/testsuite/tests/driver/T14482/B.hs-boot b/testsuite/tests/driver/T14482/B.hs-boot new file mode 100644 index 0000000000..66fadef083 --- /dev/null +++ b/testsuite/tests/driver/T14482/B.hs-boot @@ -0,0 +1,3 @@ +module B where + +data B diff --git a/testsuite/tests/driver/T14482/C.hs b/testsuite/tests/driver/T14482/C.hs new file mode 100644 index 0000000000..5cb3a6aea6 --- /dev/null +++ b/testsuite/tests/driver/T14482/C.hs @@ -0,0 +1,10 @@ +module Main where + +import A +import B + +data C = C A +data D = D B + +main :: IO () +main = putStrLn "" diff --git a/testsuite/tests/driver/T14482/Makefile b/testsuite/tests/driver/T14482/Makefile new file mode 100644 index 0000000000..e8b1fd84cc --- /dev/null +++ b/testsuite/tests/driver/T14482/Makefile @@ -0,0 +1,8 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +T14482: + rm -f *.o *.hi *.o-boot *.hi-boot C result + '$(TEST_HC)' -M C.hs -dep-suffix "p_" -dep-suffix "q_" -dep-makefile result + cat result diff --git a/testsuite/tests/driver/T14482/T14482.stdout b/testsuite/tests/driver/T14482/T14482.stdout new file mode 100644 index 0000000000..4c58ff2df4 --- /dev/null +++ b/testsuite/tests/driver/T14482/T14482.stdout @@ -0,0 +1,14 @@ +# DO NOT DELETE: Beginning of Haskell dependencies +B.q_o-boot B.p_o-boot : B.hs-boot +B.q_o : B.q_hi-boot +B.p_o : B.p_hi-boot +A.q_o A.p_o : A.hs +A.q_o : B.q_hi-boot +A.p_o : B.p_hi-boot +B.q_o B.p_o : B.hs +C.q_o C.p_o : C.hs +C.q_o : B.q_hi +C.p_o : B.p_hi +C.q_o : A.q_hi +C.p_o : A.p_hi +# DO NOT DELETE: End of Haskell dependencies diff --git a/testsuite/tests/driver/T14482/all.T b/testsuite/tests/driver/T14482/all.T new file mode 100644 index 0000000000..0337fa8abd --- /dev/null +++ b/testsuite/tests/driver/T14482/all.T @@ -0,0 +1 @@ +test('T14482', [extra_files(['A.hs', 'B.hs', 'B.hs-boot', 'C.hs'])], makefile_test, []) |
