Add data_native_bins property to java_test_host

When multiple os/arch variants are supported, java_test_host could not
find a matching arch due to java having arch:common, whereas native
binaries support a specific architecture. This change adds the property
`data_native_bins` in order to support binaries with the appropriate
os/arch variants.

Test: m FirmwareDtboVerification with data_native_bins
Test: forrest
Bug: 153848038
Change-Id: I45adebff0fde2811d5ef5620c697b97b768c951f
This commit is contained in:
Liz Kammer 2020-06-12 16:38:45 -07:00
parent 41b4d79dab
commit dd849a81f3
8 changed files with 97 additions and 16 deletions

View file

@ -10,6 +10,7 @@ bootstrap_go_package {
"soong-dexpreopt", "soong-dexpreopt",
"soong-genrule", "soong-genrule",
"soong-java-config", "soong-java-config",
"soong-python",
"soong-remoteexec", "soong-remoteexec",
"soong-tradefed", "soong-tradefed",
], ],

View file

@ -556,7 +556,20 @@ func (j *Module) XrefJavaFiles() android.Paths {
} }
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
android.InitAndroidArchModule(module, hod, android.MultilibCommon) initJavaModule(module, hod, false)
}
func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
initJavaModule(module, hod, true)
}
func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) {
multilib := android.MultilibCommon
if multiTargets {
android.InitAndroidMultiTargetsArchModule(module, hod, multilib)
} else {
android.InitAndroidArchModule(module, hod, multilib)
}
android.InitDefaultableModule(module) android.InitDefaultableModule(module)
} }
@ -575,6 +588,7 @@ func IsJniDepTag(depTag blueprint.DependencyTag) bool {
} }
var ( var (
dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
staticLibTag = dependencyTag{name: "staticlib"} staticLibTag = dependencyTag{name: "staticlib"}
libTag = dependencyTag{name: "javalib"} libTag = dependencyTag{name: "javalib"}
java9LibTag = dependencyTag{name: "java9lib"} java9LibTag = dependencyTag{name: "java9lib"}
@ -2193,6 +2207,11 @@ type testProperties struct {
Test_mainline_modules []string Test_mainline_modules []string
} }
type hostTestProperties struct {
// list of native binary modules that should be installed alongside the test
Data_native_bins []string `android:"arch_variant"`
}
type testHelperLibraryProperties struct { type testHelperLibraryProperties struct {
// list of compatibility suites (for example "cts", "vts") that the module should be // list of compatibility suites (for example "cts", "vts") that the module should be
// installed into. // installed into.
@ -2218,6 +2237,12 @@ type Test struct {
data android.Paths data android.Paths
} }
type TestHost struct {
Test
testHostProperties hostTestProperties
}
type TestHelperLibrary struct { type TestHelperLibrary struct {
Library Library
@ -2232,11 +2257,26 @@ type JavaTestImport struct {
testConfig android.Path testConfig android.Path
} }
func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
if len(j.testHostProperties.Data_native_bins) > 0 {
for _, target := range ctx.MultiTargets() {
ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...)
}
}
j.deps(ctx)
}
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
j.testProperties.Test_suites, j.testProperties.Auto_gen_config) j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
})
j.Library.GenerateAndroidBuildActions(ctx) j.Library.GenerateAndroidBuildActions(ctx)
} }
@ -2377,14 +2417,15 @@ func JavaTestImportFactory() android.Module {
// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were // A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
// compiled against the host bootclasspath. // compiled against the host bootclasspath.
func TestHostFactory() android.Module { func TestHostFactory() android.Module {
module := &Test{} module := &TestHost{}
module.addHostProperties() module.addHostProperties()
module.AddProperties(&module.testProperties) module.AddProperties(&module.testProperties)
module.AddProperties(&module.testHostProperties)
module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.properties.Installable = proptools.BoolPtr(true)
InitJavaModule(module, android.HostSupported) InitJavaModuleMultiTargets(module, android.HostSupported)
return module return module
} }

View file

@ -31,6 +31,7 @@ import (
"android/soong/cc" "android/soong/cc"
"android/soong/dexpreopt" "android/soong/dexpreopt"
"android/soong/genrule" "android/soong/genrule"
"android/soong/python"
) )
var buildDir string var buildDir string
@ -81,6 +82,7 @@ func testContext() *android.TestContext {
ctx.RegisterModuleType("java_plugin", PluginFactory) ctx.RegisterModuleType("java_plugin", PluginFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory)
RegisterDocsBuildComponents(ctx) RegisterDocsBuildComponents(ctx)
RegisterStubsBuildComponents(ctx) RegisterStubsBuildComponents(ctx)
RegisterSdkLibraryBuildComponents(ctx) RegisterSdkLibraryBuildComponents(ctx)
@ -89,6 +91,7 @@ func testContext() *android.TestContext {
RegisterPrebuiltApisBuildComponents(ctx) RegisterPrebuiltApisBuildComponents(ctx)
ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators)
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory)) ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory))
@ -2008,3 +2011,28 @@ func TestAidlExportIncludeDirsFromImports(t *testing.T) {
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
} }
} }
func TestDataNativeBinaries(t *testing.T) {
ctx, config := testJava(t, `
java_test_host {
name: "foo",
srcs: ["a.java"],
data_native_bins: ["bin"]
}
python_binary_host {
name: "bin",
srcs: ["bin.py"],
}
`)
buildOS := android.BuildOs.String()
test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
entries := android.AndroidMkEntriesForTest(t, config, "", test)[0]
expected := []string{buildDir + "/.intermediates/bin/" + buildOS + "_x86_64_PY3/bin:bin"}
actual := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
}
}

