2022-04-07 22:36:39 +02:00
|
|
|
// Copyright 2022 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
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2022-04-07 22:36:39 +02:00
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
|
|
|
"android/soong/cc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStaticPrebuiltLibrary(t *testing.T) {
|
2022-09-01 20:57:01 +02:00
|
|
|
RunBp2BuildTestCaseSimple(t,
|
2022-06-21 21:28:33 +02:00
|
|
|
Bp2buildTestCase{
|
|
|
|
Description: "prebuilt library static simple",
|
|
|
|
ModuleTypeUnderTest: "cc_prebuilt_library_static",
|
|
|
|
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-04-07 22:36:39 +02:00
|
|
|
"libf.so": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `
|
2022-04-07 22:36:39 +02:00
|
|
|
cc_prebuilt_library_static {
|
|
|
|
name: "libtest",
|
|
|
|
srcs: ["libf.so"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-10-17 16:48:57 +02:00
|
|
|
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
2022-04-07 22:36:39 +02:00
|
|
|
"static_library": `"libf.so"`,
|
|
|
|
}),
|
2023-03-10 21:57:38 +01:00
|
|
|
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
|
|
|
"static_library": `"libf.so"`,
|
|
|
|
"alwayslink": "True",
|
|
|
|
}),
|
2022-04-07 22:36:39 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticPrebuiltLibraryWithArchVariance(t *testing.T) {
|
2022-09-01 20:57:01 +02:00
|
|
|
RunBp2BuildTestCaseSimple(t,
|
2022-06-21 21:28:33 +02:00
|
|
|
Bp2buildTestCase{
|
|
|
|
Description: "prebuilt library static with arch variance",
|
|
|
|
ModuleTypeUnderTest: "cc_prebuilt_library_static",
|
|
|
|
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-04-07 22:36:39 +02:00
|
|
|
"libf.so": "",
|
|
|
|
"libg.so": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `
|
2022-04-07 22:36:39 +02:00
|
|
|
cc_prebuilt_library_static {
|
|
|
|
name: "libtest",
|
|
|
|
arch: {
|
|
|
|
arm64: { srcs: ["libf.so"], },
|
|
|
|
arm: { srcs: ["libg.so"], },
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-10-17 16:48:57 +02:00
|
|
|
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
2022-04-07 22:36:39 +02:00
|
|
|
"static_library": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
2022-04-07 22:36:39 +02:00
|
|
|
"//conditions:default": None,
|
2023-03-10 21:57:38 +01:00
|
|
|
})`}),
|
|
|
|
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
|
|
|
"alwayslink": "True",
|
|
|
|
"static_library": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
2023-03-10 21:57:38 +01:00
|
|
|
"//conditions:default": None,
|
|
|
|
})`}),
|
2022-04-07 22:36:39 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticPrebuiltLibraryStaticStanzaFails(t *testing.T) {
|
2022-09-01 20:57:01 +02:00
|
|
|
RunBp2BuildTestCaseSimple(t,
|
2022-06-21 21:28:33 +02:00
|
|
|
Bp2buildTestCase{
|
|
|
|
Description: "prebuilt library with static stanza fails because multiple sources",
|
|
|
|
ModuleTypeUnderTest: "cc_prebuilt_library_static",
|
|
|
|
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-04-07 22:36:39 +02:00
|
|
|
"libf.so": "",
|
|
|
|
"libg.so": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `
|
2022-04-07 22:36:39 +02:00
|
|
|
cc_prebuilt_library_static {
|
|
|
|
name: "libtest",
|
|
|
|
srcs: ["libf.so"],
|
|
|
|
static: {
|
|
|
|
srcs: ["libg.so"],
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
2022-04-07 22:36:39 +02:00
|
|
|
})
|
|
|
|
}
|
2022-05-13 22:55:35 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticConvertLex(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static with lex files",
|
|
|
|
ModuleTypeUnderTest: "cc_library_static",
|
|
|
|
ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-05-13 22:55:35 +02:00
|
|
|
"foo.c": "",
|
|
|
|
"bar.cc": "",
|
|
|
|
"foo1.l": "",
|
|
|
|
"bar1.ll": "",
|
|
|
|
"foo2.l": "",
|
|
|
|
"bar2.ll": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `cc_library_static {
|
2022-05-13 22:55:35 +02:00
|
|
|
name: "foo_lib",
|
|
|
|
srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
|
|
|
|
lex: { flags: ["--foo_flags"] },
|
|
|
|
include_build_directory: false,
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
|
2022-05-13 22:55:35 +02:00
|
|
|
"srcs": `[
|
|
|
|
"foo1.l",
|
|
|
|
"foo2.l",
|
|
|
|
]`,
|
|
|
|
"lexopts": `["--foo_flags"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
|
2022-05-13 22:55:35 +02:00
|
|
|
"srcs": `[
|
|
|
|
"bar1.ll",
|
|
|
|
"bar2.ll",
|
|
|
|
]`,
|
|
|
|
"lexopts": `["--foo_flags"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_lib", AttrNameToString{
|
2022-05-13 22:55:35 +02:00
|
|
|
"srcs": `[
|
|
|
|
"bar.cc",
|
|
|
|
":foo_lib_genlex_ll",
|
|
|
|
]`,
|
|
|
|
"srcs_c": `[
|
|
|
|
"foo.c",
|
|
|
|
":foo_lib_genlex_l",
|
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|