Skip to content

Change MungedPackageName to not be opaque #5812

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

Merged
merged 3 commits into from
Jan 6, 2019
Merged
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
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ library
Distribution.Types.LibraryName
Distribution.Types.MungedPackageName
Distribution.Types.PackageName
Distribution.Types.PackageName.Magic
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a separate commit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not easily. Won't do.

Distribution.Types.PkgconfigName
Distribution.Types.UnqualComponentName
Distribution.Types.IncludeRenaming
Expand Down
5 changes: 3 additions & 2 deletions Cabal/Distribution/Backpack/ComponentsGraph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ mkComponentsGraph enabled pkg_descr =
where
bi = componentBuildInfo component
internalPkgDeps = map (conv . libName) (allLibraries pkg_descr)
conv Nothing = packageNameToUnqualComponentName $ packageName pkg_descr
conv (Just s) = s

conv LMainLibName = packageNameToUnqualComponentName $ packageName pkg_descr
conv (LSubLibName s) = s

-- | Given the package description and a 'PackageDescription' (used
-- to determine if a package name is internal or not), sort the
Expand Down
3 changes: 2 additions & 1 deletion Cabal/Distribution/Backpack/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Distribution.Simple.LocalBuildInfo
import Distribution.Types.AnnotatedId
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ComponentInclude
import Distribution.Types.MungedPackageName
import Distribution.Verbosity
import qualified Distribution.Compat.Graph as Graph
import Distribution.Compat.Graph (Graph, IsNode(..))
Expand Down Expand Up @@ -277,7 +278,7 @@ mkLinkedComponentsLocalBuildInfo comp rcs = map go rcs
Right instc -> [ (m, OpenModule (DefiniteUnitId uid') m')
| (m, Module uid' m') <- instc_insts instc ]

compat_name = computeCompatPackageName (packageName rc) (libName lib)
compat_name = MungedPackageName (packageName rc) (libName lib)
compat_key = computeCompatPackageKey comp compat_name (packageVersion rc) this_uid

in LibComponentLocalBuildInfo {
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Backpack/ConfiguredComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,4 @@ fixFakePkgName pkg_descr pn =
else (pn, CLibName LMainLibName )
where
subLibName = packageNameToUnqualComponentName pn
internalLibraries = mapMaybe libName (allLibraries pkg_descr)
internalLibraries = mapMaybe (libraryNameString . libName) (allLibraries pkg_descr)
1 change: 0 additions & 1 deletion Cabal/Distribution/Backpack/Id.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
module Distribution.Backpack.Id(
computeComponentId,
computeCompatPackageKey,
computeCompatPackageName,
) where

import Prelude ()
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Backpack/PreExistingComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ipiToPreExistingComponent :: InstalledPackageInfo -> PreExistingComponent
ipiToPreExistingComponent ipi =
PreExistingComponent {
pc_pkgname = packageName ipi,
pc_compname = libraryComponentName $ Installed.sourceLibName ipi,
pc_compname = CLibName $ Installed.sourceLibName ipi,
pc_munged_id = mungedId ipi,
pc_uid = Installed.installedUnitId ipi,
pc_cid = Installed.installedComponentId ipi,
Expand Down
8 changes: 4 additions & 4 deletions Cabal/Distribution/Backpack/ReadyComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import Distribution.Types.Component
import Distribution.Types.ComponentInclude
import Distribution.Types.ComponentId
import Distribution.Types.ComponentName
import Distribution.Types.LibraryName
import Distribution.Types.PackageId
import Distribution.Types.PackageName.Magic
import Distribution.Types.UnitId
import Distribution.Compat.Graph (IsNode(..))
import Distribution.Types.Module
import Distribution.Types.MungedPackageId
import Distribution.Types.MungedPackageName
import Distribution.Types.Library
import Distribution.Types.LibraryName

import Distribution.ModuleName
import Distribution.Package
Expand Down Expand Up @@ -140,8 +141,7 @@ rc_depends rc = ordNub $
computeCompatPackageId
(ci_pkgid ci)
(case ci_cname ci of
CLibName LMainLibName -> Nothing
CLibName (LSubLibName uqn) -> Just uqn
CLibName name -> name
_ -> error $ prettyShow (rc_cid rc) ++
" depends on non-library " ++ prettyShow (ci_id ci))

Expand Down Expand Up @@ -275,7 +275,7 @@ toReadyComponents pid_map subst0 comps
fmap rc_munged_id (join (Map.lookup dep_uid s)))]
where
err_pid = MungedPackageId
(mkMungedPackageName "nonexistent-package-this-is-a-cabal-bug")
(MungedPackageName nonExistentPackageThisIsCabalBug LMainLibName)
(mkVersion [0])
instc = InstantiatedComponent {
instc_insts = Map.toList insts,
Expand Down
6 changes: 1 addition & 5 deletions Cabal/Distribution/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import Distribution.FieldGrammar.FieldDescrs
import Distribution.ModuleName
import Distribution.Package hiding (installedPackageId, installedUnitId)
import Distribution.Types.ComponentName
import Distribution.Types.LibraryName
import Distribution.Utils.Generic (toUTF8BS)

import qualified Data.Map as Map
Expand Down Expand Up @@ -97,10 +96,7 @@ installedPackageId = installedUnitId
-- Munging

sourceComponentName :: InstalledPackageInfo -> ComponentName
sourceComponentName ipi =
case sourceLibName ipi of
Nothing -> CLibName LMainLibName
Just qn -> CLibName $ LSubLibName qn
sourceComponentName = CLibName . sourceLibName

-- -----------------------------------------------------------------------------
-- Parsing
Expand Down
12 changes: 5 additions & 7 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Distribution.System
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.CondTree
import Distribution.Types.ExeDependency
import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName
import Distribution.Utils.Generic (isAscii)
import Distribution.Verbosity
Expand Down Expand Up @@ -195,7 +196,7 @@ checkSanity pkg =
PackageBuildImpossible
"No executables, libraries, tests, or benchmarks found. Nothing to do."

, check (any isNothing (map libName $ subLibraries pkg)) $
, check (any (== LMainLibName) (map libName $ subLibraries pkg)) $
PackageBuildImpossible $ "Found one or more unnamed internal libraries. "
++ "Only the non-internal library can have the same name as the package."

Expand Down Expand Up @@ -236,7 +237,7 @@ checkSanity pkg =
-- The public 'library' gets special dispensation, because it
-- is common practice to export a library and name the executable
-- the same as the package.
subLibNames = catMaybes . map libName $ subLibraries pkg
subLibNames = mapMaybe (libraryNameString . libName) $ subLibraries pkg
exeNames = map exeName $ executables pkg
testNames = map testName $ testSuites pkg
bmNames = map benchmarkName $ benchmarks pkg
Expand All @@ -254,10 +255,7 @@ checkLibrary pkg lib =
-- TODO: This check is bogus if a required-signature was passed through
, check (null (explicitLibModules lib) && null (reexportedModules lib)) $
PackageDistSuspiciousWarn $
"Library " ++ (case libName lib of
Nothing -> ""
Just n -> prettyShow n
) ++ "does not expose any modules"
showLibraryName (libName lib) ++ " does not expose any modules"

-- check use of signatures sections
, checkVersion [1,25] (not (null (signatures lib))) $
Expand Down Expand Up @@ -589,7 +587,7 @@ checkFields pkg =
, isNoVersion vr ]

internalLibraries =
map (maybe (packageName pkg) (unqualComponentNameToPackageName) . libName)
map (maybe (packageName pkg) (unqualComponentNameToPackageName) . libraryNameString . libName)
(allLibraries pkg)

internalExecutables = map exeName $ executables pkg
Expand Down
6 changes: 3 additions & 3 deletions Cabal/Distribution/PackageDescription/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ finalizePD userflags enabled satisfyDep
(mb_lib, comps) = flattenTaggedTargets targetSet
mb_lib' = fmap libFillInDefaults mb_lib
comps' = flip map comps $ \(n,c) -> foldComponent
(\l -> CLib (libFillInDefaults l) { libName = Just n
(\l -> CLib (libFillInDefaults l) { libName = LSubLibName n
, libExposed = False })
(\l -> CFLib (flibFillInDefaults l) { foreignLibName = n })
(\e -> CExe (exeFillInDefaults e) { exeName = n })
Expand Down Expand Up @@ -541,14 +541,14 @@ flattenPackageDescription
}
where
mlib = f <$> mlib0
where f lib = (libFillInDefaults . fst . ignoreConditions $ lib) { libName = Nothing }
where f lib = (libFillInDefaults . fst . ignoreConditions $ lib) { libName = LMainLibName }
sub_libs = flattenLib <$> sub_libs0
flibs = flattenFLib <$> flibs0
exes = flattenExe <$> exes0
tests = flattenTst <$> tests0
bms = flattenBm <$> bms0
flattenLib (n, t) = libFillInDefaults $ (fst $ ignoreConditions t)
{ libName = Just n, libExposed = False }
{ libName = LSubLibName n, libExposed = False }
flattenFLib (n, t) = flibFillInDefaults $ (fst $ ignoreConditions t)
{ foreignLibName = n }
flattenExe (n, t) = exeFillInDefaults $ (fst $ ignoreConditions t)
Expand Down
12 changes: 6 additions & 6 deletions Cabal/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ packageDescriptionFieldGrammar = PackageDescription

libraryFieldGrammar
:: (FieldGrammar g, Applicative (g Library), Applicative (g BuildInfo))
=> Maybe UnqualComponentName
=> LibraryName
-> g Library Library
libraryFieldGrammar n = Library n
<$> monoidalFieldAla "exposed-modules" (alaList' VCat MQuoted) L.exposedModules
Expand All @@ -134,16 +134,16 @@ libraryFieldGrammar n = Library n
<*> visibilityField
<*> blurFieldGrammar L.libBuildInfo buildInfoFieldGrammar
where
visibilityField
visibilityField = case n of
-- nameless/"main" libraries are public
| isNothing n = pure LibraryVisibilityPublic
LMainLibName -> pure LibraryVisibilityPublic
-- named libraries have the field
| otherwise =
LSubLibName _ ->
optionalFieldDef "visibility" L.libVisibility LibraryVisibilityPrivate
^^^ availableSince CabalSpecV3_0 LibraryVisibilityPrivate

{-# SPECIALIZE libraryFieldGrammar :: Maybe UnqualComponentName -> ParsecFieldGrammar' Library #-}
{-# SPECIALIZE libraryFieldGrammar :: Maybe UnqualComponentName -> PrettyFieldGrammar' Library #-}
{-# SPECIALIZE libraryFieldGrammar :: LibraryName -> ParsecFieldGrammar' Library #-}
{-# SPECIALIZE libraryFieldGrammar :: LibraryName -> PrettyFieldGrammar' Library #-}

-------------------------------------------------------------------------------
-- Foreign library
Expand Down
16 changes: 10 additions & 6 deletions Cabal/Distribution/PackageDescription/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,18 @@ goSections specVer = traverse_ process
"Multiple main libraries; have you forgotten to specify a name for an internal library?"

commonStanzas <- use stateCommonStanzas
lib <- lift $ parseCondTree' (libraryFieldGrammar Nothing) (libraryFromBuildInfo Nothing) commonStanzas fields

let name'' = LMainLibName
lib <- lift $ parseCondTree' (libraryFieldGrammar name'') (libraryFromBuildInfo name'') commonStanzas fields
--
-- TODO check that not set
stateGpd . L.condLibrary ?= lib

-- Sublibraries
-- TODO: check cabal-version
| name == "library" = do
commonStanzas <- use stateCommonStanzas
name' <- parseUnqualComponentName pos args
let name'' = Just name'
let name'' = LSubLibName name'
lib <- lift $ parseCondTree' (libraryFieldGrammar name'') (libraryFromBuildInfo name'') commonStanzas fields
-- TODO check duplicate name here?
stateGpd . L.condSubLibraries %= snoc (name', lib)
Expand Down Expand Up @@ -545,10 +547,12 @@ type CondTreeBuildInfo = CondTree ConfVar [Dependency] BuildInfo
class L.HasBuildInfo a => FromBuildInfo a where
fromBuildInfo' :: BuildInfo -> a

libraryFromBuildInfo :: Maybe UnqualComponentName -> BuildInfo -> Library
libraryFromBuildInfo :: LibraryName -> BuildInfo -> Library
libraryFromBuildInfo n bi = emptyLibrary
{ libName = n
, libVisibility = if isNothing n then LibraryVisibilityPublic else LibraryVisibilityPrivate
, libVisibility = case n of
LMainLibName -> LibraryVisibilityPublic
LSubLibName _ -> LibraryVisibilityPrivate
, libBuildInfo = bi
}

Expand Down Expand Up @@ -726,7 +730,7 @@ data Syntax = OldSyntax | NewSyntax

-- TODO:
libFieldNames :: [FieldName]
libFieldNames = fieldGrammarKnownFieldList (libraryFieldGrammar Nothing)
libFieldNames = fieldGrammarKnownFieldList (libraryFieldGrammar LMainLibName)

-------------------------------------------------------------------------------
-- Suplementary build information
Expand Down
7 changes: 4 additions & 3 deletions Cabal/Distribution/PackageDescription/PrettyPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Prelude ()
import Distribution.Types.CondTree
import Distribution.Types.Dependency
import Distribution.Types.ForeignLib (ForeignLib (foreignLibName))
import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName

import Distribution.PackageDescription
Expand Down Expand Up @@ -133,12 +134,12 @@ ppCondTree2 grammar = go
ppCondLibrary :: Maybe (CondTree ConfVar [Dependency] Library) -> [PrettyField]
ppCondLibrary Nothing = mempty
ppCondLibrary (Just condTree) = pure $ PrettySection "library" [] $
ppCondTree2 (libraryFieldGrammar Nothing) condTree
ppCondTree2 (libraryFieldGrammar LMainLibName) condTree

ppCondSubLibraries :: [(UnqualComponentName, CondTree ConfVar [Dependency] Library)] -> [PrettyField]
ppCondSubLibraries libs =
[ PrettySection "library" [pretty n]
$ ppCondTree2 (libraryFieldGrammar $ Just n) condTree
$ ppCondTree2 (libraryFieldGrammar $ LSubLibName n) condTree
| (n, condTree) <- libs
]

Expand Down Expand Up @@ -216,7 +217,7 @@ pdToGpd pd = GenericPackageDescription
-- We set CondTree's [Dependency] to an empty list, as it
-- is not pretty printed anyway.
mkCondTree x = CondNode x [] []
mkCondTreeL l = (fromMaybe (mkUnqualComponentName "") (libName l), CondNode l [] [])
mkCondTreeL l = (fromMaybe (mkUnqualComponentName "") (libraryNameString (libName l)), CondNode l [] [])

mkCondTree'
:: (a -> UnqualComponentName)
Expand Down
9 changes: 5 additions & 4 deletions Cabal/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
where
bi = testBuildInfo test
lib = Library {
libName = Nothing,
libName = LMainLibName,
exposedModules = [ m ],
reexportedModules = [],
signatures = [],
Expand All @@ -465,7 +465,8 @@ testSuiteLibV09AsLibAndExe pkg_descr
-- This is, like, the one place where we use a CTestName for a library.
-- Should NOT use library name, since that could conflict!
PackageIdentifier pkg_name pkg_ver = package pkg_descr
compat_name = computeCompatPackageName pkg_name (Just (testName test))
-- Note: we do make internal library from the test!
compat_name = MungedPackageName pkg_name (LSubLibName (testName test))
compat_key = computeCompatPackageKey (compiler lbi) compat_name pkg_ver (componentUnitId clbi)
libClbi = LibComponentLocalBuildInfo
{ componentPackageDeps = componentPackageDeps clbi
Expand All @@ -483,7 +484,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
, componentExposedModules = [IPI.ExposedModule m Nothing]
}
pkg = pkg_descr {
package = (package pkg_descr) { pkgName = mkPackageName $ unMungedPackageName compat_name }
package = (package pkg_descr) { pkgName = mkPackageName $ prettyShow compat_name }
, executables = []
, testSuites = []
, subLibraries = [lib]
Expand All @@ -505,7 +506,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
-- | The stub executable needs a new 'ComponentLocalBuildInfo'
-- that exposes the relevant test suite library.
deps = (IPI.installedUnitId ipi, mungedId ipi)
: (filter (\(_, x) -> let name = unMungedPackageName $ mungedName x
: (filter (\(_, x) -> let name = prettyShow $ mungedName x
in name == "Cabal" || name == "base")
(componentPackageDeps clbi))
exeClbi = ExeComponentLocalBuildInfo {
Expand Down
8 changes: 3 additions & 5 deletions Cabal/Distribution/Simple/Build/Macros.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ generate pkg_descr lbi clbi =
generateComponentIdMacro lbi clbi ++
generateCurrentPackageVersion pkg_descr
where
getPid (_, MungedPackageId mpn v) =
PackageIdentifier pn v
where
-- NB: Drop the component name! We're just reporting package versions.
getPid (_, MungedPackageId (MungedPackageName pn _) v) =
-- NB: Drop the library name! We're just reporting package versions.
-- This would have to be revisited if you are allowed to depend
-- on different versions of the same package
pn = fst (decodeCompatPackageName mpn)
PackageIdentifier pn v

-- | Helper function that generates just the @VERSION_pkg@ and @MIN_VERSION_pkg@
-- macros for a list of package ids (usually used with the specific deps of
Expand Down
Loading