Add PackageMeta_ autogenerated module (#11755)#11756
Conversation
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
| -- TODO: Git revision info requires IO (running git commands) but | ||
| -- builtinAutogenFiles is pure. Pass empty git info for now; a follow-up | ||
| -- will wire up the IO-based git revision lookup at the call site. | ||
| packageMetaContents = toUTF8LBS $ generatePackageMetaModule pkg lbi "" False |
There was a problem hiding this comment.
Why do we need to leave a todo here? It seems like everything can be solved right here.
builtinAutogenFiles is only used in writeBuiltinAutogenFiles :: ... -> IO ()
| , zOs :: String | ||
| , zArch :: String | ||
| , zGitRevision :: String | ||
| , zGitDirty :: Bool |
There was a problem hiding this comment.
Not really convinced of the git parts, for several reasons:
- Getting the required information into
cabalis going to be messy no matter how you spin it - Invoking
gitfrom withincabaladds attack surface (especially if it's not opt-in) - Recompilation checks will get complicated: you will need to re-run a git command for every build to check whether the PackageMeta module needs to be rebuilt
- Git isn't the only VCS out there - it's ubiquitous to the point that a lot of people will think you're insane if you use anything else, but I still think hard-coding "everyone uses git anyway" as an assumption into a build system is not a great idea
- Injecting git revision information into an executable is already possible without this (shelling out to
gitfrom Template Haskell), and doing it separately gives you much more flexibility - e.g., you can pick up branch names, tag names, etc., and interpret them according to the project's conventions, rather than just getting a commit hash and a "dirty" flag. - The git fields don't actually do anything yet; until the code that fills them is in place, they're just dead weight, so I'd suggest merging this without the git fields, and implement those, together with code to fill them, separately.
|
@angerman: could I help move this forward? |
@Mikolaj by all means yes! I'm currently swamped with other stuff 😖 @tdammers TH is imo not a solution for this (th-embed and all these others), TH shelling out to tools during compile time is IMO utterly insane. I absolutely agree that there are other VCS, git just happens to be the dominant one today, I have no objection to making this more vcs agnostic though; git was just what I needed right now. |
Summary
Adds a new autogenerated module
PackageMeta_<pkgname>that exposes build-environment metadata known at configure time. This complements the existingPackageInfo_<pkgname>(static.cabalmetadata) andPaths_<pkgname>(install paths).Closes #11755.
Related: #392, #826, #1506, #7355, #7488, #11258, #4746.
What
PackageMeta_providesTaxonomy
PackageInfo_.cabalfile editedPackageMeta_(new)Paths_Implementation
Follows the exact pattern established by
PackageInfo_(PR #8534):Distribution.Simple.Build.PackageMetaModule-- generation logicDistribution.Simple.Build.PackageMetaModule.Z-- Zinza-style rendererautogenPackageMetaModuleNameadded toBuildPathsbuiltinAutogenFilesinBuild.hsSrcDist.hsPackageMetaModule/patternNote on git revision:
generatePackageMetaModuleaccepts the git revision and dirty flag as parameters (since computing them requires IO, andbuiltinAutogenFilesis pure). This PR passes empty defaults ("",False). Wiring up the actualgit rev-parse HEADcall 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
PackageMetaModule.hsandZ.hscompilecabal checkwarnings for missingautogen-modules