Skip to content

Commit

Permalink
Add installDirs (datadir, etc) to new-build and remove them from new-…
Browse files Browse the repository at this point in the history
…install (#8556)

* handle datadir flag in newbuild

* fixup

* exclude installDirs options from cabal install

* fix tests

* changelong

Co-authored-by: Gershom Bazerman <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 4, 2023
1 parent 062ca76 commit 6467407
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ instance ToExpr Dependency where

instance ToExpr (SymbolicPath from to)

instance ToExpr a => ToExpr (InstallDirs a)

instance ToExpr AbiDependency
instance ToExpr AbiHash
instance ToExpr Arch
Expand Down
11 changes: 8 additions & 3 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ import Distribution.Client.Types.OverwritePolicy
import Distribution.Simple.Flag
( fromFlagOrDefault, flagToMaybe, flagElim )
import Distribution.Simple.Setup
( Flag(..) )
( Flag(..), installDirsOptions )
import Distribution.Solver.Types.SourcePackage
( SourcePackage(..) )
import Distribution.Simple.Command
( CommandUI(..), usageAlternatives )
( CommandUI(..), usageAlternatives, optionName )
import Distribution.Simple.Configure
( configCompilerEx )
import Distribution.Simple.Compiler
Expand Down Expand Up @@ -167,9 +167,14 @@ installCommand = CommandUI
++ " " ++ pname ++ " v2-install ./pkgfoo\n"
++ " Install the package in the ./pkgfoo directory\n"

, commandOptions = nixStyleOptions clientInstallOptions
, commandOptions = \x -> filter notInstallDirOpt $ nixStyleOptions clientInstallOptions x
, commandDefaultFlags = defaultNixStyleFlags defaultClientInstallFlags
}
where
-- install doesn't take installDirs flags, since it always installs into the store in a fixed way.
notInstallDirOpt x = not $ optionName x `elem` installDirOptNames
installDirOptNames = map optionName installDirsOptions


-- | The @install@ command actually serves four different needs. It installs:
-- * exes:
Expand Down
14 changes: 7 additions & 7 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Distribution.Simple.Setup
, TestFlags(..), testOptions', defaultTestFlags
, BenchmarkFlags(..), benchmarkOptions', defaultBenchmarkFlags
, programDbPaths', splitArgs, DumpBuildInfo (NoDumpBuildInfo, DumpBuildInfo)
, readPackageDb, showPackageDb
, readPackageDb, showPackageDb, installDirsOptions
)
import Distribution.Client.NixStyleOptions (NixStyleFlags (..))
import Distribution.Client.ProjectFlags (ProjectFlags (..), projectFlagsOptions, defaultProjectFlags)
Expand Down Expand Up @@ -102,7 +102,7 @@ import Distribution.Deprecated.ParseUtils
import Distribution.Client.ParseUtils
import Distribution.Simple.Command
( CommandUI(commandOptions), ShowOrParseArgs(..)
, OptionField, option, reqArg' )
, OptionField(..), option, reqArg' )
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint )
import Distribution.Parsec (ParsecParser, parsecToken)
Expand Down Expand Up @@ -501,7 +501,7 @@ convertLegacyAllPackageFlags globalFlags configFlags configExFlags installFlags
configHcPath = projectConfigHcPath,
configHcPkg = projectConfigHcPkg,
--configProgramPathExtra = projectConfigProgPathExtra DELETE ME
--configInstallDirs = projectConfigInstallDirs,
configInstallDirs = projectConfigInstallDirs,
--configUserInstall = projectConfigUserInstall,
configPackageDBs = projectConfigPackageDBs
} = configFlags
Expand Down Expand Up @@ -745,7 +745,8 @@ convertToLegacySharedConfig
configFlags = mempty {
configVerbosity = projectConfigVerbosity,
configDistPref = projectConfigDistDir,
configPackageDBs = projectConfigPackageDBs
configPackageDBs = projectConfigPackageDBs,
configInstallDirs = projectConfigInstallDirs
}

configExFlags = ConfigExFlags {
Expand Down Expand Up @@ -843,7 +844,7 @@ convertToLegacyAllPackageConfig
configOptimization = mempty,
configProgPrefix = mempty,
configProgSuffix = mempty,
configInstallDirs = mempty,
configInstallDirs = projectConfigInstallDirs,
configScratchDir = mempty,
configDistPref = mempty,
configCabalFilePath = mempty,
Expand Down Expand Up @@ -1140,7 +1141,7 @@ legacySharedConfigFieldDescrs constraintSrc = concat
(Disp.text . showPackageDb) (fmap readPackageDb parsecToken)
configPackageDBs (\v conf -> conf { configPackageDBs = v })
]
. filterFields ["verbose", "builddir" ]
. filterFields (["verbose", "builddir"] ++ map optionName installDirsOptions)
. commandOptionsToFields
$ configureOptions ParseArgs

