Add separate dependency tags for compat libs based on SDK version.

The version in the tag is the SDK version that in which compatibility
library was added as a separate libary. Using distinct tags makes it
possible to differentiate between dependencies for different SDK
versions (this will be needed in subsequent CLs).

Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Change-Id: I72296c05d6649e811ddc701aaeb84f91d1ba66cb
This commit is contained in:
Ulya Trafimovich 2020-10-07 15:11:32 +01:00
parent 46b3d5bd05
commit b521811d7b
2 changed files with 29 additions and 11 deletions

View file

@ -1962,8 +1962,9 @@ func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs
if hasFrameworkLibs { if hasFrameworkLibs {
// Dexpreopt needs paths to the dex jars of these libraries in order to construct // Dexpreopt needs paths to the dex jars of these libraries in order to construct
// class loader context for dex2oat. Add them as a dependency with a special tag. // class loader context for dex2oat. Add them as a dependency with a special tag.
ctx.AddVariationDependencies(nil, usesLibTag, dexpreopt.CompatUsesLibs...) ctx.AddVariationDependencies(nil, usesLibCompat29Tag, dexpreopt.CompatUsesLibs29...)
ctx.AddVariationDependencies(nil, usesLibTag, dexpreopt.OptionalCompatUsesLibs...) ctx.AddVariationDependencies(nil, usesLibCompat28Tag, dexpreopt.OptionalCompatUsesLibs28...)
ctx.AddVariationDependencies(nil, usesLibCompat30Tag, dexpreopt.OptionalCompatUsesLibs30...)
} }
} }
} }
@ -1981,14 +1982,16 @@ func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.Libr
usesLibPaths := make(dexpreopt.LibraryPaths) usesLibPaths := make(dexpreopt.LibraryPaths)
if !ctx.Config().UnbundledBuild() { if !ctx.Config().UnbundledBuild() {
ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) { ctx.VisitDirectDeps(func(m android.Module) {
dep := ctx.OtherModuleName(m) if _, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok {
if lib, ok := m.(Dependency); ok { dep := ctx.OtherModuleName(m)
usesLibPaths.AddLibraryPath(ctx, dep, lib.DexJarBuildPath(), lib.DexJarInstallPath()) if lib, ok := m.(Dependency); ok {
} else if ctx.Config().AllowMissingDependencies() { usesLibPaths.AddLibraryPath(ctx, dep, lib.DexJarBuildPath(), lib.DexJarInstallPath())
ctx.AddMissingDependencies([]string{dep}) } else if ctx.Config().AllowMissingDependencies() {
} else { ctx.AddMissingDependencies([]string{dep})
ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", dep) } else {
ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", dep)
}
} }
}) })
} }

View file

@ -547,6 +547,18 @@ type dependencyTag struct {
name string name string
} }
type usesLibraryDependencyTag struct {
dependencyTag
sdkVersion int // SDK version in which the library appared as a standalone library.
}
func makeUsesLibraryDependencyTag(sdkVersion int) usesLibraryDependencyTag {
return usesLibraryDependencyTag{
dependencyTag: dependencyTag{name: fmt.Sprintf("uses-library-%d", sdkVersion)},
sdkVersion: sdkVersion,
}
}
func IsJniDepTag(depTag blueprint.DependencyTag) bool { func IsJniDepTag(depTag blueprint.DependencyTag) bool {
return depTag == jniLibTag return depTag == jniLibTag
} }
@ -566,9 +578,12 @@ var (
proguardRaiseTag = dependencyTag{name: "proguard-raise"} proguardRaiseTag = dependencyTag{name: "proguard-raise"}
certificateTag = dependencyTag{name: "certificate"} certificateTag = dependencyTag{name: "certificate"}
instrumentationForTag = dependencyTag{name: "instrumentation_for"} instrumentationForTag = dependencyTag{name: "instrumentation_for"}
usesLibTag = dependencyTag{name: "uses-library"}
extraLintCheckTag = dependencyTag{name: "extra-lint-check"} extraLintCheckTag = dependencyTag{name: "extra-lint-check"}
jniLibTag = dependencyTag{name: "jnilib"} jniLibTag = dependencyTag{name: "jnilib"}
usesLibTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion)
usesLibCompat28Tag = makeUsesLibraryDependencyTag(28)
usesLibCompat29Tag = makeUsesLibraryDependencyTag(29)
usesLibCompat30Tag = makeUsesLibraryDependencyTag(30)
) )
func IsLibDepTag(depTag blueprint.DependencyTag) bool { func IsLibDepTag(depTag blueprint.DependencyTag) bool {