Skip to content

Commit

Permalink
Apply project local options on install
Browse files Browse the repository at this point in the history
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 <package-name>` 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 haskell#7297, haskell#8909, haskell#2997
  • Loading branch information
alt-romes committed Jan 8, 2024
1 parent f70fc98 commit 652a77c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 9 additions & 9 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,7 @@ elaborateInstallPlan
-> StoreDirLayout
-> SolverInstallPlan
-> [PackageSpecifier (SourcePackage (PackageLocation loc))]
-- ^ All the packages listed in this project
-> Map PackageId PackageSourceHash
-> InstallDirs.InstallDirTemplates
-> ProjectConfigShared
Expand All @@ -1544,7 +1545,7 @@ elaborateInstallPlan
distDirLayout@DistDirLayout{..}
storeDirLayout@StoreDirLayout{storePackageDBStack}
solverPlan
localPackages
projectPackages
sourcePackageHashes
defaultInstallDirs
sharedPackageConfig
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 652a77c

Please sign in to comment.