5146ac02a1
with the same name. Also add capability to test for errors raised in bp2build mutators / contexts. This CL does two things to filegroups: 1) If the filegroup has only 1 source file with the same name as itself, don't generate a filegroup target. Instead, dependents will depend directly on the Bazel file target instead. 2) If the filegroup has more than 1 source file and 1 of them has the same name as itself, the bp2build mutator will error out. If bp2build on CI passes, it means that the source tree / product we're testing against does not have such a case (which seems to be true for most source trees). Either way, this will allow us to be unblocked for most of the errant filegroups (case 1) in the tree. Test: CI Test: New test cases in filegroup_conversion_test.go Fixes: 194762573 Change-Id: I830c53efc8808569afe3c5f9f08436855bcdafed
62 lines
2 KiB
Go
62 lines
2 KiB
Go
// Copyright 2021 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package bp2build
|
|
|
|
import (
|
|
"android/soong/android"
|
|
"fmt"
|
|
|
|
"testing"
|
|
)
|
|
|
|
func runFilegroupTestCase(t *testing.T, tc bp2buildTestCase) {
|
|
t.Helper()
|
|
runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
|
|
}
|
|
|
|
func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
|
|
|
|
func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
|
|
runFilegroupTestCase(t, bp2buildTestCase{
|
|
description: "filegroup - same name as file, with one file",
|
|
moduleTypeUnderTest: "filegroup",
|
|
moduleTypeUnderTestFactory: android.FileGroupFactory,
|
|
moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
|
|
filesystem: map[string]string{},
|
|
blueprint: `
|
|
filegroup {
|
|
name: "foo",
|
|
srcs: ["foo"],
|
|
}
|
|
`,
|
|
expectedBazelTargets: []string{}})
|
|
}
|
|
|
|
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
|
|
runFilegroupTestCase(t, bp2buildTestCase{
|
|
description: "filegroup - same name as file, with multiple files",
|
|
moduleTypeUnderTest: "filegroup",
|
|
moduleTypeUnderTestFactory: android.FileGroupFactory,
|
|
moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
|
|
filesystem: map[string]string{},
|
|
blueprint: `
|
|
filegroup {
|
|
name: "foo",
|
|
srcs: ["foo", "bar"],
|
|
}
|
|
`,
|
|
expectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
|
|
})
|
|
}
|