Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e73f9ee authored by Anton Hansson's avatar Anton Hansson
Browse files

Collect transitive source files for java modules

This new entry in the JavaInfoProvider lists all the transitive source
files contained within the library. That is, the source files of the
module and all its static dependencies.

Bug: 151360309
Test: unit test in java_go + some manual testing
Change-Id: I7fe3035b9e46774095c0e9196cd77fa1027adf6d
parent 2863e453
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -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
@@ -1687,6 +1690,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
		j.linter.lint(ctx)
	}

	j.collectTransitiveSrcFiles(ctx, srcFiles)

	ctx.CheckbuildFile(outputFile)

	j.collectTransitiveAconfigFiles(ctx)
@@ -1701,6 +1706,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,
@@ -2025,6 +2031,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)
}
+3 −0
Original line number Diff line number Diff line
@@ -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
+22 −0
Original line number Diff line number Diff line
@@ -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 {