Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame^] | 1 | // Copyright 2023 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 bp2build |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/aconfig" |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | func registerAconfigModuleTypes(ctx android.RegistrationContext) { |
| 25 | aconfig.RegisterBuildComponents(ctx) |
| 26 | } |
| 27 | |
| 28 | func TestAconfigDeclarations(t *testing.T) { |
| 29 | bp := ` |
| 30 | aconfig_declarations { |
| 31 | name: "foo", |
| 32 | srcs: [ |
| 33 | "foo1.aconfig", |
| 34 | "test/foo2.aconfig", |
| 35 | ], |
| 36 | package: "com.android.foo", |
| 37 | } |
| 38 | ` |
| 39 | expectedBazelTarget := MakeBazelTargetNoRestrictions( |
| 40 | "aconfig_declarations", |
| 41 | "foo", |
| 42 | AttrNameToString{ |
| 43 | "srcs": `[ |
| 44 | "foo1.aconfig", |
| 45 | "test/foo2.aconfig", |
| 46 | ]`, |
| 47 | "package": `"com.android.foo"`, |
| 48 | }, |
| 49 | ) |
| 50 | RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{ |
| 51 | Blueprint: bp, |
| 52 | ExpectedBazelTargets: []string{expectedBazelTarget}, |
| 53 | }) |
| 54 | } |
| 55 | |
| 56 | func TestAconfigValues(t *testing.T) { |
| 57 | bp := ` |
| 58 | aconfig_values { |
| 59 | name: "foo", |
| 60 | srcs: [ |
| 61 | "foo1.textproto", |
| 62 | ], |
| 63 | package: "com.android.foo", |
| 64 | } |
| 65 | aconfig_value_set { |
| 66 | name: "bar", |
| 67 | values: [ |
| 68 | "foo" |
| 69 | ] |
| 70 | } |
| 71 | ` |
| 72 | expectedBazelTargets := []string{ |
| 73 | MakeBazelTargetNoRestrictions( |
| 74 | "aconfig_values", |
| 75 | "foo", |
| 76 | AttrNameToString{ |
| 77 | "srcs": `["foo1.textproto"]`, |
| 78 | "package": `"com.android.foo"`, |
| 79 | }, |
| 80 | ), |
| 81 | MakeBazelTargetNoRestrictions( |
| 82 | "aconfig_value_set", |
| 83 | "bar", |
| 84 | AttrNameToString{ |
| 85 | "values": `[":foo"]`, |
| 86 | }, |
| 87 | )} |
| 88 | RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{ |
| 89 | Blueprint: bp, |
| 90 | ExpectedBazelTargets: expectedBazelTargets, |
| 91 | }) |
| 92 | } |