[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 13:41:03 UTC 2024



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


Commits:
759d5b2f by Zubin Duggal at 2024-10-17T19:10:56+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,26 @@ def setNightlyTags(ghcup_metadata):
             ghcup_metadata['ghcupDownloads']['GHC'][version]["viTags"].append("Nightly")
 
 
+def mk_dumper(release_mode, version, date):
+  class CustomAliasDumper(yaml.Dumper):
+      def __init__(self, *args, **kwargs):
+          super().__init__(*args, **kwargs)
+          self.anchors_mapping = {}
+
+      def generate_anchor(self, node):
+          if isinstance(node, yaml.MappingNode):
+            node_dict = { k.value : v.value for (k,v) in node.value }
+            return uri_to_anchor_cache[node_dict['dlUri']].format(version=version.replace('.',''))
+          else:
+            return super().generate_anchor(node)
+
+      def represent(self, data):
+          if isinstance(data, (list, dict)) and id(data) in self.anchors:
+              if self.anchors_mapping.get(id(data)) is None:
+                  self.anchors_mapping[id(data)] = self.generate_anchor(data)
+              self.anchors[data] = self.anchors_mapping[id(data)]
+          return super().represent(data)
+  return CustomAliasDumper
 
 
 def main() -> None:
@@ -332,7 +361,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.release_mode, args.version, args.date)))
 
     else:
         with open(args.metadata, 'r') as file:



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/759d5b2f3b7171fa42b9f4400c98b8ab81ed37d1

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/759d5b2f3b7171fa42b9f4400c98b8ab81ed37d1
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/b781e5a3/attachment-0001.html>


More information about the ghc-commits mailing list