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

Zubin (@wz1000) gitlab at gitlab.haskell.org
Thu Oct 17 14:02:22 UTC 2024



Zubin pushed to branch wip/generate-ghcup-anchors at Glasgow Haskell Compiler / GHC


Commits:
9084fc88 by Zubin Duggal at 2024-10-17T19:32:10+05:30
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/9084fc8824b6ec53c3fabf82b22f2c93933d01ff

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9084fc8824b6ec53c3fabf82b22f2c93933d01ff
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/20241017/f7d6d56c/attachment-0001.html>


More information about the ghc-commits mailing list