Skip to content

Infrastructure to filter commandline arguments #5237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Cabal/Distribution/Simple/Program/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Distribution.Simple.Program.Types (
import Prelude ()
import Distribution.Compat.Prelude

import Distribution.PackageDescription
import Distribution.Simple.Program.Find
import Distribution.Version
import Distribution.Verbosity
Expand Down Expand Up @@ -74,10 +75,14 @@ data Program = Program {
-- | A function to do any additional configuration after we have
-- located the program (and perhaps identified its version). For example
-- it could add args, or environment vars.
programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram,
-- | A function that filters any arguments that don't impact the output
-- from a commandline. Used to limit the volatility of dependency hashes
-- when using new-build.
programNormaliseArgs :: Maybe Version -> PackageDescription -> [String] -> [String]
}
instance Show Program where
show (Program name _ _ _) = "Program: " ++ name
show (Program name _ _ _ _) = "Program: " ++ name

type ProgArg = String

Expand Down Expand Up @@ -161,7 +166,8 @@ simpleProgram name = Program {
programName = name,
programFindLocation = \v p -> findProgramOnSearchPath v p name,
programFindVersion = \_ _ -> return Nothing,
programPostConf = \_ p -> return p
programPostConf = \_ p -> return p,
programNormaliseArgs = \_ _ -> id
}

-- | Make a simple 'ConfiguredProgram'.
Expand Down
12 changes: 11 additions & 1 deletion cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3566,13 +3566,23 @@ packageHashConfigInputs
pkgHashStripLibs = elabStripLibs,
pkgHashStripExes = elabStripExes,
pkgHashDebugInfo = elabDebugInfo,
pkgHashProgramArgs = elabProgramArgs,
pkgHashProgramArgs = Map.mapWithKey lookupFilter elabProgramArgs,
pkgHashExtraLibDirs = elabExtraLibDirs,
pkgHashExtraFrameworkDirs = elabExtraFrameworkDirs,
pkgHashExtraIncludeDirs = elabExtraIncludeDirs,
pkgHashProgPrefix = elabProgPrefix,
pkgHashProgSuffix = elabProgSuffix
}
where
knownProgramDb = addKnownPrograms builtinPrograms pkgConfigCompilerProgs

lookupFilter :: String -> [String] -> [String]
lookupFilter n flags = case lookupKnownProgram n knownProgramDb of
Just p -> programNormaliseArgs p (getVersion p) elabPkgDescription flags
Nothing -> flags

getVersion :: Program -> Maybe Version
getVersion p = lookupProgram p knownProgramDb >>= programVersion


-- | Given the 'InstalledPackageIndex' for a nix-style package store, and an
Expand Down