View file

@ -22,6 +22,8 @@ import (
"android/soong/android" "android/soong/android"
"android/soong/cc" "android/soong/cc"
"android/soong/python"
"github.com/google/blueprint" "github.com/google/blueprint"
) )
@ -85,6 +87,10 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
"prebuilts/sdk/tools/core-lambda-stubs.jar": nil, "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
"prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`), "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`),
"bin.py": nil,
python.StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
MAIN_FILE = '%main%'`),
// For java_sdk_library // For java_sdk_library
"api/module-lib-current.txt": nil, "api/module-lib-current.txt": nil,
"api/module-lib-removed.txt": nil, "api/module-lib-removed.txt": nil,

View file

@ -65,7 +65,7 @@ type IntermPathProvider interface {
} }
var ( var (
stubTemplateHost = "build/soong/python/scripts/stub_template_host.txt" StubTemplateHost = "build/soong/python/scripts/stub_template_host.txt"
) )
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {

View file

@ -91,7 +91,7 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
if !embeddedLauncher { if !embeddedLauncher {
// the path of stub_template_host.txt from source tree. // the path of stub_template_host.txt from source tree.
template := android.PathForSource(ctx, stubTemplateHost) template := android.PathForSource(ctx, StubTemplateHost)
implicits = append(implicits, template) implicits = append(implicits, template)
// intermediate output path for __main__.py // intermediate output path for __main__.py

View file

@ -30,9 +30,11 @@ import (
) )
func init() { func init() {
android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { android.PreDepsMutators(RegisterPythonPreDepsMutators)
ctx.BottomUp("version_split", versionSplitMutator()).Parallel() }
})
func RegisterPythonPreDepsMutators(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("version_split", versionSplitMutator()).Parallel()
} }
// the version properties that apply to python libraries and binaries. // the version properties that apply to python libraries and binaries.
@ -226,15 +228,20 @@ func versionSplitMutator() func(android.BottomUpMutatorContext) {
return func(mctx android.BottomUpMutatorContext) { return func(mctx android.BottomUpMutatorContext) {
if base, ok := mctx.Module().(*Module); ok { if base, ok := mctx.Module().(*Module); ok {
versionNames := []string{} versionNames := []string{}
if base.properties.Version.Py2.Enabled != nil && // PY3 is first so that we alias the PY3 variant rather than PY2 if both
*(base.properties.Version.Py2.Enabled) == true { // are available
versionNames = append(versionNames, pyVersion2)
}
if !(base.properties.Version.Py3.Enabled != nil && if !(base.properties.Version.Py3.Enabled != nil &&
*(base.properties.Version.Py3.Enabled) == false) { *(base.properties.Version.Py3.Enabled) == false) {
versionNames = append(versionNames, pyVersion3) versionNames = append(versionNames, pyVersion3)
} }
if base.properties.Version.Py2.Enabled != nil &&
*(base.properties.Version.Py2.Enabled) == true {
versionNames = append(versionNames, pyVersion2)
}
modules := mctx.CreateVariations(versionNames...) modules := mctx.CreateVariations(versionNames...)
if len(versionNames) > 0 {
mctx.AliasVariation(versionNames[0])
}
for i, v := range versionNames { for i, v := range versionNames {
// set the actual version for Python module. // set the actual version for Python module.
modules[i].(*Module).properties.Actual_version = v modules[i].(*Module).properties.Actual_version = v

View file

@ -301,7 +301,7 @@ var (
filepath.Join("dir", "file2.py"): nil, filepath.Join("dir", "file2.py"): nil,
filepath.Join("dir", "bin.py"): nil, filepath.Join("dir", "bin.py"): nil,
filepath.Join("dir", "file4.py"): nil, filepath.Join("dir", "file4.py"): nil,
stubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%' StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
MAIN_FILE = '%main%'`), MAIN_FILE = '%main%'`),
}, },
expectedBinaries: []pyModule{ expectedBinaries: []pyModule{
@ -330,9 +330,7 @@ func TestPythonModule(t *testing.T) {
t.Run(d.desc, func(t *testing.T) { t.Run(d.desc, func(t *testing.T) {
config := android.TestConfig(buildDir, nil, "", d.mockFiles) config := android.TestConfig(buildDir, nil, "", d.mockFiles)
ctx := android.NewTestContext() ctx := android.NewTestContext()
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.PreDepsMutators(RegisterPythonPreDepsMutators)
ctx.BottomUp("version_split", versionSplitMutator()).Parallel()
})
ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory) ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory)
ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory) ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory)
ctx.RegisterModuleType("python_defaults", defaultsFactory) ctx.RegisterModuleType("python_defaults", defaultsFactory)