From 652a77c8db17b5d1acf2660948136bf4e4d2fe56 Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita Date: Mon, 8 Jan 2024 16:40:47 +0000 Subject: [PATCH] Apply project local options on install Currently, there are three kinds of cabal configurations considered when determining an option of an `ElaboratedConfiguredPackage`: * Global configuration, in `.cabal/config` * Local configuration, in - Options passed in the cabal invocation, e.g. `cabal build --enable-executable-dynamic` - Fields in the top level `cabal.project`, or `cabal.project.local`, e.g. `extra-include-dirs: /opt/homebrew/include` Note thus that top-level cabal.project flags and cli flags are treated all together at the same level (`local`). * Per package configuration, as in package HsOpenSSL extra-include-dirs: /opt/homebrew/Cellar/openssl@3/3.2.0_1/include extra-lib-dirs: /opt/homebrew/Cellar/openssl@3/3.2.0_1/lib Then, we have a definition for whether a package is local to the project. The local packages are the packages listed in the project which have a specific source package, rather than just being listed by name in a `source-repository-stanza`, or in a `package ` stanza that configures installed packages. In this patch, we try fix the mistmatch between the `local` flags and the packages which are deemed `local`, and define a specification for what exactly should happen..... TODO Fixes #7297, #8909, #2997 --- .../src/Distribution/Client/CmdInstall.hs | 4 ++-- .../src/Distribution/Client/ProjectPlanning.hs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index 5de704430f5..871b1a257a3 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -3,9 +3,9 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} --- | cabal-install CLI command: build +-- | cabal-install CLI command: install module Distribution.Client.CmdInstall - ( -- * The @build@ CLI and action + ( -- * The @install@ CLI and action installCommand , installAction diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 6d63ffcbaab..67208d4a68d 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -1528,6 +1528,7 @@ elaborateInstallPlan -> StoreDirLayout -> SolverInstallPlan -> [PackageSpecifier (SourcePackage (PackageLocation loc))] + -- ^ All the packages listed in this project -> Map PackageId PackageSourceHash -> InstallDirs.InstallDirTemplates -> ProjectConfigShared @@ -1544,7 +1545,7 @@ elaborateInstallPlan distDirLayout@DistDirLayout{..} storeDirLayout@StoreDirLayout{storePackageDBStack} solverPlan - localPackages + projectPackages sourcePackageHashes defaultInstallDirs sharedPackageConfig @@ -2305,11 +2306,7 @@ elaborateInstallPlan global `mappend` local `mappend` perpkg where global = f allPackagesConfig - local - | isLocalToProject pkg = - f localPackagesConfig - | otherwise = - mempty + local = f localPackagesConfig perpkg = maybe mempty f (Map.lookup (packageName pkg) perPackageConfig) inplacePackageDbs = @@ -2345,11 +2342,11 @@ elaborateInstallPlan (packageId pkg) pkgsLocalToProject + -- \| Determine the packages local to the project from the list of + -- project packages pkgsLocalToProject :: Set PackageId pkgsLocalToProject = - Set.fromList (catMaybes (map shouldBeLocal localPackages)) - -- TODO: localPackages is a misnomer, it's all project packages - -- here is where we decide which ones will be local! + Set.fromList (catMaybes (map shouldBeLocal projectPackages)) pkgsUseSharedLibrary :: Set PackageId pkgsUseSharedLibrary = @@ -2414,6 +2411,9 @@ elaborateInstallPlan -- TODO: Drop matchPlanPkg/matchElabPkg in favor of mkCCMapping +-- | Determine if a given package in this project is local to the project, as +-- opposed to a package referred to by name e.g. in a source-repository-stanza, +-- or an installed package shouldBeLocal :: PackageSpecifier (SourcePackage (PackageLocation loc)) -> Maybe PackageId shouldBeLocal NamedPackage{} = Nothing shouldBeLocal (SpecificSourcePackage pkg) = case srcpkgSource pkg of