Ticket #5977: 0004-Simplify-the-behavior-of-package-db-flags.patch

File 0004-Simplify-the-behavior-of-package-db-flags.patch, 9.4 KB (added by pcapriotti, 2 years ago)
  • compiler/main/DynFlags.hs

    From 53ec46f8a03def56e917acc5fa2dd7d47c42de4e Mon Sep 17 00:00:00 2001
    From: Paolo Capriotti <p.capriotti@gmail.com>
    Date: Thu, 10 May 2012 16:18:21 +0100
    Subject: [PATCH 4/4] Simplify the behavior of package db flags.
    
    ---
     compiler/main/DynFlags.hs     |   38 ++++++++++++++++++++++----------------
     compiler/main/Packages.lhs    |   12 +++---------
     docs/users_guide/flags.xml    |    6 +++---
     docs/users_guide/packages.xml |   24 +++++++++++++-----------
     4 files changed, 41 insertions(+), 39 deletions(-)
    
    diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
    index 7d22a7b..c26efb2 100644
    a b data DynFlag 
    276276   | Opt_ForceRecomp 
    277277   | Opt_ExcessPrecision 
    278278   | Opt_EagerBlackHoling 
    279    | Opt_ReadGlobalPackageConf 
    280    | Opt_ReadUserPackageConf 
    281279   | Opt_NoHsMain 
    282280   | Opt_SplitObjs 
    283281   | Opt_StgStats 
    data DynFlags = DynFlags { 
    550548  depSuffixes           :: [String], 
    551549 
    552550  --  Package flags 
    553   extraPkgConfs         :: [PkgConfRef], 
     551  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef], 
    554552        -- ^ The @-package-db@ flags given on the command line, in the order 
    555553        -- they appeared. 
    556554 
    defaultDynFlags mySettings = 
    925923 
    926924        hpcDir                  = ".hpc", 
    927925 
    928         extraPkgConfs           = [], 
     926        extraPkgConfs           = id, 
    929927        packageFlags            = [], 
    930928        pkgDatabase             = Nothing, 
    931929        pkgState                = panic "no package state yet: call GHC.setSessionDynFlags", 
    dynamic_flags = [ 
    17571755package_flags :: [Flag (CmdLineP DynFlags)] 
    17581756package_flags = [ 
    17591757        ------- Packages ---------------------------------------------------- 
    1760     Flag "package-db"            (HasArg (extraPkgConf_ . PkgConfFile)) 
     1758    Flag "package-db"            (HasArg (addPkgConfRef . PkgConfFile)) 
    17611759  , Flag "clear-package-db"      (NoArg clearPkgConf) 
    1762   , Flag "no-global-package-db"  (NoArg (unSetDynFlag Opt_ReadGlobalPackageConf)) 
    1763   , Flag "no-user-package-db"    (NoArg (unSetDynFlag Opt_ReadUserPackageConf)) 
    1764   , Flag "global-package-db"     (NoArg (extraPkgConf_ GlobalPkgConf)) 
    1765   , Flag "user-package-db"       (NoArg (extraPkgConf_ UserPkgConf)) 
     1760  , Flag "no-global-package-db"  (NoArg removeGlobalPkgConf) 
     1761  , Flag "no-user-package-db"    (NoArg removeUserPkgConf) 
     1762  , Flag "global-package-db"     (NoArg (addPkgConfRef GlobalPkgConf)) 
     1763  , Flag "user-package-db"       (NoArg (addPkgConfRef UserPkgConf)) 
    17661764 
    17671765  , Flag "package-name"          (hasArg setPackageName) 
    17681766  , Flag "package-id"            (HasArg exposePackageId) 
    xFlags = [ 
    20732071defaultFlags :: [DynFlag] 
    20742072defaultFlags 
    20752073  = [ Opt_AutoLinkPackages, 
    2076       Opt_ReadGlobalPackageConf, 
    2077       Opt_ReadUserPackageConf, 
    20782074 
    20792075      Opt_SharedImplib, 
    20802076 
    data PkgConfRef 
    24172413  | UserPkgConf 
    24182414  | PkgConfFile FilePath 
    24192415 
    2420 extraPkgConf_ :: PkgConfRef -> DynP () 
    2421 extraPkgConf_  p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s }) 
     2416addPkgConfRef :: PkgConfRef -> DynP () 
     2417addPkgConfRef p = upd $ \s -> s { extraPkgConfs = (p:) . extraPkgConfs s } 
     2418 
     2419removeUserPkgConf :: DynP () 
     2420removeUserPkgConf = upd $ \s -> s { extraPkgConfs = filter isNotUser . extraPkgConfs s } 
     2421  where 
     2422    isNotUser UserPkgConf = False 
     2423    isNotUser _ = True 
     2424 
     2425removeGlobalPkgConf :: DynP () 
     2426removeGlobalPkgConf = upd $ \s -> s { extraPkgConfs = filter isNotGlobal . extraPkgConfs s } 
     2427  where 
     2428    isNotGlobal GlobalPkgConf = False 
     2429    isNotGlobal _ = True 
    24222430 
    24232431clearPkgConf :: DynP () 
    2424 clearPkgConf = do 
    2425   unSetDynFlag Opt_ReadGlobalPackageConf 
    2426   unSetDynFlag Opt_ReadUserPackageConf 
     2432clearPkgConf = upd $ \s -> s { extraPkgConfs = const [] } 
    24272433 
    24282434exposePackage, exposePackageId, hidePackage, ignorePackage, 
    24292435        trustPackage, distrustPackage :: String -> DynP () 
  • compiler/main/Packages.lhs

    diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs
    index 6d917fa..cdda961 100644
    a b initPackages dflags = do 
    184184 
    185185readPackageConfigs :: DynFlags -> IO [PackageConfig] 
    186186readPackageConfigs dflags = do 
    187   let -- Read global package db, unless the -no-user-package-db flag was given 
    188       global_conf_refs = [GlobalPkgConf | dopt Opt_ReadGlobalPackageConf dflags] 
    189       -- Read user's package conf (eg. ~/.ghc/i386-linux-6.3/package.conf) 
    190       -- unless the -no-user-package-db flag was given. 
    191       user_conf_refs = [UserPkgConf | dopt Opt_ReadUserPackageConf dflags] 
    192  
    193       system_conf_refs = global_conf_refs ++ user_conf_refs 
     187  let system_conf_refs = [UserPkgConf, GlobalPkgConf] 
    194188 
    195189  e_pkg_path <- tryIO (getEnv "GHC_PACKAGE_PATH") 
    196190  let base_conf_refs = case e_pkg_path of 
    readPackageConfigs dflags = do 
    202196         -> map PkgConfFile cs 
    203197         where cs = parseSearchPath path 
    204198         -- if the path ends in a separator (eg. "/foo/bar:") 
    205          -- the we tack on the base paths. 
     199         -- then we tack on the system paths. 
    206200 
    207   let conf_refs = base_conf_refs ++ reverse (extraPkgConfs dflags) 
     201  let conf_refs = reverse (extraPkgConfs dflags base_conf_refs) 
    208202  -- later packages shadow earlier ones.  extraPkgConfs 
    209203  -- is in the opposite order to the flags on the 
    210204  -- command line. 
  • docs/users_guide/flags.xml

    diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml
    index ac44c02..b501961 100644
    a b  
    601601          </row> 
    602602          <row> 
    603603            <entry><option>-clear-package-db</option></entry> 
    604             <entry>Use an empty initial package db stack.</entry> 
     604            <entry>Clear the package db stack.</entry> 
    605605            <entry>static</entry> 
    606606            <entry>-</entry> 
    607607          </row> 
    608608          <row> 
    609609            <entry><option>-no-global-package-db</option></entry> 
    610             <entry>Don't add the global db to the initial package db stack.</entry> 
     610            <entry>Remove the global package db from the stack.</entry> 
    611611            <entry>static</entry> 
    612612            <entry>-</entry> 
    613613          </row> 
     
    619619          </row> 
    620620          <row> 
    621621            <entry><option>-no-user-package-db</option></entry> 
    622             <entry>Don't add the user's package db to the initial package db stack.</entry> 
     622            <entry>Remove the user's package db from the stack.</entry> 
    623623            <entry>static</entry> 
    624624            <entry>-</entry> 
    625625          </row> 
  • docs/users_guide/packages.xml

    diff --git a/docs/users_guide/packages.xml b/docs/users_guide/packages.xml
    index 8df8cb9..d1df2d4 100644
    a b _ZCMain_main_closure 
    408408      see GHC's package table by running GHC with the <option>-v</option> 
    409409      flag.</para> 
    410410 
    411     <para>Package databases mayb overlap, and they are arranged in a stack 
     411    <para>Package databases may overlap, and they are arranged in a stack 
    412412      structure. Packages closer to the top of the stack will override 
    413413      (<emphasis>shadow</emphasis>) those below them. By default, the stack 
    414414      contains just the global and the user's package databases, in that 
    _ZCMain_main_closure 
    425425        </term> 
    426426        <listitem> 
    427427          <para>Add the package database <replaceable>file</replaceable> on top 
    428             of the current stack. Packages in additional databases read this 
    429             way will override those in the initial stack and those in 
    430             previously specified databases.</para> 
     428              of the current stack. Packages in additional databases read this 
     429              way will override those in the initial stack and those in 
     430              previously specified databases.</para> 
    431431        </listitem> 
    432432      </varlistentry> 
    433433 
    _ZCMain_main_closure 
    437437          </indexterm> 
    438438        </term> 
    439439        <listitem> 
    440           <para>Prevent loading of the global package database in the initial stack.</para> 
     440          <para>Remove the global package database from the package database 
     441              stack.</para> 
    441442        </listitem> 
    442443      </varlistentry> 
    443444 
    _ZCMain_main_closure 
    447448          </indexterm> 
    448449        </term> 
    449450        <listitem> 
    450           <para>Prevent loading of the user's local package database in the initial stack.</para> 
     451          <para>Prevent loading of the user's local package database in the 
     452              initial stack.</para> 
    451453        </listitem> 
    452454      </varlistentry> 
    453455 
    _ZCMain_main_closure 
    457459          </indexterm> 
    458460        </term> 
    459461        <listitem> 
    460           <para>Start with an empty initial package database stack. This option 
    461             is equivalent to the combination of 
    462             <literal>-no-global-package-db</literal> and 
    463             <literal>-no-user-package-db.</literal></para> 
     462            <para>Reset the current package database stack. This option removes 
     463                every previously specified package database (including those 
     464                read from the <literal>GHC_PACKAGE_PATH</literal> environment 
     465                variable) from the package database stack.</para> 
    464466        </listitem> 
    465467      </varlistentry> 
    466468 
    _ZCMain_main_closure 
    508510        packages.</para> 
    509511 
    510512      <para>If <literal>GHC_PACKAGE_PATH</literal> ends in a separator, then 
    511         the initial package database stack (by default, the user and global 
     513        the default package database stack (i.e. the user and global 
    512514        package databases, in that order) is appended. For example, to augment 
    513515        the usual set of packages with a database of your own, you could say 
    514516        (on Unix):