-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8534 from blackheaven/package-infos-module
Add PackageInfos_ (#3909)
- Loading branch information
Showing
39 changed files
with
382 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Distribution.Simple.Build.PackageInfoModule | ||
-- Copyright : | ||
-- | ||
-- Maintainer : [email protected] | ||
-- Portability : portable | ||
-- | ||
-- Generating the PackageInfo_pkgname module. | ||
-- | ||
-- This is a module that Cabal generates for the benefit of packages. It | ||
-- enables them to find their package informations. | ||
-- | ||
module Distribution.Simple.Build.PackageInfoModule ( | ||
generatePackageInfoModule | ||
) where | ||
|
||
import Distribution.Compat.Prelude | ||
import Prelude () | ||
|
||
import Distribution.Package | ||
import Distribution.PackageDescription | ||
import Distribution.Simple.Compiler | ||
import Distribution.Simple.LocalBuildInfo | ||
import Distribution.Utils.ShortText | ||
import Distribution.Version | ||
|
||
import qualified Distribution.Simple.Build.PackageInfoModule.Z as Z | ||
|
||
-- ------------------------------------------------------------ | ||
-- * Building Paths_<pkg>.hs | ||
-- ------------------------------------------------------------ | ||
|
||
generatePackageInfoModule :: PackageDescription -> LocalBuildInfo -> String | ||
generatePackageInfoModule pkg_descr lbi = Z.render Z.Z | ||
{ Z.zPackageName = showPkgName $ 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.zSupportsNoRebindableSyntax = supports_rebindable_syntax | ||
} | ||
where | ||
supports_rebindable_syntax = ghc_newer_than (mkVersion [7,0,1]) | ||
|
||
ghc_newer_than minVersion = | ||
case compilerCompatVersion GHC (compiler lbi) of | ||
Nothing -> False | ||
Just version -> version `withinRange` orLaterVersion minVersion | ||
|
||
showPkgName :: PackageName -> String | ||
showPkgName = map fixchar . unPackageName | ||
|
||
fixchar :: Char -> Char | ||
fixchar '-' = '_' | ||
fixchar c = c |
60 changes: 60 additions & 0 deletions
60
Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
|
||
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) | ||
|
||
render :: Z -> String | ||
render z_root = execWriter $ do | ||
if (zSupportsNoRebindableSyntax z_root) | ||
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 " ) 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 "\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 "\n" | ||
tell "copyright :: String\n" | ||
tell "copyright = " | ||
tell (show $ zCopyright z_root) | ||
tell "\n" | ||
tell "homepage :: String\n" | ||
tell "homepage = " | ||
tell (show $ zHomepage z_root) | ||
tell "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.