2021-09-02 13:44:42 +02:00
|
|
|
// 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 (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2022-09-01 20:54:47 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2021-09-02 13:44:42 +02:00
|
|
|
)
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runFilegroupTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-09-02 13:44:42 +02:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
(&tc).ModuleTypeUnderTest = "filegroup"
|
|
|
|
(&tc).ModuleTypeUnderTestFactory = android.FileGroupFactory
|
|
|
|
RunBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
|
2021-09-02 13:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
|
|
|
|
|
|
|
|
func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "filegroup - same name as file, with one file",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: `
|
2021-09-02 13:44:42 +02:00
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo"],
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{}})
|
2021-09-02 13:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "filegroup - same name as file, with multiple files",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: `
|
2021-09-02 13:44:42 +02:00
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo", "bar"],
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
|
2021-09-02 13:44:42 +02:00
|
|
|
})
|
|
|
|
}
|
2022-08-16 19:10:31 +02:00
|
|
|
|
|
|
|
func TestFilegroupWithAidlSrcs(t *testing.T) {
|
|
|
|
testcases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
expectedBazelAttrs AttrNameToString
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "filegroup with only aidl srcs",
|
|
|
|
bp: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["aidl/foo.aidl"],
|
|
|
|
path: "aidl",
|
|
|
|
}`,
|
|
|
|
expectedBazelAttrs: AttrNameToString{
|
|
|
|
"srcs": `["aidl/foo.aidl"]`,
|
|
|
|
"strip_import_prefix": `"aidl"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filegroup without path",
|
|
|
|
bp: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["aidl/foo.aidl"],
|
|
|
|
}`,
|
|
|
|
expectedBazelAttrs: AttrNameToString{
|
|
|
|
"srcs": `["aidl/foo.aidl"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testcases {
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
|
|
|
|
}
|
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: test.name,
|
|
|
|
Blueprint: test.bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilegroupWithAidlAndNonAidlSrcs(t *testing.T) {
|
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "filegroup with aidl and non-aidl srcs",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"aidl/foo.aidl",
|
|
|
|
"buf.proto",
|
|
|
|
],
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"aidl/foo.aidl",
|
|
|
|
"buf.proto",
|
|
|
|
]`}),
|
|
|
|
}})
|
|
|
|
}
|
2022-09-01 20:54:47 +02:00
|
|
|
|
|
|
|
func TestFilegroupWithProtoSrcs(t *testing.T) {
|
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "filegroup with proto and non-proto srcs",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["proto/foo.proto"],
|
|
|
|
path: "proto",
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("proto_library", "foo_bp2build_converted", AttrNameToString{
|
|
|
|
"srcs": `["proto/foo.proto"]`,
|
2022-09-16 07:18:48 +02:00
|
|
|
"strip_import_prefix": `"proto"`,
|
|
|
|
"tags": `["manual"]`}),
|
2022-09-01 20:54:47 +02:00
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
|
|
|
"srcs": `["proto/foo.proto"]`}),
|
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilegroupWithProtoAndNonProtoSrcs(t *testing.T) {
|
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "filegroup with proto and non-proto srcs",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"foo.proto",
|
|
|
|
"buf.cpp",
|
|
|
|
],
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"foo.proto",
|
|
|
|
"buf.cpp",
|
|
|
|
]`}),
|
|
|
|
}})
|
|
|
|
}
|