Add static_libs property in java_api_library soong module
Package private stub annotations are not part of any API surfaces, but are included in the `android_<API_SURFACE_NAME>_stubs_current`. Since these cannot be included in the java_api_library by api_contributions, add static_libs property to statically include jars in the output jar file. Test: m Change-Id: Icb4401f29079ba32df4c192943a7e8814599d9ba
This commit is contained in:
parent
d48abd566b
commit
e30fff0b5c
2 changed files with 93 additions and 2 deletions
21
java/java.go
21
java/java.go
|
@ -1633,6 +1633,10 @@ type JavaApiLibraryProperties struct {
|
|||
// List of shared java libs that this module has dependencies to and
|
||||
// should be passed as classpath in javac invocation
|
||||
Libs []string
|
||||
|
||||
// List of java libs that this module has static dependencies to and will be
|
||||
// passed in metalava invocation
|
||||
Static_libs []string
|
||||
}
|
||||
|
||||
func ApiLibraryFactory() android.Module {
|
||||
|
@ -1705,6 +1709,7 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||
ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName)
|
||||
}
|
||||
ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...)
|
||||
ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...)
|
||||
}
|
||||
|
||||
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
|
@ -1724,6 +1729,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
|
||||
var srcFiles android.Paths
|
||||
var classPaths android.Paths
|
||||
var staticLibs android.Paths
|
||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||
tag := ctx.OtherModuleDependencyTag(dep)
|
||||
switch tag {
|
||||
|
@ -1737,6 +1743,9 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
case libTag:
|
||||
provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
|
||||
classPaths = append(classPaths, provider.HeaderJars...)
|
||||
case staticLibTag:
|
||||
provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
|
||||
staticLibs = append(staticLibs, provider.HeaderJars...)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1761,7 +1770,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
FlagWithArg("-D ", stubsDir.String())
|
||||
|
||||
rule.Build("metalava", "metalava merged")
|
||||
|
||||
compiledStubs := android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar")
|
||||
al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), "android.jar")
|
||||
|
||||
var flags javaBuilderFlags
|
||||
|
@ -1769,9 +1778,17 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
flags.javacFlags = strings.Join(al.properties.Javacflags, " ")
|
||||
flags.classpath = classpath(classPaths)
|
||||
|
||||
TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{},
|
||||
TransformJavaToClasses(ctx, compiledStubs, 0, android.Paths{},
|
||||
android.Paths{al.stubsSrcJar}, flags, android.Paths{})
|
||||
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
builder.Command().
|
||||
BuiltTool("merge_zips").
|
||||
Output(al.stubsJar).
|
||||
Inputs(android.Paths{compiledStubs}).
|
||||
Inputs(staticLibs)
|
||||
builder.Build("merge_zips", "merge jar files")
|
||||
|
||||
ctx.Phony(ctx.ModuleName(), al.stubsJar)
|
||||
|
||||
ctx.SetProvider(JavaInfoProvider, JavaInfo{
|
||||
|
|
|
@ -2128,6 +2128,80 @@ func TestJavaApiLibraryLibsLink(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestJavaApiLibraryStaticLibsLink(t *testing.T) {
|
||||
provider_bp_a := `
|
||||
java_api_contribution {
|
||||
name: "foo1",
|
||||
api_file: "foo1.txt",
|
||||
}
|
||||
`
|
||||
provider_bp_b := `
|
||||
java_api_contribution {
|
||||
name: "foo2",
|
||||
api_file: "foo2.txt",
|
||||
}
|
||||
`
|
||||
lib_bp_a := `
|
||||
java_library {
|
||||
name: "lib1",
|
||||
srcs: ["Lib.java"],
|
||||
}
|
||||
`
|
||||
lib_bp_b := `
|
||||
java_library {
|
||||
name: "lib2",
|
||||
srcs: ["Lib.java"],
|
||||
}
|
||||
`
|
||||
|
||||
ctx, _ := testJavaWithFS(t, `
|
||||
java_api_library {
|
||||
name: "bar1",
|
||||
api_surface: "public",
|
||||
api_contributions: ["foo1"],
|
||||
static_libs: ["lib1"],
|
||||
}
|
||||
|
||||
java_api_library {
|
||||
name: "bar2",
|
||||
api_surface: "system",
|
||||
api_contributions: ["foo1", "foo2"],
|
||||
static_libs: ["lib1", "lib2", "bar1"],
|
||||
}
|
||||
`,
|
||||
map[string][]byte{
|
||||
"a/Android.bp": []byte(provider_bp_a),
|
||||
"b/Android.bp": []byte(provider_bp_b),
|
||||
"c/Android.bp": []byte(lib_bp_a),
|
||||
"c/Lib.java": {},
|
||||
"d/Android.bp": []byte(lib_bp_b),
|
||||
"d/Lib.java": {},
|
||||
})
|
||||
|
||||
testcases := []struct {
|
||||
moduleName string
|
||||
staticLibJarNames []string
|
||||
}{
|
||||
{
|
||||
moduleName: "bar1",
|
||||
staticLibJarNames: []string{"lib1.jar"},
|
||||
},
|
||||
{
|
||||
moduleName: "bar2",
|
||||
staticLibJarNames: []string{"lib1.jar", "lib2.jar", "bar1/android.jar"},
|
||||
},
|
||||
}
|
||||
for _, c := range testcases {
|
||||
m := ctx.ModuleForTests(c.moduleName, "android_common")
|
||||
mergeZipsCommand := m.Rule("merge_zips").RuleParams.Command
|
||||
for _, jarName := range c.staticLibJarNames {
|
||||
if !strings.Contains(mergeZipsCommand, jarName) {
|
||||
t.Errorf("merge_zips command does not contain expected jar %s", jarName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTradefedOptions(t *testing.T) {
|
||||
result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
|
||||
java_test_host {
|
||||
|
|
Loading…
Reference in a new issue