@@ -9,6 +9,87 @@ load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
99load ("//antlir/bzl:internal_external.bzl" , "internal_external" )
1010load ("//antlir/bzl:target_helpers.bzl" , "normalize_target" )
1111
12+ def _release_file_dynamic_impl (
13+ actions : AnalysisActions ,
14+ rev_time : ArtifactValue ,
15+ contents_out : OutputArtifact ,
16+ os_name : str ,
17+ os_id : str ,
18+ os_version : str ,
19+ os_version_id : str ,
20+ variant : str ,
21+ ansi_color : str ,
22+ api_versions : dict ,
23+ layer_raw_target : str ,
24+ vcs_rev : str | None ,
25+ package_name : str ,
26+ package_version : str ):
27+ """
28+ Dynamic action implementation that reads the rev_time and generates
29+ the os-release file.
30+ """
31+ date , time = rev_time .read_string ().strip ().split (" " )
32+ rev_time_formatted = "{}T{}" .format (date , time )
33+
34+ api_vers = [
35+ "API_VER_{key}=\" {val}\" " .format (key = key , val = val )
36+ for key , val in api_versions .items ()
37+ ]
38+
39+ contents = """
40+ NAME="{os_name}"
41+ ID="{os_id}"
42+ VERSION="{os_version}"
43+ VERSION_ID="{os_version_id}"
44+ PRETTY_NAME="{os_name} {os_version} {variant} ({rev})"
45+ IMAGE_ID="{image_id}"
46+ IMAGE_LAYER="{target}"
47+ IMAGE_VCS_REV="{rev}"
48+ IMAGE_VCS_REV_TIME="{rev_time}"
49+ {IMAGE_PACKAGE_KEY}="{image_package}"
50+ VARIANT="{variant}"
51+ VARIANT_ID="{lower_variant}"
52+ ANSI_COLOR="{ansi_color}"
53+ {api_vers}
54+ """ .format (
55+ os_name = os_name ,
56+ os_id = os_id ,
57+ os_version = os_version ,
58+ os_version_id = os_version_id ,
59+ variant = variant ,
60+ lower_variant = variant .lower (),
61+ ansi_color = ansi_color ,
62+ image_id = native .read_config ("build_info" , "target_path" , "local" ),
63+ target = layer_raw_target ,
64+ rev = vcs_rev or "local" ,
65+ rev_time = rev_time_formatted ,
66+ api_vers = "\n " .join (api_vers ),
67+ IMAGE_PACKAGE_KEY = internal_external (fb = "IMAGE_FBPKG" , oss = "IMAGE_PACKAGE" ),
68+ image_package = package_name + ":" + package_version ,
69+ ).strip () + "\n "
70+
71+ actions .write (contents_out , contents )
72+ return []
73+
74+ _release_file_dynamic = dynamic_actions (
75+ impl = _release_file_dynamic_impl ,
76+ attrs = {
77+ "ansi_color" : dynattrs .value (str ),
78+ "api_versions" : dynattrs .value (dict ),
79+ "contents_out" : dynattrs .output (),
80+ "layer_raw_target" : dynattrs .value (str ),
81+ "os_id" : dynattrs .value (str ),
82+ "os_name" : dynattrs .value (str ),
83+ "os_version" : dynattrs .value (str ),
84+ "os_version_id" : dynattrs .value (str ),
85+ "package_name" : dynattrs .value (str ),
86+ "package_version" : dynattrs .value (str ),
87+ "rev_time" : dynattrs .artifact_value (),
88+ "variant" : dynattrs .value (str ),
89+ "vcs_rev" : dynattrs .value (str | None ),
90+ },
91+ )
92+
1293def _release_file_impl (ctx : AnalysisContext ) -> list [Provider ]:
1394 for key in ctx .attrs .api_versions .keys ():
1495 if not key .isupper ():
@@ -38,54 +119,22 @@ def _release_file_impl(ctx: AnalysisContext) -> list[Provider]:
38119
39120 contents_out = ctx .actions .declare_output ("os-release" )
40121
41- def _dyn (ctx , artifacts , outputs , rev_time = rev_time , contents_out = contents_out ):
42- date , time = artifacts [rev_time ].read_string ().strip ().split (" " )
43- rev_time = "{}T{}" .format (date , time )
44-
45- api_vers = [
46- "API_VER_{key}=\" {val}\" " .format (key = key , val = val )
47- for key , val in ctx .attrs .api_versions .items ()
48- ]
49-
50- contents = """
51- NAME="{os_name}"
52- ID="{os_id}"
53- VERSION="{os_version}"
54- VERSION_ID="{os_version_id}"
55- PRETTY_NAME="{os_name} {os_version} {variant} ({rev})"
56- IMAGE_ID="{image_id}"
57- IMAGE_LAYER="{target}"
58- IMAGE_VCS_REV="{rev}"
59- IMAGE_VCS_REV_TIME="{rev_time}"
60- {IMAGE_PACKAGE_KEY}="{image_package}"
61- VARIANT="{variant}"
62- VARIANT_ID="{lower_variant}"
63- ANSI_COLOR="{ansi_color}"
64- {api_vers}
65- """ .format (
122+ ctx .actions .dynamic_output_new (
123+ _release_file_dynamic (
124+ rev_time = rev_time ,
125+ contents_out = contents_out .as_output (),
66126 os_name = ctx .attrs .os_name ,
67127 os_id = ctx .attrs .os_id ,
68128 os_version = ctx .attrs .os_version ,
69129 os_version_id = ctx .attrs .os_version_id ,
70130 variant = ctx .attrs .variant ,
71- lower_variant = ctx .attrs .variant .lower (),
72131 ansi_color = ctx .attrs .ansi_color ,
73- image_id = native .read_config ("build_info" , "target_path" , "local" ),
74- target = ctx .attrs .layer .raw_target (),
75- rev = ctx .attrs .vcs_rev or "local" ,
76- rev_time = rev_time ,
77- api_vers = "\n " .join (api_vers ),
78- IMAGE_PACKAGE_KEY = internal_external (fb = "IMAGE_FBPKG" , oss = "IMAGE_PACKAGE" ),
79- image_package = ctx .attrs .package_name + ":" + ctx .attrs .package_version ,
80- ).strip () + "\n "
81-
82- ctx .actions .write (outputs [contents_out ], contents )
83-
84- ctx .actions .dynamic_output (
85- dynamic = [rev_time ],
86- inputs = [],
87- outputs = [contents_out .as_output ()],
88- f = _dyn ,
132+ api_versions = ctx .attrs .api_versions ,
133+ layer_raw_target = str (ctx .attrs .layer .raw_target ()),
134+ vcs_rev = ctx .attrs .vcs_rev ,
135+ package_name = ctx .attrs .package_name ,
136+ package_version = ctx .attrs .package_version ,
137+ ),
89138 )
90139
91140 return [
0 commit comments