Skip to content

Commit 2cb7c36

Browse files
c-ryan747facebook-github-bot
authored andcommitted
Add build mode to test action keys
Reviewed By: krallin Differential Revision: D48970919 fbshipit-source-id: 6f3ce14507c300d77f1db70f13a08744ab1b57be
1 parent 6655abc commit 2cb7c36

File tree

11 files changed

+50
-26
lines changed

11 files changed

+50
-26
lines changed

prelude/build_mode.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under both the MIT license found in the
4+
# LICENSE-MIT file in the root directory of this source tree and the Apache
5+
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
6+
# of this source tree.
7+
8+
BuildModeInfo = provider(
9+
fields = ["cell", "mode"],
10+
)

prelude/cxx/cxx.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def cxx_test_impl(ctx: AnalysisContext) -> list[Provider]:
620620
command = [cmd_args(output.binary).hidden(output.runtime_files)] + ctx.attrs.args
621621

622622
# Setup a RE executor based on the `remote_execution` param.
623-
re_executor = get_re_executor_from_props(ctx.attrs.remote_execution)
623+
re_executor = get_re_executor_from_props(ctx)
624624

625625
return inject_test_run_info(
626626
ctx,

prelude/decls/common.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# the generated docs, and so those should be verified to be accurate and
1313
# well-formatted (and then delete this TODO)
1414

15+
load("@prelude//:build_mode.bzl", "BuildModeInfo")
16+
1517
def validate_uri(_s):
1618
return True
1719

@@ -234,6 +236,15 @@ def _re_opts_for_tests_arg() -> "attribute":
234236
default = None,
235237
)
236238

239+
def _re_action_key_provider_arg() -> "attribute":
240+
return attrs.dep(providers = [BuildModeInfo], default = "fbcode//buck2/platform/build_mode:build_mode")
241+
242+
def _re_test_args() -> dict[str, "attribute"]:
243+
return {
244+
"remote_execution": _re_opts_for_tests_arg(),
245+
"remote_execution_action_key_providers": _re_action_key_provider_arg(),
246+
}
247+
237248
def _allow_cache_upload_arg():
238249
return {
239250
"allow_cache_upload": attrs.bool(
@@ -261,7 +272,7 @@ buck = struct(
261272
run_test_separately_arg = _run_test_separately_arg,
262273
fork_mode = _fork_mode,
263274
test_rule_timeout_ms = _test_rule_timeout_ms,
264-
re_opts_for_tests_arg = _re_opts_for_tests_arg,
275+
re_test_args = _re_test_args,
265276
target_os_type_arg = _target_os_type_arg,
266277
allow_cache_upload_arg = _allow_cache_upload_arg,
267278
)

prelude/decls/rust_rules.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ rust_test = prelude_rule(
326326
_RUST_EXECUTABLE_ATTRIBUTES |
327327
{
328328
"framework": attrs.bool(default = True),
329-
"remote_execution": buck.re_opts_for_tests_arg(),
330329
} |
330+
buck.re_test_args() |
331331
rust_common.toolchains_args() |
332332
rust_common.workspaces_arg()
333333
),

prelude/decls/shell_rules.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,12 @@ sh_test = prelude_rule(
181181
"licenses": attrs.list(attrs.source(), default = []),
182182
"list_args": attrs.option(attrs.list(attrs.string()), default = None),
183183
"list_env": attrs.option(attrs.dict(key = attrs.string(), value = attrs.string(), sorted = False), default = None),
184-
"remote_execution": buck.re_opts_for_tests_arg(),
185184
"resources": attrs.list(attrs.source(), default = []),
186185
"run_args": attrs.list(attrs.string(), default = []),
187186
"run_env": attrs.dict(key = attrs.string(), value = attrs.string(), sorted = False, default = {}),
188187
"run_test_separately": attrs.bool(default = False),
189188
"test_rule_timeout_ms": attrs.option(attrs.int(), default = None),
190-
}
189+
} | buck.re_test_args()
191190
),
192191
)
193192

prelude/python/python_needed_coverage_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def python_needed_coverage_test_impl(ctx: AnalysisContext) -> list[Provider]:
4343
test_env["TEST_PILOT"] = "1"
4444

