1// Copyright 2022 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14package bp2build 15 16import ( 17 "testing" 18 19 "android/soong/cc" 20) 21 22func runCcPrebuiltLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) { 23 t.Parallel() 24 t.Helper() 25 (&tc).ModuleTypeUnderTest = "cc_prebuilt_library_shared" 26 (&tc).ModuleTypeUnderTestFactory = cc.PrebuiltSharedLibraryFactory 27 RunBp2BuildTestCaseSimple(t, tc) 28} 29 30func TestPrebuiltLibrarySharedSimple(t *testing.T) { 31 runCcPrebuiltLibrarySharedTestCase(t, 32 Bp2buildTestCase{ 33 Description: "prebuilt library shared simple", 34 Filesystem: map[string]string{ 35 "libf.so": "", 36 }, 37 Blueprint: ` 38cc_prebuilt_library_shared { 39 name: "libtest", 40 srcs: ["libf.so"], 41 bazel_module: { bp2build_available: true }, 42}`, 43 ExpectedBazelTargets: []string{ 44 MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ 45 "shared_library": `"libf.so"`, 46 }), 47 }, 48 }) 49} 50 51func TestPrebuiltLibrarySharedWithArchVariance(t *testing.T) { 52 runCcPrebuiltLibrarySharedTestCase(t, 53 Bp2buildTestCase{ 54 Description: "prebuilt library shared with arch variance", 55 Filesystem: map[string]string{ 56 "libf.so": "", 57 "libg.so": "", 58 }, 59 Blueprint: ` 60cc_prebuilt_library_shared { 61 name: "libtest", 62 arch: { 63 arm64: { srcs: ["libf.so"], }, 64 arm: { srcs: ["libg.so"], }, 65 }, 66 bazel_module: { bp2build_available: true }, 67}`, 68 ExpectedBazelTargets: []string{ 69 MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ 70 "shared_library": `select({ 71 "//build/bazel/platforms/arch:arm": "libg.so", 72 "//build/bazel/platforms/arch:arm64": "libf.so", 73 "//conditions:default": None, 74 })`, 75 }), 76 }, 77 }) 78} 79 80func TestPrebuiltLibrarySharedAdditionalAttrs(t *testing.T) { 81 runCcPrebuiltLibrarySharedTestCase(t, 82 Bp2buildTestCase{ 83 Description: "prebuilt library shared additional attributes", 84 Filesystem: map[string]string{ 85 "libf.so": "", 86 "testdir/1/include.h": "", 87 "testdir/2/other.h": "", 88 }, 89 Blueprint: ` 90cc_prebuilt_library_shared { 91 name: "libtest", 92 srcs: ["libf.so"], 93 export_include_dirs: ["testdir/1/"], 94 export_system_include_dirs: ["testdir/2/"], 95 bazel_module: { bp2build_available: true }, 96}`, 97 ExpectedBazelTargets: []string{ 98 MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ 99 "shared_library": `"libf.so"`, 100 "export_includes": `["testdir/1/"]`, 101 "export_system_includes": `["testdir/2/"]`, 102 }), 103 }, 104 }) 105} 106 107func TestPrebuiltLibrarySharedWithExportIncludesArchVariant(t *testing.T) { 108 runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{ 109 Description: "cc_prebuilt_library_shared correctly translates export_includes with arch variance", 110 Filesystem: map[string]string{ 111 "libf.so": "", 112 "libg.so": "", 113 }, 114 Blueprint: ` 115cc_prebuilt_library_shared { 116 name: "libtest", 117 srcs: ["libf.so"], 118 arch: { 119 arm: { export_include_dirs: ["testdir/1/"], }, 120 arm64: { export_include_dirs: ["testdir/2/"], }, 121 }, 122 bazel_module: { bp2build_available: true }, 123}`, 124 ExpectedBazelTargets: []string{ 125 MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ 126 "shared_library": `"libf.so"`, 127 "export_includes": `select({ 128 "//build/bazel/platforms/arch:arm": ["testdir/1/"], 129 "//build/bazel/platforms/arch:arm64": ["testdir/2/"], 130 "//conditions:default": [], 131 })`, 132 }), 133 }, 134 }) 135} 136 137func TestPrebuiltLibrarySharedWithExportSystemIncludesArchVariant(t *testing.T) { 138 runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{ 139 Description: "cc_prebuilt_library_shared correctly translates export_system_includes with arch variance", 140 Filesystem: map[string]string{ 141 "libf.so": "", 142 "libg.so": "", 143 }, 144 Blueprint: ` 145cc_prebuilt_library_shared { 146 name: "libtest", 147 srcs: ["libf.so"], 148 arch: { 149 arm: { export_system_include_dirs: ["testdir/1/"], }, 150 arm64: { export_system_include_dirs: ["testdir/2/"], }, 151 }, 152 bazel_module: { bp2build_available: true }, 153}`, 154 ExpectedBazelTargets: []string{ 155 MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ 156 "shared_library": `"libf.so"`, 157 "export_system_includes": `select({ 158 "//build/bazel/platforms/arch:arm": ["testdir/1/"], 159 "//build/bazel/platforms/arch:arm64": ["testdir/2/"], 160 "//conditions:default": [], 161 })`, 162 }), 163 }, 164 }) 165} 166