Skip to content

Commit

Permalink
Add remote execution config to executor override
Browse files Browse the repository at this point in the history
Summary: Read RE config from attributes and pass down to executor override

Reviewed By: danalex97

Differential Revision: D60452901

fbshipit-source-id: 5c00843d9ae36fd4fb32cee88254967d3169f3e0
  • Loading branch information
Ahmed Morsy authored and facebook-github-bot committed Aug 8, 2024
1 parent 636d947 commit f268f98
Showing 1 changed file with 50 additions and 36 deletions.
86 changes: 50 additions & 36 deletions android/android_instrumentation_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ def android_instrumentation_test_impl(ctx: AnalysisContext):
],
)

remote_execution_properties = {
"platform": _compute_emulator_platform(ctx.attrs.labels or []),
"subplatform": _compute_emulator_subplatform(ctx.attrs.labels or []),
}
re_emulator_abi = _compute_emulator_abi(ctx.attrs.labels or [])
if re_emulator_abi != None:
remote_execution_properties["abi"] = re_emulator_abi

test_info = ExternalRunnerTestInfo(
type = "android_instrumentation",
command = cmd,
Expand All @@ -144,34 +136,7 @@ def android_instrumentation_test_impl(ctx: AnalysisContext):
contacts = ctx.attrs.contacts,
run_from_project_root = True,
use_project_relative_paths = True,
executor_overrides = {
"android-emulator": CommandExecutorConfig(
local_enabled = android_toolchain.instrumentation_test_can_run_locally,
remote_enabled = True,
remote_execution_properties = remote_execution_properties,
remote_execution_use_case = _compute_re_use_case(ctx.attrs.labels or []),
),
"dynamic-listing": CommandExecutorConfig(
local_enabled = android_toolchain.instrumentation_test_can_run_locally,
remote_enabled = True,
remote_execution_properties = remote_execution_properties,
remote_execution_use_case = _compute_re_use_case(ctx.attrs.labels or []),
),
"static-listing": CommandExecutorConfig(
local_enabled = True,
remote_enabled = True,
remote_execution_properties = {
"platform": "linux-remote-execution",
},
remote_execution_use_case = "buck2-default",
),
"test-execution": CommandExecutorConfig(
local_enabled = android_toolchain.instrumentation_test_can_run_locally,
remote_enabled = True,
remote_execution_properties = remote_execution_properties,
remote_execution_use_case = _compute_re_use_case(ctx.attrs.labels or []),
),
},
executor_overrides = _compute_executor_overrides(ctx, android_toolchain.instrumentation_test_can_run_locally),
local_resources = {
"android_emulator": None,
},
Expand All @@ -189,6 +154,55 @@ def android_instrumentation_test_impl(ctx: AnalysisContext):
DefaultInfo(),
] + classmap_source_info

def _compute_executor_overrides(ctx: AnalysisContext, instrumentation_test_can_run_locally: bool) -> dict[str, CommandExecutorConfig]:
remote_execution_properties = {
"platform": _compute_emulator_platform(ctx.attrs.labels or []),
"subplatform": _compute_emulator_subplatform(ctx.attrs.labels or []),
}

re_emulator_abi = _compute_emulator_abi(ctx.attrs.labels or [])
if re_emulator_abi != None:
remote_execution_properties["abi"] = re_emulator_abi

default_executor_override = CommandExecutorConfig(
local_enabled = instrumentation_test_can_run_locally,
remote_enabled = True,
remote_execution_properties = remote_execution_properties,
remote_execution_use_case = _compute_re_use_case(ctx.attrs.labels or []),
)
dynamic_listing_executor_override = default_executor_override
test_execution_executor_override = default_executor_override

if ctx.attrs.re_caps and ctx.attrs.re_use_case:
if "dynamic-listing" in ctx.attrs.re_caps and "dynamic-listing" in ctx.attrs.re_use_case:
dynamic_listing_executor_override = CommandExecutorConfig(
local_enabled = instrumentation_test_can_run_locally,
remote_enabled = True,
remote_execution_properties = ctx.attrs.re_caps["dynamic-listing"],
remote_execution_use_case = ctx.attrs.re_use_case["dynamic-listing"],
)
if "test-execution" in ctx.attrs.re_caps and "test-execution" in ctx.attrs.re_use_case:
test_execution_executor_override = CommandExecutorConfig(
local_enabled = instrumentation_test_can_run_locally,
remote_enabled = True,
remote_execution_properties = ctx.attrs.re_caps["test-execution"],
remote_execution_use_case = ctx.attrs.re_use_case["test-execution"],
)

return {
"android-emulator": default_executor_override,
"dynamic-listing": dynamic_listing_executor_override,
"static-listing": CommandExecutorConfig(
local_enabled = True,
remote_enabled = True,
remote_execution_properties = {
"platform": "linux-remote-execution",
},
remote_execution_use_case = "buck2-default",
),
"test-execution": test_execution_executor_override,
}

def _compute_emulator_abi(labels: list[str]):
emulator_abi_labels = [label for label in labels if label.startswith(ANDROID_EMULATOR_ABI_LABEL_PREFIX)]
expect(len(emulator_abi_labels) <= 1, "multiple '{}' labels were found:[{}], there must be only one!".format(ANDROID_EMULATOR_ABI_LABEL_PREFIX, ", ".join(emulator_abi_labels)))
Expand Down

0 comments on commit f268f98

Please sign in to comment.