From 8fc8b9b3437c96d774d2e5f1b24784358057cd08 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Mon, 5 Aug 2024 11:38:40 +0100 Subject: [PATCH] Include package version in --promised-dependency flag In the original implementation of promised dependencies I accidentally left over the hard coded `currentCabalId` in the `configureDependencies` function. This led to several errors happening later when the package name and version would be incorrect if you looked at this field (package arguments are not computed using it), it is used when generating cabal macros and something in the haddock options. The solution is to pass the package version in the `--promised-depenency` flag so the format is now ``` NAME-VER[:COMPONENT_NAME]=CID` ``` rather than ``` NAME[:COMPONENT_NAME]=CID ``` Fixes #10166 --- .../Distribution/Utils/Structured.hs | 4 +-- Cabal/src/Distribution/Backpack/Configure.hs | 8 ++--- .../Backpack/PreExistingComponent.hs | 6 ++-- Cabal/src/Distribution/Simple/Configure.hs | 28 ++++++++-------- Cabal/src/Distribution/Simple/GHC/Internal.hs | 6 ++-- Cabal/src/Distribution/Simple/Setup/Config.hs | 33 ++++++++++++++++--- .../src/Distribution/Types/GivenComponent.hs | 19 +++++++++++ .../Distribution/Types/LocalBuildConfig.hs | 4 +-- .../src/Distribution/Types/LocalBuildInfo.hs | 3 +- .../Distribution/Client/ProjectPlanning.hs | 11 ++++++- .../src/Distribution/Client/Setup.hs | 25 ++++++++++---- .../MultiRepl/CabalMacros/cabal.out | 10 ++++++ .../MultiRepl/CabalMacros/cabal.project | 2 ++ .../MultiRepl/CabalMacros/cabal.test.hs | 7 ++++ .../MultiRepl/CabalMacros/pkg-a/Foo.hs | 5 +++ .../MultiRepl/CabalMacros/pkg-a/pkg-a.cabal | 8 +++++ .../MultiRepl/CabalMacros/pkg-b/Bar.hs | 12 +++++++ .../MultiRepl/CabalMacros/pkg-b/pkg-b.cabal | 8 +++++ changelog.d/issue-10166 | 20 +++++++++++ 19 files changed, 178 insertions(+), 41 deletions(-) create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.out create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.project create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/Foo.hs create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/pkg-a.cabal create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/Bar.hs create mode 100644 cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/pkg-b.cabal create mode 100644 changelog.d/issue-10166 diff --git a/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs b/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs index d932ef59a33..2b795c0ef07 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs @@ -39,7 +39,7 @@ md5CheckGenericPackageDescription proxy = md5Check proxy md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion md5CheckLocalBuildInfo proxy = md5Check proxy #if MIN_VERSION_base(4,19,0) - 0xc68e9c0758c4bf2d72fe82b3d55cee34 + 0x041c4f233ad92ae5c3fc4e0384f993ff #else - 0xcf7e7bbcaec504d745fe086eec1786ff + 0x26e4eb4ac4691ca0432e8622eb5a5016 #endif diff --git a/Cabal/src/Distribution/Backpack/Configure.hs b/Cabal/src/Distribution/Backpack/Configure.hs index 8e9eb18ae6a..f3dec5055ee 100644 --- a/Cabal/src/Distribution/Backpack/Configure.hs +++ b/Cabal/src/Distribution/Backpack/Configure.hs @@ -70,7 +70,7 @@ configureComponentLocalBuildInfos -> Flag String -- configIPID -> Flag ComponentId -- configCID -> PackageDescription - -> ([PreExistingComponent], [PromisedComponent]) + -> ([PreExistingComponent], [ConfiguredPromisedComponent]) -> FlagAssignment -- configConfigurationsFlags -> [(ModuleName, Module)] -- configInstantiateWith -> InstalledPackageIndex @@ -118,7 +118,7 @@ configureComponentLocalBuildInfos `Map.union` Map.fromListWith Map.union [ (pkg, Map.singleton (ann_cname aid) aid) - | PromisedComponent pkg aid <- promisedPkgDeps + | ConfiguredPromisedComponent pkg aid <- promisedPkgDeps ] graph1 <- toConfiguredComponents @@ -151,7 +151,7 @@ configureComponentLocalBuildInfos , emptyModuleShape ) ) - | PromisedComponent _ aid <- promisedPkgDeps + | ConfiguredPromisedComponent _ aid <- promisedPkgDeps ] uid_lookup def_uid | Just pkg <- PackageIndex.lookupUnitId installedPackageSet uid = @@ -208,7 +208,7 @@ configureComponentLocalBuildInfos toComponentLocalBuildInfos :: Compiler -> InstalledPackageIndex -- FULL set - -> [PromisedComponent] + -> [ConfiguredPromisedComponent] -> PackageDescription -> [PreExistingComponent] -- external package deps -> [ReadyComponent] diff --git a/Cabal/src/Distribution/Backpack/PreExistingComponent.hs b/Cabal/src/Distribution/Backpack/PreExistingComponent.hs index 5f937de9062..0fba79bcb87 100644 --- a/Cabal/src/Distribution/Backpack/PreExistingComponent.hs +++ b/Cabal/src/Distribution/Backpack/PreExistingComponent.hs @@ -1,7 +1,7 @@ -- | See module Distribution.Backpack.PreExistingComponent ( PreExistingComponent (..) - , PromisedComponent (..) + , ConfiguredPromisedComponent (..) , ipiToPreExistingComponent ) where @@ -24,12 +24,12 @@ import Distribution.Types.AnnotatedId -- These components are promised to @configure@ but are not yet built. -- -- In other words this is 'PreExistingComponent' which doesn't yet exist. -data PromisedComponent = PromisedComponent +data ConfiguredPromisedComponent = ConfiguredPromisedComponent { pr_pkgname :: PackageName , pr_cid :: AnnotatedId ComponentId } -instance Package PromisedComponent where +instance Package ConfiguredPromisedComponent where packageId = packageId . pr_cid -- | Stripped down version of 'LinkedComponent' for things diff --git a/Cabal/src/Distribution/Simple/Configure.hs b/Cabal/src/Distribution/Simple/Configure.hs index 6e98ee6c25f..ff257887c08 100644 --- a/Cabal/src/Distribution/Simple/Configure.hs +++ b/Cabal/src/Distribution/Simple/Configure.hs @@ -828,7 +828,7 @@ computeLocalBuildConfig cfg comp programDb = do data PackageInfo = PackageInfo { internalPackageSet :: Set LibraryName - , promisedDepsSet :: Map (PackageName, ComponentName) ComponentId + , promisedDepsSet :: Map (PackageName, ComponentName) PromisedComponent , installedPackageSet :: InstalledPackageIndex , requiredDepsMap :: Map (PackageName, ComponentName) InstalledPackageInfo } @@ -1113,7 +1113,7 @@ finalCheckPackage -> LBC.PackageBuildDescr -> HookedBuildInfo -> PackageInfo - -> IO ([PreExistingComponent], [PromisedComponent]) + -> IO ([PreExistingComponent], [ConfiguredPromisedComponent]) finalCheckPackage g_pkg_descr ( LBC.PackageBuildDescr @@ -1210,7 +1210,7 @@ configureComponents :: LBC.LocalBuildConfig -> LBC.PackageBuildDescr -> PackageInfo - -> ([PreExistingComponent], [PromisedComponent]) + -> ([PreExistingComponent], [ConfiguredPromisedComponent]) -> IO LocalBuildInfo configureComponents lbc@(LBC.LocalBuildConfig{withPrograms = programDb}) @@ -1371,8 +1371,8 @@ configureComponents return lbi -mkPromisedDepsSet :: [GivenComponent] -> Map (PackageName, ComponentName) ComponentId -mkPromisedDepsSet comps = Map.fromList [((pn, CLibName ln), cid) | GivenComponent pn ln cid <- comps] +mkPromisedDepsSet :: [PromisedComponent] -> Map (PackageName, ComponentName) PromisedComponent +mkPromisedDepsSet comps = Map.fromList [((packageName pn, CLibName ln), p) | p@(PromisedComponent pn ln _) <- comps] -- | Adds the extra program paths from the flags provided to @configure@ as -- well as specified locations for certain known programs and their default @@ -1475,7 +1475,7 @@ dependencySatisfiable -- ^ installed set -> Set LibraryName -- ^ library components - -> Map (PackageName, ComponentName) ComponentId + -> Map (PackageName, ComponentName) PromisedComponent -> Map (PackageName, ComponentName) InstalledPackageInfo -- ^ required dependencies -> (Dependency -> Bool) @@ -1637,14 +1637,14 @@ configureDependencies :: Verbosity -> UseExternalInternalDeps -> Set LibraryName - -> Map (PackageName, ComponentName) ComponentId + -> Map (PackageName, ComponentName) PromisedComponent -> InstalledPackageIndex -- ^ installed packages -> Map (PackageName, ComponentName) InstalledPackageInfo -- ^ required deps -> PackageDescription -> ComponentRequestedSpec - -> IO ([PreExistingComponent], [PromisedComponent]) + -> IO ([PreExistingComponent], [ConfiguredPromisedComponent]) configureDependencies verbosity use_external_internal_deps @@ -1910,7 +1910,7 @@ data DependencyResolution -- we need to build packages in the interactive ghci session, no matter -- whether they have been built before. -- Building them in the configure phase is then redundant and costs time. - PromisedDependency PromisedComponent + PromisedDependency ConfiguredPromisedComponent | -- | An internal dependency ('PackageId' should be a library name) -- which we are going to have to build. (The -- 'PackageId' here is a hack to get a modest amount of @@ -1923,7 +1923,7 @@ selectDependency -- ^ Package id of current package -> Set LibraryName -- ^ package libraries - -> Map (PackageName, ComponentName) ComponentId + -> Map (PackageName, ComponentName) PromisedComponent -- ^ Set of components that are promised, i.e. are not installed already. See 'PromisedDependency' for more details. -> InstalledPackageIndex -- ^ Installed packages @@ -1975,8 +1975,8 @@ selectDependency -- We have to look it up externally do_external_external :: LibraryName -> Either FailedDependency DependencyResolution do_external_external lib - | Just cid <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex = - return $ PromisedDependency (PromisedComponent dep_pkgname (AnnotatedId currentCabalId (CLibName lib) cid)) + | Just pc <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex = + return $ PromisedDependency (ConfiguredPromisedComponent dep_pkgname (AnnotatedId (promisedComponentPackage pc) (CLibName lib) (promisedComponentId pc))) do_external_external lib = do ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of -- If we know the exact pkg to use, then use it. @@ -1989,8 +1989,8 @@ selectDependency do_external_internal :: LibraryName -> Either FailedDependency DependencyResolution do_external_internal lib - | Just cid <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex = - return $ PromisedDependency (PromisedComponent dep_pkgname (AnnotatedId currentCabalId (CLibName lib) cid)) + | Just pc <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex = + return $ PromisedDependency (ConfiguredPromisedComponent dep_pkgname (AnnotatedId (promisedComponentPackage pc) (CLibName lib) (promisedComponentId pc))) do_external_internal lib = do ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of -- If we know the exact pkg to use, then use it. diff --git a/Cabal/src/Distribution/Simple/GHC/Internal.hs b/Cabal/src/Distribution/Simple/GHC/Internal.hs index a4b75cdb6d3..ca78dc0fcd9 100644 --- a/Cabal/src/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/src/Distribution/Simple/GHC/Internal.hs @@ -75,8 +75,8 @@ import Distribution.Simple.Program.GHC import Distribution.Simple.Setup.Common (extraCompilationArtifacts) import Distribution.Simple.Utils import Distribution.System -import Distribution.Types.ComponentId (ComponentId) import Distribution.Types.ComponentLocalBuildInfo +import Distribution.Types.GivenComponent import Distribution.Types.LocalBuildInfo import Distribution.Types.TargetInfo import Distribution.Types.UnitId @@ -672,7 +672,7 @@ getHaskellObjects _implInfo lib lbi clbi pref wanted_obj_ext allow_split_objs -- and is a hack to avoid passing bogus `-package` arguments to GHC. The assumption being that -- in 99% of cases we will include the right `-package` so that the C file finds the right headers. mkGhcOptPackages - :: Map (PackageName, ComponentName) ComponentId + :: Map (PackageName, ComponentName) PromisedComponent -> ComponentLocalBuildInfo -> [(OpenUnitId, ModuleRenaming)] mkGhcOptPackages promisedPkgsMap clbi = @@ -680,7 +680,7 @@ mkGhcOptPackages promisedPkgsMap clbi = ] where -- Promised deps are going to be simple UnitIds - promised_cids = Set.fromList (map newSimpleUnitId (Map.elems promisedPkgsMap)) + promised_cids = Set.fromList (map (newSimpleUnitId . promisedComponentId) (Map.elems promisedPkgsMap)) substTopDir :: FilePath -> IPI.InstalledPackageInfo -> IPI.InstalledPackageInfo substTopDir topDir ipo = diff --git a/Cabal/src/Distribution/Simple/Setup/Config.hs b/Cabal/src/Distribution/Simple/Setup/Config.hs index 244f442af46..4034602a578 100644 --- a/Cabal/src/Distribution/Simple/Setup/Config.hs +++ b/Cabal/src/Distribution/Simple/Setup/Config.hs @@ -185,7 +185,7 @@ data ConfigFlags = ConfigFlags -- dependencies. , configDependencies :: [GivenComponent] -- ^ The packages depended on which already exist - , configPromisedDependencies :: [GivenComponent] + , configPromisedDependencies :: [PromisedComponent] -- ^ The packages depended on which doesn't yet exist (i.e. promised). -- Promising dependencies enables us to configure components in parallel, -- and avoids expensive builds if they are not necessary. @@ -779,13 +779,13 @@ configureOptions showOrParseArgs = , option "" ["promised-dependency"] - "A list of promised dependencies. E.g., --promised-dependency=\"void=void-0.5.8-177d5cdf20962d0581fe2e4932a6c309\"" + "A list of promised dependencies. E.g., --promised-dependency=\"void,0.1.1=void-0.5.8-177d5cdf20962d0581fe2e4932a6c309\"" configPromisedDependencies (\v flags -> flags{configPromisedDependencies = v}) ( reqArg - "NAME[:COMPONENT_NAME]=CID" - (parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecGivenComponent)) - (map prettyGivenComponent) + "NAME-VER[:COMPONENT_NAME]=CID" + (parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecPromisedComponent)) + (map prettyPromisedComponent) ) , option "" @@ -923,6 +923,29 @@ showProfDetailLevelFlag :: Flag ProfDetailLevel -> [String] showProfDetailLevelFlag NoFlag = [] showProfDetailLevelFlag (Flag dl) = [showProfDetailLevel dl] +parsecPromisedComponent :: ParsecParser PromisedComponent +parsecPromisedComponent = do + pn <- parsec + ln <- P.option LMainLibName $ do + _ <- P.char ':' + ucn <- parsec + return $ + if unUnqualComponentName ucn == unPackageName (pkgName pn) + then LMainLibName + else LSubLibName ucn + _ <- P.char '=' + cid <- parsec + return $ PromisedComponent pn ln cid + +prettyPromisedComponent :: PromisedComponent -> String +prettyPromisedComponent (PromisedComponent pn cn cid) = + prettyShow pn + ++ case cn of + LMainLibName -> "" + LSubLibName n -> ":" ++ prettyShow n + ++ "=" + ++ prettyShow cid + parsecGivenComponent :: ParsecParser GivenComponent parsecGivenComponent = do pn <- parsec diff --git a/Cabal/src/Distribution/Types/GivenComponent.hs b/Cabal/src/Distribution/Types/GivenComponent.hs index c8314311d89..235c8c372a0 100644 --- a/Cabal/src/Distribution/Types/GivenComponent.hs +++ b/Cabal/src/Distribution/Types/GivenComponent.hs @@ -3,12 +3,14 @@ module Distribution.Types.GivenComponent ( GivenComponent (..) + , PromisedComponent (..) ) where import Distribution.Compat.Prelude import Distribution.Types.ComponentId import Distribution.Types.LibraryName +import Distribution.Types.PackageId import Distribution.Types.PackageName -- | A 'GivenComponent' represents a library depended on and explicitly @@ -27,3 +29,20 @@ data GivenComponent = GivenComponent instance Binary GivenComponent instance Structured GivenComponent + +-- | A 'PromisedComponent' represents a promised library depended on and explicitly +-- specified by the user/client with @--promised-dependency@ +-- +-- It enables Cabal to know which 'ComponentId' to associate with a library +-- +-- @since 3.14.0.0 +data PromisedComponent = PromisedComponent + { promisedComponentPackage :: PackageId + , promisedComponentName :: LibraryName -- --dependency is for libraries + -- only, not for any component + , promisedComponentId :: ComponentId + } + deriving (Generic, Read, Show, Eq, Typeable) + +instance Binary PromisedComponent +instance Structured PromisedComponent diff --git a/Cabal/src/Distribution/Types/LocalBuildConfig.hs b/Cabal/src/Distribution/Types/LocalBuildConfig.hs index ce9064b2f43..929b5e60889 100644 --- a/Cabal/src/Distribution/Types/LocalBuildConfig.hs +++ b/Cabal/src/Distribution/Types/LocalBuildConfig.hs @@ -22,9 +22,9 @@ module Distribution.Types.LocalBuildConfig import Distribution.Compat.Prelude import Prelude () -import Distribution.Types.ComponentId import Distribution.Types.ComponentLocalBuildInfo import Distribution.Types.ComponentRequestedSpec +import Distribution.Types.GivenComponent import Distribution.Types.PackageDescription import Distribution.Types.UnitId @@ -101,7 +101,7 @@ data ComponentBuildDescr = ComponentBuildDescr -- ^ A map from component name to all matching -- components. These coincide with 'componentGraph' -- There may be more than one matching component because of backpack instantiations - , promisedPkgs :: Map (PackageName, ComponentName) ComponentId + , promisedPkgs :: Map (PackageName, ComponentName) PromisedComponent -- ^ The packages we were promised, but aren't already installed. -- MP: Perhaps this just needs to be a Set UnitId at this stage. , installedPkgs :: InstalledPackageIndex diff --git a/Cabal/src/Distribution/Types/LocalBuildInfo.hs b/Cabal/src/Distribution/Types/LocalBuildInfo.hs index f6af8c29c77..107eefc2766 100644 --- a/Cabal/src/Distribution/Types/LocalBuildInfo.hs +++ b/Cabal/src/Distribution/Types/LocalBuildInfo.hs @@ -103,6 +103,7 @@ import Prelude () import Distribution.Types.ComponentId import Distribution.Types.ComponentLocalBuildInfo import Distribution.Types.ComponentRequestedSpec +import Distribution.Types.GivenComponent import qualified Distribution.Types.LocalBuildConfig as LBC import Distribution.Types.PackageDescription import Distribution.Types.PackageId @@ -160,7 +161,7 @@ pattern LocalBuildInfo -> Maybe (SymbolicPath Pkg File) -> Graph ComponentLocalBuildInfo -> Map ComponentName [ComponentLocalBuildInfo] - -> Map (PackageName, ComponentName) ComponentId + -> Map (PackageName, ComponentName) PromisedComponent -> InstalledPackageIndex -> PackageDescription -> ProgramDb diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 23fed2c5bd1..896729cedae 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -4017,7 +4017,7 @@ setupHsConfigureFlags ] configPromisedDependencies = - [ cidToGivenComponent cid + [ cidToPromisedComponent cid | (cid, is_internal) <- elabLibDependencies elab , is_internal ] @@ -4058,6 +4058,15 @@ setupHsConfigureFlags Just _ -> error "non-library dependency" Nothing -> LMainLibName + cidToPromisedComponent :: ConfiguredId -> PromisedComponent + cidToPromisedComponent (ConfiguredId srcid mb_cn cid) = + PromisedComponent srcid ln cid + where + ln = case mb_cn of + Just (CLibName lname) -> lname + Just _ -> error "non-library dependency" + Nothing -> LMainLibName + configCoverageFor = determineCoverageFor elabPkgSourceId plan setupHsConfigureArgs diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 8d594b2a414..78e864d1a65 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -210,7 +210,9 @@ import Distribution.Simple.Utils import Distribution.System (Platform) import Distribution.Types.GivenComponent ( GivenComponent (..) + , PromisedComponent (..) ) +import Distribution.Types.PackageId import Distribution.Types.PackageVersionConstraint ( PackageVersionConstraint (..) ) @@ -226,6 +228,7 @@ import Distribution.Verbosity import Distribution.Version ( Version , mkVersion + , nullVersion ) import Control.Exception @@ -714,12 +717,22 @@ filterConfigureFlags' flags cabalLibVersion } flags_3_13_0 = - -- Earlier Cabal versions don't understand about .. - flags_latest - { -- Building profiled shared libraries - configProfShared = NoFlag - , configIgnoreBuildTools = NoFlag - } + let scrubVersion pc = + pc + { promisedComponentPackage = + (promisedComponentPackage pc){pkgVersion = nullVersion} + } + in -- Earlier Cabal versions don't understand about .. + flags_latest + { -- Building profiled shared libraries + configProfShared = NoFlag + , configIgnoreBuildTools = NoFlag + , -- Older versions of Cabal don't include the package version in the + -- --promised-dependency flag, by setting the version to nullVersion, + -- it won't be printed. + configPromisedDependencies = + map scrubVersion (configPromisedDependencies flags) + } flags_3_11_0 = flags_3_13_0 diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.out b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.out new file mode 100644 index 00000000000..9c141d7ac42 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.out @@ -0,0 +1,10 @@ +# cabal v2-repl +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - pkg-a-1 (interactive) (lib) (first run) + - pkg-b-0 (interactive) (lib) (first run) +Configuring library for pkg-a-1... +Preprocessing library for pkg-a-1... +Configuring library for pkg-b-0... +Preprocessing library for pkg-b-0... diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.project b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.project new file mode 100644 index 00000000000..bf8292adeb5 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.project @@ -0,0 +1,2 @@ +packages: pkg-a/*.cabal +packages: pkg-b/*.cabal diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.test.hs b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.test.hs new file mode 100644 index 00000000000..5a8434c5467 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/cabal.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude + +main = do + cabalTest $ do + skipUnlessGhcVersion ">= 9.4" + res <- cabalWithStdin "v2-repl" ["--enable-multi-repl","pkg-b", "pkg-a"] "Bar.bar" + assertOutputContains "3735929054" res diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/Foo.hs b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/Foo.hs new file mode 100644 index 00000000000..997ca89eecd --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/Foo.hs @@ -0,0 +1,5 @@ +module Foo where + +foo :: Int +foo = 42 + diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/pkg-a.cabal b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/pkg-a.cabal new file mode 100644 index 00000000000..7e4a3e9ef70 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-a/pkg-a.cabal @@ -0,0 +1,8 @@ +cabal-version: 2.2 +name: pkg-a +version: 1 + +library + default-language: Haskell2010 + build-depends: base + exposed-modules: Foo diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/Bar.hs b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/Bar.hs new file mode 100644 index 00000000000..c3179aa8db6 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/Bar.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE CPP #-} +module Bar (foo, bar) where + +import Foo (foo) + +#if MIN_VERSION_pkg_a(0,1,0) +bar :: Int +bar = 0xdeadc0de +#else +bar :: Int +bar = 0xdeadc0d1 +#endif diff --git a/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/pkg-b.cabal b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/pkg-b.cabal new file mode 100644 index 00000000000..8e1a273f0c4 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultiRepl/CabalMacros/pkg-b/pkg-b.cabal @@ -0,0 +1,8 @@ +cabal-version: 2.2 +name: pkg-b +version: 0 + +library + default-language: Haskell2010 + build-depends: base, pkg-a + exposed-modules: Bar diff --git a/changelog.d/issue-10166 b/changelog.d/issue-10166 new file mode 100644 index 00000000000..02d313adca9 --- /dev/null +++ b/changelog.d/issue-10166 @@ -0,0 +1,20 @@ +synopsis: Include package version when passing `--promised-dependency` flag +packages: Cabal Cabal-syntax +prs: #10248 +issues: #10166 + +description: { + +The --promised dependency flag now expects an argument in format + +``` +NAME-VER[:COMPONENT_NAME]=CID` +``` + +rather than + +``` +NAME[:COMPONENT_NAME]=CID +``` + +}