summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/bazel.go18
-rw-r--r--bp2build/cc_test_conversion_test.go19
-rw-r--r--cc/test.go10
3 files changed, 47 insertions, 0 deletions
diff --git a/android/bazel.go b/android/bazel.go
index e4fada0fe..94b36e3ff 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -689,3 +689,21 @@ func AttachValidationActions(ctx ModuleContext, outputFilePath Path, validations
})
return validatedOutputFilePath
}
+
+func RunsOn(hostSupported bool, deviceSupported bool, unitTest bool) []string {
+ var runsOn []string
+
+ if hostSupported && deviceSupported {
+ runsOn = []string{"host_without_device", "device"}
+ } else if hostSupported {
+ if unitTest {
+ runsOn = []string{"host_without_device"}
+ } else {
+ runsOn = []string{"host_with_device"}
+ }
+ } else if deviceSupported {
+ runsOn = []string{"device"}
+ }
+
+ return runsOn
+}
diff --git a/bp2build/cc_test_conversion_test.go b/bp2build/cc_test_conversion_test.go
index 3c037b494..abceac844 100644
--- a/bp2build/cc_test_conversion_test.go
+++ b/bp2build/cc_test_conversion_test.go
@@ -135,6 +135,10 @@ cc_test_library {
"//build/bazel/platforms/os:linux_musl": ["linux.cpp"],
"//conditions:default": [],
})`,
+ "runs_on": `[
+ "host_without_device",
+ "device",
+ ]`,
},
},
},
@@ -158,6 +162,10 @@ cc_test {
"gtest": "False",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
+ "runs_on": `[
+ "host_without_device",
+ "device",
+ ]`,
},
},
},
@@ -185,6 +193,10 @@ cc_test {
":libgtest_main",
":libgtest",
]`,
+ "runs_on": `[
+ "host_without_device",
+ "device",
+ ]`,
},
},
},
@@ -215,6 +227,7 @@ cc_test {
":libgtest_main",
":libgtest",
]`,
+ "runs_on": `["device"]`,
},
},
},
@@ -244,6 +257,7 @@ cc_test {
":libgtest_main",
":libgtest",
]`,
+ "runs_on": `["device"]`,
},
},
},
@@ -280,6 +294,7 @@ cc_test {
"template_test_config": `"test_config_template.xml"`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
+ "runs_on": `["device"]`,
},
},
},
@@ -306,6 +321,7 @@ cc_test {
":libgtest",
":libgtest_main",
]`,
+ "runs_on": `["device"]`,
},
},
},
@@ -331,6 +347,7 @@ cc_test {
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
+ "runs_on": `["device"]`,
},
},
},
@@ -361,12 +378,14 @@ cc_test {
]`,
"gtest": "True",
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
+ "runs_on": `["device"]`,
},
},
{"cc_test", "mytest_with_no_gtest", AttrNameToString{
"local_includes": `["."]`,
"gtest": "False",
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
+ "runs_on": `["device"]`,
},
},
},
diff --git a/cc/test.go b/cc/test.go
index 0be230151..adc80c2f0 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -686,6 +686,8 @@ type testBinaryAttributes struct {
tidyAttributes
tradefed.TestConfigAttributes
+
+ Runs_on bazel.StringListAttribute
}
// testBinaryBp2build is the bp2build converter for cc_test modules. A cc_test's
@@ -730,6 +732,8 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
+ var unitTest *bool
+
for _, testProps := range m.GetProperties() {
if p, ok := testProps.(*TestBinaryProperties); ok {
useVendor := false // TODO Bug: 262914724
@@ -745,9 +749,15 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
&testInstallBase,
)
testBinaryAttrs.TestConfigAttributes = testConfigAttributes
+ unitTest = p.Test_options.Unit_test
}
}
+ testBinaryAttrs.Runs_on = bazel.MakeStringListAttribute(android.RunsOn(
+ m.ModuleBase.HostSupported(),
+ m.ModuleBase.DeviceSupported(),
+ gtest || (unitTest != nil && *unitTest)))
+
// TODO (b/262914724): convert to tradefed_cc_test and tradefed_cc_test_host
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{