summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/aar.go4
-rw-r--r--java/device_host_converter.go4
-rw-r--r--java/dexpreopt_bootjars_test.go2
-rw-r--r--java/dexpreopt_config.go16
-rw-r--r--java/droiddoc.go89
-rw-r--r--java/java.go76
-rw-r--r--java/java_test.go179
7 files changed, 316 insertions, 54 deletions
diff --git a/java/aar.go b/java/aar.go
index d8db19251..e0bea5df3 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -694,6 +694,10 @@ func (a *AARImport) ExportedSdkLibs() []string {
return nil
}
+func (d *AARImport) ExportedPlugins() (android.Paths, []string) {
+ return nil, nil
+}
+
func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
return nil, nil
}
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index 14db52152..15244184e 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -162,6 +162,10 @@ func (d *DeviceHostConverter) ExportedSdkLibs() []string {
return nil
}
+func (d *DeviceHostConverter) ExportedPlugins() (android.Paths, []string) {
+ return nil, nil
+}
+
func (d *DeviceHostConverter) SrcJarArgs() ([]string, android.Paths) {
return d.srcJarArgs, d.srcJarDeps
}
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index a684ab232..29a5abe7f 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -53,7 +53,7 @@ func TestDexpreoptBootJars(t *testing.T) {
ctx := testContext(bp, nil)
- ctx.RegisterSingletonType("dex_bootjars", android.SingletonFactoryAdaptor(dexpreoptBootJarsFactory))
+ ctx.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory)
run(t, ctx, config)
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index a6661b33d..15f11e11c 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -15,6 +15,7 @@
package java
import (
+ "fmt"
"path/filepath"
"strings"
@@ -65,6 +66,16 @@ func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt.
var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig")
var dexpreoptTestGlobalConfigKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
+// Expected format for apexJarValue = <apex name>:<jar name>
+func splitApexJarPair(apexJarValue string) (string, string) {
+ var apexJarPair []string = strings.SplitN(apexJarValue, ":", 2)
+ if apexJarPair == nil || len(apexJarPair) != 2 {
+ panic(fmt.Errorf("malformed apexJarValue: %q, expected format: <apex>:<jar>",
+ apexJarValue))
+ }
+ return apexJarPair[0], apexJarPair[1]
+}
+
// systemServerClasspath returns the on-device locations of the modules in the system server classpath. It is computed
// once the first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same
// ctx.Config().
@@ -77,6 +88,11 @@ func systemServerClasspath(ctx android.PathContext) []string {
systemServerClasspathLocations = append(systemServerClasspathLocations,
filepath.Join("/system/framework", m+".jar"))
}
+ for _, m := range global.UpdatableSystemServerJars {
+ apex, jar := splitApexJarPair(m)
+ systemServerClasspathLocations = append(systemServerClasspathLocations,
+ filepath.Join("/apex", apex, "javalib", jar + ".jar"))
+ }
return systemServerClasspathLocations
})
}
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 54f93fec2..83a1ad588 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -37,6 +37,8 @@ func init() {
android.RegisterModuleType("droidstubs", DroidstubsFactory)
android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
+
+ android.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
}
var (
@@ -1163,6 +1165,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
//
type Droidstubs struct {
Javadoc
+ android.SdkBase
properties DroidstubsProperties
apiFile android.WritablePath
@@ -1208,6 +1211,7 @@ func DroidstubsFactory() android.Module {
&module.Javadoc.properties)
InitDroiddocModule(module, android.HostAndDeviceSupported)
+ android.InitSdkAwareModule(module)
return module
}
@@ -1913,3 +1917,88 @@ func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
rule.Command().Text("rm -rf").Text(srcJarDir.String())
}
+
+var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
+
+type PrebuiltStubsSourcesProperties struct {
+ Srcs []string `android:"path"`
+}
+
+type PrebuiltStubsSources struct {
+ android.ModuleBase
+ android.DefaultableModuleBase
+ prebuilt android.Prebuilt
+ android.SdkBase
+
+ properties PrebuiltStubsSourcesProperties
+
+ srcs android.Paths
+ stubsSrcJar android.ModuleOutPath
+}
+
+func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
+}
+
+func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
+ return &p.prebuilt
+}
+
+func (p *PrebuiltStubsSources) Name() string {
+ return p.prebuilt.Name(p.ModuleBase.Name())
+}
+
+func (p *PrebuiltStubsSources) Srcs() android.Paths {
+ return append(android.Paths{}, p.srcs...)
+}
+
+// prebuilt_stubs_sources imports a set of java source files as if they were
+// generated by droidstubs.
+//
+// By default, a prebuilt_stubs_sources has a single variant that expects a
+// set of `.java` files generated by droidstubs.
+//
+// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
+// for host modules.
+//
+// Intended only for use by sdk snapshots.
+func PrebuiltStubsSourcesFactory() android.Module {
+ module := &PrebuiltStubsSources{}
+
+ module.AddProperties(&module.properties)
+
+ android.InitPrebuiltModule(module, &module.properties.Srcs)
+ android.InitSdkAwareModule(module)
+ InitDroiddocModule(module, android.HostAndDeviceSupported)
+ return module
+}
+
+func (d *Droidstubs) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) {
+ stubsSrcJar := d.stubsSrcJar
+
+ snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
+ builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
+
+ name := d.Name()
+ bp := builder.AndroidBpFile()
+ bp.Printfln("prebuilt_stubs_sources {")
+ bp.Indent()
+ bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
+ bp.Printfln("sdk_member_name: %q,", name)
+ bp.Printfln("srcs: [%q],", snapshotRelativeDir)
+ bp.Dedent()
+ bp.Printfln("}")
+ bp.Printfln("")
+
+ // This module is for the case when the source tree for the unversioned module
+ // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
+ // so that this module does not eclipse the unversioned module if it exists.
+ bp.Printfln("prebuilt_stubs_sources {")
+ bp.Indent()
+ bp.Printfln("name: %q,", name)
+ bp.Printfln("srcs: [%q],", snapshotRelativeDir)
+ bp.Printfln("prefer: false,")
+ bp.Dedent()
+ bp.Printfln("}")
+ bp.Printfln("")
+}
diff --git a/java/java.go b/java/java.go
index d4f65ba42..1c52575d2 100644
--- a/java/java.go
+++ b/java/java.go
@@ -145,6 +145,9 @@ type CompilerProperties struct {
// List of modules to use as annotation processors
Plugins []string
+ // List of modules to export to libraries that directly depend on this library as annotation processors
+ Exported_plugins []string
+
// The number of Java source entries each Javac instance can process
Javac_shard_size *int64
@@ -360,10 +363,16 @@ type Module struct {
// manifest file to use instead of properties.Manifest
overrideManifest android.OptionalPath
- // list of SDK lib names that this java moudule is exporting
+ // list of SDK lib names that this java module is exporting
exportedSdkLibs []string
- // list of source files, collected from srcFiles with uniqie java and all kt files,
+ // list of plugins that this java module is exporting
+ exportedPluginJars android.Paths
+
+ // list of plugins that this java module is exporting
+ exportedPluginClasses []string
+
+ // list of source files, collected from srcFiles with unique java and all kt files,
// will be used by android.IDEInfo struct
expandIDEInfoCompiledSrcs []string
@@ -410,6 +419,7 @@ type Dependency interface {
DexJar() android.Path
AidlIncludeDirs() android.Paths
ExportedSdkLibs() []string
+ ExportedPlugins() (android.Paths, []string)
SrcJarArgs() ([]string, android.Paths)
BaseModuleName() string
}
@@ -452,6 +462,7 @@ var (
libTag = dependencyTag{name: "javalib"}
java9LibTag = dependencyTag{name: "java9lib"}
pluginTag = dependencyTag{name: "plugin"}
+ exportedPluginTag = dependencyTag{name: "exported-plugin"}
bootClasspathTag = dependencyTag{name: "bootclasspath"}
systemModulesTag = dependencyTag{name: "system modules"}
frameworkResTag = dependencyTag{name: "framework-res"}
@@ -561,6 +572,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
android.ProtoDeps(ctx, &j.protoProperties)
if j.hasSrcExt(".proto") {
@@ -800,6 +812,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
// sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
+ pluginJars, pluginClasses := dep.ExportedPlugins()
+ addPlugins(&deps, pluginJars, pluginClasses...)
case java9LibTag:
deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
case staticLibTag:
@@ -810,16 +824,31 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
// sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
+ pluginJars, pluginClasses := dep.ExportedPlugins()
+ addPlugins(&deps, pluginJars, pluginClasses...)
case pluginTag:
if plugin, ok := dep.(*Plugin); ok {
- deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
if plugin.pluginProperties.Processor_class != nil {
- deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
+ addPlugins(&deps, plugin.ImplementationAndResourcesJars(), *plugin.pluginProperties.Processor_class)
+ } else {
+ addPlugins(&deps, plugin.ImplementationAndResourcesJars())
}
deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
} else {
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
}
+ case exportedPluginTag:
+ if plugin, ok := dep.(*Plugin); ok {
+ if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api {
+ ctx.PropertyErrorf("exported_plugins", "Cannot export plugins with generates_api = true, found %v", otherName)
+ }
+ j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...)
+ if plugin.pluginProperties.Processor_class != nil {
+ j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
+ }
+ } else {
+ ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
+ }
case frameworkApkTag:
if ctx.ModuleName() == "android_stubs_current" ||
ctx.ModuleName() == "android_system_stubs_current" ||
@@ -875,6 +904,11 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
return deps
}
+func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
+ deps.processorPath = append(deps.processorPath, pluginJars...)
+ deps.processorClasses = append(deps.processorClasses, pluginClasses...)
+}
+
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
v := sdkContext.sdkVersion()
// For PDK builds, use the latest SDK version instead of "current"
@@ -1569,6 +1603,10 @@ func (j *Module) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+func (j *Module) ExportedPlugins() (android.Paths, []string) {
+ return j.exportedPluginJars, j.exportedPluginClasses
+}
+
func (j *Module) SrcJarArgs() ([]string, android.Paths) {
return j.srcJarArgs, j.srcJarDeps
}
@@ -1691,25 +1729,27 @@ func (j *Library) BuildSnapshot(sdkModuleContext android.ModuleContext, builder
}
}
- name := j.Name()
- bp := builder.AndroidBpFile()
- bp.Printfln("java_import {")
- bp.Indent()
- bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
- bp.Printfln("sdk_member_name: %q,", name)
- bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath)
- bp.Dedent()
- bp.Printfln("}")
- bp.Printfln("")
+ j.generateJavaImport(builder, snapshotRelativeJavaLibPath, true)
// This module is for the case when the source tree for the unversioned module
// doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
// so that this module does not eclipse the unversioned module if it exists.
+ j.generateJavaImport(builder, snapshotRelativeJavaLibPath, false)
+}
+
+func (j *Library) generateJavaImport(builder android.SnapshotBuilder, snapshotRelativeJavaLibPath string, versioned bool) {
+ bp := builder.AndroidBpFile()
+ name := j.Name()
bp.Printfln("java_import {")
bp.Indent()
- bp.Printfln("name: %q,", name)
+ if versioned {
+ bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
+ bp.Printfln("sdk_member_name: %q,", name)
+ } else {
+ bp.Printfln("name: %q,", name)
+ bp.Printfln("prefer: false,")
+ }
bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath)
- bp.Printfln("prefer: false,")
bp.Dedent()
bp.Printfln("}")
bp.Printfln("")
@@ -2143,6 +2183,10 @@ func (j *Import) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+func (j *Import) ExportedPlugins() (android.Paths, []string) {
+ return nil, nil
+}
+
func (j *Import) SrcJarArgs() ([]string, android.Paths) {
return nil, nil
}
diff --git a/java/java_test.go b/java/java_test.go
index 0f7e6dee8..dc498a492 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -63,37 +63,38 @@ func testConfig(env map[string]string) android.Config {
func testContext(bp string, fs map[string][]byte) *android.TestContext {
ctx := android.NewTestArchContext()
- ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
- ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(AndroidAppCertificateFactory))
- ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(AndroidAppImportFactory))
- ctx.RegisterModuleType("android_library", android.ModuleFactoryAdaptor(AndroidLibraryFactory))
- ctx.RegisterModuleType("android_test", android.ModuleFactoryAdaptor(AndroidTestFactory))
- ctx.RegisterModuleType("android_test_helper_app", android.ModuleFactoryAdaptor(AndroidTestHelperAppFactory))
- ctx.RegisterModuleType("android_test_import", android.ModuleFactoryAdaptor(AndroidTestImportFactory))
- ctx.RegisterModuleType("java_binary", android.ModuleFactoryAdaptor(BinaryFactory))
- ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory))
- ctx.RegisterModuleType("java_device_for_host", android.ModuleFactoryAdaptor(DeviceForHostFactory))
- ctx.RegisterModuleType("java_host_for_device", android.ModuleFactoryAdaptor(HostForDeviceFactory))
- ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory))
- ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory))
- ctx.RegisterModuleType("java_test", android.ModuleFactoryAdaptor(TestFactory))
- ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
- ctx.RegisterModuleType("java_import_host", android.ModuleFactoryAdaptor(ImportFactoryHost))
- ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
- ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(SystemModulesFactory))
- ctx.RegisterModuleType("java_genrule", android.ModuleFactoryAdaptor(genRuleFactory))
- ctx.RegisterModuleType("java_plugin", android.ModuleFactoryAdaptor(PluginFactory))
- ctx.RegisterModuleType("dex_import", android.ModuleFactoryAdaptor(DexImportFactory))
- ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
- ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory))
- ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory))
- ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory))
- ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(ExportedDroiddocDirFactory))
- ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(SdkLibraryFactory))
- ctx.RegisterModuleType("java_sdk_library_import", android.ModuleFactoryAdaptor(sdkLibraryImportFactory))
- ctx.RegisterModuleType("override_android_app", android.ModuleFactoryAdaptor(OverrideAndroidAppModuleFactory))
- ctx.RegisterModuleType("override_android_test", android.ModuleFactoryAdaptor(OverrideAndroidTestModuleFactory))
- ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(PrebuiltApisFactory))
+ ctx.RegisterModuleType("android_app", AndroidAppFactory)
+ ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
+ ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
+ ctx.RegisterModuleType("android_library", AndroidLibraryFactory)
+ ctx.RegisterModuleType("android_test", AndroidTestFactory)
+ ctx.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
+ ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
+ ctx.RegisterModuleType("java_binary", BinaryFactory)
+ ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
+ ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
+ ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
+ ctx.RegisterModuleType("java_library", LibraryFactory)
+ ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
+ ctx.RegisterModuleType("java_test", TestFactory)
+ ctx.RegisterModuleType("java_import", ImportFactory)
+ ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
+ ctx.RegisterModuleType("java_defaults", defaultsFactory)
+ ctx.RegisterModuleType("java_system_modules", SystemModulesFactory)
+ ctx.RegisterModuleType("java_genrule", genRuleFactory)
+ ctx.RegisterModuleType("java_plugin", PluginFactory)
+ ctx.RegisterModuleType("dex_import", DexImportFactory)
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
+ ctx.RegisterModuleType("droiddoc", DroiddocFactory)
+ ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
+ ctx.RegisterModuleType("droiddoc_template", ExportedDroiddocDirFactory)
+ ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
+ ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
+ ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
+ ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
+ ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
+ ctx.RegisterModuleType("prebuilt_apis", PrebuiltApisFactory)
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
@@ -105,11 +106,11 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext {
ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory))
// Register module types and mutators from cc needed for JNI testing
- ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
- ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
- ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
- ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
- ctx.RegisterModuleType("ndk_prebuilt_shared_stl", android.ModuleFactoryAdaptor(cc.NdkPrebuiltSharedStlFactory))
+ ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
+ ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
+ ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
+ ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
+ ctx.RegisterModuleType("ndk_prebuilt_shared_stl", cc.NdkPrebuiltSharedStlFactory)
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("link", cc.LinkageMutator).Parallel()
ctx.BottomUp("begin", cc.BeginMutator).Parallel()
@@ -207,6 +208,9 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext {
"cert/new_cert.pk8": nil,
"testdata/data": nil,
+
+ "stubs-sources/foo/Foo.java": nil,
+ "stubs/sources/foo/Foo.java": nil,
}
for k, v := range fs {
@@ -328,6 +332,89 @@ func TestSimple(t *testing.T) {
}
}
+func TestExportedPlugins(t *testing.T) {
+ type Result struct {
+ library string
+ processors string
+ }
+ var tests = []struct {
+ name string
+ extra string
+ results []Result
+ }{
+ {
+ name: "Exported plugin is not a direct plugin",
+ extra: `java_library { name: "exports", srcs: ["a.java"], exported_plugins: ["plugin"] }`,
+ results: []Result{{library: "exports", processors: "-proc:none"}},
+ },
+ {
+ name: "Exports plugin to dependee",
+ extra: `
+ java_library{name: "exports", exported_plugins: ["plugin"]}
+ java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
+ java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
+ `,
+ results: []Result{
+ {library: "foo", processors: "-processor com.android.TestPlugin"},
+ {library: "bar", processors: "-processor com.android.TestPlugin"},
+ },
+ },
+ {
+ name: "Exports plugin to android_library",
+ extra: `
+ java_library{name: "exports", exported_plugins: ["plugin"]}
+ android_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
+ android_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
+ `,
+ results: []Result{
+ {library: "foo", processors: "-processor com.android.TestPlugin"},
+ {library: "bar", processors: "-processor com.android.TestPlugin"},
+ },
+ },
+ {
+ name: "Exports plugin is not propagated via transitive deps",
+ extra: `
+ java_library{name: "exports", exported_plugins: ["plugin"]}
+ java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
+ java_library{name: "bar", srcs: ["a.java"], static_libs: ["foo"]}
+ `,
+ results: []Result{
+ {library: "foo", processors: "-processor com.android.TestPlugin"},
+ {library: "bar", processors: "-proc:none"},
+ },
+ },
+ {
+ name: "Exports plugin appends to plugins",
+ extra: `
+ java_plugin{name: "plugin2", processor_class: "com.android.TestPlugin2"}
+ java_library{name: "exports", exported_plugins: ["plugin"]}
+ java_library{name: "foo", srcs: ["a.java"], libs: ["exports"], plugins: ["plugin2"]}
+ `,
+ results: []Result{
+ {library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"},
+ },
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_plugin {
+ name: "plugin",
+ processor_class: "com.android.TestPlugin",
+ }
+ `+test.extra)
+
+ for _, want := range test.results {
+ javac := ctx.ModuleForTests(want.library, "android_common").Rule("javac")
+ if javac.Args["processor"] != want.processors {
+ t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"])
+ }
+ }
+ })
+ }
+}
+
func TestSdkVersionByPartition(t *testing.T) {
testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
java_library {
@@ -415,7 +502,7 @@ func TestPrebuilts(t *testing.T) {
ctx, _ := testJava(t, `
java_library {
name: "foo",
- srcs: ["a.java"],
+ srcs: ["a.java", ":stubs-source"],
libs: ["bar", "sdklib"],
static_libs: ["baz"],
}
@@ -439,6 +526,11 @@ func TestPrebuilts(t *testing.T) {
name: "sdklib",
jars: ["b.jar"],
}
+
+ prebuilt_stubs_sources {
+ name: "stubs-source",
+ srcs: ["stubs/sources/**/*.java"],
+ }
`)
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
@@ -447,6 +539,19 @@ func TestPrebuilts(t *testing.T) {
bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output
sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output
+ inputs := []string{}
+ for _, p := range javac.BuildParams.Inputs {
+ inputs = append(inputs, p.String())
+ }
+
+ expected := []string{
+ "a.java",
+ "stubs/sources/foo/Foo.java",
+ }
+ if !reflect.DeepEqual(expected, inputs) {
+ t.Errorf("foo inputs incorrect: expected %q, found %q", expected, inputs)
+ }
+
if !strings.Contains(javac.Args["classpath"], barJar.String()) {
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
}