Merge "Add dep_api_srcs property to java_api_library module" am: 91a86d4112
am: 6f8a62b72a
am: 22bd36e459
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2485976 Change-Id: I18de957424949775bfa3a6fec6534d37bb0d4f86 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
96
java/java.go
96
java/java.go
@@ -388,6 +388,8 @@ var (
|
||||
jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true}
|
||||
r8LibraryJarTag = dependencyTag{name: "r8-libraryjar", runtimeLinked: true}
|
||||
syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
|
||||
javaApiContributionTag = dependencyTag{name: "java-api-contribution"}
|
||||
depApiSrcsTag = dependencyTag{name: "dep-api-srcs"}
|
||||
jniInstallTag = installDependencyTag{name: "jni install"}
|
||||
binaryInstallTag = installDependencyTag{name: "binary install"}
|
||||
usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false)
|
||||
@@ -1608,6 +1610,13 @@ func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleCon
|
||||
})
|
||||
}
|
||||
|
||||
type JavaApiLibraryDepsInfo struct {
|
||||
StubsJar android.Path
|
||||
StubsSrcJar android.Path
|
||||
}
|
||||
|
||||
var JavaApiLibraryDepsProvider = blueprint.NewProvider(JavaApiLibraryDepsInfo{})
|
||||
|
||||
type ApiLibrary struct {
|
||||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
@@ -1617,8 +1626,10 @@ type ApiLibrary struct {
|
||||
|
||||
properties JavaApiLibraryProperties
|
||||
|
||||
stubsSrcJar android.WritablePath
|
||||
stubsJar android.WritablePath
|
||||
stubsSrcJar android.WritablePath
|
||||
stubsJar android.WritablePath
|
||||
stubsJarWithoutStaticLibs android.WritablePath
|
||||
extractedSrcJar android.WritablePath
|
||||
// .dex of stubs, used for hiddenapi processing
|
||||
dexJarFile OptionalDexJarPath
|
||||
}
|
||||
@@ -1644,8 +1655,13 @@ type JavaApiLibraryProperties struct {
|
||||
Libs []string
|
||||
|
||||
// List of java libs that this module has static dependencies to and will be
|
||||
// passed in metalava invocation
|
||||
// merge zipped after metalava invocation
|
||||
Static_libs []string
|
||||
|
||||
// Java Api library to provide the full API surface text files and jar file.
|
||||
// If this property is set, the provided full API surface text files and
|
||||
// jar file are passed to metalava invocation.
|
||||
Dep_api_srcs *string
|
||||
}
|
||||
|
||||
func ApiLibraryFactory() android.Module {
|
||||
@@ -1724,7 +1740,36 @@ func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBui
|
||||
}
|
||||
}
|
||||
|
||||
var javaApiContributionTag = dependencyTag{name: "java-api-contribution"}
|
||||
// This method extracts the stub java files from the srcjar file provided from dep_api_srcs module
|
||||
// and replaces the java stubs generated by invoking metalava in this module.
|
||||
// This method is used because metalava can generate compilable from-text stubs only when
|
||||
// the codebase encompasses all classes listed in the input API text file, but a class can extend
|
||||
// a class that is not within the same API domain.
|
||||
func (al *ApiLibrary) extractApiSrcs(ctx android.ModuleContext, rule *android.RuleBuilder, stubsDir android.OptionalPath, depApiSrcsSrcJar android.Path) {
|
||||
generatedStubsList := android.PathForModuleOut(ctx, "metalava", "sources.txt")
|
||||
unzippedSrcJarDir := android.PathForModuleOut(ctx, "metalava", "unzipDir")
|
||||
|
||||
rule.Command().
|
||||
BuiltTool("list_files").
|
||||
Text(stubsDir.String()).
|
||||
FlagWithOutput("--out ", generatedStubsList).
|
||||
FlagWithArg("--extensions ", ".java").
|
||||
FlagWithArg("--root ", unzippedSrcJarDir.String())
|
||||
|
||||
rule.Command().
|
||||
Text("unzip").
|
||||
Flag("-q").
|
||||
Input(depApiSrcsSrcJar).
|
||||
FlagWithArg("-d ", unzippedSrcJarDir.String())
|
||||
|
||||
rule.Command().
|
||||
BuiltTool("soong_zip").
|
||||
Flag("-srcjar").
|
||||
Flag("-write_if_changed").
|
||||
FlagWithArg("-C ", unzippedSrcJarDir.String()).
|
||||
FlagWithInput("-l ", generatedStubsList).
|
||||
FlagWithOutput("-o ", al.stubsSrcJar)
|
||||
}
|
||||
|
||||
func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
apiContributions := al.properties.Api_contributions
|
||||
@@ -1733,6 +1778,9 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...)
|
||||
ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...)
|
||||
if al.properties.Dep_api_srcs != nil {
|
||||
ctx.AddVariationDependencies(nil, depApiSrcsTag, String(al.properties.Dep_api_srcs))
|
||||
}
|
||||
}
|
||||
|
||||
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
@@ -1753,6 +1801,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
var srcFiles android.Paths
|
||||
var classPaths android.Paths
|
||||
var staticLibs android.Paths
|
||||
var depApiSrcsStubsSrcJar android.Path
|
||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||
tag := ctx.OtherModuleDependencyTag(dep)
|
||||
switch tag {
|
||||
@@ -1769,6 +1818,10 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
case staticLibTag:
|
||||
provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
|
||||
staticLibs = append(staticLibs, provider.HeaderJars...)
|
||||
case depApiSrcsTag:
|
||||
provider := ctx.OtherModuleProvider(dep, JavaApiLibraryDepsProvider).(JavaApiLibraryDepsInfo)
|
||||
classPaths = append(classPaths, provider.StubsJar)
|
||||
depApiSrcsStubsSrcJar = provider.StubsSrcJar
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1779,21 +1832,31 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
srcFiles = append(srcFiles, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), api))
|
||||
}
|
||||
|
||||
if srcFiles == nil {
|
||||
ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())
|
||||
}
|
||||
|
||||
cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir)
|
||||
|
||||
al.stubsFlags(ctx, cmd, stubsDir)
|
||||
|
||||
al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar")
|
||||
rule.Command().
|
||||
BuiltTool("soong_zip").
|
||||
Flag("-write_if_changed").
|
||||
Flag("-jar").
|
||||
FlagWithOutput("-o ", al.stubsSrcJar).
|
||||
FlagWithArg("-C ", stubsDir.String()).
|
||||
FlagWithArg("-D ", stubsDir.String())
|
||||
|
||||
if depApiSrcsStubsSrcJar != nil {
|
||||
al.extractApiSrcs(ctx, rule, stubsDir, depApiSrcsStubsSrcJar)
|
||||
} else {
|
||||
rule.Command().
|
||||
BuiltTool("soong_zip").
|
||||
Flag("-write_if_changed").
|
||||
Flag("-jar").
|
||||
FlagWithOutput("-o ", al.stubsSrcJar).
|
||||
FlagWithArg("-C ", stubsDir.String()).
|
||||
FlagWithArg("-D ", stubsDir.String())
|
||||
}
|
||||
|
||||
rule.Build("metalava", "metalava merged")
|
||||
compiledStubs := android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar")
|
||||
|
||||
al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar")
|
||||
al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName()))
|
||||
|
||||
var flags javaBuilderFlags
|
||||
@@ -1801,14 +1864,14 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
flags.javacFlags = strings.Join(al.properties.Javacflags, " ")
|
||||
flags.classpath = classpath(classPaths)
|
||||
|
||||
TransformJavaToClasses(ctx, compiledStubs, 0, android.Paths{},
|
||||
TransformJavaToClasses(ctx, al.stubsJarWithoutStaticLibs, 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(android.Paths{al.stubsJarWithoutStaticLibs}).
|
||||
Inputs(staticLibs)
|
||||
builder.Build("merge_zips", "merge jar files")
|
||||
|
||||
@@ -1834,6 +1897,11 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
ImplementationJars: android.PathsIfNonNil(al.stubsJar),
|
||||
AidlIncludeDirs: android.Paths{},
|
||||
})
|
||||
|
||||
ctx.SetProvider(JavaApiLibraryDepsProvider, JavaApiLibraryDepsInfo{
|
||||
StubsJar: al.stubsJar,
|
||||
StubsSrcJar: al.stubsSrcJar,
|
||||
})
|
||||
}
|
||||
|
||||
func (al *ApiLibrary) DexJarBuildPath() OptionalDexJarPath {
|
||||
|
Reference in New Issue
Block a user