Skip to content

Commit

Permalink
only check for compiler when project file has conditionals (#8358)
Browse files Browse the repository at this point in the history
* only check for compiler when project file has conditionals

* fix sdist options a bit plus test

* whitespace

* poke tests around

* Update cabal.out

* Update cabal.test.hs

* changelog/docs

Co-authored-by: Gershom Bazerman <[email protected]>
  • Loading branch information
gbaz and gbaz authored Sep 20, 2022
1 parent 182e2c1 commit 1d4491f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdOutdated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Distribution.Client.DistDirLayout
, DistDirLayout(distProjectRootDirectory, distProjectFile) )
import Distribution.Client.ProjectConfig
import Distribution.Client.ProjectConfig.Legacy
( instantiateProjectConfigSkeleton )
( instantiateProjectConfigSkeletonWithCompiler )
import Distribution.Client.ProjectFlags
( projectFlagsOptions, ProjectFlags(..), defaultProjectFlags
, removeIgnoreProjectOption )
Expand Down Expand Up @@ -306,7 +306,7 @@ depsFromNewFreezeFile verbosity httpTransport compiler (Platform arch os) mproje
{- TODO: Support dist dir override -} Nothing
projectConfig <- runRebuild (distProjectRootDirectory distDirLayout) $ do
pcs <- readProjectLocalFreezeConfig verbosity httpTransport distDirLayout
pure $ instantiateProjectConfigSkeleton os arch (compilerInfo compiler) mempty pcs
pure $ instantiateProjectConfigSkeletonWithCompiler os arch (compilerInfo compiler) mempty pcs
let ucnstrs = map fst . projectConfigConstraints . projectConfigShared
$ projectConfig
deps = userConstraintsToDependencies ucnstrs
Expand Down
3 changes: 2 additions & 1 deletion cabal-install/src/Distribution/Client/CmdSdist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sdistOptions showOrParseArgs =
-------------------------------------------------------------------------------

sdistAction :: (ProjectFlags, SdistFlags) -> [String] -> GlobalFlags -> IO ()
sdistAction (ProjectFlags{..}, SdistFlags{..}) targetStrings globalFlags = do
sdistAction (pf@ProjectFlags{..}, SdistFlags{..}) targetStrings globalFlags = do
(baseCtx, distDirLayout) <- withProjectOrGlobalConfig verbosity flagIgnoreProject globalConfigFlag withProject withoutProject

let localPkgs = localPackages baseCtx
Expand Down Expand Up @@ -196,6 +196,7 @@ sdistAction (ProjectFlags{..}, SdistFlags{..}) targetStrings globalFlags = do
{ configVerbosity = sdistVerbosity
, configDistPref = sdistDistDir
}
, projectFlags = pf
}
mempty

