Skip to content

Commit

Permalink
Extend the InstalledPackageInfo record with 2 fields for artifacts.
Browse files Browse the repository at this point in the history
These 2 fields involve configuration flags that affect which build artifacts
(dynamic and static files) are provided.  (This record corresponds to the
‘.conf’ files in the package-db directories, and Cabal-syntax provides an
interface to this record.  Cabal-syntax is used as a dependency by ‘ghc-pkg’
and ‘cabal-install’, and old Cabal-syntax implementations may produce an
‘Unknown field’ warning when used with new ‘.conf’ files.)

Add these IPI build artifact fields to enable tracking build artifacts in
installed packages.  The modular resolver could then use these new fields to
filter out installed package options missing required build artifacts that
would lead to a failing build plan.
  • Loading branch information
bairyn committed Jan 24, 2023
1 parent 8aad429 commit 111a46a
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 8 deletions.
9 changes: 7 additions & 2 deletions Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ data InstalledPackageInfo
frameworks :: [String],
haddockInterfaces :: [FilePath],
haddockHTMLs :: [FilePath],
pkgRoot :: Maybe FilePath
pkgRoot :: Maybe FilePath,
-- Artifacts included in this package:
providesStaticArtifacts :: Bool,
providesDynamicArtifacts :: Bool
}
deriving (Eq, Generic, Typeable, Read, Show)

Expand Down Expand Up @@ -173,5 +176,7 @@ emptyInstalledPackageInfo
haddockInterfaces = [],
haddockHTMLs = [],
pkgRoot = Nothing,
libVisibility = LibraryVisibilityPrivate
libVisibility = LibraryVisibilityPrivate,
providesStaticArtifacts = True,
providesDynamicArtifacts = True
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ ipiFieldGrammar = mkInstalledPackageInfo
<@> monoidalFieldAla "haddock-interfaces" (alaList' FSep FilePathNT) L.haddockInterfaces
<@> monoidalFieldAla "haddock-html" (alaList' FSep FilePathNT) L.haddockHTMLs
<@> optionalFieldAla "pkgroot" FilePathNT L.pkgRoot
<@> booleanFieldDef "provides-static-artifacts" L.providesStaticArtifacts True
<@> booleanFieldDef "provides-dynamic-artifacts" L.providesDynamicArtifacts True
where
mkInstalledPackageInfo _ Basic {..} = InstalledPackageInfo
-- _basicPkgName is not used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,11 @@ libVisibility :: Lens' InstalledPackageInfo LibraryVisibility
libVisibility f s = fmap (\x -> s { T.libVisibility = x }) (f (T.libVisibility s))
{-# INLINE libVisibility #-}

providesStaticArtifacts :: Lens' InstalledPackageInfo Bool
providesStaticArtifacts f s = fmap (\x -> s { T.providesStaticArtifacts = x }) (f (T.providesStaticArtifacts s))
{-# INLINE providesStaticArtifacts #-}

providesDynamicArtifacts :: Lens' InstalledPackageInfo Bool
providesDynamicArtifacts f s = fmap (\x -> s { T.providesDynamicArtifacts = x }) (f (T.providesDynamicArtifacts s))
{-# INLINE providesDynamicArtifacts #-}

4 changes: 3 additions & 1 deletion Cabal-tests/tests/ParserTests/ipi/Includes2.expr
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ InstalledPackageInfo {
haddockHTMLs =
[
"/home/travis/build/haskell/cabal/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.dist/work/./dist/build/x86_64-linux/ghc-8.2.2/Includes2-0.1.0.0/l/mylib/Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n/doc/html/Includes2"],
pkgRoot = Nothing}
pkgRoot = Nothing,
providesStaticArtifacts = True,
providesDynamicArtifacts = True}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ InstalledPackageInfo {
"/home/ogre/Documents/other-haskell/cabal/cabal-testsuite/PackageTests/CustomPreProcess/setup.dist/work/dist/doc/html/internal-preprocessor-test"],
pkgRoot =
Just
"/home/ogre/Documents/other-haskell/cabal/cabal-testsuite/PackageTests/CustomPreProcess/setup.dist/work/dist"}
"/home/ogre/Documents/other-haskell/cabal/cabal-testsuite/PackageTests/CustomPreProcess/setup.dist/work/dist",
providesStaticArtifacts = True,
providesDynamicArtifacts = True}
4 changes: 3 additions & 1 deletion Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr
Original file line number Diff line number Diff line change
Expand Up @@ -2181,4 +2181,6 @@ InstalledPackageInfo {
"/opt/ghc/8.2.2/share/doc/ghc-8.2.2/html/libraries/transformers-0.5.2.0/transformers.haddock"],
haddockHTMLs = [
"/opt/ghc/8.2.2/share/doc/ghc-8.2.2/html/libraries/transformers-0.5.2.0"],
pkgRoot = Nothing}
pkgRoot = Nothing,
providesStaticArtifacts = True,
providesDynamicArtifacts = True}
4 changes: 3 additions & 1 deletion Cabal-tests/tests/ParserTests/ipi/transformers.expr
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,6 @@ InstalledPackageInfo {
haddockHTMLs = [
"/opt/ghc/8.2.2/share/doc/ghc-8.2.2/html/libraries/transformers-0.5.2.0"],
pkgRoot = Just
"/opt/ghc/8.2.2/lib/ghc-8.2.2"}
"/opt/ghc/8.2.2/lib/ghc-8.2.2",
providesStaticArtifacts = True,
providesDynamicArtifacts = True}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured"
, testCase "GenericPackageDescription" $
md5Check (Proxy :: Proxy GenericPackageDescription) 0xa3e9433662ecf0c7a3c26f6d75a53ba1
, testCase "LocalBuildInfo" $
md5Check (Proxy :: Proxy LocalBuildInfo) 0x91ffcd61bbd83525e8edba877435a031
md5Check (Proxy :: Proxy LocalBuildInfo) 0x89eabee921ae834a5222e4a10ce68439
#endif
]

