Make container mandatory in aconfig_declarations.

Bug: 330354107
Test: Unit test and CI.

Ignore-AOSP-First: It is easier to detect all the missing ones in internal
master.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e916a2c758d2a95037d1d366e7cd0e10d241d510)
Merged-In: I4ab4271c67a35d0fdcc0b57c27260e29fb7dea56
Change-Id: I4ab4271c67a35d0fdcc0b57c27260e29fb7dea56
This commit is contained in:
Yu Liu 2024-04-24 16:41:57 +00:00 committed by Android Build Cherrypicker Worker
parent b39c877ae0
commit 315a53c5cb
13 changed files with 126 additions and 20 deletions

View file

@ -73,8 +73,9 @@ func (module *DeclarationsModule) DepsMutator(ctx android.BottomUpMutatorContext
if len(module.properties.Package) == 0 { if len(module.properties.Package) == 0 {
ctx.PropertyErrorf("package", "missing package property") ctx.PropertyErrorf("package", "missing package property")
} }
// TODO(b/311155208): Add mandatory check for container after all pre-existing if len(module.properties.Container) == 0 {
// ones are changed. ctx.PropertyErrorf("container", "missing container property")
}
// Add a dependency on the aconfig_value_sets defined in // Add a dependency on the aconfig_value_sets defined in
// RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that // RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that

View file

@ -88,19 +88,49 @@ func TestAconfigDeclarationsWithContainer(t *testing.T) {
android.AssertStringEquals(t, "rule must contain container", rule.Args["container"], "--container com.android.foo") android.AssertStringEquals(t, "rule must contain container", rule.Args["container"], "--container com.android.foo")
} }
func TestAconfigDeclarationsWithoutContainer(t *testing.T) { func TestMandatoryProperties(t *testing.T) {
bp := ` testCases := []struct {
aconfig_declarations { name string
name: "module_name", expectedError string
package: "com.example.package", bp string
srcs: [ }{
"foo.aconfig", {
], name: "Srcs missing from aconfig_declarations",
} bp: `
` aconfig_declarations {
result := runTest(t, android.FixtureExpectsNoErrors, bp) name: "my_aconfig_declarations_foo",
package: "com.example.package",
module := result.ModuleForTests("module_name", "") container: "otherapex",
rule := module.Rule("aconfig") }`,
android.AssertIntEquals(t, "rule must not contain container", len(rule.Args["container"]), 0) expectedError: `missing source files`,
},
{
name: "Package missing from aconfig_declarations",
bp: `
aconfig_declarations {
name: "my_aconfig_declarations_foo",
container: "otherapex",
srcs: ["foo.aconfig"],
}`,
expectedError: `missing package property`,
},
{
name: "Container missing from aconfig_declarations",
bp: `
aconfig_declarations {
name: "my_aconfig_declarations_foo",
package: "com.example.package",
srcs: ["foo.aconfig"],
}`,
expectedError: `missing container property`,
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError)
android.GroupFixturePreparers(PrepareForTestWithAconfigBuildComponents).
ExtendWithErrorHandler(errorHandler).
RunTestWithBp(t, test.bp)
})
}
} }

View file