Expand Down
19 changes: 14 additions & 5 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Distribution.Client.ProjectConfig.Legacy (
-- Project config skeletons
ProjectConfigSkeleton,
parseProjectSkeleton,
instantiateProjectConfigSkeleton,
instantiateProjectConfigSkeletonFetchingCompiler,
instantiateProjectConfigSkeletonWithCompiler,
singletonProjectConfigSkeleton,
projectSkeletonImports,

Expand Down Expand Up @@ -44,15 +45,15 @@ import Distribution.Client.CmdInstall.ClientInstallFlags
( ClientInstallFlags(..), defaultClientInstallFlags
, clientInstallOptions )

import Distribution.Compat.Lens (view)
import Distribution.Compat.Lens (view, toListOf)

import Distribution.Solver.Types.ConstraintSource

import Distribution.FieldGrammar
import Distribution.Package
import Distribution.Types.SourceRepo (RepoType)
import Distribution.Types.CondTree
( CondTree (..), CondBranch (..), mapTreeConds, traverseCondTreeC )
( CondTree (..), CondBranch (..), mapTreeConds, traverseCondTreeC, traverseCondTreeV, ignoreConditions )
import Distribution.PackageDescription
( dispFlagAssignment, Condition (..), ConfVar (..), FlagAssignment )
import Distribution.PackageDescription.Configuration (simplifyWithSysParams)
Expand Down Expand Up @@ -135,8 +136,16 @@ type ProjectConfigImport = String
singletonProjectConfigSkeleton :: ProjectConfig -> ProjectConfigSkeleton
singletonProjectConfigSkeleton x = CondNode x mempty mempty

instantiateProjectConfigSkeleton :: OS -> Arch -> CompilerInfo -> FlagAssignment -> ProjectConfigSkeleton -> ProjectConfig
instantiateProjectConfigSkeleton os arch impl _flags skel = go $ mapTreeConds (fst . simplifyWithSysParams os arch impl) skel
instantiateProjectConfigSkeletonFetchingCompiler :: Monad m => m (OS, Arch, CompilerInfo) -> FlagAssignment -> ProjectConfigSkeleton -> m ProjectConfig
instantiateProjectConfigSkeletonFetchingCompiler fetch flags skel
| null (toListOf traverseCondTreeV skel) = pure $ fst (ignoreConditions skel)
| otherwise = do
(os, arch, impl) <- fetch
pure $ instantiateProjectConfigSkeletonWithCompiler os arch impl flags skel


instantiateProjectConfigSkeletonWithCompiler :: OS -> Arch -> CompilerInfo -> FlagAssignment -> ProjectConfigSkeleton -> ProjectConfig
instantiateProjectConfigSkeletonWithCompiler os arch impl _flags skel = go $ mapTreeConds (fst . simplifyWithSysParams os arch impl) skel
where
go :: CondTree
FlagName
Expand Down
7 changes: 5 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,11 @@ rebuildProjectConfig verbosity
liftIO $ createDirectoryIfMissingVerbose verbosity True distProjectCacheDirectory
projectConfigSkeleton <- phaseReadProjectConfig
-- have to create the cache directory before configuring the compiler
(compiler, Platform arch os, _) <- configureCompiler verbosity distDirLayout ((fst $ PD.ignoreConditions projectConfigSkeleton) <> cliConfig)
let projectConfig = instantiateProjectConfigSkeleton os arch (compilerInfo compiler) mempty projectConfigSkeleton
let fetchCompiler = do
(compiler, Platform arch os, _) <- configureCompiler verbosity distDirLayout ((fst $ PD.ignoreConditions projectConfigSkeleton) <> cliConfig)
pure (os, arch, compilerInfo compiler)

projectConfig <- instantiateProjectConfigSkeletonFetchingCompiler fetchCompiler mempty projectConfigSkeleton
localPackages <- phaseReadLocalPackages (projectConfig <> cliConfig)
return (projectConfig, localPackages)

Expand Down
8 changes: 5 additions & 3 deletions cabal-install/src/Distribution/Client/ScriptUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Distribution.Client.ProjectConfig
, projectConfigHttpTransport )
import Distribution.Client.ProjectConfig.Legacy
( ProjectConfigSkeleton
, parseProjectSkeleton, instantiateProjectConfigSkeleton )
, parseProjectSkeleton, instantiateProjectConfigSkeletonFetchingCompiler )
import Distribution.Client.ProjectFlags
( flagIgnoreProject )
import Distribution.Client.RebuildMonad
Expand Down Expand Up @@ -243,9 +243,11 @@ withContextAndSelectors noTargets kind flags@NixStyleFlags {..} targetStrings gl

projectCfgSkeleton <- readProjectBlockFromScript verbosity httpTransport (distDirLayout ctx) (takeFileName script) scriptContents

(compiler, Platform arch os, _) <- runRebuild (distProjectRootDirectory . distDirLayout $ ctx) $ configureCompiler verbosity (distDirLayout ctx) ((fst $ ignoreConditions projectCfgSkeleton) <> projectConfig ctx)
let fetchCompiler = do
(compiler, Platform arch os, _) <- runRebuild (distProjectRootDirectory . distDirLayout $ ctx) $ configureCompiler verbosity (distDirLayout ctx) ((fst $ ignoreConditions projectCfgSkeleton) <> projectConfig ctx)
pure (os, arch, compilerInfo compiler)

let projectCfg = instantiateProjectConfigSkeleton os arch (compilerInfo compiler) mempty projectCfgSkeleton :: ProjectConfig
projectCfg <- instantiateProjectConfigSkeletonFetchingCompiler fetchCompiler mempty projectCfgSkeleton

let executable' = executable & L.buildInfo . L.defaultLanguage %~ maybe (Just Haskell2010) Just
ctx' = ctx & lProjectConfig %~ (<> projectCfg)
Expand Down
10 changes: 10 additions & 0 deletions changelog.d/pr-8358
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
synopsis: Update and sdist now only check for compiler when project file has conditionals
packages: cabal-install
prs: #8358
issues: #8352

description: {

- Cabal update and sdist will not require a ghc in path unless the project has conditionals that require it

}
5 changes: 5 additions & 0 deletions doc/cabal-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ freeze files. As a usage example:

import: /absolutepath/some-project.project

Using conditionals will force cabal to find a ghc to derive
architecture and version information from, which will force some
commands (update, sdist) to require ghc present where otherwise it
would not be necessitated.

Specifying the local packages
-----------------------------

Expand Down

0 comments on commit 1d4491f

Please sign in to comment.