Skip to content

Add PackageMeta_ autogenerated module (#11755)#11756

Open
angerman wants to merge 4 commits intohaskell:masterfrom
angerman:angerman/add-package-meta-module
Open

Add PackageMeta_ autogenerated module (#11755)#11756
angerman wants to merge 4 commits intohaskell:masterfrom
angerman:angerman/add-package-meta-module

Conversation

@angerman
Copy link
Copy Markdown
Collaborator

Summary

Adds a new autogenerated module PackageMeta_<pkgname> that exposes build-environment metadata known at configure time. This complements the existing PackageInfo_<pkgname> (static .cabal metadata) and Paths_<pkgname> (install paths).

Closes #11755.
Related: #392, #826, #1506, #7355, #7488, #11258, #4746.

What PackageMeta_ provides

module PackageMeta_mypackage where

compiler        :: String   -- e.g. "ghc"
compilerVersion :: Version  -- e.g. Version [9,6,7] []
os              :: String   -- e.g. "linux", "darwin"
arch            :: String   -- e.g. "x86_64", "aarch64"
gitRevision     :: String   -- e.g. "abc123..." or ""
gitDirty        :: Bool     -- working tree dirty?
flag_debug      :: Bool     -- one Bool per cabal flag
flag_benchmarks :: Bool

Taxonomy

Module Changes when... Content
PackageInfo_ .cabal file edited name, version, synopsis, copyright, homepage
PackageMeta_ (new) Build environment changes compiler, os, arch, flags, gitRevision
Paths_ Package installed to different prefix bindir, libdir, datadir

Implementation

Follows the exact pattern established by PackageInfo_ (PR #8534):

  • Distribution.Simple.Build.PackageMetaModule -- generation logic
  • Distribution.Simple.Build.PackageMetaModule.Z -- Zinza-style renderer
  • autogenPackageMetaModuleName added to BuildPaths
  • Wired into builtinAutogenFiles in Build.hs
  • Filtered from sdist in SrcDist.hs
  • Test cases following the PackageMetaModule/ pattern

Note on git revision: generatePackageMetaModule accepts the git revision and dirty flag as parameters (since computing them requires IO, and builtinAutogenFiles is pure). This PR passes empty defaults ("", False). Wiring up the actual git rev-parse HEAD call at the appropriate IO call site is left for a follow-up, pending discussion on the issue about whether VCS info should be opt-in.

Test plan

  • Verify PackageMetaModule.hs and Z.hs compile
  • Verify generated module is valid Haskell (validated end-to-end with standalone renderer test)
  • Verify cabal check warnings for missing autogen-modules
  • Verify sdist filtering works
  • Run existing test suite to check for regressions

Adds a new autogenerated module `PackageMeta_<pkgname>` that exposes
build-environment metadata: compiler flavour and version, platform OS
and architecture, git revision, git dirty flag, and per-flag booleans.

This follows the exact pattern of `PackageInfo_` (PR haskell#8534).

The git revision fields are currently passed as empty/false because
`builtinAutogenFiles` is pure; a follow-up will wire up the IO-based
git revision lookup at the call site.

New modules:
  - Distribution.Simple.Build.PackageMetaModule (generation logic)
  - Distribution.Simple.Build.PackageMetaModule.Z (zinza renderer)

Modified modules:
  - Distribution.Simple.BuildPaths (autogenPackageMetaModuleName)
  - Distribution.Simple.Build (builtinAutogenFiles integration)
  - Distribution.Simple.SrcDist (filterAutogenModules)
  - Cabal.cabal (exposed-modules / other-modules)

Test cases:
  - PackageTests/PackageMetaModule/Executable
  - PackageTests/PackageMetaModule/Library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PackageMeta_ autogenerated module for build-time metadata

1 participant