Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 android |
| 16 | |
| 17 | import ( |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 18 | "path/filepath" |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 19 | "reflect" |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "github.com/google/blueprint" |
| 23 | ) |
| 24 | |
| 25 | func TestDependingOnModuleInSameNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 26 | result := GroupFixturePreparers( |
| 27 | prepareForTestWithNamespace, |
| 28 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 29 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 30 | soong_namespace { |
| 31 | } |
| 32 | test_module { |
| 33 | name: "a", |
| 34 | } |
| 35 | test_module { |
| 36 | name: "b", |
| 37 | deps: ["a"], |
| 38 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 39 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 40 | }), |
| 41 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 42 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 43 | a := getModule(result, "a") |
| 44 | b := getModule(result, "b") |
| 45 | if !dependsOn(result, b, a) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 46 | t.Errorf("module b does not depend on module a in the same namespace") |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestDependingOnModuleInRootNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 51 | result := GroupFixturePreparers( |
| 52 | prepareForTestWithNamespace, |
| 53 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 54 | ".": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 55 | test_module { |
| 56 | name: "b", |
| 57 | deps: ["a"], |
| 58 | } |
| 59 | test_module { |
| 60 | name: "a", |
| 61 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 62 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 63 | }), |
| 64 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 65 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 66 | a := getModule(result, "a") |
| 67 | b := getModule(result, "b") |
| 68 | if !dependsOn(result, b, a) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 69 | t.Errorf("module b in root namespace does not depend on module a in the root namespace") |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func TestImplicitlyImportRootNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 74 | GroupFixturePreparers( |
| 75 | prepareForTestWithNamespace, |
| 76 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 77 | ".": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 78 | test_module { |
| 79 | name: "a", |
| 80 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 81 | `, |
| 82 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 83 | soong_namespace { |
| 84 | } |
| 85 | test_module { |
| 86 | name: "b", |
| 87 | deps: ["a"], |
| 88 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 89 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 90 | }), |
| 91 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 92 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 93 | // RunTest will report any errors |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 96 | func TestDependingOnBlueprintModuleInRootNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 97 | GroupFixturePreparers( |
| 98 | prepareForTestWithNamespace, |
| 99 | dirBpToPreparer(map[string]string{ |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 100 | ".": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 101 | blueprint_test_module { |
| 102 | name: "a", |
| 103 | } |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 104 | `, |
| 105 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 106 | soong_namespace { |
| 107 | } |
| 108 | blueprint_test_module { |
| 109 | name: "b", |
| 110 | deps: ["a"], |
| 111 | } |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 112 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 113 | }), |
| 114 | ).RunTest(t) |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 115 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 116 | // RunTest will report any errors |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 119 | func TestDependingOnModuleInImportedNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 120 | result := GroupFixturePreparers( |
| 121 | prepareForTestWithNamespace, |
| 122 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 123 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 124 | soong_namespace { |
| 125 | } |
| 126 | test_module { |
| 127 | name: "a", |
| 128 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 129 | `, |
| 130 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 131 | soong_namespace { |
| 132 | imports: ["dir1"], |
| 133 | } |
| 134 | test_module { |
| 135 | name: "b", |
| 136 | deps: ["a"], |
| 137 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 138 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 139 | }), |
| 140 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 141 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 142 | a := getModule(result, "a") |
| 143 | b := getModule(result, "b") |
| 144 | if !dependsOn(result, b, a) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 145 | t.Errorf("module b does not depend on module a in the same namespace") |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | func TestDependingOnModuleInNonImportedNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 150 | GroupFixturePreparers( |
| 151 | prepareForTestWithNamespace, |
| 152 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 153 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 154 | soong_namespace { |
| 155 | } |
| 156 | test_module { |
| 157 | name: "a", |
| 158 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 159 | `, |
| 160 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 161 | soong_namespace { |
| 162 | } |
| 163 | test_module { |
| 164 | name: "a", |
| 165 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 166 | `, |
| 167 | "dir3": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 168 | soong_namespace { |
| 169 | } |
| 170 | test_module { |
| 171 | name: "b", |
| 172 | deps: ["a"], |
| 173 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 174 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 175 | }), |
| 176 | ). |
| 177 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir3/Android.bp:4:5: "b" depends on undefined module "a" |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 178 | Module "b" is defined in namespace "dir3" which can read these 2 namespaces: ["dir3" "."] |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 179 | Module "a" can be found in these namespaces: ["dir1" "dir2"]\E`)). |
| 180 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | func TestDependingOnModuleByFullyQualifiedReference(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 184 | result := GroupFixturePreparers( |
| 185 | prepareForTestWithNamespace, |
| 186 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 187 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 188 | soong_namespace { |
| 189 | } |
| 190 | test_module { |
| 191 | name: "a", |
| 192 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 193 | `, |
| 194 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 195 | soong_namespace { |
| 196 | } |
| 197 | test_module { |
| 198 | name: "b", |
| 199 | deps: ["//dir1:a"], |
| 200 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 201 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 202 | }), |
| 203 | ).RunTest(t) |
| 204 | |
| 205 | a := getModule(result, "a") |
| 206 | b := getModule(result, "b") |
| 207 | if !dependsOn(result, b, a) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 208 | t.Errorf("module b does not depend on module a") |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | func TestSameNameInTwoNamespaces(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 213 | result := GroupFixturePreparers( |
| 214 | prepareForTestWithNamespace, |
| 215 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 216 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 217 | soong_namespace { |
| 218 | } |
| 219 | test_module { |
| 220 | name: "a", |
| 221 | id: "1", |
| 222 | } |
| 223 | test_module { |
| 224 | name: "b", |
| 225 | deps: ["a"], |
| 226 | id: "2", |
| 227 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 228 | `, |
| 229 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 230 | soong_namespace { |
| 231 | } |
| 232 | test_module { |
| 233 | name: "a", |
| 234 | id:"3", |
| 235 | } |
| 236 | test_module { |
| 237 | name: "b", |
| 238 | deps: ["a"], |
| 239 | id:"4", |
| 240 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 241 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 242 | }), |
| 243 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 244 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 245 | one := findModuleById(result, "1") |
| 246 | two := findModuleById(result, "2") |
| 247 | three := findModuleById(result, "3") |
| 248 | four := findModuleById(result, "4") |
| 249 | if !dependsOn(result, two, one) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 250 | t.Fatalf("Module 2 does not depend on module 1 in its namespace") |
| 251 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 252 | if dependsOn(result, two, three) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 253 | t.Fatalf("Module 2 depends on module 3 in another namespace") |
| 254 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 255 | if !dependsOn(result, four, three) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 256 | t.Fatalf("Module 4 does not depend on module 3 in its namespace") |
| 257 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 258 | if dependsOn(result, four, one) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 259 | t.Fatalf("Module 4 depends on module 1 in another namespace") |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | func TestSearchOrder(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 264 | result := GroupFixturePreparers( |
| 265 | prepareForTestWithNamespace, |
| 266 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 267 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 268 | soong_namespace { |
| 269 | } |
| 270 | test_module { |
| 271 | name: "a", |
| 272 | id: "1", |
| 273 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 274 | `, |
| 275 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 276 | soong_namespace { |
| 277 | } |
| 278 | test_module { |
| 279 | name: "a", |
| 280 | id:"2", |
| 281 | } |
| 282 | test_module { |
| 283 | name: "b", |
| 284 | id:"3", |
| 285 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 286 | `, |
| 287 | "dir3": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 288 | soong_namespace { |
| 289 | } |
| 290 | test_module { |
| 291 | name: "a", |
| 292 | id:"4", |
| 293 | } |
| 294 | test_module { |
| 295 | name: "b", |
| 296 | id:"5", |
| 297 | } |
| 298 | test_module { |
| 299 | name: "c", |
| 300 | id:"6", |
| 301 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 302 | `, |
| 303 | ".": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 304 | test_module { |
| 305 | name: "a", |
| 306 | id: "7", |
| 307 | } |
| 308 | test_module { |
| 309 | name: "b", |
| 310 | id: "8", |
| 311 | } |
| 312 | test_module { |
| 313 | name: "c", |
| 314 | id: "9", |
| 315 | } |
| 316 | test_module { |
| 317 | name: "d", |
| 318 | id: "10", |
| 319 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 320 | `, |
| 321 | "dir4": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 322 | soong_namespace { |
| 323 | imports: ["dir1", "dir2", "dir3"] |
| 324 | } |
| 325 | test_module { |
| 326 | name: "test_me", |
| 327 | id:"0", |
| 328 | deps: ["a", "b", "c", "d"], |
| 329 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 330 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 331 | }), |
| 332 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 333 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 334 | testMe := findModuleById(result, "0") |
| 335 | if !dependsOn(result, testMe, findModuleById(result, "1")) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 336 | t.Errorf("test_me doesn't depend on id 1") |
| 337 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 338 | if !dependsOn(result, testMe, findModuleById(result, "3")) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 339 | t.Errorf("test_me doesn't depend on id 3") |
| 340 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 341 | if !dependsOn(result, testMe, findModuleById(result, "6")) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 342 | t.Errorf("test_me doesn't depend on id 6") |
| 343 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 344 | if !dependsOn(result, testMe, findModuleById(result, "10")) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 345 | t.Errorf("test_me doesn't depend on id 10") |
| 346 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 347 | if numDeps(result, testMe) != 4 { |
| 348 | t.Errorf("num dependencies of test_me = %v, not 4\n", numDeps(result, testMe)) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | func TestTwoNamespacesCanImportEachOther(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 353 | GroupFixturePreparers( |
| 354 | prepareForTestWithNamespace, |
| 355 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 356 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 357 | soong_namespace { |
| 358 | imports: ["dir2"] |
| 359 | } |
| 360 | test_module { |
| 361 | name: "a", |
| 362 | } |
| 363 | test_module { |
| 364 | name: "c", |
| 365 | deps: ["b"], |
| 366 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 367 | `, |
| 368 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 369 | soong_namespace { |
| 370 | imports: ["dir1"], |
| 371 | } |
| 372 | test_module { |
| 373 | name: "b", |
| 374 | deps: ["a"], |
| 375 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 376 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 377 | }), |
| 378 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 379 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 380 | // RunTest will report any errors |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | func TestImportingNonexistentNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 384 | GroupFixturePreparers( |
| 385 | prepareForTestWithNamespace, |
| 386 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 387 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 388 | soong_namespace { |
| 389 | imports: ["a_nonexistent_namespace"] |
| 390 | } |
| 391 | test_module { |
| 392 | name: "a", |
| 393 | deps: ["a_nonexistent_module"] |
| 394 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 395 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 396 | }), |
| 397 | ). |
| 398 | // should complain about the missing namespace and not complain about the unresolvable dependency |
| 399 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:2:5: module "soong_namespace": namespace a_nonexistent_namespace does not exist\E`)). |
| 400 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | func TestNamespacesDontInheritParentNamespaces(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 404 | GroupFixturePreparers( |
| 405 | prepareForTestWithNamespace, |
| 406 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 407 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 408 | soong_namespace { |
| 409 | } |
| 410 | test_module { |
| 411 | name: "a", |
| 412 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 413 | `, |
| 414 | "dir1/subdir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 415 | soong_namespace { |
| 416 | } |
| 417 | test_module { |
| 418 | name: "b", |
| 419 | deps: ["a"], |
| 420 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 421 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 422 | }), |
| 423 | ). |
| 424 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/subdir1/Android.bp:4:5: "b" depends on undefined module "a" |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 425 | Module "b" is defined in namespace "dir1/subdir1" which can read these 2 namespaces: ["dir1/subdir1" "."] |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 426 | Module "a" can be found in these namespaces: ["dir1"]\E`)). |
| 427 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | func TestModulesDoReceiveParentNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 431 | GroupFixturePreparers( |
| 432 | prepareForTestWithNamespace, |
| 433 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 434 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 435 | soong_namespace { |
| 436 | } |
| 437 | test_module { |
| 438 | name: "a", |
| 439 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 440 | `, |
| 441 | "dir1/subdir": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 442 | test_module { |
| 443 | name: "b", |
| 444 | deps: ["a"], |
| 445 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 446 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 447 | }), |
| 448 | ).RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 449 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 450 | // RunTest will report any errors |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | func TestNamespaceImportsNotTransitive(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 454 | GroupFixturePreparers( |
| 455 | prepareForTestWithNamespace, |
| 456 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 457 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 458 | soong_namespace { |
| 459 | } |
| 460 | test_module { |
| 461 | name: "a", |
| 462 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 463 | `, |
| 464 | "dir2": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 465 | soong_namespace { |
| 466 | imports: ["dir1"], |
| 467 | } |
| 468 | test_module { |
| 469 | name: "b", |
| 470 | deps: ["a"], |
| 471 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 472 | `, |
| 473 | "dir3": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 474 | soong_namespace { |
| 475 | imports: ["dir2"], |
| 476 | } |
| 477 | test_module { |
| 478 | name: "c", |
| 479 | deps: ["a"], |
| 480 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 481 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 482 | }), |
| 483 | ). |
| 484 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir3/Android.bp:5:5: "c" depends on undefined module "a" |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 485 | Module "c" is defined in namespace "dir3" which can read these 3 namespaces: ["dir3" "dir2" "."] |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 486 | Module "a" can be found in these namespaces: ["dir1"]\E`)). |
| 487 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | func TestTwoNamepacesInSameDir(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 491 | GroupFixturePreparers( |
| 492 | prepareForTestWithNamespace, |
| 493 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 494 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 495 | soong_namespace { |
| 496 | } |
| 497 | soong_namespace { |
| 498 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 499 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 500 | }), |
| 501 | ). |
| 502 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:4:5: namespace dir1 already exists\E`)). |
| 503 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | func TestNamespaceNotAtTopOfFile(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 507 | GroupFixturePreparers( |
| 508 | prepareForTestWithNamespace, |
| 509 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 510 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 511 | test_module { |
| 512 | name: "a" |
| 513 | } |
| 514 | soong_namespace { |
| 515 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 516 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 517 | }), |
| 518 | ). |
| 519 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:5:5: a namespace must be the first module in the file\E`)). |
| 520 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | func TestTwoModulesWithSameNameInSameNamespace(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 524 | GroupFixturePreparers( |
| 525 | prepareForTestWithNamespace, |
| 526 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 527 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 528 | soong_namespace { |
| 529 | } |
| 530 | test_module { |
| 531 | name: "a" |
| 532 | } |
| 533 | test_module { |
| 534 | name: "a" |
| 535 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 536 | `, |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 537 | }), |
| 538 | ). |
| 539 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:7:5: module "a" already defined |
| 540 | dir1/Android.bp:4:5 <-- previous definition here\E`)). |
| 541 | RunTest(t) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Jeff Gaston | 5c3886d | 2017-11-30 16:46:47 -0800 | [diff] [blame] | 544 | func TestDeclaringNamespaceInNonAndroidBpFile(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 545 | GroupFixturePreparers( |
| 546 | prepareForTestWithNamespace, |
| 547 | FixtureWithRootAndroidBp(` |
Jeff Gaston | 5c3886d | 2017-11-30 16:46:47 -0800 | [diff] [blame] | 548 | build = ["include.bp"] |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 549 | `), |
| 550 | FixtureAddTextFile("include.bp", ` |
Jeff Gaston | 5c3886d | 2017-11-30 16:46:47 -0800 | [diff] [blame] | 551 | soong_namespace { |
| 552 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 553 | `), |
| 554 | ). |
| 555 | ExtendWithErrorHandler(FixtureExpectsOneErrorPattern( |
| 556 | `\Qinclude.bp:2:5: A namespace may only be declared in a file named Android.bp\E`, |
| 557 | )). |
| 558 | RunTest(t) |
Jeff Gaston | 5c3886d | 2017-11-30 16:46:47 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 561 | // so that the generated .ninja file will have consistent names |
| 562 | func TestConsistentNamespaceNames(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 563 | result := GroupFixturePreparers( |
| 564 | prepareForTestWithNamespace, |
| 565 | dirBpToPreparer(map[string]string{ |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 566 | "dir1": "soong_namespace{}", |
| 567 | "dir2": "soong_namespace{}", |
| 568 | "dir3": "soong_namespace{}", |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 569 | }), |
| 570 | ).RunTest(t) |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 571 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 572 | ns1, _ := result.NameResolver.namespaceAt("dir1") |
| 573 | ns2, _ := result.NameResolver.namespaceAt("dir2") |
| 574 | ns3, _ := result.NameResolver.namespaceAt("dir3") |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 575 | actualIds := []string{ns1.id, ns2.id, ns3.id} |
| 576 | expectedIds := []string{"1", "2", "3"} |
| 577 | if !reflect.DeepEqual(actualIds, expectedIds) { |
| 578 | t.Errorf("Incorrect namespace ids.\nactual: %s\nexpected: %s\n", actualIds, expectedIds) |
| 579 | } |
| 580 | } |
| 581 | |
Colin Cross | eafb10c | 2018-04-16 13:58:10 -0700 | [diff] [blame] | 582 | // so that the generated .ninja file will have consistent names |
| 583 | func TestRename(t *testing.T) { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 584 | GroupFixturePreparers( |
| 585 | prepareForTestWithNamespace, |
| 586 | dirBpToPreparer(map[string]string{ |
Colin Cross | eafb10c | 2018-04-16 13:58:10 -0700 | [diff] [blame] | 587 | "dir1": ` |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 588 | soong_namespace { |
| 589 | } |
| 590 | test_module { |
| 591 | name: "a", |
| 592 | deps: ["c"], |
| 593 | } |
| 594 | test_module { |
| 595 | name: "b", |
| 596 | rename: "c", |
| 597 | } |
| 598 | `, |
| 599 | }), |
| 600 | ).RunTest(t) |
| 601 | |
| 602 | // RunTest will report any errors |
Colin Cross | eafb10c | 2018-04-16 13:58:10 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Paul Duffin | 3f7bf9f | 2022-11-08 12:21:15 +0000 | [diff] [blame^] | 605 | func TestNamespace_Exports(t *testing.T) { |
| 606 | result := GroupFixturePreparers( |
| 607 | prepareForTestWithNamespace, |
| 608 | FixtureModifyProductVariables(func(variables FixtureProductVariables) { |
| 609 | variables.NamespacesToExport = []string{"dir1"} |
| 610 | }), |
| 611 | dirBpToPreparer(map[string]string{ |
| 612 | "dir1": ` |
| 613 | soong_namespace { |
| 614 | } |
| 615 | test_module { |
| 616 | name: "a", |
| 617 | } |
| 618 | `, |
| 619 | "dir2": ` |
| 620 | soong_namespace { |
| 621 | } |
| 622 | test_module { |
| 623 | name: "b", |
| 624 | } |
| 625 | `, |
| 626 | }), |
| 627 | ).RunTest(t) |
| 628 | |
| 629 | aModule := result.Module("a", "") |
| 630 | AssertBoolEquals(t, "a exported", true, aModule.ExportedToMake()) |
| 631 | bModule := result.Module("b", "") |
| 632 | AssertBoolEquals(t, "b not exported", false, bModule.ExportedToMake()) |
| 633 | } |
| 634 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 635 | // some utils to support the tests |
| 636 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 637 | var prepareForTestWithNamespace = GroupFixturePreparers( |
| 638 | FixtureRegisterWithContext(registerNamespaceBuildComponents), |
| 639 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 640 | ctx.PreArchMutators(RegisterNamespaceMutator) |
| 641 | }), |
| 642 | FixtureModifyContext(func(ctx *TestContext) { |
| 643 | ctx.RegisterModuleType("test_module", newTestModule) |
| 644 | ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule) |
| 645 | ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { |
| 646 | ctx.BottomUp("rename", renameMutator) |
| 647 | }) |
| 648 | }), |
| 649 | ) |
| 650 | |
| 651 | // dirBpToPreparer takes a map from directory to the contents of the Android.bp file and produces a |
| 652 | // FixturePreparer. |
| 653 | func dirBpToPreparer(bps map[string]string) FixturePreparer { |
| 654 | files := make(MockFS, len(bps)) |
Jeff Gaston | 5c3886d | 2017-11-30 16:46:47 -0800 | [diff] [blame] | 655 | files["Android.bp"] = []byte("") |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 656 | for dir, text := range bps { |
Jeff Gaston | 5c3886d | 2017-11-30 16:46:47 -0800 | [diff] [blame] | 657 | files[filepath.Join(dir, "Android.bp")] = []byte(text) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 658 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 659 | return files.AddToFixture() |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 660 | } |
| 661 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 662 | func dependsOn(result *TestResult, module TestingModule, possibleDependency TestingModule) bool { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 663 | depends := false |
| 664 | visit := func(dependency blueprint.Module) { |
| 665 | if dependency == possibleDependency.module { |
| 666 | depends = true |
| 667 | } |
| 668 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 669 | result.VisitDirectDeps(module.module, visit) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 670 | return depends |
| 671 | } |
| 672 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 673 | func numDeps(result *TestResult, module TestingModule) int { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 674 | count := 0 |
| 675 | visit := func(dependency blueprint.Module) { |
| 676 | count++ |
| 677 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 678 | result.VisitDirectDeps(module.module, visit) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 679 | return count |
| 680 | } |
| 681 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 682 | func getModule(result *TestResult, moduleName string) TestingModule { |
| 683 | return result.ModuleForTests(moduleName, "") |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 684 | } |
| 685 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 686 | func findModuleById(result *TestResult, id string) (module TestingModule) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 687 | visit := func(candidate blueprint.Module) { |
| 688 | testModule, ok := candidate.(*testModule) |
| 689 | if ok { |
| 690 | if testModule.properties.Id == id { |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 691 | module = newTestingModule(result.config, testModule) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | } |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 695 | result.VisitAllModules(visit) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 696 | return module |
| 697 | } |
| 698 | |
| 699 | type testModule struct { |
| 700 | ModuleBase |
| 701 | properties struct { |
Colin Cross | eafb10c | 2018-04-16 13:58:10 -0700 | [diff] [blame] | 702 | Rename string |
| 703 | Deps []string |
| 704 | Id string |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) { |
Colin Cross | eafb10c | 2018-04-16 13:58:10 -0700 | [diff] [blame] | 709 | if m.properties.Rename != "" { |
| 710 | ctx.Rename(m.properties.Rename) |
| 711 | } |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 712 | for _, d := range m.properties.Deps { |
| 713 | ctx.AddDependency(ctx.Module(), nil, d) |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | func (m *testModule) GenerateAndroidBuildActions(ModuleContext) { |
| 718 | } |
| 719 | |
Colin Cross | eafb10c | 2018-04-16 13:58:10 -0700 | [diff] [blame] | 720 | func renameMutator(ctx BottomUpMutatorContext) { |
| 721 | if m, ok := ctx.Module().(*testModule); ok { |
| 722 | if m.properties.Rename != "" { |
| 723 | ctx.Rename(m.properties.Rename) |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 728 | func newTestModule() Module { |
| 729 | m := &testModule{} |
| 730 | m.AddProperties(&m.properties) |
| 731 | InitAndroidModule(m) |
| 732 | return m |
| 733 | } |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 734 | |
| 735 | type blueprintTestModule struct { |
| 736 | blueprint.SimpleName |
| 737 | properties struct { |
| 738 | Deps []string |
| 739 | } |
| 740 | } |
| 741 | |
Paul Duffin | 0fc6d32 | 2021-07-06 22:36:33 +0100 | [diff] [blame] | 742 | func (b *blueprintTestModule) DynamicDependencies(_ blueprint.DynamicDependerModuleContext) []string { |
Colin Cross | cd84b4e | 2019-06-14 11:26:09 -0700 | [diff] [blame] | 743 | return b.properties.Deps |
| 744 | } |
| 745 | |
| 746 | func (b *blueprintTestModule) GenerateBuildActions(blueprint.ModuleContext) { |
| 747 | } |
| 748 | |
| 749 | func newBlueprintTestModule() (blueprint.Module, []interface{}) { |
| 750 | m := &blueprintTestModule{} |
| 751 | return m, []interface{}{&m.properties, &m.SimpleName.Properties} |
| 752 | } |