Skip to content
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

Extend the InstalledPackageInfo record with 2 fields for artifacts. #8696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need more documentation. What do we mean by "artifacts" here? How do these relate to GHC's notion of ways? Why are "static" and "dynamic" special (e.g. what about profiling)?

Copy link
Collaborator

@gbaz gbaz Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ben: this is discussed in the prior two PRs -- #8624 and #8461

Initially it had added five fields, not just two. However, the other part of the split PR only now makes use of these two, so the scope was scaled back for simplicity. (Unfortunately, this isn't in the history of the linked PR due to it being force-pushed). I think extending the logic to profiling (and teaching the solver about that) would also be useful, but its out of scope for the current round of work, so having those fields added without then being used opened the way to some bikeshedding and confusion which this hopefully avoids.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ben: do you mean documentation in the code included in GHC so that GHC devs don't need to rummage in cabal PRs? That makes sense. Or at least ready links to the aformentioned PRs from the code comments. Or both.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on common practice in GHC, I suspect the answer is "document it right there in the code." I think it's a best practice in any case. :)

(Wrong @ben fyi)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I'm sorry, @bgamari.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'm sorry @ben. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chreekat hit the nail on the head. Yes, the documentation should be next to the implementation otherwise future us has little chance of finding it.

Copy link
Member

@Mikolaj Mikolaj Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I should have been more specific when asking @bairyn for the artificial commit, but I lacked foresight. Let's wait with resuming the 3.10 semi-freeze and publishing a new dogfooding tag till today's devs meeting. I know @bairyn is busy, so that probably means the PRs have to wait until GHC 9.8. Tough luck.

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]
Comment on lines +502 to +503
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These uses of any can be simplified now that the lists have length one.

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.
}