blob: cbf42ac069c552869cc8e0f6f0ac875bc3ba3dfb [file] [log] [blame]
Yu Liu2cc802a2023-09-05 17:19:45 -07001// 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
15package bp2build
16
17import (
18 "testing"
19
20 "android/soong/aconfig"
21 "android/soong/android"
Yu Liu855cfc22023-09-14 15:10:03 -070022 "android/soong/cc"
Yu Liu2cc802a2023-09-05 17:19:45 -070023)
24
25func registerAconfigModuleTypes(ctx android.RegistrationContext) {
26 aconfig.RegisterBuildComponents(ctx)
Yu Liu855cfc22023-09-14 15:10:03 -070027 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Yu Liu2cc802a2023-09-05 17:19:45 -070028}
29
30func TestAconfigDeclarations(t *testing.T) {
31 bp := `
32 aconfig_declarations {
33 name: "foo",
34 srcs: [
35 "foo1.aconfig",
36 "test/foo2.aconfig",
37 ],
38 package: "com.android.foo",
39 }
40 `
41 expectedBazelTarget := MakeBazelTargetNoRestrictions(
42 "aconfig_declarations",
43 "foo",
44 AttrNameToString{
45 "srcs": `[
46 "foo1.aconfig",
47 "test/foo2.aconfig",
48 ]`,
49 "package": `"com.android.foo"`,
50 },
51 )
52 RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
53 Blueprint: bp,
54 ExpectedBazelTargets: []string{expectedBazelTarget},
55 })
56}
57
58func TestAconfigValues(t *testing.T) {
59 bp := `
60 aconfig_values {
61 name: "foo",
62 srcs: [
63 "foo1.textproto",
64 ],
65 package: "com.android.foo",
66 }
67 aconfig_value_set {
68 name: "bar",
69 values: [
70 "foo"
71 ]
72 }
73 `
74 expectedBazelTargets := []string{
75 MakeBazelTargetNoRestrictions(
76 "aconfig_values",
77 "foo",
78 AttrNameToString{
79 "srcs": `["foo1.textproto"]`,
80 "package": `"com.android.foo"`,
81 },
82 ),
83 MakeBazelTargetNoRestrictions(
84 "aconfig_value_set",
85 "bar",
86 AttrNameToString{
87 "values": `[":foo"]`,
88 },
89 )}
90 RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
91 Blueprint: bp,
92 ExpectedBazelTargets: expectedBazelTargets,
93 })
94}
Yu Liu855cfc22023-09-14 15:10:03 -070095
96func TestCcAconfigLibrary(t *testing.T) {
97 bp := `
98 aconfig_declarations {
99 name: "foo_aconfig_declarations",
100 srcs: [
101 "foo1.aconfig",
102 ],
103 package: "com.android.foo",
104 }
105 cc_library {
106 name: "server_configurable_flags",
107 srcs: ["bar.cc"],
108 bazel_module: { bp2build_available: false },
109 }
110 cc_aconfig_library {
111 name: "foo",
112 aconfig_declarations: "foo_aconfig_declarations",
113 }
114 `
115 expectedBazelTargets := []string{
116 MakeBazelTargetNoRestrictions(
117 "aconfig_declarations",
118 "foo_aconfig_declarations",
119 AttrNameToString{
120 "srcs": `["foo1.aconfig"]`,
121 "package": `"com.android.foo"`,
122 },
123 ),
124 MakeBazelTargetNoRestrictions(
125 "cc_aconfig_library",
126 "foo",
127 AttrNameToString{
128 "aconfig_declarations": `":foo_aconfig_declarations"`,
129 "dynamic_deps": `[":server_configurable_flags"]`,
130 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
131 },
132 )}
133 RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
134 Blueprint: bp,
135 ExpectedBazelTargets: expectedBazelTargets,
136 })
137}