[project @ 2005-04-07 11:35:48 by simonmar]
authorsimonmar <unknown>
Thu, 7 Apr 2005 11:35:48 +0000 (11:35 +0000)
committersimonmar <unknown>
Thu, 7 Apr 2005 11:35:48 +0000 (11:35 +0000)
Add the -hide-all-packages flag.

ghc/compiler/main/DynFlags.hs
ghc/compiler/main/Packages.lhs
ghc/docs/users_guide/flags.xml
ghc/docs/users_guide/packages.xml

index f02c27d..c3324ad 100644 (file)
@@ -60,7 +60,9 @@ import Util           ( notNull, splitLongestPrefix, split, normalisePath )
 import DATA_IOREF      ( readIORef )
 import EXCEPTION       ( throwDyn )
 import Monad           ( when )
+#ifdef mingw32_TARGET_OS
 import Data.List       ( isPrefixOf )
+#endif
 import Maybe           ( fromJust )
 import Char            ( isDigit, isUpper )
 
@@ -168,6 +170,7 @@ data DynFlag
    | Opt_NoHsMain
    | Opt_SplitObjs
    | Opt_StgStats
+   | Opt_HideAllPackages
 
    -- keeping stuff
    | Opt_KeepHiDiffs
@@ -819,6 +822,7 @@ dynamic_flags = [
   ,  ( "package-name"   , HasArg ignorePackage ) -- for compatibility
   ,  ( "package"        , HasArg exposePackage )
   ,  ( "hide-package"   , HasArg hidePackage )
+  ,  ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
   ,  ( "ignore-package" , HasArg ignorePackage )
   ,  ( "syslib"         , HasArg exposePackage )  -- for compatibility
 
index 911da2f..a7e48b8 100644 (file)
@@ -228,9 +228,16 @@ readPackageConfig dflags pkg_map conf_file = do
   debugTraceMsg dflags 2 ("Using package config file: " ++ conf_file)
   proto_pkg_configs <- loadPackageConfig conf_file
   top_dir          <- getTopDir
-  let pkg_configs = mungePackagePaths top_dir proto_pkg_configs
-  return (extendPackageConfigMap pkg_map pkg_configs)
-
+  let pkg_configs1 = mungePackagePaths top_dir proto_pkg_configs
+      pkg_configs2 = maybeHidePackages dflags pkg_configs1
+  return (extendPackageConfigMap pkg_map pkg_configs2)
+
+maybeHidePackages :: DynFlags -> [PackageConfig] -> [PackageConfig]
+maybeHidePackages dflags pkgs
+  | dopt Opt_HideAllPackages dflags = map hide pkgs
+  | otherwise                      = pkgs
+  where
+    hide pkg = pkg{ exposed = False }
 
 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
 -- Replace the string "$topdir" at the beginning of a path
@@ -257,7 +264,7 @@ mkPackageState :: DynFlags -> PackageConfigMap -> IO PackageState
 mkPackageState dflags pkg_db = do
   --
   -- Modify the package database according to the command-line flags
-  -- (-package, -hide-package, -ignore-package).
+  -- (-package, -hide-package, -ignore-package, -hide-all-packages).
   --
   -- Also, here we build up a set of the packages mentioned in -package
   -- flags on the command line; these are called the "explicit" packages.
index e24226d..0bb4400 100644 (file)
              <entry>-</entry>
            </row>
            <row>
+             <entry><option>-hide-all-packages</option></entry>
+             <entry>Hide all packages by default</entry>
+             <entry>static</entry>
+             <entry>-</entry>
+           </row>
+           <row>
              <entry><option>-hide-package</option> <replaceable>name</replaceable></entry>
              <entry>Hide package <replaceable>P</replaceable></entry>
              <entry>static</entry>
index 6bacd66..b55e58d 100644 (file)
@@ -131,6 +131,23 @@ exposed-modules: Network.BSD,
       </varlistentry>
       
       <varlistentry>
+       <term><option>-hide-all-packages</option>
+       <indexterm><primary><option>-hide-package</option></primary>
+         </indexterm></term>
+       <listitem>
+         <para>Ignore the exposed flag on installed packages, and hide them
+           all by default.  If you use
+           this flag, then any packages you require (including
+           <literal>base</literal>) need to be explicitly exposed using
+           <option>-package</option> options.</para>
+
+         <para>This is a good way to insulate your program from differences
+           in the globally exposed packages, and being explicit about package
+           dependencies is a Good Thing.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term><option>-hide-package</option> <replaceable>P</replaceable>
        <indexterm><primary><option>-hide-package</option></primary>
          </indexterm></term>