Expand Down Expand Up @@ -1337,7 +1338,6 @@ legacyPackageConfigFieldDescrs =
. commandOptionsToFields
) (benchmarkOptions' ParseArgs)


where
overrideFieldCompiler =
simpleFieldParsec "compiler"
Expand Down
9 changes: 4 additions & 5 deletions cabal-install/src/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Setup
( Flag, HaddockTarget(..), TestShowDetails(..), DumpBuildInfo (..) )
import Distribution.Simple.InstallDirs
( PathTemplate )
( PathTemplate, InstallDirs )
import Distribution.Utils.NubList
( NubList )

Expand Down Expand Up @@ -169,12 +169,11 @@ data ProjectConfigShared
projectConfigHcPkg :: Flag FilePath,
projectConfigHaddockIndex :: Flag PathTemplate,

-- Things that only make sense for manual mode, not --local mode
-- Only makes sense for manual mode, not --local mode
-- too much control!
--projectConfigUserInstall :: Flag Bool,
--projectConfigInstallDirs :: InstallDirs (Flag PathTemplate),
--TODO: [required eventually] decide what to do with InstallDirs
-- currently we don't allow it to be specified in the config file

projectConfigInstallDirs :: InstallDirs (Flag PathTemplate),
projectConfigPackageDBs :: [Maybe PackageDB],

-- configuration used both by the solver and other phases
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ rebuildInstallPlan verbosity
getPackageSourceHashes verbosity withRepoCtx solverPlan

defaultInstallDirs <- liftIO $ userInstallDirTemplates compiler
let installDirs = fmap Cabal.fromFlag $ (fmap Flag defaultInstallDirs) <> (projectConfigInstallDirs projectConfigShared)
(elaboratedPlan, elaboratedShared)
<- liftIO . runLogProgress verbosity $
elaborateInstallPlan
Expand All @@ -696,7 +697,7 @@ rebuildInstallPlan verbosity
solverPlan
localPackages
sourcePackageHashes
defaultInstallDirs
installDirs
projectPackagesNamed
projectConfigShared
projectConfigAllPackages
Expand All @@ -705,7 +706,7 @@ rebuildInstallPlan verbosity
let instantiatedPlan
= instantiateInstallPlan
cabalStoreDirLayout
defaultInstallDirs
installDirs
elaboratedShared
elaboratedPlan
liftIO $ debugNoWrap verbosity (InstallPlan.showInstallPlan instantiatedPlan)
Expand Down Expand Up @@ -3486,7 +3487,6 @@ storePackageInstallDirs' StoreDirLayout{ storePackageDirectory
sysconfdir = prefix </> "etc"



computeInstallDirs :: StoreDirLayout
-> InstallDirs.InstallDirTemplates
-> ElaboratedSharedConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Distribution.Version
import Distribution.Simple.Program.Types
import Distribution.Simple.Program.Db
import Distribution.Simple.Utils (toUTF8BS)
import qualified Distribution.Simple.InstallDirs as InstallDirs
import Distribution.Types.PackageVersionConstraint

import Distribution.Parsec
Expand Down Expand Up @@ -456,6 +457,7 @@ instance Arbitrary ProjectConfigShared where
projectConfigHcPath <- arbitraryFlag arbitraryShortToken
projectConfigHcPkg <- arbitraryFlag arbitraryShortToken
projectConfigHaddockIndex <- arbitrary
projectConfigInstallDirs <- fixInstallDirs <$> arbitrary
projectConfigPackageDBs <- shortListOf 2 arbitrary
projectConfigRemoteRepos <- arbitrary
projectConfigLocalNoIndexRepos <- arbitrary
Expand Down Expand Up @@ -486,6 +488,7 @@ instance Arbitrary ProjectConfigShared where
arbitraryConstraints :: Gen [(UserConstraint, ConstraintSource)]
arbitraryConstraints =
fmap (\uc -> (uc, projectConfigConstraintSource)) <$> arbitrary
fixInstallDirs x = x {InstallDirs.includedir = mempty, InstallDirs.mandir = mempty, InstallDirs.flibdir = mempty}

shrink ProjectConfigShared {..} = runShrinker $ pure ProjectConfigShared
<*> shrinker projectConfigDistDir
Expand All @@ -496,6 +499,7 @@ instance Arbitrary ProjectConfigShared where
<*> shrinkerAla (fmap NonEmpty) projectConfigHcPath
<*> shrinkerAla (fmap NonEmpty) projectConfigHcPkg
<*> shrinker projectConfigHaddockIndex
<*> shrinker projectConfigInstallDirs
<*> shrinker projectConfigPackageDBs
<*> shrinker projectConfigRemoteRepos
<*> shrinker projectConfigLocalNoIndexRepos
Expand Down
11 changes: 11 additions & 0 deletions changelog.d/pr-8556
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Add installDirs (datadir, etc) to v2-build and remove them from v2-install
packages: cabal-install
prs: #8556
significance: significant

description: {

- Passes through --prefix --datadir and other installdir arguments properly in v2-build, allowing its use in perparing somewhat more relocatable compilation targets (no worse than v1-build).
- Removes these flags (which never worked) from v2-install

}

0 comments on commit 6467407

Please sign in to comment.