Merge "Remove restriction on exported plugins that generate APIs"
This commit is contained in:
@@ -836,8 +836,8 @@ func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *AARImport) ExportedPlugins() (android.Paths, []string) {
|
func (d *AARImport) ExportedPlugins() (android.Paths, []string, bool) {
|
||||||
return nil, nil
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
|
func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
|
||||||
|
@@ -167,8 +167,8 @@ func (d *DeviceHostConverter) ClassLoaderContexts() dexpreopt.ClassLoaderContext
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DeviceHostConverter) ExportedPlugins() (android.Paths, []string) {
|
func (d *DeviceHostConverter) ExportedPlugins() (android.Paths, []string, bool) {
|
||||||
return nil, nil
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DeviceHostConverter) SrcJarArgs() ([]string, android.Paths) {
|
func (d *DeviceHostConverter) SrcJarArgs() ([]string, android.Paths) {
|
||||||
|
40
java/java.go
40
java/java.go
@@ -201,7 +201,10 @@ type CompilerProperties struct {
|
|||||||
// List of modules to use as annotation processors
|
// List of modules to use as annotation processors
|
||||||
Plugins []string
|
Plugins []string
|
||||||
|
|
||||||
// List of modules to export to libraries that directly depend on this library as annotation processors
|
// List of modules to export to libraries that directly depend on this library as annotation
|
||||||
|
// processors. Note that if the plugins set generates_api: true this will disable the turbine
|
||||||
|
// optimization on modules that depend on this module, which will reduce parallelism and cause
|
||||||
|
// more recompilation.
|
||||||
Exported_plugins []string
|
Exported_plugins []string
|
||||||
|
|
||||||
// The number of Java source entries each Javac instance can process
|
// The number of Java source entries each Javac instance can process
|
||||||
@@ -428,6 +431,9 @@ type Module struct {
|
|||||||
// list of plugins that this java module is exporting
|
// list of plugins that this java module is exporting
|
||||||
exportedPluginClasses []string
|
exportedPluginClasses []string
|
||||||
|
|
||||||
|
// if true, the exported plugins generate API and require disabling turbine.
|
||||||
|
exportedDisableTurbine bool
|
||||||
|
|
||||||
// list of source files, collected from srcFiles with unique java and all kt files,
|
// list of source files, collected from srcFiles with unique java and all kt files,
|
||||||
// will be used by android.IDEInfo struct
|
// will be used by android.IDEInfo struct
|
||||||
expandIDEInfoCompiledSrcs []string
|
expandIDEInfoCompiledSrcs []string
|
||||||
@@ -513,7 +519,7 @@ type Dependency interface {
|
|||||||
ResourceJars() android.Paths
|
ResourceJars() android.Paths
|
||||||
AidlIncludeDirs() android.Paths
|
AidlIncludeDirs() android.Paths
|
||||||
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
||||||
ExportedPlugins() (android.Paths, []string)
|
ExportedPlugins() (android.Paths, []string, bool)
|
||||||
SrcJarArgs() ([]string, android.Paths)
|
SrcJarArgs() ([]string, android.Paths)
|
||||||
BaseModuleName() string
|
BaseModuleName() string
|
||||||
JacocoReportClassesFile() android.Path
|
JacocoReportClassesFile() android.Path
|
||||||
@@ -1049,8 +1055,9 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
// sdk lib names from dependencies are re-exported
|
// sdk lib names from dependencies are re-exported
|
||||||
j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
|
j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
|
||||||
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
||||||
pluginJars, pluginClasses := dep.ExportedPlugins()
|
pluginJars, pluginClasses, disableTurbine := dep.ExportedPlugins()
|
||||||
addPlugins(&deps, pluginJars, pluginClasses...)
|
addPlugins(&deps, pluginJars, pluginClasses...)
|
||||||
|
deps.disableTurbine = deps.disableTurbine || disableTurbine
|
||||||
case java9LibTag:
|
case java9LibTag:
|
||||||
deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
|
deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
|
||||||
case staticLibTag:
|
case staticLibTag:
|
||||||
@@ -1061,8 +1068,12 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
// sdk lib names from dependencies are re-exported
|
// sdk lib names from dependencies are re-exported
|
||||||
j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
|
j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
|
||||||
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
||||||
pluginJars, pluginClasses := dep.ExportedPlugins()
|
pluginJars, pluginClasses, disableTurbine := dep.ExportedPlugins()
|
||||||
addPlugins(&deps, pluginJars, pluginClasses...)
|
addPlugins(&deps, pluginJars, pluginClasses...)
|
||||||
|
// Turbine doesn't run annotation processors, so any module that uses an
|
||||||
|
// annotation processor that generates API is incompatible with the turbine
|
||||||
|
// optimization.
|
||||||
|
deps.disableTurbine = deps.disableTurbine || disableTurbine
|
||||||
case pluginTag:
|
case pluginTag:
|
||||||
if plugin, ok := dep.(*Plugin); ok {
|
if plugin, ok := dep.(*Plugin); ok {
|
||||||
if plugin.pluginProperties.Processor_class != nil {
|
if plugin.pluginProperties.Processor_class != nil {
|
||||||
@@ -1070,6 +1081,9 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
} else {
|
} else {
|
||||||
addPlugins(&deps, plugin.ImplementationAndResourcesJars())
|
addPlugins(&deps, plugin.ImplementationAndResourcesJars())
|
||||||
}
|
}
|
||||||
|
// Turbine doesn't run annotation processors, so any module that uses an
|
||||||
|
// annotation processor that generates API is incompatible with the turbine
|
||||||
|
// optimization.
|
||||||
deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
|
deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
|
||||||
} else {
|
} else {
|
||||||
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
|
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
|
||||||
@@ -1082,13 +1096,14 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
}
|
}
|
||||||
case exportedPluginTag:
|
case exportedPluginTag:
|
||||||
if plugin, ok := dep.(*Plugin); ok {
|
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()...)
|
j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...)
|
||||||
if plugin.pluginProperties.Processor_class != nil {
|
if plugin.pluginProperties.Processor_class != nil {
|
||||||
j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
|
j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
|
||||||
}
|
}
|
||||||
|
// Turbine doesn't run annotation processors, so any module that uses an
|
||||||
|
// annotation processor that generates API is incompatible with the turbine
|
||||||
|
// optimization.
|
||||||
|
j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api)
|
||||||
} else {
|
} else {
|
||||||
ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
|
ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
|
||||||
}
|
}
|
||||||
@@ -1922,8 +1937,11 @@ func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|||||||
return j.classLoaderContexts
|
return j.classLoaderContexts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) ExportedPlugins() (android.Paths, []string) {
|
// ExportedPlugins returns the list of jars needed to run the exported plugins, the list of
|
||||||
return j.exportedPluginJars, j.exportedPluginClasses
|
// classes for the plugins, and a boolean for whether turbine needs to be disabled due to plugins
|
||||||
|
// that generate APIs.
|
||||||
|
func (j *Module) ExportedPlugins() (android.Paths, []string, bool) {
|
||||||
|
return j.exportedPluginJars, j.exportedPluginClasses, j.exportedDisableTurbine
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) SrcJarArgs() ([]string, android.Paths) {
|
func (j *Module) SrcJarArgs() ([]string, android.Paths) {
|
||||||
@@ -2865,8 +2883,8 @@ func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|||||||
return j.classLoaderContexts
|
return j.classLoaderContexts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) ExportedPlugins() (android.Paths, []string) {
|
func (j *Import) ExportedPlugins() (android.Paths, []string, bool) {
|
||||||
return nil, nil
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) SrcJarArgs() ([]string, android.Paths) {
|
func (j *Import) SrcJarArgs() ([]string, android.Paths) {
|
||||||
|
@@ -315,8 +315,9 @@ func TestSimple(t *testing.T) {
|
|||||||
|
|
||||||
func TestExportedPlugins(t *testing.T) {
|
func TestExportedPlugins(t *testing.T) {
|
||||||
type Result struct {
|
type Result struct {
|
||||||
library string
|
library string
|
||||||
processors string
|
processors string
|
||||||
|
disableTurbine bool
|
||||||
}
|
}
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
name string
|
name string
|
||||||
@@ -375,6 +376,18 @@ func TestExportedPlugins(t *testing.T) {
|
|||||||
{library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"},
|
{library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Exports plugin to with generates_api to dependee",
|
||||||
|
extra: `
|
||||||
|
java_library{name: "exports", exported_plugins: ["plugin_generates_api"]}
|
||||||
|
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", disableTurbine: true},
|
||||||
|
{library: "bar", processors: "-processor com.android.TestPlugin", disableTurbine: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -384,6 +397,11 @@ func TestExportedPlugins(t *testing.T) {
|
|||||||
name: "plugin",
|
name: "plugin",
|
||||||
processor_class: "com.android.TestPlugin",
|
processor_class: "com.android.TestPlugin",
|
||||||
}
|
}
|
||||||
|
java_plugin {
|
||||||
|
name: "plugin_generates_api",
|
||||||
|
generates_api: true,
|
||||||
|
processor_class: "com.android.TestPlugin",
|
||||||
|
}
|
||||||
`+test.extra)
|
`+test.extra)
|
||||||
|
|
||||||
for _, want := range test.results {
|
for _, want := range test.results {
|
||||||
@@ -391,6 +409,11 @@ func TestExportedPlugins(t *testing.T) {
|
|||||||
if javac.Args["processor"] != want.processors {
|
if javac.Args["processor"] != want.processors {
|
||||||
t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"])
|
t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"])
|
||||||
}
|
}
|
||||||
|
turbine := ctx.ModuleForTests(want.library, "android_common").MaybeRule("turbine")
|
||||||
|
disableTurbine := turbine.BuildParams.Rule == nil
|
||||||
|
if disableTurbine != want.disableTurbine {
|
||||||
|
t.Errorf("For library %v, expected disableTurbine %v, found %v", want.library, want.disableTurbine, disableTurbine)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user