Skip to content

Commit 48e09f3

Browse files
vmagrometa-codesync[bot]
authored andcommitted
[antlir2][buck] create a wrapper for feature rules
Summary: All feature rules must share certain attrs. Until this diff stack, that was only the `plugin`, but now I want to add `location`, so I'm defining a macro and converting all features to use it so that the rest of this stack is a bit simpler. Test Plan: waitforsandcastle Reviewed By: naveedgol Differential Revision: D87938675 fbshipit-source-id: b93a81f13276907a07923082c5a26146fd0f45fa
1 parent 311ca84 commit 48e09f3

File tree

13 files changed

+46
-33
lines changed

13 files changed

+46
-33
lines changed

antlir/antlir2/features/clone/clone.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load("//antlir/antlir2/bzl:types.bzl", "LayerInfo")
77
load("//antlir/antlir2/features:dependency_layer_info.bzl", "layer_dep", "layer_dep_analyze")
8-
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature")
8+
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature", "new_feature_rule")
99

1010
def clone(
1111
*,
@@ -151,13 +151,12 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
151151
),
152152
]
153153

154-
clone_rule = rule(
154+
clone_rule = new_feature_rule(
155155
impl = _impl,
156156
attrs = {
157157
"dst_path": attrs.option(attrs.string(), default = None),
158158
"group": attrs.option(attrs.string(), default = None),
159159
"path": attrs.option(attrs.string(), default = None),
160-
"plugin": attrs.label(),
161160
"src_layer": attrs.dep(providers = [LayerInfo]),
162161
"src_path": attrs.option(attrs.string(), default = None),
163162
"user": attrs.option(attrs.string(), default = None),

antlir/antlir2/features/dot_meta/dot_meta.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55

66
load("//antlir/antlir2/bzl:build_phase.bzl", "BuildPhase")
7-
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature")
7+
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature", "new_feature_rule")
88

99
def dot_meta(
1010
*,
@@ -58,10 +58,9 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
5858
),
5959
]
6060

61-
dot_meta_rule = rule(
61+
dot_meta_rule = new_feature_rule(
6262
impl = _impl,
6363
attrs = {
6464
"build_info": attrs.dict(attrs.string(), attrs.option(attrs.string())),
65-
"plugin": attrs.label(),
6665
},
6766
)

antlir/antlir2/features/ensure_dir_exists/ensure_dir_exists.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ load(
1010
"FeatureAnalysis",
1111
"MultiFeatureAnalysis",
1212
"ParseTimeFeature",
13+
"new_feature_rule",
1314
)
1415
load("//antlir/bzl:stat.bzl", "stat")
1516

@@ -89,14 +90,13 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
8990
),
9091
]
9192

92-
ensure_dir_exists_rule = rule(
93+
ensure_dir_exists_rule = new_feature_rule(
9394
impl = _impl,
9495
attrs = {
9596
"build_phase": attrs.enum(BuildPhase.values(), default = "compile"),
9697
"group": attrs.string(),
9798
"into_dir": attrs.string(),
9899
"mode": attrs.one_of(attrs.string(), attrs.int()),
99-
"plugin": attrs.label(),
100100
"subdirs_to_create": attrs.string(),
101101
"user": attrs.string(),
102102
},

antlir/antlir2/features/extract/extract.bzl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ load("//antlir/antlir2/bzl:debuginfo.bzl", "split_binary_anon")
2626
load("//antlir/antlir2/bzl:platform.bzl", "arch_select")
2727
load("//antlir/antlir2/bzl:types.bzl", "LayerInfo")
2828
load("//antlir/antlir2/features:dependency_layer_info.bzl", "layer_dep_analyze")
29-
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature")
29+
load(
30+
"//antlir/antlir2/features:feature_info.bzl",
31+
"FeatureAnalysis",
32+
"ParseTimeFeature",
33+
"new_feature_rule",
34+
)
3035
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
3136
load("//antlir/bzl:internal_external.bzl", "internal_external")
3237

@@ -127,12 +132,11 @@ def _extract_from_layer_impl(ctx: AnalysisContext) -> list[Provider]:
127132
),
128133
]
129134

130-
extract_from_layer_rule = rule(
135+
extract_from_layer_rule = new_feature_rule(
131136
impl = _extract_from_layer_impl,
132137
attrs = {
133138
"binaries": attrs.list(attrs.string(), default = []),
134139
"layer": attrs.dep(providers = [LayerInfo]),
135-
"plugin": attrs.label(),
136140
},
137141
)
138142

@@ -182,11 +186,10 @@ def _extract_buck_binary_impl(ctx: AnalysisContext) -> list[Provider]:
182186
),
183187
]
184188

