From e180d685b33e7e3ebd12350f08c8953af1cf57e3 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 6 Dec 2024 14:53:37 -0800 Subject: [PATCH] Prevent rebuilds when the project file changes ...provided that nothing else changes. --- .../Client/ProjectPlanning/Types.hs | 13 +++++++++++- .../ConditionalAndImport/cabal.out | 21 +++---------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs b/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs index e38779b8d34..ea9194be944 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs @@ -111,6 +111,9 @@ import Distribution.Simple.Utils (ordNub) import Distribution.Solver.Types.ComponentDeps (ComponentDeps) import qualified Distribution.Solver.Types.ComponentDeps as CD import Distribution.Solver.Types.OptionalStanza +import Distribution.Solver.Types.ConstraintSource + ( ConstraintSource (..) + ) import Distribution.Solver.Types.WithConstraintSource ( WithConstraintSource (..) ) @@ -348,7 +351,15 @@ normaliseConfiguredPackage -> ElaboratedConfiguredPackage -> ElaboratedConfiguredPackage normaliseConfiguredPackage ElaboratedSharedConfig{pkgConfigCompilerProgs} pkg = - pkg{elabProgramArgs = Map.mapMaybeWithKey lookupFilter (elabProgramArgs pkg)} + pkg + { elabProgramArgs = Map.mapMaybeWithKey lookupFilter (elabProgramArgs pkg) + , -- Wipe the constraint source so that if (e.g.) a project file changes we + -- don't necessarily force a rebuild if nothing else changes. + elabPkgSourceLocation = + (elabPkgSourceLocation pkg) + { constraintSource = ConstraintSourceUnknown + } + } where knownProgramDb = addKnownPrograms builtinPrograms pkgConfigCompilerProgs diff --git a/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out b/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out index 3a14c5cfd14..c26aaec2886 100644 --- a/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out +++ b/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out @@ -90,12 +90,7 @@ Configuration is affected by the following files: - same-filename/noncyclical-same-filename-b.config imported by: noncyclical-same-filename-b.project Resolving dependencies... -Build profile: -w ghc- -O1 -In order, the following will be built: - - my-0.1 (lib:my) (configuration changed) -Configuring my-0.1... -Preprocessing library for my-0.1... -Building library for my-0.1... +Up to date # checking that cyclical check catches a same file name that imports itself # cabal v2-build Error: [Cabal-7090] @@ -182,12 +177,7 @@ Configuration is affected by the following files: imported by: hops/hops-1.config imported by: hops-0.project Resolving dependencies... -Build profile: -w ghc- -O1 -In order, the following will be built: - - my-0.1 (lib:my) (configuration changed) -Configuring my-0.1... -Preprocessing library for my-0.1... -Building library for my-0.1... +Up to date # checking conflicting constraints skipping into a subfolder and then back out again and again # cabal v2-build Configuration is affected by the following files: @@ -391,12 +381,7 @@ Configuration is affected by the following files: imported by: yops/yops-1.config imported by: yops-0.project Resolving dependencies... -Build profile: -w ghc- -O1 -In order, the following will be built: - - my-0.1 (lib:my) (configuration changed) -Configuring my-0.1... -Preprocessing library for my-0.1... -Building library for my-0.1... +Up to date # checking bad conditional # cabal v2-build Error: [Cabal-7090]