Generate android_certificate_directory

Previously, partners were required to add an
android_certificate_directory filegroup in their certificate
directories, and allowlist that BUILD file. Now, we generate the
filegroup automatically.

We're using a different name, generated_android_certificate_directory,
to avoid conflicts with already-checked-in filegroups.

Bug: 285777389
Test: b test //build/bazel/rules/apex/...
Change-Id: Ib1bde487acd79d58368faf0aad02ded0bcdaceb4
This commit is contained in:
Cole Faust
2023-09-12 10:07:07 -07:00
parent d753c2e53c
commit 6054cdf3b1
4 changed files with 141 additions and 78 deletions

View File

@@ -83,7 +83,8 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
testConfig := android.TestConfig("", make(map[string]string), "", make(map[string][]byte))
files, err := soongInjectionFiles(testConfig, CreateCodegenMetrics())
codegenCtx := NewCodegenContext(testConfig, android.NewTestContext(testConfig).Context, Bp2Build, "")
files, err := createSoongInjectionDirFiles(codegenCtx, CreateCodegenMetrics())
if err != nil {
t.Error(err)
}
@@ -104,6 +105,10 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
dir: "cc_toolchain",
basename: "config_constants.bzl",
},
{
dir: "cc_toolchain",
basename: "ndk_libs.bzl",
},
{
dir: "cc_toolchain",
basename: "sanitizer_constants.bzl",
@@ -182,15 +187,45 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
},
}
if len(files) != len(expectedFilePaths) {
t.Errorf("Expected %d file, got %d", len(expectedFilePaths), len(files))
less := func(a bazelFilepath, b bazelFilepath) bool {
return a.dir+"/"+a.basename < b.dir+"/"+b.basename
}
for i := range files {
actualFile, expectedFile := files[i], expectedFilePaths[i]
fileToFilepath := func(a BazelFile) bazelFilepath {
return bazelFilepath{basename: a.Basename, dir: a.Dir}
}
if actualFile.Dir != expectedFile.dir || actualFile.Basename != expectedFile.basename {
t.Errorf("Did not find expected file %s/%s", actualFile.Dir, actualFile.Basename)
sort.Slice(expectedFilePaths, func(i, j int) bool {
return less(expectedFilePaths[i], expectedFilePaths[j])
})
sort.Slice(files, func(i, j int) bool {
return less(fileToFilepath(files[i]), fileToFilepath(files[j]))
})
i := 0
j := 0
for i < len(expectedFilePaths) && j < len(files) {
expectedFile, actualFile := expectedFilePaths[i], files[j]
if actualFile.Dir == expectedFile.dir && actualFile.Basename == expectedFile.basename {
i++
j++
} else if less(expectedFile, fileToFilepath(actualFile)) {
t.Errorf("Did not find expected file %s/%s", expectedFile.dir, expectedFile.basename)
i++
} else {
t.Errorf("Found unexpected file %s/%s", actualFile.Dir, actualFile.Basename)
j++
}
}
for i < len(expectedFilePaths) {
expectedFile := expectedFilePaths[i]
t.Errorf("Did not find expected file %s/%s", expectedFile.dir, expectedFile.basename)
i++
}
for j < len(files) {
actualFile := files[j]
t.Errorf("Found unexpected file %s/%s", actualFile.Dir, actualFile.Basename)
j++
}
}