summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/aar.go10
-rw-r--r--java/base.go21
-rw-r--r--java/droidstubs.go4
-rw-r--r--java/droidstubs_test.go34
-rw-r--r--java/java.go3
-rw-r--r--java/java_test.go22
-rw-r--r--java/platform_bootclasspath.go17
-rw-r--r--java/platform_bootclasspath_test.go29
8 files changed, 98 insertions, 42 deletions
diff --git a/java/aar.go b/java/aar.go
index c0535a4d7..44496dc57 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -1356,10 +1356,12 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext)
if !commonAttrs.Srcs.IsEmpty() {
deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
} else if !depLabels.Deps.IsEmpty() {
- ctx.MarkBp2buildUnconvertible(
- bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED,
- "Module has direct dependencies but no sources. Bazel will not allow this.")
- return
+ // android_library does not accept deps when there are no srcs because
+ // there is no compilation happening, but it accepts exports.
+ // The non-empty deps here are unnecessary as deps on the android_library
+ // since they aren't being propagated to any dependencies.
+ // So we can drop deps here.
+ deps = bazel.LabelListAttribute{}
}
name := a.Name()
props := AndroidLibraryBazelTargetModuleProperties()
diff --git a/java/base.go b/java/base.go
index fb7b95a38..db237dac0 100644
--- a/java/base.go
+++ b/java/base.go
@@ -432,6 +432,9 @@ type Module struct {
srcJarArgs []string
srcJarDeps android.Paths
+ // the source files of this module and all its static dependencies
+ transitiveSrcFiles *android.DepSet[android.Path]
+
// jar file containing implementation classes and resources including static library
// dependencies
implementationAndResourcesJar android.Path
@@ -1694,6 +1697,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
j.linter.lint(ctx)
}
+ j.collectTransitiveSrcFiles(ctx, srcFiles)
+
ctx.CheckbuildFile(outputFile)
j.collectTransitiveAconfigFiles(ctx)
@@ -1708,6 +1713,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
AidlIncludeDirs: j.exportAidlIncludeDirs,
SrcJarArgs: j.srcJarArgs,
SrcJarDeps: j.srcJarDeps,
+ TransitiveSrcFiles: j.transitiveSrcFiles,
ExportedPlugins: j.exportedPluginJars,
ExportedPluginClasses: j.exportedPluginClasses,
ExportedPluginDisableTurbine: j.exportedDisableTurbine,
@@ -2032,6 +2038,21 @@ func (j *Module) JacocoReportClassesFile() android.Path {
return j.jacocoReportClassesFile
}
+func (j *Module) collectTransitiveSrcFiles(ctx android.ModuleContext, mine android.Paths) {
+ var fromDeps []*android.DepSet[android.Path]
+ ctx.VisitDirectDeps(func(module android.Module) {
+ tag := ctx.OtherModuleDependencyTag(module)
+ if tag == staticLibTag {
+ depInfo := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
+ if depInfo.TransitiveSrcFiles != nil {
+ fromDeps = append(fromDeps, depInfo.TransitiveSrcFiles)
+ }
+ }
+ })
+
+ j.transitiveSrcFiles = android.NewDepSet(android.POSTORDER, mine, fromDeps)
+}
+
func (j *Module) IsInstallable() bool {
return Bool(j.properties.Installable)
}
diff --git a/java/droidstubs.go b/java/droidstubs.go
index b059c0abf..67a55bd49 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -540,10 +540,6 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
// See b/285312164 for more information.
cmd.FlagWithArg("--format-defaults ", "overloaded-method-order=source")
- if ctx.DeviceConfig().HideFlaggedApis() {
- cmd.FlagWithArg("--hide-annotation ", "android.annotation.FlaggedApi")
- }
-
return cmd
}
diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go
index 3c2580105..7a04d7326 100644
--- a/java/droidstubs_test.go
+++ b/java/droidstubs_test.go
@@ -22,8 +22,6 @@ import (
"testing"
"android/soong/android"
-
- "github.com/google/blueprint/proptools"
)
func TestDroidstubs(t *testing.T) {
@@ -405,35 +403,3 @@ func TestGeneratedApiContributionVisibilityTest(t *testing.T) {
ctx.ModuleForTests("bar", "android_common")
}
-
-func TestDroidstubsHideFlaggedApi(t *testing.T) {
- result := android.GroupFixturePreparers(
- prepareForJavaTest,
- android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
- variables.NextReleaseHideFlaggedApi = proptools.BoolPtr(true)
- variables.ReleaseExposeFlaggedApi = proptools.BoolPtr(false)
- }),
- android.FixtureMergeMockFs(map[string][]byte{
- "a/A.java": nil,
- "a/current.txt": nil,
- "a/removed.txt": nil,
- }),
- ).RunTestWithBp(t, `
- droidstubs {
- name: "foo",
- srcs: ["a/A.java"],
- api_surface: "public",
- check_api: {
- current: {
- api_file: "a/current.txt",
- removed_api_file: "a/removed.txt",
- }
- },
- }
- `)
-
- m := result.ModuleForTests("foo", "android_common")
- manifest := m.Output("metalava.sbox.textproto")
- cmdline := String(android.RuleBuilderSboxProtoForTests(t, manifest).Commands[0].Command)
- android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "--hide-annotation android.annotation.FlaggedApi")
-}
diff --git a/java/java.go b/java/java.go
index bf692be24..cac49a2c5 100644
--- a/java/java.go
+++ b/java/java.go
@@ -278,6 +278,9 @@ type JavaInfo struct {
// SrcJarDeps is a list of paths to depend on when packaging the sources of this module.
SrcJarDeps android.Paths
+ // The source files of this module and all its transitive static dependencies.
+ TransitiveSrcFiles *android.DepSet[android.Path]
+
// ExportedPlugins is a list of paths that should be used as annotation processors for any
// module that depends on this module.
ExportedPlugins android.Paths
diff --git a/java/java_test.go b/java/java_test.go
index b555a9513..d51604a25 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -2263,6 +2263,28 @@ func TestJavaApiLibraryFullApiSurfaceStub(t *testing.T) {
android.AssertStringDoesContain(t, "Command expected to contain full_api_surface_stub output jar", manifestCommand, "lib1.jar")
}
+func TestTransitiveSrcFiles(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_library {
+ name: "a",
+ srcs: ["a.java"],
+ }
+ java_library {
+ name: "b",
+ srcs: ["b.java"],
+ }
+ java_library {
+ name: "c",
+ srcs: ["c.java"],
+ libs: ["a"],
+ static_libs: ["b"],
+ }
+ `)
+ c := ctx.ModuleForTests("c", "android_common").Module()
+ transitiveSrcFiles := android.Paths(ctx.ModuleProvider(c, JavaInfoProvider).(JavaInfo).TransitiveSrcFiles.ToList())
+ android.AssertArrayString(t, "unexpected jar deps", []string{"b.java", "c.java"}, transitiveSrcFiles.Strings())
+}
+
func TestTradefedOptions(t *testing.T) {
result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
java_test_host {
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index ade739552..02a2298cd 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -57,6 +57,9 @@ type platformBootclasspathModule struct {
// Path to the monolithic hiddenapi-unsupported.csv file.
hiddenAPIMetadataCSV android.OutputPath
+
+ // Path to a srcjar containing all the transitive sources of the bootclasspath.
+ srcjar android.OutputPath
}
type platformBootclasspathProperties struct {
@@ -95,6 +98,8 @@ func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, er
return android.Paths{b.hiddenAPIIndexCSV}, nil
case "hiddenapi-metadata.csv":
return android.Paths{b.hiddenAPIMetadataCSV}, nil
+ case ".srcjar":
+ return android.Paths{b.srcjar}, nil
}
return nil, fmt.Errorf("unknown tag %s", tag)
@@ -173,6 +178,18 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo
allModules = append(allModules, apexModules...)
b.configuredModules = allModules
+ var transitiveSrcFiles android.Paths
+ for _, module := range allModules {
+ depInfo := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
+ if depInfo.TransitiveSrcFiles != nil {
+ transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...)
+ }
+ }
+ jarArgs := resourcePathsToJarArgs(transitiveSrcFiles)
+ jarArgs = append(jarArgs, "-srcjar") // Move srcfiles to the right package
+ b.srcjar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-transitive.srcjar").OutputPath
+ TransformResourcesToJar(ctx, b.srcjar, jarArgs, transitiveSrcFiles)
+
// Gather all the fragments dependencies.
b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go
index ff2da4bb2..37ff6395c 100644
--- a/java/platform_bootclasspath_test.go
+++ b/java/platform_bootclasspath_test.go
@@ -81,6 +81,15 @@ func TestPlatformBootclasspath(t *testing.T) {
RunTest(t)
})
+ fooSourceSrc := "source/a.java"
+ barSrc := "a.java"
+
+ checkSrcJarInputs := func(t *testing.T, result *android.TestResult, name string, expected []string) {
+ t.Helper()
+ srcjar := result.ModuleForTests(name, "android_common").Output(name + "-transitive.srcjar")
+ android.AssertStringDoesContain(t, "srcjar arg", srcjar.Args["jarArgs"], "-srcjar")
+ android.AssertArrayString(t, "srcjar inputs", expected, srcjar.Implicits.Strings())
+ }
t.Run("source", func(t *testing.T) {
result := android.GroupFixturePreparers(
preparer,
@@ -91,6 +100,10 @@ func TestPlatformBootclasspath(t *testing.T) {
"platform:foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ fooSourceSrc,
+ barSrc,
+ })
})
t.Run("prebuilt", func(t *testing.T) {
@@ -103,6 +116,10 @@ func TestPlatformBootclasspath(t *testing.T) {
"platform:prebuilt_foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ // TODO(b/151360309): This should also have the srcs for prebuilt_foo
+ barSrc,
+ })
})
t.Run("source+prebuilt - source preferred", func(t *testing.T) {
@@ -116,6 +133,10 @@ func TestPlatformBootclasspath(t *testing.T) {
"platform:foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ fooSourceSrc,
+ barSrc,
+ })
})
t.Run("source+prebuilt - prebuilt preferred", func(t *testing.T) {
@@ -129,6 +150,10 @@ func TestPlatformBootclasspath(t *testing.T) {
"platform:prebuilt_foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ // TODO(b/151360309): This should also have the srcs for prebuilt_foo
+ barSrc,
+ })
})
t.Run("dex import", func(t *testing.T) {
@@ -146,6 +171,10 @@ func TestPlatformBootclasspath(t *testing.T) {
"platform:prebuilt_foo",
"platform:bar",
})
+ checkSrcJarInputs(t, result, "platform-bootclasspath", []string{
+ // TODO(b/151360309): This should also have the srcs for prebuilt_foo
+ barSrc,
+ })
})
}