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"],
|
|
|
|
}
|
|
|
|
`,
|
2023-09-28 00:39:45 +02:00
|
|
|
ExpectedBazelTargets: []string{},
|
|
|
|
ExpectedHandcraftedModules: []string{"foo"}},
|
|
|
|
)
|
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"`,
|
2023-03-23 16:51:49 +01:00
|
|
|
"tags": `["apex_available=//apex_available:anyapex"]`,
|
2022-08-16 19:10:31 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filegroup without path",
|
|
|
|
bp: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["aidl/foo.aidl"],
|
|
|
|
}`,
|
|
|
|
expectedBazelAttrs: AttrNameToString{
|
|
|
|
"srcs": `["aidl/foo.aidl"]`,
|
2023-03-23 16:51:49 +01:00
|
|
|
"tags": `["apex_available=//apex_available:anyapex"]`,
|
2022-08-16 19:10:31 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testcases {
|
2023-03-23 16:51:49 +01:00
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
|
|
|
|
}
|
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: test.name,
|
|
|
|
Blueprint: test.bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
2022-08-16 19:10:31 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2023-08-04 04:19:53 +02:00
|
|
|
MakeBazelTargetNoRestrictions("proto_library", "foo_proto", AttrNameToString{
|
2022-09-01 20:54:47 +02:00
|
|
|
"srcs": `["proto/foo.proto"]`,
|
2022-09-16 07:18:48 +02:00
|
|
|
"strip_import_prefix": `"proto"`,
|
2023-03-23 16:51:49 +01:00
|
|
|
"tags": `[
|
|
|
|
"apex_available=//apex_available:anyapex",
|
|
|
|
"manual",
|
2023-08-04 04:19:53 +02:00
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTargetNoRestrictions("alias", "foo_bp2build_converted", AttrNameToString{
|
|
|
|
"actual": `"//.:foo_proto"`,
|
|
|
|
"tags": `[
|
|
|
|
"apex_available=//apex_available:anyapex",
|
|
|
|
"manual",
|
2023-03-23 16:51:49 +01:00
|
|
|
]`,
|
|
|
|
}),
|
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",
|
|
|
|
]`}),
|
|
|
|
}})
|
|
|
|
}
|
2023-08-04 04:19:53 +02:00
|
|
|
|
|
|
|
func TestFilegroupWithProtoInDifferentPackage(t *testing.T) {
|
|
|
|
runFilegroupTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "filegroup with .proto in different package",
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"subdir/Android.bp": "",
|
|
|
|
},
|
|
|
|
Blueprint: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["subdir/foo.proto"],
|
|
|
|
}`,
|
|
|
|
Dir: "subdir", // check in subdir
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("proto_library", "foo_proto", AttrNameToString{
|
|
|
|
"srcs": `["//subdir:foo.proto"]`,
|
|
|
|
"import_prefix": `"subdir"`,
|
|
|
|
"strip_import_prefix": `""`,
|
|
|
|
"tags": `[
|
|
|
|
"apex_available=//apex_available:anyapex",
|
|
|
|
"manual",
|
|
|
|
]`}),
|
|
|
|
}})
|
|
|
|
}
|