@ -15,9 +15,10 @@
package codegen package codegen
import ( import (
"testing"
"android/soong/android" "android/soong/android"
"android/soong/java" "android/soong/java"
"testing"
) )
func TestAconfigDeclarationsGroup(t *testing.T) { func TestAconfigDeclarationsGroup(t *testing.T) {
@ -28,6 +29,7 @@ func TestAconfigDeclarationsGroup(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "foo-aconfig", name: "foo-aconfig",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
@ -39,6 +41,7 @@ func TestAconfigDeclarationsGroup(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar-aconfig", name: "bar-aconfig",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }

View file

@ -50,6 +50,7 @@ func testCCCodegenModeHelper(t *testing.T, bpMode string, ruleMode string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
@ -112,6 +113,7 @@ func testIncorrectCCCodegenModeHelper(t *testing.T, bpMode string, err string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
@ -167,6 +169,7 @@ func TestAndroidMkCcLibrary(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations_bar", name: "my_aconfig_declarations_bar",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["bar.aconfig"], srcs: ["bar.aconfig"],
} }
@ -241,6 +244,7 @@ func TestForceReadOnly(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }

View file

@ -35,6 +35,7 @@ func runJavaAndroidMkTest(t *testing.T, bp string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations_foo", name: "my_aconfig_declarations_foo",
package: "com.example.package.foo", package: "com.example.package.foo",
container: "system",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
@ -46,6 +47,7 @@ func runJavaAndroidMkTest(t *testing.T, bp string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations_bar", name: "my_aconfig_declarations_bar",
package: "com.example.package.bar", package: "com.example.package.bar",
container: "system",
srcs: ["bar.aconfig"], srcs: ["bar.aconfig"],
} }
@ -60,7 +62,7 @@ func runJavaAndroidMkTest(t *testing.T, bp string) {
entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0] entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]
makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"] makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"]
android.EnsureListContainsSuffix(t, makeVar, "android_common/aconfig_merged.pb") android.EnsureListContainsSuffix(t, makeVar, "android_common/system/aconfig_merged.pb")
} }
func TestAndroidMkJavaLibrary(t *testing.T) { func TestAndroidMkJavaLibrary(t *testing.T) {
@ -175,6 +177,7 @@ func testCodegenMode(t *testing.T, bpMode string, ruleMode string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
exportable: true, exportable: true,
} }
@ -200,6 +203,7 @@ func testCodegenModeWithError(t *testing.T, bpMode string, err string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
@ -234,3 +238,52 @@ func TestForceReadOnlyMode(t *testing.T) {
func TestUnsupportedMode(t *testing.T) { func TestUnsupportedMode(t *testing.T) {
testCodegenModeWithError(t, "mode: `unsupported`,", "mode: \"unsupported\" is not a supported mode") testCodegenModeWithError(t, "mode: `unsupported`,", "mode: \"unsupported\" is not a supported mode")
} }
func TestMkEntriesMatchedContainer(t *testing.T) {
result := android.GroupFixturePreparers(
PrepareForTestWithAconfigBuildComponents,
java.PrepareForTestWithJavaDefaultModules).
ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
RunTestWithBp(t, `
aconfig_declarations {
name: "my_aconfig_declarations_foo",
package: "com.example.package.foo",
container: "system",
srcs: ["foo.aconfig"],
}
java_aconfig_library {
name: "my_java_aconfig_library_foo",
aconfig_declarations: "my_aconfig_declarations_foo",
}
aconfig_declarations {
name: "my_aconfig_declarations_bar",
package: "com.example.package.bar",
container: "system_ext",
srcs: ["bar.aconfig"],
}
java_aconfig_library {
name: "my_java_aconfig_library_bar",
aconfig_declarations: "my_aconfig_declarations_bar",
}
java_library {
name: "my_module",
srcs: [
"src/foo.java",
],
static_libs: [
"my_java_aconfig_library_foo",
"my_java_aconfig_library_bar",
],
platform_apis: true,
}
`)
module := result.ModuleForTests("my_module", "android_common").Module()
entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]
makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"]
android.EnsureListContainsSuffix(t, makeVar, "my_aconfig_declarations_foo/intermediate.pb")
}

View file

@ -46,6 +46,7 @@ func TestRustAconfigLibrary(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
@ -131,6 +132,7 @@ func testRustCodegenModeHelper(t *testing.T, bpMode string, ruleMode string) {
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
rust_aconfig_library { rust_aconfig_library {
@ -193,6 +195,7 @@ func testIncorrectRustCodegenModeHelper(t *testing.T, bpMode string, err string)
aconfig_declarations { aconfig_declarations {
name: "my_aconfig_declarations", name: "my_aconfig_declarations",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: ["foo.aconfig"], srcs: ["foo.aconfig"],
} }
rust_aconfig_library { rust_aconfig_library {

View file

@ -11425,6 +11425,7 @@ func TestAconfifDeclarationsValidation(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "%[1]s", name: "%[1]s",
package: "com.example.package", package: "com.example.package",
container: "system",
srcs: [ srcs: [
"%[1]s.aconfig", "%[1]s.aconfig",
], ],

View file

@ -15,8 +15,9 @@
package java package java
import ( import (
"android/soong/android"
"testing" "testing"
"android/soong/android"
) )
func TestAarImportProducesJniPackages(t *testing.T) { func TestAarImportProducesJniPackages(t *testing.T) {
@ -98,6 +99,7 @@ func TestLibraryFlagsPackages(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package.bar", package: "com.example.package.bar",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],
@ -105,6 +107,7 @@ func TestLibraryFlagsPackages(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "baz", name: "baz",
package: "com.example.package.baz", package: "com.example.package.baz",
container: "com.android.foo",
srcs: [ srcs: [
"baz.aconfig", "baz.aconfig",
], ],

View file

@ -4382,6 +4382,7 @@ func TestAppFlagsPackages(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package.bar", package: "com.example.package.bar",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],
@ -4389,6 +4390,7 @@ func TestAppFlagsPackages(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "baz", name: "baz",
package: "com.example.package.baz", package: "com.example.package.baz",
container: "com.android.foo",
srcs: [ srcs: [
"baz.aconfig", "baz.aconfig",
], ],

View file

@ -379,6 +379,7 @@ func TestAconfigDeclarations(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],
@ -434,6 +435,7 @@ func TestReleaseExportRuntimeApis(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],

View file

@ -2801,6 +2801,7 @@ func TestApiLibraryAconfigDeclarations(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],

View file

@ -421,6 +421,7 @@ func TestRuntimeResourceOverlayFlagsPackages(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package.bar", package: "com.example.package.bar",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],
@ -428,6 +429,7 @@ func TestRuntimeResourceOverlayFlagsPackages(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "baz", name: "baz",
package: "com.example.package.baz", package: "com.example.package.baz",
container: "com.android.foo",
srcs: [ srcs: [
"baz.aconfig", "baz.aconfig",
], ],

View file

@ -1715,6 +1715,7 @@ func TestSdkLibraryExportableStubsLibrary(t *testing.T) {
aconfig_declarations { aconfig_declarations {
name: "bar", name: "bar",
package: "com.example.package", package: "com.example.package",
container: "com.android.foo",
srcs: [ srcs: [
"bar.aconfig", "bar.aconfig",
], ],