import Digraph ( SCC(..), flattenSCC, flattenSCCs )
import Outputable
import Panic ( panic )
+import BasicTypes ( GhciMode(..) )
#include "HsVersions.h"
\end{code}
-- between CmLink and DriverPipeline. Same deal as with
-- CmSummarise.summarise.
link :: ([String] -> IO ())
- -> Bool -- was the upsweep completely successful?
+ -> GhciMode -- interactive or batch
+ -> Bool -- attempt linking in batch mode?
-> PackageConfigInfo
-> [SCC Linkable]
-> PersistentLinkerState
-- For the moment, in the batch linker, we don't bother to
-- tell doLink which packages to link -- it just tries all that
-- are available.
-link doLink upsweep_complete_success pci groups pls1
- | upsweep_complete_success
- = do putStrLn "Hello from the Linker!"
+-- batch_attempt_linking should only be *looked at* in
+-- batch mode. It should only be True if the upsweep was
+-- successful and someone exports main, i.e., we have good
+-- reason to believe that linking will succeed.
+link doLink Batch batch_attempt_linking pci groups pls1
+ | batch_attempt_linking
+ = do putStrLn "LINK(batch): linkables are ..."
putStrLn (showSDoc (vcat (map ppLinkableSCC groups)))
let o_files = concatMap getOfiles (flattenSCCs groups)
doLink o_files
- putStrLn "Bye-bye from the Linker!"
+ -- doLink only returns if it succeeds
+ putStrLn "LINK(batch): done"
return (LinkOK pls1)
| otherwise
- = do putStrLn "LINKER: upsweep (partially?) failed; not doing batch linking"
+ = do putStrLn "LINKER(batch): upsweep (partially?) failed OR main not exported;"
+ putStrLn " -- not doing linking"
return (LinkOK pls1)
where
getOfiles (LP _) = []
getOfiles (LM _ us) = map nameOfObject (filter isObject us)
-
+link doLink Interactive batch_attempt_linking pci groups pls1
+ = do putStrLn "LINKER(interactive): not yet implemented"
+ return (LinkOK pls1)
+
ppLinkableSCC :: SCC Linkable -> SDoc
ppLinkableSCC = ppr . flattenSCC
import List ( nub )
import Maybe ( catMaybes, maybeToList, fromMaybe )
+import Maybes ( maybeToBool )
import Outputable
import UniqFM ( emptyUFM, lookupUFM, addToUFM, delListFromUFM )
import Digraph ( SCC(..), stronglyConnComp, flattenSCC, flattenSCCs )
name_of_summary, deps_of_summary,
mimp_name, ms_get_imports )
import Module ( ModuleName, moduleName, packageOfModule,
- isModuleInThisPackage, PackageName )
+ isModuleInThisPackage, PackageName, moduleEnvElts )
import CmStaticInfo ( Package(..), PackageConfigInfo )
import DriverPipeline ( compile, preprocess, doLink, CompResult(..) )
import HscTypes ( HomeSymbolTable, HomeIfaceTable,
- PersistentCompilerState )
+ PersistentCompilerState, ModDetails(..) )
+import Name ( lookupNameEnv )
+import PrelNames ( mainName )
import HscMain ( initPersistentCompilerState )
import Finder ( findModule, emptyHomeDirCache )
+import BasicTypes ( GhciMode(..) )
+import Util ( unJust )
\end{code}
-- Try and do linking in some form, depending on whether the
-- upsweep was completely or only partially successful.
+ let ghci_mode = Batch -- ToDo: fix!
if upsweepOK
then
do putStrLn "UPSWEEP COMPLETELY SUCCESSFUL"
+ let someone_exports_main = any exports_main (moduleEnvElts hst3)
let mods_to_relink = upwards_closure mg2
(map modname_of_linkable newLis)
pkg_linkables <- find_pkg_linkables_for pcii
let sccs_to_relink = group_uis ui3 mg2 mods_to_relink
let all_to_relink = map AcyclicSCC pkg_linkables
++ sccs_to_relink
- linkresult <- link doLink True pcii all_to_relink pls1
+ linkresult <- link doLink ghci_mode someone_exports_main
+ pcii all_to_relink pls1
case linkresult of
LinkErrs _ _
-> panic "cmLoadModule: link failed (1)"
let sccs_to_relink = group_uis ui3 mg2 mods_to_relink
let all_to_relink = map AcyclicSCC pkg_linkables
++ sccs_to_relink
- linkresult <- link doLink False pcii all_to_relink pls1
+ linkresult <- link doLink ghci_mode False pcii all_to_relink pls1
let (hst4, hit4, ui4)
= removeFromTopLevelEnvs mods_to_relink (hst3,hit3,ui3)
case linkresult of
= CmState { pcms=pcms4, pcs=pcs3, pls=pls4 }
return (cmstate4, Just modname)
+exports_main :: ModDetails -> Bool
+exports_main md
+ = maybeToBool (lookupNameEnv (md_types md) mainName)
-- Given a (home) module graph and a bunch of names of (home) modules
-- within that graph, return the names of any packages needed by the