From 24149528a0a2d17ff9b5b087e0a8249c8c9cef98 Mon Sep 17 00:00:00 2001 From: Kai Harries Date: Thu, 24 Mar 2016 22:33:27 +0100 Subject: Add option `no-keep-hi-files` and `no-keep-o-files` (fixes #4114) Summary: Remove `.hi` and `.o` files if the flags `no-keep-hi-files` and `no-keep-o-files` are given. Test Plan: ./validate Reviewers: austin, thomie, bgamari Reviewed By: thomie, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2021 GHC Trac Issues: #4114 --- compiler/main/DriverPipeline.hs | 6 ++++++ compiler/main/DynFlags.hs | 20 ++++++++++++++++++++ docs/users_guide/separate_compilation.rst | 21 +++++++++++++++++++-- testsuite/tests/driver/T4114a.hs | 14 ++++++++++++++ testsuite/tests/driver/T4114aSub.hs | 20 ++++++++++++++++++++ testsuite/tests/driver/T4114b.hs | 13 +++++++++++++ testsuite/tests/driver/T4114bSub.hs | 20 ++++++++++++++++++++ testsuite/tests/driver/T4114c.hs | 14 ++++++++++++++ testsuite/tests/driver/T4114cSub.hs | 20 ++++++++++++++++++++ testsuite/tests/driver/T4114d.hs | 14 ++++++++++++++ testsuite/tests/driver/T4114dSub.hs | 20 ++++++++++++++++++++ testsuite/tests/driver/all.T | 5 +++++ .../mkUserGuidePart/Options/KeepingIntermediates.hs | 12 ++++++++++++ 13 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/driver/T4114a.hs create mode 100644 testsuite/tests/driver/T4114aSub.hs create mode 100644 testsuite/tests/driver/T4114b.hs create mode 100644 testsuite/tests/driver/T4114bSub.hs create mode 100644 testsuite/tests/driver/T4114c.hs create mode 100644 testsuite/tests/driver/T4114cSub.hs create mode 100644 testsuite/tests/driver/T4114d.hs create mode 100644 testsuite/tests/driver/T4114dSub.hs diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index 41a7c5bb42..89fbb42346 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -137,6 +137,12 @@ compileOne' m_tc_result mHscMessage m_tc_result mHscMessage hsc_env summary source_modified mb_old_iface (mod_index, nmods) + let flags = hsc_dflags hsc_env0 + in do unless (gopt Opt_KeepHiFiles flags) $ + addFilesToClean flags [ml_hi_file $ ms_location summary] + unless (gopt Opt_KeepOFiles flags) $ + addFilesToClean flags [ml_obj_file $ ms_location summary] + case (status, hsc_lang) of (HscUpToDate, _) -> ASSERT( isJust maybe_old_linkable || isNoLink (ghcLink dflags) ) diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index f14a36ff7e..99d80d63bf 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -527,6 +527,8 @@ data GeneralFlag | Opt_KeepTmpFiles | Opt_KeepRawTokenStream | Opt_KeepLlvmFiles + | Opt_KeepHiFiles + | Opt_KeepOFiles | Opt_BuildDynamicToo @@ -2505,6 +2507,22 @@ dynamic_flags_deps = [ -- This only makes sense as plural , make_ord_flag defGhcFlag "keep-tmp-files" (NoArg (setGeneralFlag Opt_KeepTmpFiles)) + , make_ord_flag defGhcFlag "keep-hi-file" + (NoArg (setGeneralFlag Opt_KeepHiFiles)) + , make_ord_flag defGhcFlag "no-keep-hi-file" + (NoArg (unSetGeneralFlag Opt_KeepHiFiles)) + , make_ord_flag defGhcFlag "keep-hi-files" + (NoArg (setGeneralFlag Opt_KeepHiFiles)) + , make_ord_flag defGhcFlag "no-keep-hi-files" + (NoArg (unSetGeneralFlag Opt_KeepHiFiles)) + , make_ord_flag defGhcFlag "keep-o-file" + (NoArg (setGeneralFlag Opt_KeepOFiles)) + , make_ord_flag defGhcFlag "no-keep-o-file" + (NoArg (unSetGeneralFlag Opt_KeepOFiles)) + , make_ord_flag defGhcFlag "keep-o-files" + (NoArg (setGeneralFlag Opt_KeepOFiles)) + , make_ord_flag defGhcFlag "no-keep-o-files" + (NoArg (unSetGeneralFlag Opt_KeepOFiles)) ------- Miscellaneous ---------------------------------------------- , make_ord_flag defGhcFlag "no-auto-link-packages" @@ -3615,6 +3633,8 @@ defaultFlags settings Opt_GhciHistory, Opt_GhciSandbox, Opt_HelpfulErrors, + Opt_KeepHiFiles, + Opt_KeepOFiles, Opt_OmitYields, Opt_PrintBindContents, Opt_ProfCountEntries, diff --git a/docs/users_guide/separate_compilation.rst b/docs/users_guide/separate_compilation.rst index a2ce5ebd50..c0d42e9c24 100644 --- a/docs/users_guide/separate_compilation.rst +++ b/docs/users_guide/separate_compilation.rst @@ -330,8 +330,9 @@ Keeping Intermediate Files single: .ll files, saving single: .s files, saving -The following options are useful for keeping certain intermediate files -around, when normally GHC would throw these away after compilation: +The following options are useful for keeping (or not keeping) certain +intermediate files around, when normally GHC would throw these away after +compilation: .. ghc-flag:: -keep-hc-file -keep-hc-files @@ -340,6 +341,14 @@ around, when normally GHC would throw these away after compilation: compilations via :ref:`C ` (Note: ``.hc`` files are only generated by :ref:`unregisterised ` compilers). +.. ghc-flag:: -keep-hi-files + + .. index:: + single: temporary files; keeping + + Keep intermediate ``.hi`` files. This is the default. You may use + ``-no-keep-hi-files`` if you are not interested in the ``.hi`` files. + .. ghc-flag:: -keep-llvm-file -keep-llvm-files @@ -350,6 +359,14 @@ around, when normally GHC would throw these away after compilation: aren't generated when using the native code generator, you may need to use :ghc-flag:`-fllvm` to force them to be produced). +.. ghc-flag:: -keep-o-files + + .. index:: + single: temporary files; keeping + + Keep intermediate ``.o`` files. This is the default. You may use + ``-no-keep-o-files`` if you are not interested in the ``.o`` files. + .. ghc-flag:: -keep-s-file -keep-s-files diff --git a/testsuite/tests/driver/T4114a.hs b/testsuite/tests/driver/T4114a.hs new file mode 100644 index 0000000000..ff835d61a7 --- /dev/null +++ b/testsuite/tests/driver/T4114a.hs @@ -0,0 +1,14 @@ +-- Test the flage `force-no-intermediates` (issue #4114) +module Main (main) where + +import T4114aSub + +keep, nokeep :: [FilePath] +keep = ["T4114a", "T4114aSub.hi", "T4114aSub.o", "T4114a.hi", "T4114a.o"] +nokeep = [ ] + + +main :: IO () +main = do + mapM_ assertNoKeep nokeep + mapM_ assertKeep keep diff --git a/testsuite/tests/driver/T4114aSub.hs b/testsuite/tests/driver/T4114aSub.hs new file mode 100644 index 0000000000..782f32cea4 --- /dev/null +++ b/testsuite/tests/driver/T4114aSub.hs @@ -0,0 +1,20 @@ +module T4114aSub (assertKeep, assertNoKeep) where + +import Control.Monad (unless, when) +import System.Directory (doesFileExist) + +assertNoKeep :: FilePath -> IO () +assertNoKeep a = + whenM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' exists") + +assertKeep :: FilePath -> IO () +assertKeep a = + unlessM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' is missing") + +whenM :: Monad m => m Bool -> m () -> m () +whenM mp f = mp >>= \p -> when p f + +unlessM :: Monad m => m Bool -> m () -> m () +unlessM mp f = mp >>= \p -> unless p f diff --git a/testsuite/tests/driver/T4114b.hs b/testsuite/tests/driver/T4114b.hs new file mode 100644 index 0000000000..07486c54cb --- /dev/null +++ b/testsuite/tests/driver/T4114b.hs @@ -0,0 +1,13 @@ +-- Test the flage `force-no-intermediates` (issue #4114) +module Main (main) where + +import T4114bSub + +keep, nokeep :: [FilePath] +keep = ["T4114b", "T4114bSub.o", "T4114b.o"] +nokeep = ["T4114bSub.hi", "T4114b.hi"] + +main :: IO () +main = do + mapM_ assertNoKeep nokeep + mapM_ assertKeep keep diff --git a/testsuite/tests/driver/T4114bSub.hs b/testsuite/tests/driver/T4114bSub.hs new file mode 100644 index 0000000000..41041d99f1 --- /dev/null +++ b/testsuite/tests/driver/T4114bSub.hs @@ -0,0 +1,20 @@ +module T4114bSub (assertKeep, assertNoKeep) where + +import Control.Monad (unless, when) +import System.Directory (doesFileExist) + +assertNoKeep :: FilePath -> IO () +assertNoKeep a = + whenM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' exists") + +assertKeep :: FilePath -> IO () +assertKeep a = + unlessM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' is missing") + +whenM :: Monad m => m Bool -> m () -> m () +whenM mp f = mp >>= \p -> when p f + +unlessM :: Monad m => m Bool -> m () -> m () +unlessM mp f = mp >>= \p -> unless p f diff --git a/testsuite/tests/driver/T4114c.hs b/testsuite/tests/driver/T4114c.hs new file mode 100644 index 0000000000..f7802e13de --- /dev/null +++ b/testsuite/tests/driver/T4114c.hs @@ -0,0 +1,14 @@ +-- Test the flage `force-no-intermediates` (issue #4114) +module Main (main) where + +import T4114cSub + +keep, nokeep :: [FilePath] +keep = ["T4114c", "T4114cSub.hi", "T4114c.hi"] +nokeep = ["T4114cSub.o", "T4114c.o"] + + +main :: IO () +main = do + mapM_ assertNoKeep nokeep + mapM_ assertKeep keep diff --git a/testsuite/tests/driver/T4114cSub.hs b/testsuite/tests/driver/T4114cSub.hs new file mode 100644 index 0000000000..3ecd0c9dc2 --- /dev/null +++ b/testsuite/tests/driver/T4114cSub.hs @@ -0,0 +1,20 @@ +module T4114cSub (assertKeep, assertNoKeep) where + +import Control.Monad (unless, when) +import System.Directory (doesFileExist) + +assertNoKeep :: FilePath -> IO () +assertNoKeep a = + whenM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' exists") + +assertKeep :: FilePath -> IO () +assertKeep a = + unlessM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' is missing") + +whenM :: Monad m => m Bool -> m () -> m () +whenM mp f = mp >>= \p -> when p f + +unlessM :: Monad m => m Bool -> m () -> m () +unlessM mp f = mp >>= \p -> unless p f diff --git a/testsuite/tests/driver/T4114d.hs b/testsuite/tests/driver/T4114d.hs new file mode 100644 index 0000000000..2ff717b396 --- /dev/null +++ b/testsuite/tests/driver/T4114d.hs @@ -0,0 +1,14 @@ +-- Test the flage `force-no-intermediates` (issue #4114) +module Main (main) where + +import T4114dSub + +keep, nokeep :: [FilePath] +keep = ["T4114d", "T4114dSub.myhi", "T4114d.myhi"] +nokeep = ["T4114dSub.myo", "T4114d.myo"] + + +main :: IO () +main = do + mapM_ assertNoKeep nokeep + mapM_ assertKeep keep diff --git a/testsuite/tests/driver/T4114dSub.hs b/testsuite/tests/driver/T4114dSub.hs new file mode 100644 index 0000000000..0616a216d2 --- /dev/null +++ b/testsuite/tests/driver/T4114dSub.hs @@ -0,0 +1,20 @@ +module T4114dSub (assertKeep, assertNoKeep) where + +import Control.Monad (unless, when) +import System.Directory (doesFileExist) + +assertNoKeep :: FilePath -> IO () +assertNoKeep a = + whenM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' exists") + +assertKeep :: FilePath -> IO () +assertKeep a = + unlessM (doesFileExist a) $ + error ("error: intermediate '" ++ a ++ "' is missing") + +whenM :: Monad m => m Bool -> m () -> m () +whenM mp f = mp >>= \p -> when p f + +unlessM :: Monad m => m Bool -> m () -> m () +unlessM mp f = mp >>= \p -> unless p f diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T index ae75823f0b..2798dd5ba3 100644 --- a/testsuite/tests/driver/all.T +++ b/testsuite/tests/driver/all.T @@ -372,6 +372,11 @@ test('spacesInArgs', compile_and_run, ['']) +test( 'T4114a', normal, compile_and_run, ['-cpp']) +test( 'T4114b', normal, compile_and_run, ['-no-keep-hi-files']) +test( 'T4114c', normal, compile_and_run, ['-no-keep-o-files']) +test( 'T4114d', normal, compile_and_run, ['-hisuf .myhi -osuf .myo -no-keep-o-files']) + test('T5584', extra_clean(['T5584_in/A.hi-boot', 'T5584_out/T5584/A.o-boot']), run_command, ['$MAKE -s --no-print-directory T5584']) diff --git a/utils/mkUserGuidePart/Options/KeepingIntermediates.hs b/utils/mkUserGuidePart/Options/KeepingIntermediates.hs index dd68de493e..eb264092a4 100644 --- a/utils/mkUserGuidePart/Options/KeepingIntermediates.hs +++ b/utils/mkUserGuidePart/Options/KeepingIntermediates.hs @@ -8,11 +8,23 @@ keepingIntermediatesOptions = , flagDescription = "Retain intermediate ``.hc`` files." , flagType = DynamicFlag } + , flag { flagName = "-keep-hi-files" + , flagDescription = + "Retain intermediate ``.hi`` files (the default)." + , flagType = DynamicFlag + , flagReverse = "-no-keep-hi-files" + } , flag { flagName = "-keep-llvm-file, -keep-llvm-files" , flagDescription = "Retain intermediate LLVM ``.ll`` files. "++ "Implies :ghc-flag:`-fllvm`." , flagType = DynamicFlag } + , flag { flagName = "-keep-o-files" + , flagDescription = + "Retain intermediate ``.o`` files (the default)." + , flagType = DynamicFlag + , flagReverse = "-no-keep-o-files" + } , flag { flagName = "-keep-s-file, -keep-s-files" , flagDescription = "Retain intermediate ``.s`` files." , flagType = DynamicFlag -- cgit v1.2.1