[Git][ghc/ghc][master] rel-eng: ghcup metadata generation: generated yaml anchors with meaningful names

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sun Oct 20 01:57:54 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
280b6278 by Zubin Duggal at 2024-10-19T21:56:31-04:00
rel-eng: ghcup metadata generation: generated yaml anchors with meaningful names

(cherry picked from commit d83f5bd730a8aef37d8a38b3560590d9798f8e45)

- - - - -


1 changed file:

- .gitlab/rel_eng/mk-ghcup-metadata/mk_ghcup_metadata.py


Changes:

=====================================
.gitlab/rel_eng/mk-ghcup-metadata/mk_ghcup_metadata.py
=====================================
@@ -67,6 +67,7 @@ class Artifact(NamedTuple):
     download_name: str
     output_name: str
     subdir: str
+    anchor_name: str
 
 # Platform spec provides a specification which is agnostic to Job
 # PlatformSpecs are converted into Artifacts by looking in the jobs-metadata.json file.
@@ -77,11 +78,13 @@ class PlatformSpec(NamedTuple):
 source_artifact = Artifact('source-tarball'
                           , 'ghc-{version}-src.tar.xz'
                           , 'ghc-{version}-src.tar.xz'
-                          , 'ghc-{version}' )
+                          , 'ghc-{version}'
+                          , 'ghc{version}-src')
 test_artifact = Artifact('source-tarball'
                         , 'ghc-{version}-testsuite.tar.xz'
                         , 'ghc-{version}-testsuite.tar.xz'
-                        , 'ghc-{version}/testsuite' )
+                        , 'ghc-{version}/testsuite'
+                        , 'ghc{version}-testsuite')
 
 def debian(n, arch='x86_64'):
     return linux_platform(arch, "{arch}-linux-deb{n}".format(arch=arch, n=n))
@@ -132,6 +135,8 @@ def download_and_hash(url):
     hash_cache[url] = digest
     return digest
 
+uri_to_anchor_cache=dict()
+
 # Make the metadata for one platform.
 def mk_one_metadata(release_mode, version, job_map, artifact):
     job_id = job_map[artifact.job_name].id
@@ -169,6 +174,9 @@ def mk_one_metadata(release_mode, version, job_map, artifact):
         res["dlOutput"] = output
 
     eprint(res)
+
+    # add the uri to the anchor name cache so we can lookup an anchor for this uri
+    uri_to_anchor_cache[final_url] = artifact.anchor_name
     return res
 
 # Turns a platform into an Artifact respecting pipeline_type
@@ -179,7 +187,8 @@ def mk_from_platform(pipeline_type, platform):
     return Artifact(info['name']
                    , f"{info['jobInfo']['bindistName']}.tar.xz"
                    , "ghc-{version}-{pn}.tar.xz".format(version="{version}", pn=platform.name)
-                   , platform.subdir)
+                   , platform.subdir
+                   , f"ghc{{version}}-{platform.name}")
 
 
 # Generate the new metadata for a specific GHC mode etc
@@ -297,6 +306,19 @@ def setNightlyTags(ghcup_metadata):
             ghcup_metadata['ghcupDownloads']['GHC'][version]["viTags"].append("Nightly")
 
 
+def mk_dumper(version):
+  class CustomAliasDumper(yaml.Dumper):
+      def __init__(self, *args, **kwargs):
+          super().__init__(*args, **kwargs)
+
+      def generate_anchor(self, node):
+          if isinstance(node, yaml.MappingNode):
+            node_dict = { k.value : v.value for (k,v) in node.value }
+            if 'dlUri' in node_dict:
+              return uri_to_anchor_cache[node_dict['dlUri']].format(version=version.replace('.',''))
+          return super().generate_anchor(node)
+
+  return CustomAliasDumper
 
 
 def main() -> None:
@@ -332,7 +354,7 @@ def main() -> None:
 
     new_yaml = mk_new_yaml(args.release_mode, args.version, args.date, pipeline_type, job_map)
     if args.fragment:
-        print(yaml.dump({ args.version : new_yaml }))
+        print(yaml.dump({ args.version : new_yaml }, Dumper=mk_dumper(args.version)))
 
     else:
         with open(args.metadata, 'r') as file:



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/280b627869da55a22b4b9a3458e6115b06b5fff4

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/280b627869da55a22b4b9a3458e6115b06b5fff4
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/20241019/8d9dc457/attachment-0001.html>


More information about the ghc-commits mailing list