// query all_apex_contributions to see if any module in this family has been selected
for_,moduleInFamily:=rangeallModulesInFamily{
// validate that are no duplicates
ifpsi.IsSelected(moduleInFamily.Name()){
ifselectedModuleInFamily==nil{
// Store this so we can validate that there are no duplicates
selectedModuleInFamily=moduleInFamily
}else{
// There are duplicate modules from the same mainline module family
ctx.ModuleErrorf("Found duplicate variations of the same module in apex_contributions: %s and %s. Please remove one of these.\n",selectedModuleInFamily.Name(),moduleInFamily.Name())
}
}
}
// If a module has been selected, hide all other modules
testPrebuiltErrorWithFixture(t,`Cannot use Soong module: prebuilt_foo from apex_contributions: my_apex_contributions because it has been added previously as: foo from apex_contributions: my_apex_contributions`,`
testPrebuiltErrorWithFixture(t,`Found duplicate variations of the same module in apex_contributions: foo and prebuilt_foo. Please remove one of these`,`
android.AssertStringEquals(t,"LOCAL_MODULE of the prebuilt apex must match the name listed in PRODUCT_PACKAGES",expectedLocalModuleName,entries[0].EntryMap["LOCAL_MODULE"][0])
}
// for a mainline module family, check that only the flagged soong module is visible to make
android.AssertBoolEquals(t,"Apex "+visibleModuleName+" selected using apex_contributions should be visible to make",false,visibleModule.IsHideFromMake())
android.AssertBoolEquals(t,"Apex "+hiddenModuleName+" not selected using apex_contributions should be hidden from make",true,hiddenModule.IsHideFromMake())
}
}
bp:=`
apex_key {
name: "com.android.foo.key",
public_key: "com.android.foo.avbpubkey",
private_key: "com.android.foo.pem",
}
// AOSP source apex
apex {
name: "com.android.foo",
key: "com.android.foo.key",
updatable: false,
}
// Google source apex
override_apex {
name: "com.google.android.foo",
base: "com.android.foo",
key: "com.android.foo.key",
}
// Prebuilt Google APEX.
prebuilt_apex {
name: "com.google.android.foo",
apex_name: "com.android.foo",
src: "com.android.foo-arm.apex",
prefer: true, // prefer is set to true on both the prebuilts to induce an error if flagging is not present
}
// Another Prebuilt Google APEX
prebuilt_apex {
name: "com.google.android.foo.v2",
apex_name: "com.android.foo",
source_apex_name: "com.google.android.foo", // source_apex_name becomes LOCAL_MODULE in the generated mk file
src: "com.android.foo-arm.apex",
prefer: true, // prefer is set to true on both the prebuilts to induce an error if flagging is not present
}
// APEX contribution modules
apex_contributions {
name: "foo.source.contributions",
api_domain: "com.android.foo",
contents: ["com.google.android.foo"],
}
apex_contributions {
name: "foo.prebuilt.contributions",
api_domain: "com.android.foo",
contents: ["prebuilt_com.google.android.foo"],
}
apex_contributions {
name: "foo.prebuilt.v2.contributions",
api_domain: "com.android.foo",
contents: ["prebuilt_com.google.android.foo.v2"],
}
// This is an incompatible module because it selects multiple versions of the same mainline module
apex_contributions {
name: "foo.prebuilt.duplicate.contributions",
api_domain: "com.android.foo",
contents: [
"prebuilt_com.google.android.foo",
"prebuilt_com.google.android.foo.v2",
],
}
`
testCases:=[]struct{
descstring
selectedApexContributionsstring
expectedVisibleModuleNamestring
expectedHiddenModuleNames[]string
expectedErrorstring
}{
{
desc:"Source apex is selected, prebuilts should be hidden from make",
expectedError:"Found duplicate variations of the same module in apex_contributions: prebuilt_com.google.android.foo and prebuilt_com.google.android.foo.v2",