Skip to content

More information in the generated modules Paths_<pkgname> and PackageInfo_<pkgname> #9250

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

Closed
wants to merge 5 commits into from
Closed
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 .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs
- --ignore-glob=Cabal-syntax/src/Distribution/Fields/Lexer.hs
- --ignore-glob=templates/Paths_pkg.template.hs
- --ignore-glob=templates/PackageInfo_pkg.template.hs
- --ignore-glob=templates/SPDX.LicenseExceptionId.template.hs
- --ignore-glob=templates/SPDX.LicenseId.template.hs
19 changes: 15 additions & 4 deletions Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Prelude ()

import Distribution.Package
import Distribution.PackageDescription
import Distribution.Pretty (prettyShow)
import Distribution.Simple.Compiler
import Distribution.Simple.LocalBuildInfo
import Distribution.Utils.ShortText
Expand All @@ -37,12 +38,22 @@ generatePackageInfoModule :: PackageDescription -> LocalBuildInfo -> String
generatePackageInfoModule pkg_descr lbi =
Z.render
Z.Z
{ Z.zPackageName = showPkgName $ packageName pkg_descr
{ Z.zPackageName = packageName pkg_descr
, Z.zVersionDigits = show $ versionNumbers $ packageVersion pkg_descr
, Z.zSynopsis = fromShortText $ synopsis pkg_descr
, Z.zCopyright = fromShortText $ copyright pkg_descr
, Z.zHomepage = fromShortText $ homepage pkg_descr
, Z.zLicense = show $ prettyShow $ license pkg_descr
, Z.zCopyright = show $ fromShortText $ copyright pkg_descr
, Z.zMaintainer = show $ fromShortText $ maintainer pkg_descr
, Z.zAuthor = show $ fromShortText $ author pkg_descr
, Z.zStability = show $ fromShortText $ stability pkg_descr
, Z.zHomepage = show $ fromShortText $ homepage pkg_descr
, Z.zPkgUrl = show $ fromShortText $ pkgUrl pkg_descr
, Z.zBugReports = show $ fromShortText $ bugReports pkg_descr
, Z.zSynopsis = show $ fromShortText $ synopsis pkg_descr
, Z.zDescription = show $ fromShortText $ description pkg_descr
, Z.zCategory = show $ fromShortText $ category pkg_descr
, Z.zSupportsNoRebindableSyntax = supports_rebindable_syntax
, Z.zManglePkgName = showPkgName
, Z.zShow = show
}
where
supports_rebindable_syntax = ghc_newer_than (mkVersion [7, 0, 1])
Expand Down
121 changes: 89 additions & 32 deletions Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs
Original file line number Diff line number Diff line change
@@ -1,60 +1,117 @@
{- FOURMOLU_DISABLE -}
{-# LANGUAGE DeriveGeneric #-}

module Distribution.Simple.Build.PackageInfoModule.Z (render, Z (..)) where

module Distribution.Simple.Build.PackageInfoModule.Z (render, Z(..)) where
import Distribution.ZinzaPrelude

data Z = Z
{ zPackageName :: String
, zVersionDigits :: String
, zSynopsis :: String
, zCopyright :: String
, zHomepage :: String
, zSupportsNoRebindableSyntax :: Bool
}
deriving (Generic)

data Z
= Z {zPackageName :: PackageName,
zVersionDigits :: String,
zLicense :: String,
zCopyright :: String,
zMaintainer :: String,
zAuthor :: String,
zStability :: String,
zHomepage :: String,
zPkgUrl :: String,
zBugReports :: String,
zSynopsis :: String,
zDescription :: String,
zCategory :: String,
zSupportsNoRebindableSyntax :: Bool,
zManglePkgName :: (PackageName -> String),
zShow :: (String -> String)}
deriving Generic
render :: Z -> String
render z_root = execWriter $ do
if (zSupportsNoRebindableSyntax z_root)
then do
tell "{-# LANGUAGE NoRebindableSyntax #-}\n"
return ()
else do
return ()
then do
tell "{-# LANGUAGE NoRebindableSyntax #-}\n"
return ()
else do
return ()
tell "{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}\n"
tell "{-# OPTIONS_GHC -w #-}\n"
tell "module PackageInfo_"
tell (zPackageName z_root)
tell " (\n"
tell " name,\n"
tell " version,\n"
tell " synopsis,\n"
tell " copyright,\n"
tell " homepage,\n"
tell (zManglePkgName z_root (zPackageName z_root))
tell "\n"
tell " ( name\n"
tell " , version\n"
tell " , license\n"
tell " , copyright\n"
tell " , maintainer\n"
tell " , author\n"
tell " , stability\n"
tell " , homepage\n"
tell " , pkgUrl\n"
tell " , bugReports\n"
tell " , synopsis\n"
tell " , description\n"
tell " , category\n"
tell " ) where\n"
tell "\n"
tell "import Data.Version (Version(..))\n"
tell "import Prelude\n"
tell "\n"
tell "name :: String\n"
tell "name = "
tell (show $ zPackageName z_root)
tell (zShow z_root (zManglePkgName z_root (zPackageName z_root)))
tell "\n"
tell "\n"
tell "version :: Version\n"
tell "version = Version "
tell (zVersionDigits z_root)
tell " []\n"
tell "\n"
tell "synopsis :: String\n"
tell "synopsis = "
tell (show $ zSynopsis z_root)
tell "license :: String\n"
tell "license = "
tell (zLicense z_root)
tell "\n"
tell "\n"
tell "copyright :: String\n"
tell "copyright = "
tell (show $ zCopyright z_root)
tell (zCopyright z_root)
tell "\n"
tell "\n"
tell "maintainer :: String\n"
tell "maintainer = "
tell (zMaintainer z_root)
tell "\n"
tell "\n"
tell "author :: String\n"
tell "author = "
tell (zAuthor z_root)
tell "\n"
tell "\n"
tell "stability :: String\n"
tell "stability = "
tell (zStability z_root)
tell "\n"
tell "\n"
tell "homepage :: String\n"
tell "homepage = "
tell (show $ zHomepage z_root)
tell (zHomepage z_root)
tell "\n"
tell "\n"
tell "pkgUrl :: String\n"
tell "pkgUrl = "
tell (zPkgUrl z_root)
tell "\n"
tell "\n"
tell "bugReports :: String\n"
tell "bugReports = "
tell (zBugReports z_root)
tell "\n"
tell "\n"
tell "synopsis :: String\n"
tell "synopsis = "
tell (zSynopsis z_root)
tell "\n"
tell "\n"
tell "description :: String\n"
tell "description = "
tell (zDescription z_root)
tell "\n"
tell "\n"
tell "category :: String\n"
tell "category = "
tell (zCategory z_root)
tell "\n"
14 changes: 12 additions & 2 deletions Cabal/src/Distribution/Simple/Build/PathsModule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import Prelude ()

import Distribution.Package
import Distribution.PackageDescription
import Distribution.Pretty ()
import Distribution.Simple.Compiler
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Utils (shortRelativePath)
import Distribution.System
import Distribution.Utils.Path (getSymbolicPath)
import Distribution.Version

import qualified Distribution.Simple.Build.PathsModule.Z as Z
Expand All @@ -44,6 +46,7 @@ generatePathsModule pkg_descr lbi clbi =
Z.Z
{ Z.zPackageName = packageName pkg_descr
, Z.zVersionDigits = show $ versionNumbers $ packageVersion pkg_descr
, Z.zLicenseFiles = show $ getSymbolicPath <$> licenseFiles pkg_descr
, Z.zSupportsCpp = supports_cpp
, Z.zSupportsNoRebindableSyntax = supports_rebindable_syntax
, Z.zAbsolute = absolute
Expand All @@ -58,6 +61,7 @@ generatePathsModule pkg_descr lbi clbi =
, Z.zLibdir = zLibdir
, Z.zDynlibdir = zDynlibdir
, Z.zDatadir = zDatadir
, Z.zDocdir = zDocdir
, Z.zLibexecdir = zLibexecdir
, Z.zSysconfdir = zSysconfdir
}
Expand Down Expand Up @@ -93,6 +97,7 @@ generatePathsModule pkg_descr lbi clbi =
, libdir = flat_libdir
, dynlibdir = flat_dynlibdir
, datadir = flat_datadir
, docdir = flat_docdir
, libexecdir = flat_libexecdir
, sysconfdir = flat_sysconfdir
, prefix = flat_prefix
Expand All @@ -103,17 +108,19 @@ generatePathsModule pkg_descr lbi clbi =
, libdir = flat_libdirrel
, dynlibdir = flat_dynlibdirrel
, datadir = flat_datadirrel
, docdir = flat_docdirrel
, libexecdir = flat_libexecdirrel
, sysconfdir = flat_sysconfdirrel
} = prefixRelativeComponentInstallDirs (packageId pkg_descr) lbi cid

zBindir, zLibdir, zDynlibdir, zDatadir, zLibexecdir, zSysconfdir :: String
(zBindir, zLibdir, zDynlibdir, zDatadir, zLibexecdir, zSysconfdir)
zBindir, zLibdir, zDynlibdir, zDatadir, zDocdir, zLibexecdir, zSysconfdir :: String
(zBindir, zLibdir, zDynlibdir, zDatadir, zDocdir, zLibexecdir, zSysconfdir)
| relocatable lbi =
( show flat_bindir_reloc
, show flat_libdir_reloc
, show flat_dynlibdir_reloc
, show flat_datadir_reloc
, show flat_docdir_reloc
, show flat_libexecdir_reloc
, show flat_sysconfdir_reloc
)
Expand All @@ -122,6 +129,7 @@ generatePathsModule pkg_descr lbi clbi =
, show flat_libdir
, show flat_dynlibdir
, show flat_datadir
, show flat_docdir
, show flat_libexecdir
, show flat_sysconfdir
)
Expand All @@ -130,6 +138,7 @@ generatePathsModule pkg_descr lbi clbi =
, mkGetDir flat_libdir flat_libdirrel
, mkGetDir flat_dynlibdir flat_dynlibdirrel
, mkGetDir flat_datadir flat_datadirrel
, mkGetDir flat_docdir flat_docdirrel
, mkGetDir flat_libexecdir flat_libexecdirrel
, mkGetDir flat_sysconfdir flat_sysconfdirrel
)
Expand All @@ -144,6 +153,7 @@ generatePathsModule pkg_descr lbi clbi =
flat_libdir_reloc = shortRelativePath flat_prefix flat_libdir
flat_dynlibdir_reloc = shortRelativePath flat_prefix flat_dynlibdir
flat_datadir_reloc = shortRelativePath flat_prefix flat_datadir
flat_docdir_reloc = shortRelativePath flat_prefix flat_docdir
flat_libexecdir_reloc = shortRelativePath flat_prefix flat_libexecdir
flat_sysconfdir_reloc = shortRelativePath flat_prefix flat_sysconfdir

Expand Down
34 changes: 30 additions & 4 deletions Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Distribution.ZinzaPrelude
data Z
= Z {zPackageName :: PackageName,
zVersionDigits :: String,
zLicenseFiles :: String,
zSupportsCpp :: Bool,
zSupportsNoRebindableSyntax :: Bool,
zAbsolute :: Bool,
Expand All @@ -17,6 +18,7 @@ data Z
zLibdir :: FilePath,
zDynlibdir :: FilePath,
zDatadir :: FilePath,
zDocdir :: FilePath,
zLibexecdir :: FilePath,
zSysconfdir :: FilePath,
zNot :: (Bool -> Bool),
Expand Down Expand Up @@ -55,9 +57,9 @@ render z_root = execWriter $ do
tell "module Paths_"
tell (zManglePkgName z_root (zPackageName z_root))
tell " (\n"
tell " version,\n"
tell " getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,\n"
tell " getDataFileName, getSysconfDir\n"
tell " version, licenseFiles,\n"
tell " getBinDir, getLibDir, getDynLibDir, getDataDir, getDocDir, getLibexecDir,\n"
tell " getDataFileName, getDocFileName, getSysconfDir\n"
tell " ) where\n"
tell "\n"
if (zNot z_root (zAbsolute z_root))
Expand Down Expand Up @@ -106,12 +108,22 @@ render z_root = execWriter $ do
tell (zVersionDigits z_root)
tell " []\n"
tell "\n"
tell "licenseFiles :: [FilePath]\n"
tell "licenseFiles = "
tell (zLicenseFiles z_root)
tell "\n"
tell "\n"
tell "getDataFileName :: FilePath -> IO FilePath\n"
tell "getDataFileName name = do\n"
tell " dir <- getDataDir\n"
tell " return (dir `joinFileName` name)\n"
tell "\n"
tell "getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath\n"
tell "getDocFileName :: FilePath -> IO FilePath\n"
tell "getDocFileName name = do\n"
tell " dir <- getDocDir\n"
tell " return (dir `joinFileName` name)\n"
tell "\n"
tell "getBinDir, getLibDir, getDynLibDir, getDataDir, getDocDir, getLibexecDir, getSysconfDir :: IO FilePath\n"
tell "\n"
let
z_var0_function_defs = do
Expand Down Expand Up @@ -168,6 +180,11 @@ render z_root = execWriter $ do
tell "_datadir\") (\\_ -> getPrefixDirReloc $ "
tell (zDatadir z_root)
tell ")\n"
tell "getDocDir = catchIO (getEnv \""
tell (zManglePkgName z_root (zPackageName z_root))
tell "_docdir\") (\\_ -> getPrefixDirReloc $ "
tell (zDocdir z_root)
tell ")\n"
tell "getLibexecDir = catchIO (getEnv \""
tell (zManglePkgName z_root (zPackageName z_root))
tell "_libexecdir\") (\\_ -> getPrefixDirReloc $ "
Expand Down Expand Up @@ -199,6 +216,9 @@ render z_root = execWriter $ do
tell "datadir = "
tell (zDatadir z_root)
tell "\n"
tell "docdir = "
tell (zDocdir z_root)
tell "\n"
tell "libexecdir = "
tell (zLibexecdir z_root)
tell "\n"
Expand All @@ -218,6 +238,9 @@ render z_root = execWriter $ do
tell "getDataDir = catchIO (getEnv \""
tell (zManglePkgName z_root (zPackageName z_root))
tell "_datadir\") (\\_ -> return datadir)\n"
tell "getDocDir = catchIO (getEnv \""
tell (zManglePkgName z_root (zPackageName z_root))
tell "_docdir\") (\\_ -> return docdir)\n"
tell "getLibexecDir = catchIO (getEnv \""
tell (zManglePkgName z_root (zPackageName z_root))
tell "_libexecdir\") (\\_ -> return libexecdir)\n"
Expand Down Expand Up @@ -249,6 +272,9 @@ render z_root = execWriter $ do
tell "_datadir\") (\\_ -> "
tell (zDatadir z_root)
tell ")\n"
tell "getDocDir = "
tell (zDocdir z_root)
tell "\n"
tell "getLibexecDir = "
tell (zLibexecdir z_root)
tell "\n"
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ $(SPDX_EXCEPTION_HS) : templates/SPDX.LicenseExceptionId.template.hs cabal-dev-s

TEMPLATE_MACROS:=Cabal/src/Distribution/Simple/Build/Macros/Z.hs
TEMPLATE_PATHS:=Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs
TEMPLATE_PKGINFO:=Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs

templates : phony $(TEMPLATE_MACROS) $(TEMPLATE_PATHS)
templates : phony $(TEMPLATE_MACROS) $(TEMPLATE_PATHS) $(TEMPLATE_PKGINFO)

$(TEMPLATE_MACROS) : templates/cabal_macros.template.h cabal-dev-scripts/src/GenCabalMacros.hs
cabal run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-cabal-macros -- $< $@

$(TEMPLATE_PATHS) : templates/Paths_pkg.template.hs cabal-dev-scripts/src/GenPathsModule.hs
cabal run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-paths-module -- $< $@

$(TEMPLATE_PKGINFO) : templates/PackageInfo_pkg.template.hs cabal-dev-scripts/src/GenPackageInfoModule.hs
cabal run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-pkg-info-module -- $< $@

# generated docs

buildinfo-fields-reference : phony
Expand Down
Loading