185-
extract_buck_binary_rule = rule(
189+
extract_buck_binary_rule = new_feature_rule(
186190
impl = _extract_buck_binary_impl,
187191
attrs = {
188192
"dst": attrs.option(attrs.string(), default = None),
189-
"plugin": attrs.label(),
190193
"src": attrs.dep(providers = [RunInfo]),
191194
"strip": attrs.bool(default = True),
192195
"target_arch": attrs.string(),

antlir/antlir2/features/feature_info.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ def data_only_feature_rule(
164164
attrs = feature_attrs | {"plugin": attrs.label()},
165165
)
166166

167+
def new_feature_rule(
168+
*,
169+
impl,
170+
attrs: dict[str, Attr]):
171+
return rule(
172+
impl = impl,
173+
attrs = {
174+
"plugin": native.attrs.label(),
175+
} | attrs,
176+
)
177+
167178
def with_phase_override(
168179
feature: FeatureAnalysis,
169180
*,

antlir/antlir2/features/genrule/genrule.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55

66
load("//antlir/antlir2/bzl:build_phase.bzl", "BuildPhase")
7-
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature")
7+
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature", "new_feature_rule")
88

99
def genrule(
1010
*,
@@ -58,14 +58,13 @@ def _genrule_impl(ctx: AnalysisContext) -> list[Provider]:
5858
plugin = ctx.attrs.plugin,
5959
)]
6060

61-
genrule_rule = rule(
61+
genrule_rule = new_feature_rule(
6262
impl = _genrule_impl,
6363
attrs = {
6464
# TODO: just use attrs.arg() by itself
6565
"args": attrs.dict(attrs.string(), attrs.arg()),
6666
"bind_repo_ro": attrs.bool(),
6767
"mount_platform": attrs.bool(),
68-
"plugin": attrs.label(),
6968
"user": attrs.string(),
7069
},
7170
)

antlir/antlir2/features/group/group.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ load(
88
"//antlir/antlir2/features:feature_info.bzl",
99
"FeatureAnalysis",
1010
"ParseTimeFeature",
11+
"new_feature_rule",
1112
)
1213
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
1314

@@ -48,11 +49,10 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
4849
),
4950
]
5051

51-
group_rule = rule(
52+
group_rule = new_feature_rule(
5253
impl = _impl,
5354
attrs = {
5455
"groupname": attrs.string(),
55-
"plugin": attrs.label(),
5656
"uidmap": attrs.dep(),
5757
},
5858
)

antlir/antlir2/features/install/install.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ load(
1717
"FeatureAnalysis",
1818
"MultiFeatureAnalysis",
1919
"ParseTimeFeature",
20+
"new_feature_rule",
2021
)
2122
load("//antlir/antlir2/features/rpm:rpm.bzl", "rpms_rule")
2223
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
@@ -515,7 +516,7 @@ def _impl(ctx: AnalysisContext) -> list[Provider] | Promise:
515516

516517
return anon_rpm_target.promise.map(_map)
517518

518-
install_rule = rule(
519+
install_rule = new_feature_rule(
519520
impl = _impl,
520521
attrs = {
521522
"always_use_gnu_debuglink": attrs.bool(default = True),
@@ -535,7 +536,6 @@ install_rule = rule(
535536
default = False,
536537
doc = "Always install as a regular file, even in @mode/dev",
537538
),
538-
"plugin": attrs.label(),
539539
"setcap": attrs.option(attrs.string(), default = None),
540540
"split_debuginfo": attrs.bool(default = True),
541541
"src": attrs.option(

antlir/antlir2/features/mount/mount.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55

66
load("//antlir/antlir2/bzl:types.bzl", "LayerInfo")
7-
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature")
7+
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature", "new_feature_rule")
88
load("//antlir/bzl:types.bzl", "types")
99

1010
# IMO this is a misfeature, but it is used in many places throughout the legacy
@@ -92,14 +92,13 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
9292
else:
9393
fail("invalid source_kind '{}'".format(ctx.attrs.source_kind))
9494

95-
mount_rule = rule(
95+
mount_rule = new_feature_rule(
9696
impl = _impl,
9797
attrs = {
9898
"host_source": attrs.option(attrs.string()),
9999
"is_directory": attrs.option(attrs.bool()),
100100
"layer": attrs.option(attrs.dep(providers = [LayerInfo]), default = None),
101101
"mountpoint": attrs.option(attrs.string()),
102-
"plugin": attrs.label(),
103102
"source_kind": attrs.enum(["layer", "host"]),
104103
},
105104
)

antlir/antlir2/features/rpm/rpm.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ load(
1515
"ParseTimeFeature",
1616
"Planner",
1717
"feature_record",
18+
"new_feature_rule",
1819
)
1920
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
2021
load("//antlir/bzl:structs.bzl", "structs")
@@ -288,7 +289,7 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
288289
),
289290
]
290291

291-
rpms_rule = rule(
292+
rpms_rule = new_feature_rule(
292293
impl = _impl,
293294
attrs = {
294295
"action": attrs.enum(["install", "remove", "remove_if_exists", "upgrade", "module_enable"]),
@@ -300,7 +301,6 @@ rpms_rule = rule(
300301
# support
301302
"driver": attrs.dep(providers = [RunInfo]),
302303
"plan": attrs.exec_dep(providers = [RunInfo]),
303-
"plugin": attrs.label(),
304304
"resolve": attrs.dep(providers = [RunInfo]),
305305
"subjects": attrs.list(attrs.string()),
306306
"subjects_src": attrs.option(attrs.source(), default = None),

0 commit comments

Comments
 (0)