diff options
author | Paul Duffin <paulduffin@google.com> | 2019-12-03 18:06:47 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2019-12-31 15:08:59 +0000 |
commit | 1b82e6a108ce8104c3f7ed7e63d6b0a88cd8a918 (patch) | |
tree | 78204e6d78a7688c7a31d012dbee6728a879addf /java/java.go | |
parent | e602918294cdfdb50dd2e9f246808adae932b5ce (diff) |
Add support for java_test in sdk
Adds java_test_import module type for use by the sdk snapshot and
adds java_tests property to the sdk and sdk_snapshot module type.
This is needed for the conscrypt test sdk.
Bug: 143678475
Test: m nothing
Change-Id: Ied4c56c978dac2f92a9b3bc34b3235d7eeba2fd3
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 113 |
1 files changed, 107 insertions, 6 deletions
diff --git a/java/java.go b/java/java.go index 27f69b848..a48b5a300 100644 --- a/java/java.go +++ b/java/java.go @@ -53,6 +53,12 @@ func init() { }, }, }) + + android.RegisterSdkMemberType(&testSdkMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "java_tests", + }, + }) } func RegisterJavaBuildComponents(ctx android.RegistrationContext) { @@ -66,6 +72,7 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_test", TestFactory) ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory) ctx.RegisterModuleType("java_test_host", TestHostFactory) + ctx.RegisterModuleType("java_test_import", JavaTestImportFactory) ctx.RegisterModuleType("java_import", ImportFactory) ctx.RegisterModuleType("java_import_host", ImportFactoryHost) ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory) @@ -1765,14 +1772,19 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { } const ( - aidlIncludeDir = "aidl" - javaDir = "java" - jarFileSuffix = ".jar" + aidlIncludeDir = "aidl" + javaDir = "java" + jarFileSuffix = ".jar" + testConfigSuffix = "-AndroidTest.xml" ) // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> -func (j *Library) sdkSnapshotFilePathForJar() string { - return filepath.Join(javaDir, j.Name()+jarFileSuffix) +func sdkSnapshotFilePathForJar(member android.SdkMember) string { + return sdkSnapshotFilePathForMember(member, jarFileSuffix) +} + +func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string { + return filepath.Join(javaDir, member.Name()+suffix) } type librarySdkMemberType struct { @@ -1805,7 +1817,7 @@ func (mt *librarySdkMemberType) buildSnapshot( j := variant.(*Library) exportedJar := jarToExportGetter(j) - snapshotRelativeJavaLibPath := j.sdkSnapshotFilePathForJar() + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) for _, dir := range j.AidlIncludeDirs() { @@ -1932,6 +1944,16 @@ type testHelperLibraryProperties struct { Test_suites []string `android:"arch_variant"` } +type prebuiltTestProperties struct { + // list of compatibility suites (for example "cts", "vts") that the module should be + // installed into. + Test_suites []string `android:"arch_variant"` + + // the name of the test configuration (for example "AndroidTest.xml") that should be + // installed with the module. + Test_config *string `android:"path,arch_variant"` +} + type Test struct { Library @@ -1947,6 +1969,14 @@ type TestHelperLibrary struct { testHelperLibraryProperties testHelperLibraryProperties } +type JavaTestImport struct { + Import + + prebuiltTestProperties prebuiltTestProperties + + testConfig android.Path +} + func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, j.testProperties.Test_suites, j.testProperties.Auto_gen_config) @@ -1959,6 +1989,53 @@ func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContex j.Library.GenerateAndroidBuildActions(ctx) } +func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil, + j.prebuiltTestProperties.Test_suites, nil) + + j.Import.GenerateAndroidBuildActions(ctx) +} + +type testSdkMemberType struct { + android.SdkMemberTypeBase +} + +func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { + mctx.AddVariationDependencies(nil, dependencyTag, names...) +} + +func (mt *testSdkMemberType) IsInstance(module android.Module) bool { + _, ok := module.(*Test) + return ok +} + +func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { + variants := member.Variants() + if len(variants) != 1 { + sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) + for _, variant := range variants { + sdkModuleContext.ModuleErrorf(" %q", variant) + } + } + variant := variants[0] + j := variant.(*Test) + + implementationJars := j.ImplementationJars() + if len(implementationJars) != 1 { + panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) + } + + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) + builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath) + + snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix) + builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath) + + module := builder.AddPrebuiltModule(member, "java_test_import") + module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + module.AddProperty("test_config", snapshotRelativeTestConfigPath) +} + // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. // @@ -2002,6 +2079,30 @@ func TestHelperLibraryFactory() android.Module { return module } +// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module +// and makes sure that it is added to the appropriate test suite. +// +// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were +// compiled against an Android classpath. +// +// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one +// for host modules. +func JavaTestImportFactory() android.Module { + module := &JavaTestImport{} + + module.AddProperties( + &module.Import.properties, + &module.prebuiltTestProperties) + + module.Import.properties.Installable = proptools.BoolPtr(true) + + android.InitPrebuiltModule(module, &module.properties.Jars) + android.InitApexModule(module) + android.InitSdkAwareModule(module) + InitJavaModule(module, android.HostAndDeviceSupported) + return module +} + // java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to // allow running the test with `atest` or a `TEST_MAPPING` file. // |