4545
# Setup a RE executor based on the `remote_execution` param.
46-
re_executor = get_re_executor_from_props(ctx.attrs.remote_execution)
46+
re_executor = get_re_executor_from_props(ctx)
4747

4848
return inject_test_run_info(
4949
ctx,

prelude/python/python_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def python_test_impl(ctx: AnalysisContext) -> list[Provider]:
6262
test_cmd = pex.run_cmd
6363

6464
# Setup a RE executor based on the `remote_execution` param.
65-
re_executor = get_re_executor_from_props(ctx.attrs.remote_execution)
65+
re_executor = get_re_executor_from_props(ctx)
6666

6767
return inject_test_run_info(
6868
ctx,

prelude/rules_impl.bzl

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,8 @@ def _python_executable_attrs():
348348

349349
def _python_test_attrs():
350350
test_attrs = _python_executable_attrs()
351-
test_attrs.update({
352-
"remote_execution": buck.re_opts_for_tests_arg(),
353-
"_test_main": attrs.source(default = "prelude//python/tools:__test_main__.py"),
354-
})
351+
test_attrs["_test_main"] = attrs.source(default = "prelude//python/tools:__test_main__.py")
352+
test_attrs.update(buck.re_test_args())
355353
return test_attrs
356354

357355
def _cxx_binary_and_test_attrs():
@@ -435,10 +433,7 @@ inlined_extra_attributes = {
435433
"_omnibus_environment": omnibus_environment_attr(),
436434
},
437435
"cxx_python_extension": _cxx_python_extension_attrs(),
438-
"cxx_test": dict(
439-
remote_execution = buck.re_opts_for_tests_arg(),
440-
**_cxx_binary_and_test_attrs()
441-
),
436+
"cxx_test": buck.re_test_args() | _cxx_binary_and_test_attrs(),
442437
"cxx_toolchain": cxx_toolchain_extra_attributes(is_toolchain_rule = False),
443438

444439
# Generic rule to build from a command
@@ -550,14 +545,14 @@ inlined_extra_attributes = {
550545
"_cxx_toolchain": toolchains_common.cxx(),
551546
"_python_toolchain": toolchains_common.python(),
552547
},
553-
"python_needed_coverage_test": {
554-
"contacts": attrs.list(attrs.string(), default = []),
555-
"env": attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}),
556-
"labels": attrs.list(attrs.string(), default = []),
557-
"needed_coverage": attrs.list(attrs.tuple(attrs.int(), attrs.dep(), attrs.option(attrs.string())), default = []),
558-
"remote_execution": buck.re_opts_for_tests_arg(),
559-
"test": attrs.dep(providers = [ExternalRunnerTestInfo]),
560-
},
548+
"python_needed_coverage_test": dict(
549+
contacts = attrs.list(attrs.string(), default = []),
550+
env = attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}),
551+
labels = attrs.list(attrs.string(), default = []),
552+
needed_coverage = attrs.list(attrs.tuple(attrs.int(), attrs.dep(), attrs.option(attrs.string())), default = []),
553+
test = attrs.dep(providers = [ExternalRunnerTestInfo]),
554+
**buck.re_test_args()
555+
),
561556
"python_test": _python_test_attrs(),
562557
"remote_file": {
563558
"sha1": attrs.option(attrs.string(), default = None),

prelude/rust/rust_binary.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def rust_test_impl(ctx: AnalysisContext) -> list[[DefaultInfo.type, RunInfo.type
359359
)
360360

361361
# Setup a RE executor based on the `remote_execution` param.
362-
re_executor = get_re_executor_from_props(ctx.attrs.remote_execution)
362+
re_executor = get_re_executor_from_props(ctx)
363363

364364
return inject_test_run_info(
365365
ctx,

prelude/sh_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def sh_test_impl(ctx: AnalysisContext) -> list[Provider]:
4242
command = [args] + ctx.attrs.args
4343

4444
# Setup a RE executor based on the `remote_execution` param.
45-
re_executor = get_re_executor_from_props(ctx.attrs.remote_execution)
45+
re_executor = get_re_executor_from_props(ctx)
4646

4747
# We implicitly make the target run from the project root if remote
4848
# excution options were specified

0 commit comments

Comments
 (0)