Disallow missing api source files for java_api_library module
The purpose of this change is to enable filegroups to be taken as inputs for `java_api_library` module `api_files` property. However, since android.MaybeExistentPathForSource() does not support this, it needs to be replaced with android.PathForModuleSrc(), which checks for the files' existence. Bug: 283006953 Test: go test ./java Change-Id: I8a7d7f200f900219cc17243194a4c26071329ee6
This commit is contained in:
@@ -1651,7 +1651,7 @@ type JavaApiLibraryProperties struct {
|
|||||||
// list of api.txt files relative to this directory that contribute to the
|
// list of api.txt files relative to this directory that contribute to the
|
||||||
// API surface.
|
// API surface.
|
||||||
// This is a list of relative paths
|
// This is a list of relative paths
|
||||||
Api_files []string
|
Api_files []string `android:"path"`
|
||||||
|
|
||||||
// List of flags to be passed to the javac compiler to generate jar file
|
// List of flags to be passed to the javac compiler to generate jar file
|
||||||
Javacflags []string
|
Javacflags []string
|
||||||
@@ -1833,9 +1833,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
|
|
||||||
// Add the api_files inputs
|
// Add the api_files inputs
|
||||||
for _, api := range al.properties.Api_files {
|
for _, api := range al.properties.Api_files {
|
||||||
// Use MaybeExistentPathForSource since the api file might not exist during analysis.
|
srcFiles = append(srcFiles, android.PathForModuleSrc(ctx, api))
|
||||||
// This will be provided by the orchestrator in the combined execution.
|
|
||||||
srcFiles = append(srcFiles, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), api))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if srcFiles == nil {
|
if srcFiles == nil {
|
||||||
|
@@ -2252,6 +2252,29 @@ func TestJavaApiLibraryDepApiSrcs(t *testing.T) {
|
|||||||
android.AssertStringDoesContain(t, "Command expected to contain output files list text file flag", manifestCommand, "--out __SBOX_SANDBOX_DIR__/out/sources.txt")
|
android.AssertStringDoesContain(t, "Command expected to contain output files list text file flag", manifestCommand, "--out __SBOX_SANDBOX_DIR__/out/sources.txt")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJavaApiLibraryFilegroupInput(t *testing.T) {
|
||||||
|
ctx, _ := testJavaWithFS(t, `
|
||||||
|
filegroup {
|
||||||
|
name: "default_current.txt",
|
||||||
|
srcs: ["current.txt"],
|
||||||
|
}
|
||||||
|
|
||||||
|
java_api_library {
|
||||||
|
name: "foo",
|
||||||
|
api_files: [":default_current.txt"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
map[string][]byte{
|
||||||
|
"current.txt": nil,
|
||||||
|
})
|
||||||
|
|
||||||
|
m := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
outputs := fmt.Sprint(m.AllOutputs())
|
||||||
|
if !strings.Contains(outputs, "foo/foo.jar") {
|
||||||
|
t.Errorf("Module output does not contain expected jar %s", "foo/foo.jar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTradefedOptions(t *testing.T) {
|
func TestTradefedOptions(t *testing.T) {
|
||||||
result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
|
result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
|
||||||
java_test_host {
|
java_test_host {
|
||||||
|
@@ -72,6 +72,11 @@ var prepareForTestWithFrameworkDeps = android.GroupFixturePreparers(
|
|||||||
defaultJavaDir + "/framework/aidl": nil,
|
defaultJavaDir + "/framework/aidl": nil,
|
||||||
// Needed for various deps defined in GatherRequiredDepsForTest()
|
// Needed for various deps defined in GatherRequiredDepsForTest()
|
||||||
defaultJavaDir + "/a.java": nil,
|
defaultJavaDir + "/a.java": nil,
|
||||||
|
defaultJavaDir + "/api/current.txt": nil,
|
||||||
|
defaultJavaDir + "/api/system-current.txt": nil,
|
||||||
|
defaultJavaDir + "/api/test-current.txt": nil,
|
||||||
|
defaultJavaDir + "/api/module-lib-current.txt": nil,
|
||||||
|
defaultJavaDir + "/api/system-server-current.txt": nil,
|
||||||
|
|
||||||
// Needed for R8 rules on apps
|
// Needed for R8 rules on apps
|
||||||
"build/make/core/proguard.flags": nil,
|
"build/make/core/proguard.flags": nil,
|
||||||
|
Reference in New Issue
Block a user