summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go61
1 files changed, 47 insertions, 14 deletions
diff --git a/java/java.go b/java/java.go
index cac49a2c5..3b20ea406 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1087,6 +1087,10 @@ func (j *JavaTestImport) InstallInTestcases() bool {
return true
}
+func (j *TestHost) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
+ return ctx.DeviceConfig().NativeCoverageEnabled()
+}
+
func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) {
if len(j.testHostProperties.Data_device_bins_first) > 0 {
deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
@@ -1689,6 +1693,12 @@ type JavaApiLibraryProperties struct {
// Version of previously released API file for compatibility check.
Previous_api *string `android:"path"`
+
+ // java_system_modules module providing the jar to be added to the
+ // bootclasspath when compiling the stubs.
+ // The jar will also be passed to metalava as a classpath to
+ // generate compilable stubs.
+ System_modules *string
}
func ApiLibraryFactory() android.Module {
@@ -1708,7 +1718,8 @@ func (al *ApiLibrary) StubsJar() android.Path {
}
func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
- srcs android.Paths, homeDir android.WritablePath) *android.RuleBuilderCommand {
+ srcs android.Paths, homeDir android.WritablePath,
+ classpath android.Paths) *android.RuleBuilderCommand {
rule.Command().Text("rm -rf").Flag(homeDir.String())
rule.Command().Text("mkdir -p").Flag(homeDir.String())
@@ -1747,12 +1758,17 @@ func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
FlagWithArg("--hide ", "InvalidNullabilityOverride").
FlagWithArg("--hide ", "ChangedDefault")
- // The main purpose of the `--api-class-resolution api` option is to force metalava to ignore
- // classes on the classpath when an API file contains missing classes. However, as this command
- // does not specify `--classpath` this is not needed for that. However, this is also used as a
- // signal to the special metalava code for generating stubs from text files that it needs to add
- // some additional items into the API (e.g. default constructors).
- cmd.FlagWithArg("--api-class-resolution ", "api")
+ if len(classpath) == 0 {
+ // The main purpose of the `--api-class-resolution api` option is to force metalava to ignore
+ // classes on the classpath when an API file contains missing classes. However, as this command
+ // does not specify `--classpath` this is not needed for that. However, this is also used as a
+ // signal to the special metalava code for generating stubs from text files that it needs to add
+ // some additional items into the API (e.g. default constructors).
+ cmd.FlagWithArg("--api-class-resolution ", "api")
+ } else {
+ cmd.FlagWithArg("--api-class-resolution ", "api:classpath")
+ cmd.FlagWithInputList("--classpath ", classpath, ":")
+ }
return cmd
}
@@ -1815,6 +1831,9 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
if al.properties.Full_api_surface_stub != nil {
ctx.AddVariationDependencies(nil, depApiSrcsTag, String(al.properties.Full_api_surface_stub))
}
+ if al.properties.System_modules != nil {
+ ctx.AddVariationDependencies(nil, systemModulesTag, String(al.properties.System_modules))
+ }
}
// Map where key is the api scope name and value is the int value
@@ -1854,6 +1873,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var classPaths android.Paths
var staticLibs android.Paths
var depApiSrcsStubsJar android.Path
+ var systemModulesPaths android.Paths
ctx.VisitDirectDeps(func(dep android.Module) {
tag := ctx.OtherModuleDependencyTag(dep)
switch tag {
@@ -1872,6 +1892,9 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
case depApiSrcsTag:
provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
depApiSrcsStubsJar = provider.HeaderJars[0]
+ case systemModulesTag:
+ module := dep.(SystemModulesProvider)
+ systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...)
}
})
@@ -1885,7 +1908,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())
}
- cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir)
+ cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths)
al.stubsFlags(ctx, cmd, stubsDir)
@@ -1917,6 +1940,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
flags.javaVersion = getStubsJavaVersion()
flags.javacFlags = strings.Join(al.properties.Javacflags, " ")
flags.classpath = classpath(classPaths)
+ flags.bootClasspath = classpath(systemModulesPaths)
annoSrcJar := android.PathForModuleOut(ctx, ctx.ModuleName(), "anno.srcjar")
@@ -2751,7 +2775,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
type javaResourcesAttributes struct {
Resources bazel.LabelListAttribute
Resource_strip_prefix *string
- Additional_resources bazel.LabelListAttribute
+ Additional_resources bazel.LabelListAttribute `blueprint:"mutated"`
}
func (m *Library) getResourceFilegroupStripPrefix(ctx android.Bp2buildMutatorContext, resourceFilegroup string) (*string, bool) {
@@ -2911,8 +2935,8 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext
archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
for axis, configToProps := range archVariantProps {
- for config, _props := range configToProps {
- if archProps, ok := _props.(*CommonProperties); ok {
+ for config, p := range configToProps {
+ if archProps, ok := p.(*CommonProperties); ok {
archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs)
srcs.SetSelectValue(axis, config, archSrcs)
if archProps.Jarjar_rules != nil {
@@ -2922,6 +2946,11 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext
}
}
}
+ srcs.Append(
+ bazel.MakeLabelListAttribute(
+ android.BazelLabelForModuleSrcExcludes(ctx,
+ m.properties.Openjdk9.Srcs,
+ m.properties.Exclude_srcs)))
srcs.ResolveExcludes()
javaSrcPartition := "java"
@@ -3005,8 +3034,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext
plugins := bazel.MakeLabelListAttribute(
android.BazelLabelForModuleDeps(ctx, m.properties.Plugins),
)
- if m.properties.Javacflags != nil {
- javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
+ if m.properties.Javacflags != nil || m.properties.Openjdk9.Javacflags != nil {
+ javacopts = bazel.MakeStringListAttribute(
+ append(append([]string{}, m.properties.Javacflags...), m.properties.Openjdk9.Javacflags...))
}
epEnabled := m.properties.Errorprone.Enabled
@@ -3022,9 +3052,11 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext
javacopts.Append(bazel.MakeStringListAttribute([]string{"-XepDisableAllChecks"}))
}
+ resourcesAttrs := m.convertJavaResourcesAttributes(ctx)
+
commonAttrs := &javaCommonAttributes{
Srcs: javaSrcs,
- javaResourcesAttributes: m.convertJavaResourcesAttributes(ctx),
+ javaResourcesAttributes: resourcesAttrs,
Plugins: plugins,
Javacopts: javacopts,
Java_version: bazel.StringAttribute{Value: m.properties.Java_version},
@@ -3047,6 +3079,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext
}
depLabels := &javaDependencyLabels{}
+ deps.Append(resourcesAttrs.Additional_resources)
depLabels.Deps = deps
for axis, configToProps := range archVariantProps {