Commit 426e0396 authored by simonmar's avatar simonmar
Browse files

[project @ 2005-03-31 16:11:49 by simonmar]

DriverPipeline.compile: we should be grabbing the OPTIONS from the
StringBuffer, not reading the file again (duh!)

SysTools: some message cleanups
parent c1909a1b
...@@ -22,7 +22,7 @@ module DriverPipeline ( ...@@ -22,7 +22,7 @@ module DriverPipeline (
-- DLL building -- DLL building
doMkDLL, doMkDLL,
matchOptions, -- used in module GHC getOptionsFromStringBuffer, -- used in module GHC
) where ) where
#include "HsVersions.h" #include "HsVersions.h"
...@@ -48,11 +48,12 @@ import StringBuffer ( hGetStringBuffer ) ...@@ -48,11 +48,12 @@ import StringBuffer ( hGetStringBuffer )
import BasicTypes ( SuccessFlag(..) ) import BasicTypes ( SuccessFlag(..) )
import Maybes ( expectJust ) import Maybes ( expectJust )
import Ctype ( is_ident ) import Ctype ( is_ident )
import StringBuffer ( StringBuffer(..), lexemeToString )
import ParserCoreUtils ( getCoreModuleName ) import ParserCoreUtils ( getCoreModuleName )
import EXCEPTION import EXCEPTION
import DATA_IOREF ( readIORef, writeIORef, IORef ) import DATA_IOREF ( readIORef, writeIORef, IORef )
import GLAEXTS ( Int(..) )
import Directory import Directory
import System import System
...@@ -118,12 +119,13 @@ compile hsc_env mod_summary maybe_old_linkable old_iface = do ...@@ -118,12 +119,13 @@ compile hsc_env mod_summary maybe_old_linkable old_iface = do
let input_fn = expectJust "compile:hs" (ml_hs_file location) let input_fn = expectJust "compile:hs" (ml_hs_file location)
let input_fnpp = expectJust "compile:hspp" (ms_hspp_file mod_summary) let input_fnpp = expectJust "compile:hspp" (ms_hspp_file mod_summary)
when (verb >= 2) (hPutStrLn stderr ("compile: input file " ++ input_fnpp)) when (verb >= 2) (putMsg ("compile: input file " ++ input_fnpp))
-- Add in the OPTIONS from the source file -- Add in the OPTIONS from the source file
-- This is nasty: we've done this once already, in the compilation manager -- This is nasty: we've done this once already, in the compilation manager
-- It might be better to cache the flags in the ml_hspp_file field,say -- It might be better to cache the flags in the ml_hspp_file field,say
opts <- getOptionsFromSource input_fnpp let hspp_buf = expectJust "compile:hspp_buf" (ms_hspp_buf mod_summary)
opts = getOptionsFromStringBuffer hspp_buf
(dflags1,unhandled_flags) <- parseDynamicFlags dflags0 opts (dflags1,unhandled_flags) <- parseDynamicFlags dflags0 opts
checkProcessArgsResult unhandled_flags input_fn checkProcessArgsResult unhandled_flags input_fn
...@@ -248,6 +250,9 @@ link Interactive dflags batch_attempt_linking hpt ...@@ -248,6 +250,9 @@ link Interactive dflags batch_attempt_linking hpt
return Succeeded return Succeeded
#endif #endif
link JustTypecheck dflags batch_attempt_linking hpt
= return Succeeded
link BatchCompile dflags batch_attempt_linking hpt link BatchCompile dflags batch_attempt_linking hpt
| batch_attempt_linking | batch_attempt_linking
= do = do
...@@ -1305,6 +1310,24 @@ getOptionsFromSource file ...@@ -1305,6 +1310,24 @@ getOptionsFromSource file
return (opts ++ rest) return (opts ++ rest)
| otherwise -> return [] | otherwise -> return []
getOptionsFromStringBuffer :: StringBuffer -> [String]
getOptionsFromStringBuffer buffer@(StringBuffer _ len# _) =
let
ls = lines (lexemeToString buffer (I# len#)) -- lazy, so it's ok
in
look ls
where
look [] = []
look (l':ls) = do
let l = removeSpaces l'
case () of
() | null l -> look ls
| prefixMatch "#" l -> look ls
| prefixMatch "{-# LINE" l -> look ls -- -}
| Just opts <- matchOptions l
-> opts ++ look ls
| otherwise -> []
-- detect {-# OPTIONS_GHC ... #-}. For the time being, we accept OPTIONS -- detect {-# OPTIONS_GHC ... #-}. For the time being, we accept OPTIONS
-- instead of OPTIONS_GHC, but that is deprecated. -- instead of OPTIONS_GHC, but that is deprecated.
matchOptions s matchOptions s
......
...@@ -122,10 +122,10 @@ import Module ...@@ -122,10 +122,10 @@ import Module
import FiniteMap import FiniteMap
import Panic import Panic
import Digraph import Digraph
import ErrUtils ( showPass, Messages ) import ErrUtils ( showPass, Messages, putMsg )
import qualified ErrUtils import qualified ErrUtils
import Util import Util
import StringBuffer ( StringBuffer(..), hGetStringBuffer, lexemeToString ) import StringBuffer ( StringBuffer, hGetStringBuffer )
import Outputable import Outputable
import SysTools ( cleanTempFilesExcept ) import SysTools ( cleanTempFilesExcept )
import BasicTypes ( SuccessFlag(..), succeeded, failed ) import BasicTypes ( SuccessFlag(..), succeeded, failed )
...@@ -140,7 +140,6 @@ import Monad ( unless, when, foldM ) ...@@ -140,7 +140,6 @@ import Monad ( unless, when, foldM )
import System ( exitWith, ExitCode(..) ) import System ( exitWith, ExitCode(..) )
import Time ( ClockTime ) import Time ( ClockTime )
import EXCEPTION as Exception hiding (handle) import EXCEPTION as Exception hiding (handle)
import GLAEXTS ( Int(..) )
import DATA_IOREF import DATA_IOREF
import IO import IO
import Prelude hiding (init) import Prelude hiding (init)
...@@ -480,8 +479,7 @@ load s@(Session ref) how_much ...@@ -480,8 +479,7 @@ load s@(Session ref) how_much
then then
-- Easy; just relink it all. -- Easy; just relink it all.
do when (verb >= 2) $ do when (verb >= 2) $ putMsg "Upsweep completely successful."
hPutStrLn stderr "Upsweep completely successful."
-- Clean up after ourselves -- Clean up after ourselves
cleanTempFilesExcept dflags (ppFilesFromSummaries modsDone) cleanTempFilesExcept dflags (ppFilesFromSummaries modsDone)
...@@ -504,7 +502,7 @@ load s@(Session ref) how_much ...@@ -504,7 +502,7 @@ load s@(Session ref) how_much
when (ghci_mode == BatchCompile && isJust ofile && not do_linking when (ghci_mode == BatchCompile && isJust ofile && not do_linking
&& verb > 0) $ && verb > 0) $
hPutStrLn stderr ("Warning: output was redirected with -o, " ++ putMsg ("Warning: output was redirected with -o, " ++
"but no output will be generated\n" ++ "but no output will be generated\n" ++
"because there is no " ++ main_mod ++ " module.") "because there is no " ++ main_mod ++ " module.")
...@@ -517,8 +515,7 @@ load s@(Session ref) how_much ...@@ -517,8 +515,7 @@ load s@(Session ref) how_much
-- Tricky. We need to back out the effects of compiling any -- Tricky. We need to back out the effects of compiling any
-- half-done cycles, both so as to clean up the top level envs -- half-done cycles, both so as to clean up the top level envs
-- and to avoid telling the interactive linker to link them. -- and to avoid telling the interactive linker to link them.
do when (verb >= 2) $ do when (verb >= 2) $ putMsg "Upsweep partially successful."
hPutStrLn stderr "Upsweep partially successful."
let modsDone_names let modsDone_names
= map ms_mod modsDone = map ms_mod modsDone
...@@ -613,7 +610,8 @@ checkModule session@(Session ref) mod msg_act = do ...@@ -613,7 +610,8 @@ checkModule session@(Session ref) mod msg_act = do
unload :: HscEnv -> [Linkable] -> IO () unload :: HscEnv -> [Linkable] -> IO ()
unload hsc_env stable_linkables -- Unload everthing *except* 'stable_linkables' unload hsc_env stable_linkables -- Unload everthing *except* 'stable_linkables'
= case ghcMode (hsc_dflags hsc_env) of = case ghcMode (hsc_dflags hsc_env) of
BatchCompile -> return () BatchCompile -> return ()
JustTypecheck -> return ()
#ifdef GHCI #ifdef GHCI
Interactive -> Linker.unload (hsc_dflags hsc_env) stable_linkables Interactive -> Linker.unload (hsc_dflags hsc_env) stable_linkables
#else #else
...@@ -1335,25 +1333,6 @@ preprocessFile dflags src_fn (Just (buf, time)) ...@@ -1335,25 +1333,6 @@ preprocessFile dflags src_fn (Just (buf, time))
return (dflags', "<buffer>", buf) return (dflags', "<buffer>", buf)
-- code adapted from the file-based version in DriverUtil
getOptionsFromStringBuffer :: StringBuffer -> [String]
getOptionsFromStringBuffer buffer@(StringBuffer _ len# _) =
let
ls = lines (lexemeToString buffer (I# len#)) -- lazy, so it's ok
in
look ls
where
look [] = []
look (l':ls) = do
let l = removeSpaces l'
case () of
() | null l -> look ls
| prefixMatch "#" l -> look ls
| prefixMatch "{-# LINE" l -> look ls -- -}
| Just opts <- matchOptions l
-> opts ++ look ls
| otherwise -> []
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Error messages -- Error messages
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
......
...@@ -47,6 +47,7 @@ module SysTools ( ...@@ -47,6 +47,7 @@ module SysTools (
import DriverPhases ( isHaskellUserSrcFilename ) import DriverPhases ( isHaskellUserSrcFilename )
import Config import Config
import Outputable import Outputable
import ErrUtils ( putMsg )
import Panic ( GhcException(..) ) import Panic ( GhcException(..) )
import Util ( Suffix, global, notNull, consIORef, import Util ( Suffix, global, notNull, consIORef,
normalisePath, pgmPath, platformPath ) normalisePath, pgmPath, platformPath )
...@@ -621,8 +622,8 @@ traceCmd :: DynFlags -> String -> String -> IO () -> IO () ...@@ -621,8 +622,8 @@ traceCmd :: DynFlags -> String -> String -> IO () -> IO ()
-- b) don't do it at all if dry-run is set -- b) don't do it at all if dry-run is set
traceCmd dflags phase_name cmd_line action traceCmd dflags phase_name cmd_line action
= do { let verb = verbosity dflags = do { let verb = verbosity dflags
; when (verb >= 2) $ hPutStrLn stderr ("*** " ++ phase_name) ; when (verb >= 2) $ putMsg ("*** " ++ phase_name)
; when (verb >= 3) $ hPutStrLn stderr cmd_line ; when (verb >= 3) $ putMsg cmd_line
; hFlush stderr ; hFlush stderr
-- Test for -n flag -- Test for -n flag
......
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