Skip to content

Commit

Permalink
[WIP] Add --json solver config arg
Browse files Browse the repository at this point in the history
This allows the cabal-install solver logs to be mechanized, e.g., similar to
the tree view provided by nix-output-monitor for Nix.
  • Loading branch information
yvan-sraka committed Dec 19, 2023
1 parent f10dbcf commit f8a74e5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cabal-install/src/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module Distribution.Client.Dependency
, setSolveExecutables
, setGoalOrder
, setSolverVerbosity
, setSolverOutputJson
, removeLowerBounds
, removeUpperBounds
, addDefaultSetupDependencies
Expand Down Expand Up @@ -266,6 +267,7 @@ data DepResolverParams = DepResolverParams
, depResolverGoalOrder :: Maybe (Variable QPN -> Variable QPN -> Ordering)
-- ^ Function to override the solver's goal-ordering heuristics.
, depResolverVerbosity :: Verbosity
, depResolverOutputJson :: Bool
}

showDepResolverParams :: DepResolverParams -> String
Expand Down Expand Up @@ -363,6 +365,7 @@ basicDepResolverParams installedPkgIndex sourcePkgIndex =
, depResolverSolveExecutables = SolveExecutables True
, depResolverGoalOrder = Nothing
, depResolverVerbosity = normal
, depResolverOutputJson = False
}

addTargets
Expand Down Expand Up @@ -498,6 +501,12 @@ setSolverVerbosity verbosity params =
{ depResolverVerbosity = verbosity
}

setSolverOutputJson :: Bool -> DepResolverParams -> DepResolverParams
setSolverOutputJson outputJson params =
params
{ depResolverOutputJson = outputJson
}

-- | Some packages are specific to a given compiler version and should never be
-- reinstalled.
dontInstallNonReinstallablePackages :: DepResolverParams -> DepResolverParams
Expand Down Expand Up @@ -886,13 +895,16 @@ resolveDependencies platform comp pkgConfigDB params =
solveExes
order
verbosity
outputJson
) =
if asBool (depResolverAllowBootLibInstalls params)
then params
else dontInstallNonReinstallablePackages params

formatProgress :: Progress SummarizedMessage String a -> Progress String String a
formatProgress p = foldProgress (\x xs -> Step (renderSummarizedMessage x) xs) Fail Done p
formatProgress p = foldProgress (\x xs -> Step (formatter x) xs) Fail Done p
where
formatter = if outputJson then error "FIXME: To be implemented ..." else renderSummarizedMessage

preferences :: PackageName -> PackagePreferences
preferences = interpretPackagesPreference targets defpref prefs
Expand Down Expand Up @@ -1210,6 +1222,7 @@ resolveWithoutDependencies
_onlyConstrained
_order
_verbosity
_outputJson
) =
collectEithers $ map selectPackage (Set.toList targets)
where
Expand Down

0 comments on commit f8a74e5

Please sign in to comment.