Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +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 | |
| 15 | package sysprop |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/bp2build" |
| 21 | ) |
| 22 | |
| 23 | func TestSyspropLibrarySimple(t *testing.T) { |
| 24 | bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{ |
| 25 | Description: "sysprop_library simple", |
| 26 | ModuleTypeUnderTest: "sysprop_library", |
| 27 | ModuleTypeUnderTestFactory: syspropLibraryFactory, |
| 28 | Filesystem: map[string]string{ |
| 29 | "foo.sysprop": "", |
| 30 | "bar.sysprop": "", |
| 31 | }, |
| 32 | Blueprint: ` |
| 33 | sysprop_library { |
| 34 | name: "sysprop_foo", |
| 35 | srcs: [ |
| 36 | "foo.sysprop", |
| 37 | "bar.sysprop", |
| 38 | ], |
| 39 | property_owner: "Platform", |
| 40 | } |
| 41 | `, |
| 42 | ExpectedBazelTargets: []string{ |
| 43 | bp2build.MakeBazelTargetNoRestrictions("sysprop_library", |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 44 | "sysprop_foo", |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 45 | bp2build.AttrNameToString{ |
| 46 | "srcs": `[ |
| 47 | "foo.sysprop", |
| 48 | "bar.sysprop", |
| 49 | ]`, |
| 50 | }), |
| 51 | bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared", |
| 52 | "libsysprop_foo", |
| 53 | bp2build.AttrNameToString{ |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 54 | "dep": `":sysprop_foo"`, |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 55 | }), |
| 56 | bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static", |
| 57 | "libsysprop_foo_bp2build_cc_library_static", |
| 58 | bp2build.AttrNameToString{ |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 59 | "dep": `":sysprop_foo"`, |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 60 | }), |
Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 61 | bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library", |
| 62 | "sysprop_foo_java_library", |
| 63 | bp2build.AttrNameToString{ |
| 64 | "dep": `":sysprop_foo"`, |
| 65 | }), |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 66 | }, |
| 67 | }) |
| 68 | } |
| 69 | |
| 70 | func TestSyspropLibraryCppMinSdkVersion(t *testing.T) { |
| 71 | bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{ |
Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 72 | Description: "sysprop_library with cpp min_sdk_version", |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 73 | ModuleTypeUnderTest: "sysprop_library", |
| 74 | ModuleTypeUnderTestFactory: syspropLibraryFactory, |
| 75 | Filesystem: map[string]string{ |
| 76 | "foo.sysprop": "", |
| 77 | "bar.sysprop": "", |
| 78 | }, |
| 79 | Blueprint: ` |
| 80 | sysprop_library { |
| 81 | name: "sysprop_foo", |
| 82 | srcs: [ |
| 83 | "foo.sysprop", |
| 84 | "bar.sysprop", |
| 85 | ], |
| 86 | cpp: { |
| 87 | min_sdk_version: "5", |
| 88 | }, |
| 89 | property_owner: "Platform", |
| 90 | } |
| 91 | `, |
| 92 | ExpectedBazelTargets: []string{ |
| 93 | bp2build.MakeBazelTargetNoRestrictions("sysprop_library", |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 94 | "sysprop_foo", |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 95 | bp2build.AttrNameToString{ |
| 96 | "srcs": `[ |
| 97 | "foo.sysprop", |
| 98 | "bar.sysprop", |
| 99 | ]`, |
| 100 | }), |
| 101 | bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared", |
| 102 | "libsysprop_foo", |
| 103 | bp2build.AttrNameToString{ |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 104 | "dep": `":sysprop_foo"`, |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 105 | "min_sdk_version": `"5"`, |
| 106 | }), |
| 107 | bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static", |
| 108 | "libsysprop_foo_bp2build_cc_library_static", |
| 109 | bp2build.AttrNameToString{ |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 110 | "dep": `":sysprop_foo"`, |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 111 | "min_sdk_version": `"5"`, |
| 112 | }), |
Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 113 | bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library", |
| 114 | "sysprop_foo_java_library", |
| 115 | bp2build.AttrNameToString{ |
| 116 | "dep": `":sysprop_foo"`, |
| 117 | }), |
Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 118 | }, |
| 119 | }) |
| 120 | } |
Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 121 | |
| 122 | func TestSyspropLibraryJavaMinSdkVersion(t *testing.T) { |
| 123 | bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{ |
| 124 | Description: "sysprop_library with java min_sdk_version", |
| 125 | ModuleTypeUnderTest: "sysprop_library", |
| 126 | ModuleTypeUnderTestFactory: syspropLibraryFactory, |
| 127 | Filesystem: map[string]string{ |
| 128 | "foo.sysprop": "", |
| 129 | "bar.sysprop": "", |
| 130 | }, |
| 131 | Blueprint: ` |
| 132 | sysprop_library { |
| 133 | name: "sysprop_foo", |
| 134 | srcs: [ |
| 135 | "foo.sysprop", |
| 136 | "bar.sysprop", |
| 137 | ], |
| 138 | java: { |
| 139 | min_sdk_version: "5", |
| 140 | }, |
| 141 | property_owner: "Platform", |
| 142 | } |
| 143 | `, |
| 144 | ExpectedBazelTargets: []string{ |
| 145 | bp2build.MakeBazelTargetNoRestrictions("sysprop_library", |
| 146 | "sysprop_foo", |
| 147 | bp2build.AttrNameToString{ |
| 148 | "srcs": `[ |
| 149 | "foo.sysprop", |
| 150 | "bar.sysprop", |
| 151 | ]`, |
| 152 | }), |
| 153 | bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared", |
| 154 | "libsysprop_foo", |
| 155 | bp2build.AttrNameToString{ |
| 156 | "dep": `":sysprop_foo"`, |
| 157 | }), |
| 158 | bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static", |
| 159 | "libsysprop_foo_bp2build_cc_library_static", |
| 160 | bp2build.AttrNameToString{ |
| 161 | "dep": `":sysprop_foo"`, |
| 162 | }), |
| 163 | bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library", |
| 164 | "sysprop_foo_java_library", |
| 165 | bp2build.AttrNameToString{ |
| 166 | "dep": `":sysprop_foo"`, |
| 167 | "min_sdk_version": `"5"`, |
| 168 | }), |
| 169 | }, |
| 170 | }) |
| 171 | } |
| 172 | |
| 173 | func TestSyspropLibraryOwnerNotPlatformUnconvertible(t *testing.T) { |
| 174 | bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{ |
| 175 | Description: "sysprop_library simple", |
| 176 | ModuleTypeUnderTest: "sysprop_library", |
| 177 | ModuleTypeUnderTestFactory: syspropLibraryFactory, |
| 178 | Filesystem: map[string]string{ |
| 179 | "foo.sysprop": "", |
| 180 | "bar.sysprop": "", |
| 181 | }, |
| 182 | Blueprint: ` |
| 183 | sysprop_library { |
| 184 | name: "sysprop_foo", |
| 185 | srcs: [ |
| 186 | "foo.sysprop", |
| 187 | "bar.sysprop", |
| 188 | ], |
| 189 | property_owner: "Vendor", |
| 190 | device_specific: true, |
| 191 | } |
| 192 | `, |
| 193 | ExpectedBazelTargets: []string{}, |
| 194 | }) |
| 195 | } |