2022-07-30 00:58:33 +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
|
|
|
|
//
|
|
|
|
// 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 (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
)
|
|
|
|
|
2022-08-08 16:52:27 +02:00
|
|
|
func runYasmTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2022-07-30 00:58:33 +02:00
|
|
|
t.Helper()
|
2022-08-08 16:52:27 +02:00
|
|
|
RunBp2BuildTestCase(t, registerYasmModuleTypes, tc)
|
2022-07-30 00:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func registerYasmModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
cc.RegisterCCBuildComponents(ctx)
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
|
|
|
|
ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYasmSimple(t *testing.T) {
|
2022-08-08 16:52:27 +02:00
|
|
|
runYasmTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "Simple yasm test",
|
|
|
|
ModuleTypeUnderTest: "cc_library",
|
|
|
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"main.cpp": "",
|
|
|
|
"myfile.asm": "",
|
|
|
|
},
|
2022-08-08 16:52:27 +02:00
|
|
|
Blueprint: `
|
2022-07-30 00:58:33 +02:00
|
|
|
cc_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["main.cpp", "myfile.asm"],
|
|
|
|
}`,
|
2022-08-08 16:52:27 +02:00
|
|
|
ExpectedBazelTargets: append([]string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"include_dirs": `["."]`,
|
|
|
|
"srcs": `["myfile.asm"]`,
|
|
|
|
}),
|
|
|
|
}, makeCcLibraryTargets("foo", map[string]string{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `[
|
|
|
|
"main.cpp",
|
|
|
|
":foo_yasm",
|
|
|
|
]`,
|
|
|
|
})...),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYasmWithIncludeDirs(t *testing.T) {
|
2022-08-08 16:52:27 +02:00
|
|
|
runYasmTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "Simple yasm test",
|
|
|
|
ModuleTypeUnderTest: "cc_library",
|
|
|
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"main.cpp": "",
|
|
|
|
"myfile.asm": "",
|
|
|
|
"include1/foo/myinclude.inc": "",
|
|
|
|
"include2/foo/myinclude2.inc": "",
|
|
|
|
},
|
2022-08-08 16:52:27 +02:00
|
|
|
Blueprint: `
|
2022-07-30 00:58:33 +02:00
|
|
|
cc_library {
|
|
|
|
name: "foo",
|
|
|
|
local_include_dirs: ["include1/foo"],
|
|
|
|
export_include_dirs: ["include2/foo"],
|
|
|
|
srcs: ["main.cpp", "myfile.asm"],
|
|
|
|
}`,
|
2022-08-08 16:52:27 +02:00
|
|
|
ExpectedBazelTargets: append([]string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"include_dirs": `[
|
|
|
|
"include1/foo",
|
|
|
|
".",
|
|
|
|
"include2/foo",
|
|
|
|
]`,
|
|
|
|
"srcs": `["myfile.asm"]`,
|
|
|
|
}),
|
|
|
|
}, makeCcLibraryTargets("foo", map[string]string{
|
|
|
|
"local_includes": `[
|
|
|
|
"include1/foo",
|
|
|
|
".",
|
|
|
|
]`,
|
|
|
|
"export_includes": `["include2/foo"]`,
|
|
|
|
"srcs": `[
|
|
|
|
"main.cpp",
|
|
|
|
":foo_yasm",
|
|
|
|
]`,
|
|
|
|
})...),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYasmConditionalBasedOnArch(t *testing.T) {
|
2022-08-08 16:52:27 +02:00
|
|
|
runYasmTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "Simple yasm test",
|
|
|
|
ModuleTypeUnderTest: "cc_library",
|
|
|
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"main.cpp": "",
|
|
|
|
"myfile.asm": "",
|
|
|
|
},
|
2022-08-08 16:52:27 +02:00
|
|
|
Blueprint: `
|
2022-07-30 00:58:33 +02:00
|
|
|
cc_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["main.cpp"],
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
srcs: ["myfile.asm"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
2022-08-08 16:52:27 +02:00
|
|
|
ExpectedBazelTargets: append([]string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"include_dirs": `["."]`,
|
|
|
|
"srcs": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": ["myfile.asm"],
|
2022-07-30 00:58:33 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
}, makeCcLibraryTargets("foo", map[string]string{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `["main.cpp"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": [":foo_yasm"],
|
2022-07-30 00:58:33 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
})...),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYasmPartiallyConditional(t *testing.T) {
|
2022-08-08 16:52:27 +02:00
|
|
|
runYasmTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "Simple yasm test",
|
|
|
|
ModuleTypeUnderTest: "cc_library",
|
|
|
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
Filesystem: map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"main.cpp": "",
|
|
|
|
"myfile.asm": "",
|
|
|
|
"mysecondfile.asm": "",
|
|
|
|
},
|
2022-08-08 16:52:27 +02:00
|
|
|
Blueprint: `
|
2022-07-30 00:58:33 +02:00
|
|
|
cc_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["main.cpp", "myfile.asm"],
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
srcs: ["mysecondfile.asm"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
2022-08-08 16:52:27 +02:00
|
|
|
ExpectedBazelTargets: append([]string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
2022-07-30 00:58:33 +02:00
|
|
|
"include_dirs": `["."]`,
|
|
|
|
"srcs": `["myfile.asm"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": ["mysecondfile.asm"],
|
2022-07-30 00:58:33 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
}, makeCcLibraryTargets("foo", map[string]string{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `[
|
|
|
|
"main.cpp",
|
|
|
|
":foo_yasm",
|
|
|
|
]`,
|
|
|
|
})...),
|
|
|
|
})
|
|
|
|
}
|