Do not allow duplicate deapexer dependencies.

Without these errors, the last encountered deapexer would silently be
used, and we wouldn't know if it was taken from the prebuilt APEX that
actually get installed in the system image.

With this error check there may be only one enabled prebuilt_apex or
apex_set for each apex_name (which defaults to the module name). E.g.
if there are both prebuilt com.android.foo and com.google.android.foo,
it is necessary to disable one of them in the .bp file.

Merged-In is set from https://r.android.com/1745454, a change that has
gone into AOSP and internal master, as well as sc-dev-plus-aosp, but
specifically not sc-dev. This change cannot merge into sc-dev-plus-aosp
and others, because they may or may not have the com.google.android.art
prebuilt APEX present depending on manifest, and with this check
exactly one of com.android.art and com.google.android.art prebuilts has
to be present and enabled. It'll be cherry-picked to AOSP along with a
full fix for b/192006406, when it can be safely enabled everywhere.

Test: m nothing SOONG_CONFIG_art_module_source_build=false
Test: m nothing SOONG_CONFIG_art_module_source_build=true
Test: m nothing
  with enabled:true for the com.android.art prebuilt APEX - check that
  it fails with an "ambiguous duplicate deapexer" error
Bug: 192006406
Bug: 192542393
Change-Id: I44566fd26b12f82a8a67fe4a69e56303460756d0
Merged-In: Id2410b4e38a78ec2146a42298840954381a7c472
This commit is contained in:
Martin Stjernholm 2021-06-30 16:35:07 +01:00
parent e6e499b3eb
commit 95994067b1
4 changed files with 82 additions and 3 deletions

View File

@ -6568,6 +6568,73 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.F
return result.TestContext
}
func TestDuplicateDeapexeresFromPrebuiltApexes(t *testing.T) {
preparers := android.GroupFixturePreparers(
java.PrepareForTestWithJavaDefaultModules,
PrepareForTestWithApexBuildComponents,
).
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
`Ambiguous duplicate deapexer module dependencies "com.android.myapex.deapexer" and "com.mycompany.android.myapex.deapexer"`))
bpBase := `
apex_set {
name: "com.android.myapex",
exported_bootclasspath_fragments: ["my-bootclasspath-fragment"],
set: "myapex.apks",
}
apex_set {
name: "com.mycompany.android.myapex",
apex_name: "com.android.myapex",
exported_bootclasspath_fragments: ["my-bootclasspath-fragment"],
set: "company-myapex.apks",
}
prebuilt_bootclasspath_fragment {
name: "my-bootclasspath-fragment",
apex_available: ["com.android.myapex"],
%s
}
`
t.Run("java_import", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+`
java_import {
name: "libfoo",
jars: ["libfoo.jar"],
apex_available: ["com.android.myapex"],
}
`)
})
t.Run("java_sdk_library_import", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+`
java_sdk_library_import {
name: "libfoo",
public: {
jars: ["libbar.jar"],
},
apex_available: ["com.android.myapex"],
}
`)
})
t.Run("prebuilt_bootclasspath_fragment", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `
image_name: "art",
contents: ["libfoo"],
`)+`
java_sdk_library_import {
name: "libfoo",
public: {
jars: ["libbar.jar"],
},
apex_available: ["com.android.myapex"],
}
`)
})
}
func TestUpdatable_should_set_min_sdk_version(t *testing.T) {
testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, `
apex {

View File

@ -933,11 +933,15 @@ func (module *prebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
}
var deapexerModule android.Module
ctx.VisitDirectDeps(func(module android.Module) {
tag := ctx.OtherModuleDependencyTag(module)
ctx.VisitDirectDeps(func(to android.Module) {
tag := ctx.OtherModuleDependencyTag(to)
// Save away the `deapexer` module on which this depends, if any.
if tag == android.DeapexerTag {
deapexerModule = module
if deapexerModule != nil {
ctx.ModuleErrorf("Ambiguous duplicate deapexer module dependencies %q and %q",
deapexerModule.Name(), to.Name())
}
deapexerModule = to
}
})

View File

@ -1283,6 +1283,10 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Save away the `deapexer` module on which this depends, if any.
if tag == android.DeapexerTag {
if deapexerModule != nil {
ctx.ModuleErrorf("Ambiguous duplicate deapexer module dependencies %q and %q",
deapexerModule.Name(), module.Name())
}
deapexerModule = module
}
})

View File

@ -2160,6 +2160,10 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
// Save away the `deapexer` module on which this depends, if any.
if tag == android.DeapexerTag {
if deapexerModule != nil {
ctx.ModuleErrorf("Ambiguous duplicate deapexer module dependencies %q and %q",
deapexerModule.Name(), to.Name())
}
deapexerModule = to
}
})