Commit f7b16cf0 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by Edward Z. Yang

The --deterministic flag tries to make Cabal deterministic.

Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 06bda066
......@@ -59,6 +59,7 @@ configureComponentLocalBuildInfos
:: Verbosity
-> Bool -- use_external_internal_deps
-> ComponentRequestedSpec
-> Bool -- deterministic
-> Flag String -- configIPID
-> Flag ComponentId -- configCID
-> PackageDescription
......@@ -69,7 +70,7 @@ configureComponentLocalBuildInfos
-> Compiler
-> LogProgress ([ComponentLocalBuildInfo], InstalledPackageIndex)
configureComponentLocalBuildInfos
verbosity use_external_internal_deps enabled ipid_flag cid_flag pkg_descr
verbosity use_external_internal_deps enabled deterministic ipid_flag cid_flag pkg_descr
prePkgDeps flagAssignment instantiate_with installedPackageSet comp = do
-- NB: In single component mode, this returns a *single* component.
-- In this graph, the graph is NOT closed.
......@@ -84,7 +85,7 @@ configureComponentLocalBuildInfos
| pkg <- prePkgDeps]
graph1 = toConfiguredComponents use_external_internal_deps
flagAssignment
ipid_flag cid_flag pkg_descr
deterministic ipid_flag cid_flag pkg_descr
conf_pkg_map (map fst graph0)
infoProgress $ hang (text "Configured component graph:") 4
(vcat (map dispConfiguredComponent graph1))
......
......@@ -183,6 +183,7 @@ toConfiguredComponent'
:: Bool -- use_external_internal_deps
-> FlagAssignment
-> PackageDescription
-> Bool -- deterministic
-> Flag String -- configIPID (todo: remove me)
-> Flag ComponentId -- configCID
-> Map PackageName (ComponentId, PackageId) -- external
......@@ -190,7 +191,7 @@ toConfiguredComponent'
-> Component
-> ConfiguredComponent
toConfiguredComponent' use_external_internal_deps flags
pkg_descr ipid_flag cid_flag
pkg_descr deterministic ipid_flag cid_flag
external_lib_map (lib_map, exe_map) component =
let cc = toConfiguredComponent
pkg_descr this_cid
......@@ -199,7 +200,7 @@ toConfiguredComponent' use_external_internal_deps flags
then cc { cc_public = True }
else cc
where
this_cid = computeComponentId ipid_flag cid_flag (package pkg_descr)
this_cid = computeComponentId deterministic ipid_flag cid_flag (package pkg_descr)
(componentName component) (Just (deps, flags))
deps = [ cid | (cid, _) <- Map.elems external_lib_map ]
......@@ -232,6 +233,7 @@ extendConfiguredComponentMap cc (lib_map, exe_map) =
toConfiguredComponents
:: Bool -- use_external_internal_deps
-> FlagAssignment
-> Bool -- deterministic
-> Flag String -- configIPID
-> Flag ComponentId -- configCID
-> PackageDescription
......@@ -239,13 +241,14 @@ toConfiguredComponents
-> [Component]
-> [ConfiguredComponent]
toConfiguredComponents
use_external_internal_deps flags ipid_flag cid_flag pkg_descr
use_external_internal_deps flags deterministic ipid_flag cid_flag pkg_descr
external_lib_map comps
= snd (mapAccumL go (Map.empty, Map.empty) comps)
where
go m component = (extendConfiguredComponentMap cc m, cc)
where cc = toConfiguredComponent'
use_external_internal_deps flags pkg_descr ipid_flag cid_flag
use_external_internal_deps flags pkg_descr
deterministic ipid_flag cid_flag
external_lib_map m component
......
......@@ -28,14 +28,15 @@ import Distribution.Text
-- for a package. The intent is that cabal-install (or the user) will
-- specify a more detailed IPID via the @--ipid@ flag if necessary.
computeComponentId
:: Flag String
:: Bool -- deterministic mode
-> Flag String
-> Flag ComponentId
-> PackageIdentifier
-> ComponentName
-- This is used by cabal-install's legacy codepath
-> Maybe ([ComponentId], FlagAssignment)
-> ComponentId
computeComponentId mb_ipid mb_cid pid cname mb_details =
computeComponentId deterministic mb_ipid mb_cid pid cname mb_details =
-- show is found to be faster than intercalate and then replacement of
-- special character used in intercalating. We cannot simply hash by
-- doubly concating list, as it just flatten out the nested list, so
......@@ -58,7 +59,8 @@ computeComponentId mb_ipid mb_cid pid cname mb_details =
where env = packageTemplateEnv pid (mkUnitId "")
actual_base = case mb_ipid of
Flag ipid0 -> explicit_base ipid0
NoFlag -> generated_base
NoFlag | deterministic -> display pid
| otherwise -> generated_base
in case mb_cid of
Flag cid -> cid
NoFlag -> mkComponentId $ actual_base
......
......@@ -609,6 +609,7 @@ configure (pkg_descr0', pbi) cfg = do
verbosity
use_external_internal_deps
enabled
(fromFlagOrDefault False (configDeterministic cfg))
(configIPID cfg)
(configCID cfg)
pkg_descr
......
......@@ -401,6 +401,9 @@ data ConfigFlags = ConfigFlags {
configExtraIncludeDirs :: [FilePath], -- ^ path to search for header files
configIPID :: Flag String, -- ^ explicit IPID to be used
configCID :: Flag ComponentId, -- ^ explicit CID to be used
configDeterministic :: Flag Bool, -- ^ be as deterministic as possible
-- (e.g., invariant over GHC, database,
-- etc). Used by the test suite
configDistPref :: Flag FilePath, -- ^"dist" prefix
configCabalFilePath :: Flag FilePath, -- ^ Cabal file to use
......@@ -471,6 +474,7 @@ instance Eq ConfigFlags where
&& equal configExtraLibDirs
&& equal configExtraIncludeDirs
&& equal configIPID
&& equal configDeterministic
&& equal configDistPref
&& equal configVerbosity
&& equal configUserInstall
......@@ -746,6 +750,11 @@ configureOptions showOrParseArgs =
configExtraIncludeDirs (\v flags -> flags {configExtraIncludeDirs = v})
(reqArg' "PATH" (\x -> [x]) id)
,option "" ["deterministic"]
"Try to be as deterministic as possible (used by the test suite)"
configDeterministic (\v flags -> flags {configDeterministic = v})
(boolOpt [] [])
,option "" ["ipid"]
"Installed package ID to compile this package as"
configIPID (\v flags -> flags {configIPID = v})
......
......@@ -306,6 +306,7 @@ instance Semigroup SavedConfig where
configExtraFrameworkDirs = lastNonEmpty configExtraFrameworkDirs,
-- TODO: NubListify
configExtraIncludeDirs = lastNonEmpty configExtraIncludeDirs,
configDeterministic = combine configDeterministic,
configIPID = combine configIPID,
configCID = combine configCID,
configDistPref = combine configDistPref,
......
......@@ -146,7 +146,7 @@ configure verbosity packageDBs repoCtxt comp platform progdb
Nothing configureCommand (const configFlags) extraArgs
Right installPlan0 ->
let installPlan = InstallPlan.configureInstallPlan installPlan0
let installPlan = InstallPlan.configureInstallPlan configFlags installPlan0
in case fst (InstallPlan.ready installPlan) of
[pkg@(ReadyPackage
(ConfiguredPackage _ (SourcePackage _ _ (LocalUnpackedPackage _) _)
......
......@@ -329,7 +329,7 @@ processInstallPlan :: Verbosity -> InstallArgs -> InstallContext
-> SolverInstallPlan
-> IO ()
processInstallPlan verbosity
args@(_,_, _, _, _, _, _, _, _, _, installFlags, _)
args@(_,_, _, _, _, _, _, _, configFlags, _, installFlags, _)
(installedPkgIndex, sourcePkgDb, _,
userTargets, pkgSpecifiers, _) installPlan0 = do
......@@ -341,7 +341,7 @@ processInstallPlan verbosity
args installedPkgIndex installPlan
postInstallActions verbosity args userTargets installPlan buildOutcomes
where
installPlan = InstallPlan.configureInstallPlan installPlan0
installPlan = InstallPlan.configureInstallPlan configFlags installPlan0
dryRun = fromFlag (installDryRun installFlags)
nothingToInstall = null (fst (InstallPlan.ready installPlan))
......
......@@ -476,8 +476,8 @@ fromSolverInstallPlanWithProgress f plan = do
-- | Conversion of 'SolverInstallPlan' to 'InstallPlan'.
-- Similar to 'elaboratedInstallPlan'
configureInstallPlan :: SolverInstallPlan -> InstallPlan
configureInstallPlan solverPlan =
configureInstallPlan :: Cabal.ConfigFlags -> SolverInstallPlan -> InstallPlan
configureInstallPlan configFlags solverPlan =
flip fromSolverInstallPlan solverPlan $ \mapDep planpkg ->
[case planpkg of
SolverInstallPlan.PreExisting pkg ->
......@@ -493,6 +493,8 @@ configureInstallPlan solverPlan =
configureSolverPackage mapDep spkg =
ConfiguredPackage {
confPkgId = Configure.computeComponentId
(Cabal.fromFlagOrDefault False
(Cabal.configDeterministic configFlags))
Cabal.NoFlag
Cabal.NoFlag
(packageId spkg)
......
......@@ -573,6 +573,7 @@ convertToLegacyAllPackageConfig
configConstraints = mempty,
configDependencies = mempty,
configExtraIncludeDirs = mempty,
configDeterministic = mempty,
configIPID = mempty,
configCID = mempty,
configConfigurationsFlags = mempty,
......@@ -641,6 +642,7 @@ convertToLegacyPerPackageConfig PackageConfig {..} =
configExtraIncludeDirs = packageConfigExtraIncludeDirs,
configIPID = mempty,
configCID = mempty,
configDeterministic = mempty,
configConfigurationsFlags = packageConfigFlagAssignment,
configTests = packageConfigTests,
configCoverage = packageConfigCoverage, --TODO: don't merge
......
......@@ -2705,6 +2705,7 @@ setupHsConfigureFlags (ReadyPackage elab@ElaboratedConfiguredPackage{..})
configInstantiateWith = Map.toList elabInstantiatedWith
configDeterministic = mempty -- doesn't matter, configIPID/configCID overridese
configIPID = case elabPkgOrComp of
ElabPackage pkg -> toFlag (display (pkgInstalledId pkg))
ElabComponent _ -> mempty
......
......@@ -403,7 +403,9 @@ filterConfigureFlags flags cabalLibVersion
-- Cabal < 1.25.0 doesn't know about --dynlibdir.
configInstallDirs = configInstallDirs_1_25_0,
-- Cabal < 1.25 doesn't have extended verbosity syntax
configVerbosity = fmap verboseNoFlags (configVerbosity flags_latest)
configVerbosity = fmap verboseNoFlags (configVerbosity flags_latest),
-- Cabal < 1.25 doesn't support --deterministic
configDeterministic = mempty
}
configInstallDirs_1_25_0 = (configInstallDirs flags) { dynlibdir = NoFlag }
......
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