Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 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. |
| 14 | package bp2build |
| 15 | |
| 16 | import ( |
| 17 | "fmt" |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/cc" |
| 21 | ) |
| 22 | |
| 23 | func TestStaticPrebuiltLibrary(t *testing.T) { |
| 24 | runBp2BuildTestCaseSimple(t, |
| 25 | bp2buildTestCase{ |
| 26 | description: "prebuilt library static simple", |
| 27 | moduleTypeUnderTest: "cc_prebuilt_library_static", |
| 28 | moduleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, |
| 29 | filesystem: map[string]string{ |
| 30 | "libf.so": "", |
| 31 | }, |
| 32 | blueprint: ` |
| 33 | cc_prebuilt_library_static { |
| 34 | name: "libtest", |
| 35 | srcs: ["libf.so"], |
| 36 | bazel_module: { bp2build_available: true }, |
| 37 | }`, |
| 38 | expectedBazelTargets: []string{ |
| 39 | makeBazelTarget("prebuilt_library_static", "libtest", attrNameToString{ |
| 40 | "static_library": `"libf.so"`, |
| 41 | }), |
| 42 | }, |
| 43 | }) |
| 44 | } |
| 45 | |
| 46 | func TestStaticPrebuiltLibraryWithArchVariance(t *testing.T) { |
| 47 | runBp2BuildTestCaseSimple(t, |
| 48 | bp2buildTestCase{ |
| 49 | description: "prebuilt library static with arch variance", |
| 50 | moduleTypeUnderTest: "cc_prebuilt_library_static", |
| 51 | moduleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, |
| 52 | filesystem: map[string]string{ |
| 53 | "libf.so": "", |
| 54 | "libg.so": "", |
| 55 | }, |
| 56 | blueprint: ` |
| 57 | cc_prebuilt_library_static { |
| 58 | name: "libtest", |
| 59 | arch: { |
| 60 | arm64: { srcs: ["libf.so"], }, |
| 61 | arm: { srcs: ["libg.so"], }, |
| 62 | }, |
| 63 | bazel_module: { bp2build_available: true }, |
| 64 | }`, |
| 65 | expectedBazelTargets: []string{ |
| 66 | makeBazelTarget("prebuilt_library_static", "libtest", attrNameToString{ |
| 67 | "static_library": `select({ |
| 68 | "//build/bazel/platforms/arch:arm": "libg.so", |
| 69 | "//build/bazel/platforms/arch:arm64": "libf.so", |
| 70 | "//conditions:default": None, |
| 71 | })`, |
| 72 | }), |
| 73 | }, |
| 74 | }) |
| 75 | } |
| 76 | |
| 77 | func TestStaticPrebuiltLibraryStaticStanzaFails(t *testing.T) { |
| 78 | runBp2BuildTestCaseSimple(t, |
| 79 | bp2buildTestCase{ |
| 80 | description: "prebuilt library with static stanza fails because multiple sources", |
| 81 | moduleTypeUnderTest: "cc_prebuilt_library_static", |
| 82 | moduleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, |
| 83 | filesystem: map[string]string{ |
| 84 | "libf.so": "", |
| 85 | "libg.so": "", |
| 86 | }, |
| 87 | blueprint: ` |
| 88 | cc_prebuilt_library_static { |
| 89 | name: "libtest", |
| 90 | srcs: ["libf.so"], |
| 91 | static: { |
| 92 | srcs: ["libg.so"], |
| 93 | }, |
| 94 | bazel_module: { bp2build_available: true }, |
| 95 | }`, |
| 96 | expectedErr: fmt.Errorf("Expected at most one source file"), |
| 97 | }) |
| 98 | } |