Expand Down
13 changes: 12 additions & 1 deletion Cabal/src/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
IPI.haddockInterfaces = [haddockdir installDirs </> haddockName pkg],
IPI.haddockHTMLs = [htmldir installDirs],
IPI.pkgRoot = Nothing,
IPI.libVisibility = libVisibility lib
IPI.libVisibility = libVisibility lib,
IPI.providesStaticArtifacts = providesStaticArtifacts,
IPI.providesDynamicArtifacts = providesDynamicArtifacts
}
where
ghc84 = case compilerId $ compiler lbi of
Expand Down Expand Up @@ -492,6 +494,15 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
= (libdir installDirs : dynlibdir installDirs : extraLibDirs bi, [])
-- the compiler doesn't understand the dynamic-library-dirs field so we
-- add the dyn directory to the "normal" list in the library-dirs field
(providesStaticArtifacts, providesDynamicArtifacts) = case compilerFlavor comp of
GHC ->
let
none f t = all (not . f) t
libDefaults = none ($ lbi) [withVanillaLib, withSharedLib] && hasLibrary
statics = libDefaults || any ($ lbi) [withVanillaLib]
dynamics = any ($ lbi) [withSharedLib]
in (statics, dynamics)
_ -> (True, True) -- Assume nothing is missing.

-- | Construct 'InstalledPackageInfo' for a library that is in place in the
-- build tree.
Expand Down
10 changes: 10 additions & 0 deletions changelog.d/pr-8696
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
synopsis: Extend the InstalledPackageInfo record with fields for artifacts.
packages: Cabal-syntax Cabal Cabal-tests
prs: #8696
description: {
Extend the InstalledPackageInfo record with new fields involving build
artifact configuration. The moduler resolver could then (in a separate set
of changes) use these new fields to avoid selecting installed package
options missing required artifacts and producing build plans that would
fail, even if alternatives would succeed.
}

0 comments on commit 111a46a

Please sign in to comment.