-
Notifications
You must be signed in to change notification settings - Fork 710
add base to cabal install --lib default env file #8903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e3b57e3
7acef4f
9d85d8b
3fe3de3
428b78f
b4c8c4c
90afcd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ import Distribution.Simple.Configure | |
( configCompilerEx ) | ||
import Distribution.Simple.Compiler | ||
( Compiler(..), CompilerId(..), CompilerFlavor(..) | ||
, PackageDBStack ) | ||
, PackageDBStack, PackageDB(..) ) | ||
import Distribution.Simple.GHC | ||
( ghcPlatformAndVersionString, getGhcAppDir | ||
, GhcImplInfo(..), getImplInfo | ||
|
@@ -123,11 +123,13 @@ import Distribution.Verbosity | |
import Distribution.Simple.Utils | ||
( wrapText, die', notice, warn | ||
, withTempDirectory, createDirectoryIfMissingVerbose | ||
, ordNub ) | ||
, ordNub, safeHead ) | ||
import Distribution.Utils.Generic | ||
( writeFileAtomic ) | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as BS | ||
import Data.Ord | ||
( Down(..) ) | ||
import qualified Data.Map as Map | ||
import qualified Data.Set as S | ||
import qualified Data.List.NonEmpty as NE | ||
|
@@ -424,7 +426,7 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe | |
unless dryRun $ | ||
if installLibs | ||
then installLibraries verbosity | ||
buildCtx compiler packageDbs envFile nonGlobalEnvEntries' | ||
buildCtx installedIndex compiler packageDbs envFile nonGlobalEnvEntries' | ||
else installExes verbosity | ||
baseCtx buildCtx platform compiler configFlags clientInstallFlags | ||
where | ||
|
@@ -687,20 +689,31 @@ installExes verbosity baseCtx buildCtx platform compiler | |
installLibraries | ||
:: Verbosity | ||
-> ProjectBuildContext | ||
-> PI.PackageIndex InstalledPackageInfo | ||
-> Compiler | ||
-> PackageDBStack | ||
-> FilePath -- ^ Environment file | ||
-> [GhcEnvironmentFileEntry] | ||
-> IO () | ||
installLibraries verbosity buildCtx compiler | ||
packageDbs envFile envEntries = do | ||
installLibraries verbosity buildCtx installedIndex compiler | ||
packageDbs' envFile envEntries = do | ||
if supportsPkgEnvFiles $ getImplInfo compiler | ||
then do | ||
let validDb (SpecificPackageDB fp) = doesPathExist fp | ||
validDb _ = pure True | ||
-- if a user "installs" a global package and no existing cabal db exists, none will be created. | ||
-- this ensures we don't add the "phantom" path to the file. | ||
packageDbs <- filterM validDb packageDbs' | ||
let | ||
getLatest = (=<<) (maybeToList . safeHead . snd) . take 1 . sortBy (comparing (Down . fst)) | ||
. PI.lookupPackageName installedIndex | ||
globalLatest = concat (getLatest <$> globalPackages) | ||
globalEntries = GhcEnvFilePackageId . installedUnitId <$> globalLatest | ||
baseEntries = | ||
GhcEnvFileClearPackageDbStack : fmap GhcEnvFilePackageDb packageDbs | ||
pkgEntries = ordNub $ | ||
envEntries | ||
globalEntries | ||
++ envEntries | ||
++ entriesForLibraryComponents (targetsMap buildCtx) | ||
contents' = renderGhcEnvironmentFile (baseEntries ++ pkgEntries) | ||
createDirectoryIfMissing True (takeDirectory envFile) | ||
|
@@ -711,6 +724,12 @@ installLibraries verbosity buildCtx compiler | |
++ "so only executables will be available. (Library installation is " | ||
++ "supported on GHC 8.0+ only)" | ||
|
||
-- See ticket #8894. This is safe to include any nonreinstallable boot pkg, | ||
-- but the particular package users will always expect to be in scope without specific installation | ||
-- is base, so that they can access prelude, regardles of if they specifically asked for it. | ||
globalPackages :: [PackageName] | ||
globalPackages = mkPackageName <$> [ "base" ] | ||
Comment on lines
+730
to
+731
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add here a reason why we unconditionally add "base". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And not any other built-in package or whatever the smallest enclosing set is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow-up in #8938 |
||
|
||
warnIfNoExes :: Verbosity -> ProjectBuildContext -> IO () | ||
warnIfNoExes verbosity buildCtx = | ||
when noExes $ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
synopsis: add base to cabal install --lib default env file | ||
packages: cabal-install | ||
prs: #8903 | ||
|
||
description: { | ||
|
||
This adds base by default to the env file created by `cabal install --lib`. Further it ensures that packagedbs have been created before adding them to the env file. | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be universally useful, how about adding this function to
PackageIndex
with documentation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping we could backport this into the cabal 3.10 series, which last I understood, we hoped to release just
cabal-install
without a newCabal
library...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need to have a fresh look at the planned fixes to make sure it's possible, but not releasing a new Cabal version would indeed be preferred.