Commit 6ef41c26 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

ghc-pkg: don't expand ${name}-style env vars by default

For shell-based build systems the feature is still available as:
  ghc-pkg register --expand-env-vars

Historically, ghc-pkg allowed environment variables to appear in the
input files for ghc-pkg register. They are not stored in the package
database but are expanded upon registration. This feature helped for
build systems based on makefiles and shell scripts. These days the
vast majority of such files are generated by Cabal and we don't want
any ${name} strings (e.g. perhaps in a package description) getting
accidentally interpreted as an environment variable.
parent 7256b301
...@@ -101,6 +101,7 @@ data Flag ...@@ -101,6 +101,7 @@ data Flag
| FlagForce | FlagForce
| FlagForceFiles | FlagForceFiles
| FlagAutoGHCiLibs | FlagAutoGHCiLibs
| FlagExpandEnvVars
| FlagSimpleOutput | FlagSimpleOutput
| FlagNamesOnly | FlagNamesOnly
| FlagIgnoreCase | FlagIgnoreCase
...@@ -126,6 +127,8 @@ flags = [ ...@@ -126,6 +127,8 @@ flags = [
"ignore missing directories and libraries only", "ignore missing directories and libraries only",
Option ['g'] ["auto-ghci-libs"] (NoArg FlagAutoGHCiLibs) Option ['g'] ["auto-ghci-libs"] (NoArg FlagAutoGHCiLibs)
"automatically build libs for GHCi (with register)", "automatically build libs for GHCi (with register)",
Option [] ["expand-env-vars"] (NoArg FlagExpandEnvVars)
"expand environment variables (${name}-style) in input package descriptions",
Option ['?'] ["help"] (NoArg FlagHelp) Option ['?'] ["help"] (NoArg FlagHelp)
"display this help and exit", "display this help and exit",
Option ['V'] ["version"] (NoArg FlagVersion) Option ['V'] ["version"] (NoArg FlagVersion)
...@@ -274,6 +277,7 @@ runit verbosity cli nonopts = do ...@@ -274,6 +277,7 @@ runit verbosity cli nonopts = do
| FlagForceFiles `elem` cli = ForceFiles | FlagForceFiles `elem` cli = ForceFiles
| otherwise = NoForce | otherwise = NoForce
auto_ghci_libs = FlagAutoGHCiLibs `elem` cli auto_ghci_libs = FlagAutoGHCiLibs `elem` cli
expand_env_vars= FlagExpandEnvVars `elem` cli
splitFields fields = unfoldr splitComma (',':fields) splitFields fields = unfoldr splitComma (',':fields)
where splitComma "" = Nothing where splitComma "" = Nothing
splitComma fs = Just $ break (==',') (tail fs) splitComma fs = Just $ break (==',') (tail fs)
...@@ -313,9 +317,11 @@ runit verbosity cli nonopts = do ...@@ -313,9 +317,11 @@ runit verbosity cli nonopts = do
["init", filename] -> ["init", filename] ->
initPackageDB filename verbosity cli initPackageDB filename verbosity cli
["register", filename] -> ["register", filename] ->
registerPackage filename verbosity cli auto_ghci_libs False force registerPackage filename verbosity cli
auto_ghci_libs expand_env_vars False force
["update", filename] -> ["update", filename] ->
registerPackage filename verbosity cli auto_ghci_libs True force registerPackage filename verbosity cli
auto_ghci_libs expand_env_vars True force
["unregister", pkgid_str] -> do ["unregister", pkgid_str] -> do
pkgid <- readGlobPkgId pkgid_str pkgid <- readGlobPkgId pkgid_str
unregisterPackage pkgid verbosity cli force unregisterPackage pkgid verbosity cli force
...@@ -624,10 +630,11 @@ registerPackage :: FilePath ...@@ -624,10 +630,11 @@ registerPackage :: FilePath
-> Verbosity -> Verbosity
-> [Flag] -> [Flag]
-> Bool -- auto_ghci_libs -> Bool -- auto_ghci_libs
-> Bool -- expand_env_vars
-> Bool -- update -> Bool -- update
-> Force -> Force
-> IO () -> IO ()
registerPackage input verbosity my_flags auto_ghci_libs update force = do registerPackage input verbosity my_flags auto_ghci_libs expand_env_vars update force = do
(db_stack, Just to_modify, _flag_dbs) <- (db_stack, Just to_modify, _flag_dbs) <-
getPkgDatabases verbosity True True my_flags getPkgDatabases verbosity True True my_flags
...@@ -648,7 +655,8 @@ registerPackage input verbosity my_flags auto_ghci_libs update force = do ...@@ -648,7 +655,8 @@ registerPackage input verbosity my_flags auto_ghci_libs update force = do
putStr ("Reading package info from " ++ show f ++ " ... ") putStr ("Reading package info from " ++ show f ++ " ... ")
readUTF8File f readUTF8File f
expanded <- expandEnvVars s force expanded <- if expand_env_vars then expandEnvVars s force
else return s
pkg <- parsePackageInfo expanded pkg <- parsePackageInfo expanded
when (verbosity >= Normal) $ when (verbosity >= Normal) $
......
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