Commit 24149528 authored by kaiha's avatar kaiha Committed by Ben Gamari
Browse files

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
parent 173a5d8e
......@@ -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) )
......
......@@ -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,
......
......@@ -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 <c-code-gen>` (Note: ``.hc`` files are only
generated by :ref:`unregisterised <unreg>` 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
......
-- 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
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
-- 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
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
-- 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
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
-- 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
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
......@@ -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'])
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment