Skip to content

Commit

Permalink
[ new ] Add fields licenseFiles and docDir to Paths_<pkgname>
Browse files Browse the repository at this point in the history
  • Loading branch information
L-TChen committed Aug 18, 2023
1 parent fa2ad55 commit 91d3f9d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
16 changes: 14 additions & 2 deletions Cabal/src/Distribution/Simple/Build/PathsModule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ import Prelude ()

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

import System.FilePath
import qualified Distribution.Simple.Build.PathsModule.Z as Z

-- ------------------------------------------------------------
Expand All @@ -44,6 +48,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 +63,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 +99,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 +110,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 +131,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 +140,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 +155,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
2 changes: 2 additions & 0 deletions cabal-dev-scripts/src/GenPathsModule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $(capture "decls" [d|
data Z = Z
{ zPackageName :: PackageName
, zVersionDigits :: String
, zLicenseFiles :: String
, zSupportsCpp :: Bool
, zSupportsNoRebindableSyntax :: Bool
, zAbsolute :: Bool
Expand All @@ -38,6 +39,7 @@ $(capture "decls" [d|
, zLibdir :: FilePath
, zDynlibdir :: FilePath
, zDatadir :: FilePath
, zDocdir :: FilePath
, zLibexecdir :: FilePath
, zSysconfdir :: FilePath

Expand Down
20 changes: 16 additions & 4 deletions templates/Paths_pkg.template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
{-# OPTIONS_GHC -w #-}
module Paths_{{ manglePkgName packageName }} (
version,
getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,
getDataFileName, getSysconfDir
version, licenseFiles,
getBinDir, getLibDir, getDynLibDir, getDataDir, getDocDir, getLibexecDir,
getDataFileName, getDocFileName, getSysconfDir
) where

{% if not absolute %}
Expand Down Expand Up @@ -56,12 +56,20 @@ catchIO = Exception.catch
version :: Version
version = Version {{ versionDigits }} []

licenseFiles :: [FilePath]
licenseFiles = {{ licenseFiles }}

getDataFileName :: FilePath -> IO FilePath
getDataFileName name = do
dir <- getDataDir
return (dir `joinFileName` name)

getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath
getDocFileName :: FilePath -> IO FilePath
getDocFileName name = do
dir <- getDocDir
return (dir `joinFileName` name)

getBinDir, getLibDir, getDynLibDir, getDataDir, getDocDir, getLibexecDir, getSysconfDir :: IO FilePath

{% defblock function_defs %}
minusFileName :: FilePath -> String -> FilePath
Expand Down Expand Up @@ -100,6 +108,7 @@ getBinDir = catchIO (getEnv "{{ manglePkgName packageName }}_bindir") (\
getLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_libdir") (\_ -> getPrefixDirReloc $ {{ libdir }})
getDynLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_dynlibdir") (\_ -> getPrefixDirReloc $ {{ dynlibdir }})
getDataDir = catchIO (getEnv "{{ manglePkgName packageName }}_datadir") (\_ -> getPrefixDirReloc $ {{ datadir }})
getDocDir = catchIO (getEnv "{{ manglePkgName packageName }}_docdir") (\_ -> getPrefixDirReloc $ {{ docdir }})
getLibexecDir = catchIO (getEnv "{{ manglePkgName packageName }}_libexecdir") (\_ -> getPrefixDirReloc $ {{ libexecdir }})
getSysconfDir = catchIO (getEnv "{{ manglePkgName packageName }}_sysconfdir") (\_ -> getPrefixDirReloc $ {{ sysconfdir }})

Expand All @@ -112,13 +121,15 @@ bindir = {{ bindir }}
libdir = {{ libdir }}
dynlibdir = {{ dynlibdir }}
datadir = {{ datadir }}
docdir = {{ docdir }}
libexecdir = {{ libexecdir }}
sysconfdir = {{ sysconfdir }}

getBinDir = catchIO (getEnv "{{ manglePkgName packageName }}_bindir") (\_ -> return bindir)
getLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_libdir") (\_ -> return libdir)
getDynLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_dynlibdir") (\_ -> return dynlibdir)
getDataDir = catchIO (getEnv "{{ manglePkgName packageName }}_datadir") (\_ -> return datadir)
getDocDir = catchIO (getEnv "{{ manglePkgName packageName }}_docdir") (\_ -> return docdir)
getLibexecDir = catchIO (getEnv "{{ manglePkgName packageName }}_libexecdir") (\_ -> return libexecdir)
getSysconfDir = catchIO (getEnv "{{ manglePkgName packageName }}_sysconfdir") (\_ -> return sysconfdir)

Expand All @@ -131,6 +142,7 @@ getBinDir = getPrefixDirRel $ {{ bindir }}
getLibDir = {{ libdir }}
getDynLibDir = {{ dynlibdir }}
getDataDir = catchIO (getEnv "{{ manglePkgName packageName }}_datadir") (\_ -> {{ datadir }})
getDocDir = {{ docdir }}
getLibexecDir = {{ libexecdir }}
getSysconfDir = {{ sysconfdir }}

Expand Down

0 comments on commit 91d3f9d

Please sign in to comment.