[Git][ghc/ghc][wip/T22686] gitlab: Collect metadata about binary distributions
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Fri Jan 27 19:12:46 UTC 2023
Ben Gamari pushed to branch wip/T22686 at Glasgow Haskell Compiler / GHC
Commits:
083f9d8e by Ben Gamari at 2023-01-27T14:12:16-05:00
gitlab: Collect metadata about binary distributions
Fixes #22686.
- - - - -
3 changed files:
- + .gitlab/bindist_metadata.py
- .gitlab/ci.sh
- .gitlab/gen_ci.hs
Changes:
=====================================
.gitlab/bindist_metadata.py
=====================================
@@ -0,0 +1,141 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import shutil
+import re
+import ast
+from pathlib import Path
+import subprocess
+import json
+from typing import Dict, List, Set
+
+def run(args: List[str]) -> str:
+ return subprocess.check_output(args, encoding='UTF-8')
+
+def parse_hadrian_cfg(cfg: str) -> Dict[str,str]:
+ res = {}
+ for l in cfg.split('\n'):
+ if l.startswith('#'):
+ continue
+ elif '=' in l:
+ i = l.find('=')
+ k = l[:i].strip()
+ v = l[i+1:].strip()
+ res[k] = v
+
+ return res
+
+def get_ghc_info(ghc: Path) -> Dict[str,str]:
+ import ast
+ out = run([ghc, '--info'])
+ pairs = ast.literal_eval(out.strip())
+ res = {}
+ for k,v in pairs:
+ if v == 'YES':
+ v = True
+ elif v == 'NO':
+ v = False
+ res[k] = v
+
+ return res
+
+def get_configure_cmdline() -> str:
+ r = Path('config.log').read_text()
+ m = re.search(r' $ .+', r)
+ return m
+
+def get_dpkg_packages() -> Dict[str, str]:
+ pkgs = {}
+ for l in run(['dpkg-query', '--show']).split('\n'):
+ parts = l.split()
+ if len(parts) == 2:
+ k = parts[0].strip()
+ v = parts[1].strip()
+ pkgs[k] = v
+
+ return pkgs
+
+def get_rpm_packages() -> Dict[str, str]:
+ pkgs = {}
+ for l in run(['rpm', '-qa', '--queryformat=%{NAME} %{VERSION}\n']).split('\n'):
+ parts = l.split()
+ if len(parts) == 2:
+ k = parts[0].strip()
+ v = parts[1].strip()
+ pkgs[k] = v
+
+ return pkgs
+
+def main() -> None:
+ ghc = Path('_build/stage1/bin/ghc')
+ ghc_pkg = Path('_build/stage1/bin/ghc-pkg')
+
+ metadata = {}
+
+ system_config = Path('.') / 'hadrian' / 'cfg' / 'system.config'
+ cfg = parse_hadrian_cfg(system_config.read_text())
+
+ ######
+ # GHC build configuration
+ ######
+ metadata['ghc_version'] = cfg['project-version']
+ metadata['git_commit_id'] = cfg['project-git-commit-id']
+ metadata['tables_next_to_code'] = cfg['tables-next-to-code']
+ metadata['unregisterised'] = cfg['ghc-unregisterised']
+ metadata['build_triple'] = cfg['build-platform']
+ metadata['host_triple'] = cfg['host-platform']
+ metadata['target_triple'] = cfg['target-platform']
+ metadata['build_flavour'] = os.environ.get('BUILD_FLAVOUR')
+ metadata['configure_cmdline'] = get_configure_cmdline()
+
+ ######
+ # Information about the bootstrapping environment
+ ######
+ try:
+ lsb_release = run(['lsb_release'])
+ except:
+ lsb_release = 'unknown'
+
+ metadata['bootstrap_environment'] = {
+ 'ghc': run([cfg['system-ghc'], '--version']).split('\n')[0],
+ 'cc': run([cfg['system-cc'], '--version']).split('\n')[0],
+ 'lsb_release': lsb_release,
+ }
+
+ ######
+ # Information about the bootstrapping environment's packages
+ ######
+ if shutil.which('dpkg'):
+ metadata['bootstrap_environment']['package_system'] = 'dpkg'
+ metadata['bootstrap_environment']['installed_packages'] = get_dpkg_packages()
+ elif shutil.which('rpm'):
+ metadata['bootstrap_environment']['package_system'] = 'rpm'
+ metadata['bootstrap_environment']['installed_packages'] = get_rpm_packages()
+ else:
+ metadata['bootstrap_environment']['package_system'] = 'unknown'
+ metadata['bootstrap_environment']['installed_packages'] = None
+
+ ######
+ # The contents of the compiler's global package database
+ ######
+ def call_ghc_pkg(args: List[str]) -> str:
+ return run([ghc_pkg, '--simple-output'] + args).strip()
+
+ metadata['global_packages'] = {
+ pkg: {
+ 'version': call_ghc_pkg(['field', pkg, 'version']),
+ 'extra-libraries': call_ghc_pkg(['field', pkg, 'extra-libraries']).split(),
+ }
+ for pkg in call_ghc_pkg(['list', '--names-only']).split()
+ }
+
+ ######
+ # Information about the resulting compiler
+ ######
+ metadata['inplace_ghc_info'] = get_ghc_info(ghc)
+
+ json.dump(metadata, sys.stdout, indent=2)
+
+if __name__ == '__main__':
+ main()
=====================================
.gitlab/ci.sh
=====================================
@@ -580,6 +580,7 @@ function install_bindist() {
function test_hadrian() {
check_msys2_deps _build/stage1/bin/ghc --version
check_release_build
+ $TOP/.gitlab/bindist_metadata.py > metadata.json
# Ensure that statically-linked builds are actually static
if [[ "${BUILD_FLAVOUR}" = *static* ]]; then
=====================================
.gitlab/gen_ci.hs
=====================================
@@ -681,6 +681,7 @@ job arch opsys buildConfig = NamedJob { name = jobName, jobInfo = Job {..} }
{ junitReport = "junit.xml"
, expireIn = "2 weeks"
, artifactPaths = [binDistName arch opsys buildConfig ++ ".tar.xz"
+ ,"metadata.json"
,"junit.xml"]
, artifactsWhen = ArtifactsAlways
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/083f9d8ea62aac03879d96008ff906009c4759a7
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/083f9d8ea62aac03879d96008ff906009c4759a7
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230127/2343b23b/attachment-0001.html>
More information about the ghc-commits
mailing list