| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 1 | // Copyright 2021 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 ( | 
| Yu Liu | d620101 | 2022-10-17 12:29:15 -0700 | [diff] [blame] | 18 | "fmt" | 
| Liz Kammer | 0db0e34 | 2023-07-18 11:39:30 -0400 | [diff] [blame] | 19 | "path/filepath" | 
| Yu Liu | d620101 | 2022-10-17 12:29:15 -0700 | [diff] [blame] | 20 | "testing" | 
|  | 21 |  | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 22 | "android/soong/android" | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 23 | "android/soong/cc" | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 24 | "android/soong/genrule" | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 25 | "android/soong/java" | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 26 | ) | 
|  | 27 |  | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 28 | func registerGenruleModuleTypes(ctx android.RegistrationContext) { | 
|  | 29 | ctx.RegisterModuleType("genrule_defaults", func() android.Module { return genrule.DefaultsFactory() }) | 
| Spandan Das | f62e80a | 2023-08-17 22:35:04 +0000 | [diff] [blame] | 30 | ctx.RegisterModuleType("cc_binary", func() android.Module { return cc.BinaryFactory() }) | 
|  | 31 | ctx.RegisterModuleType("soong_namespace", func() android.Module { return android.NamespaceFactory() }) | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 34 | func runGenruleTestCase(t *testing.T, tc Bp2buildTestCase) { | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 35 | t.Helper() | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 36 | (&tc).ModuleTypeUnderTest = "genrule" | 
|  | 37 | (&tc).ModuleTypeUnderTestFactory = genrule.GenRuleFactory | 
|  | 38 | RunBp2BuildTestCase(t, registerGenruleModuleTypes, tc) | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 39 | } | 
|  | 40 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 41 | func otherGenruleBp(genruleTarget string) map[string]string { | 
|  | 42 | return map[string]string{ | 
|  | 43 | "other/Android.bp": fmt.Sprintf(`%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 44 | name: "foo.tool", | 
|  | 45 | out: ["foo_tool.out"], | 
|  | 46 | srcs: ["foo_tool.in"], | 
|  | 47 | cmd: "cp $(in) $(out)", | 
|  | 48 | } | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 49 | %s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 50 | name: "other.tool", | 
|  | 51 | out: ["other_tool.out"], | 
|  | 52 | srcs: ["other_tool.in"], | 
|  | 53 | cmd: "cp $(in) $(out)", | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 54 | }`, genruleTarget, genruleTarget), | 
| Liz Kammer | 1e75324 | 2023-06-02 19:03:06 -0400 | [diff] [blame] | 55 | "other/file.txt": "", | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 56 | } | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | func TestGenruleCliVariableReplacement(t *testing.T) { | 
|  | 60 | testCases := []struct { | 
|  | 61 | moduleType string | 
|  | 62 | factory    android.ModuleFactory | 
|  | 63 | genDir     string | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 64 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 65 | }{ | 
|  | 66 | { | 
|  | 67 | moduleType: "genrule", | 
|  | 68 | factory:    genrule.GenRuleFactory, | 
| Vinh Tran | f19b658 | 2022-09-21 17:01:49 -0400 | [diff] [blame] | 69 | genDir:     "$(RULEDIR)", | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 70 | }, | 
|  | 71 | { | 
|  | 72 | moduleType: "cc_genrule", | 
|  | 73 | factory:    cc.GenRuleFactory, | 
|  | 74 | genDir:     "$(RULEDIR)", | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 75 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 76 | }, | 
|  | 77 | { | 
|  | 78 | moduleType: "java_genrule", | 
|  | 79 | factory:    java.GenRuleFactory, | 
|  | 80 | genDir:     "$(RULEDIR)", | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 81 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 82 | }, | 
|  | 83 | { | 
|  | 84 | moduleType: "java_genrule_host", | 
|  | 85 | factory:    java.GenRuleFactoryHost, | 
|  | 86 | genDir:     "$(RULEDIR)", | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 87 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 88 | }, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 91 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 92 | name: "foo.tool", | 
|  | 93 | out: ["foo_tool.out"], | 
|  | 94 | srcs: ["foo_tool.in"], | 
|  | 95 | cmd: "cp $(in) $(out)", | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 98 | %s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 99 | name: "foo", | 
|  | 100 | out: ["foo.out"], | 
|  | 101 | srcs: ["foo.in"], | 
|  | 102 | tools: [":foo.tool"], | 
|  | 103 | cmd: "$(location :foo.tool) --genDir=$(genDir) arg $(in) $(out)", | 
|  | 104 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 105 | }` | 
|  | 106 |  | 
|  | 107 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 108 | moduleAttrs := AttrNameToString{ | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 109 | "cmd":   fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir), | 
|  | 110 | "outs":  `["foo.out"]`, | 
|  | 111 | "srcs":  `["foo.in"]`, | 
|  | 112 | "tools": `[":foo.tool"]`, | 
|  | 113 | } | 
|  | 114 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 115 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 116 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 117 | } | 
|  | 118 |  | 
|  | 119 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 120 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 121 | Bp2buildTestCase{ | 
|  | 122 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 123 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 124 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType, tc.moduleType), | 
|  | 125 | ExpectedBazelTargets:       expectedBazelTargets, | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 126 | StubbedBuildDefinitions:    []string{"foo.tool", "other.tool"}, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 127 | }) | 
|  | 128 | }) | 
|  | 129 | } | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | func TestGenruleLocationsLabel(t *testing.T) { | 
|  | 133 | testCases := []struct { | 
|  | 134 | moduleType string | 
|  | 135 | factory    android.ModuleFactory | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 136 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 137 | }{ | 
|  | 138 | { | 
|  | 139 | moduleType: "genrule", | 
|  | 140 | factory:    genrule.GenRuleFactory, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 141 | }, | 
|  | 142 | { | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 143 | moduleType: "cc_genrule", | 
|  | 144 | factory:    cc.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 145 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 146 | }, | 
|  | 147 | { | 
|  | 148 | moduleType: "java_genrule", | 
|  | 149 | factory:    java.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 150 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 151 | }, | 
|  | 152 | { | 
|  | 153 | moduleType: "java_genrule_host", | 
|  | 154 | factory:    java.GenRuleFactoryHost, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 155 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 156 | }, | 
|  | 157 | } | 
|  | 158 |  | 
|  | 159 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 160 | name: "foo.tools", | 
|  | 161 | out: ["foo_tool.out", "foo_tool2.out"], | 
|  | 162 | srcs: ["foo_tool.in"], | 
|  | 163 | cmd: "cp $(in) $(out)", | 
|  | 164 | bazel_module: { bp2build_available: true }, | 
|  | 165 | } | 
|  | 166 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 167 | %s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 168 | name: "foo", | 
|  | 169 | out: ["foo.out"], | 
|  | 170 | srcs: ["foo.in"], | 
|  | 171 | tools: [":foo.tools"], | 
|  | 172 | cmd: "$(locations :foo.tools) -s $(out) $(in)", | 
|  | 173 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 174 | }` | 
|  | 175 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 176 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 177 | fooAttrs := AttrNameToString{ | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 178 | "cmd":   `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`, | 
|  | 179 | "outs":  `["foo.out"]`, | 
|  | 180 | "srcs":  `["foo.in"]`, | 
|  | 181 | "tools": `[":foo.tools"]`, | 
|  | 182 | } | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 183 | fooToolsAttrs := AttrNameToString{ | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 184 | "cmd": `"cp $(SRCS) $(OUTS)"`, | 
|  | 185 | "outs": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 186 | "foo_tool.out", | 
|  | 187 | "foo_tool2.out", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 188 | ]`, | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 189 | "srcs": `["foo_tool.in"]`, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 192 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 193 | makeBazelTargetHostOrDevice("genrule", "foo", fooAttrs, tc.hod), | 
|  | 194 | makeBazelTargetHostOrDevice("genrule", "foo.tools", fooToolsAttrs, tc.hod), | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 197 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 198 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 199 | Bp2buildTestCase{ | 
|  | 200 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 201 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 202 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType, tc.moduleType), | 
|  | 203 | ExpectedBazelTargets:       expectedBazelTargets, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 204 | }) | 
|  | 205 | }) | 
|  | 206 | } | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 | func TestGenruleLocationsAbsoluteLabel(t *testing.T) { | 
|  | 210 | testCases := []struct { | 
|  | 211 | moduleType string | 
|  | 212 | factory    android.ModuleFactory | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 213 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 214 | }{ | 
|  | 215 | { | 
|  | 216 | moduleType: "genrule", | 
|  | 217 | factory:    genrule.GenRuleFactory, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 218 | }, | 
|  | 219 | { | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 220 | moduleType: "cc_genrule", | 
|  | 221 | factory:    cc.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 222 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 223 | }, | 
|  | 224 | { | 
|  | 225 | moduleType: "java_genrule", | 
|  | 226 | factory:    java.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 227 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 228 | }, | 
|  | 229 | { | 
|  | 230 | moduleType: "java_genrule_host", | 
|  | 231 | factory:    java.GenRuleFactoryHost, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 232 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 233 | }, | 
|  | 234 | } | 
|  | 235 |  | 
|  | 236 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 237 | name: "foo", | 
|  | 238 | out: ["foo.out"], | 
|  | 239 | srcs: ["foo.in"], | 
|  | 240 | tool_files: [":foo.tool"], | 
|  | 241 | cmd: "$(locations :foo.tool) -s $(out) $(in)", | 
|  | 242 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 243 | }` | 
|  | 244 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 245 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 246 | moduleAttrs := AttrNameToString{ | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 247 | "cmd":   `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, | 
|  | 248 | "outs":  `["foo.out"]`, | 
|  | 249 | "srcs":  `["foo.in"]`, | 
|  | 250 | "tools": `["//other:foo.tool"]`, | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 251 | } | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 252 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 253 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 254 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 255 | } | 
|  | 256 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 257 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 258 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 259 | Bp2buildTestCase{ | 
|  | 260 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 261 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 262 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 263 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 264 | Filesystem:                 otherGenruleBp(tc.moduleType), | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 265 | StubbedBuildDefinitions:    []string{"//other:foo.tool"}, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 266 | }) | 
|  | 267 | }) | 
|  | 268 | } | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) { | 
|  | 272 | testCases := []struct { | 
|  | 273 | moduleType string | 
|  | 274 | factory    android.ModuleFactory | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 275 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 276 | }{ | 
|  | 277 | { | 
|  | 278 | moduleType: "genrule", | 
|  | 279 | factory:    genrule.GenRuleFactory, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 280 | }, | 
|  | 281 | { | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 282 | moduleType: "cc_genrule", | 
|  | 283 | factory:    cc.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 284 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 285 | }, | 
|  | 286 | { | 
|  | 287 | moduleType: "java_genrule", | 
|  | 288 | factory:    java.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 289 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 290 | }, | 
|  | 291 | { | 
|  | 292 | moduleType: "java_genrule_host", | 
|  | 293 | factory:    java.GenRuleFactoryHost, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 294 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 295 | }, | 
|  | 296 | } | 
|  | 297 |  | 
|  | 298 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 299 | name: "foo", | 
|  | 300 | out: ["foo.out"], | 
| Liz Kammer | 1e75324 | 2023-06-02 19:03:06 -0400 | [diff] [blame] | 301 | srcs: [":other.tool", "other/file.txt",], | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 302 | tool_files: [":foo.tool"], | 
| Liz Kammer | 1e75324 | 2023-06-02 19:03:06 -0400 | [diff] [blame] | 303 | cmd: "$(locations :foo.tool) $(location other/file.txt) -s $(out) $(location :other.tool)", | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 304 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 305 | }` | 
|  | 306 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 307 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 308 | moduleAttrs := AttrNameToString{ | 
| Liz Kammer | 1e75324 | 2023-06-02 19:03:06 -0400 | [diff] [blame] | 309 | "cmd":  `"$(locations //other:foo.tool) $(location //other:file.txt) -s $(OUTS) $(location //other:other.tool)"`, | 
|  | 310 | "outs": `["foo.out"]`, | 
|  | 311 | "srcs": `[ | 
|  | 312 | "//other:other.tool", | 
|  | 313 | "//other:file.txt", | 
|  | 314 | ]`, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 315 | "tools": `["//other:foo.tool"]`, | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 316 | } | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 317 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 318 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 319 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 320 | } | 
|  | 321 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 322 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 323 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 324 | Bp2buildTestCase{ | 
|  | 325 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 326 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 327 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 328 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 329 | Filesystem:                 otherGenruleBp(tc.moduleType), | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 330 | StubbedBuildDefinitions:    []string{"//other:foo.tool", "//other:other.tool"}, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 331 | }) | 
|  | 332 | }) | 
|  | 333 | } | 
|  | 334 | } | 
|  | 335 |  | 
|  | 336 | func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { | 
|  | 337 | testCases := []struct { | 
|  | 338 | moduleType string | 
|  | 339 | factory    android.ModuleFactory | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 340 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 341 | }{ | 
|  | 342 | { | 
|  | 343 | moduleType: "genrule", | 
|  | 344 | factory:    genrule.GenRuleFactory, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 345 | }, | 
|  | 346 | { | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 347 | moduleType: "cc_genrule", | 
|  | 348 | factory:    cc.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 349 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 350 | }, | 
|  | 351 | { | 
|  | 352 | moduleType: "java_genrule", | 
|  | 353 | factory:    java.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 354 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 355 | }, | 
|  | 356 | { | 
|  | 357 | moduleType: "java_genrule_host", | 
|  | 358 | factory:    java.GenRuleFactoryHost, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 359 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 360 | }, | 
|  | 361 | } | 
|  | 362 |  | 
|  | 363 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 364 | name: "foo", | 
|  | 365 | out: ["foo.out"], | 
|  | 366 | srcs: ["foo.in"], | 
|  | 367 | tool_files: [":foo.tool", ":other.tool"], | 
|  | 368 | cmd: "$(location) -s $(out) $(in)", | 
|  | 369 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 370 | }` | 
|  | 371 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 372 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 373 | moduleAttrs := AttrNameToString{ | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 374 | "cmd":  `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`, | 
|  | 375 | "outs": `["foo.out"]`, | 
|  | 376 | "srcs": `["foo.in"]`, | 
|  | 377 | "tools": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 378 | "//other:foo.tool", | 
|  | 379 | "//other:other.tool", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 380 | ]`, | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 381 | } | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 382 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 383 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 384 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 385 | } | 
|  | 386 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 387 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 388 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 389 | Bp2buildTestCase{ | 
|  | 390 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 391 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 392 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 393 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 394 | Filesystem:                 otherGenruleBp(tc.moduleType), | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 395 | StubbedBuildDefinitions:    []string{"//other:foo.tool", "//other:other.tool"}, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 396 | }) | 
|  | 397 | }) | 
|  | 398 | } | 
|  | 399 | } | 
|  | 400 |  | 
|  | 401 | func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { | 
|  | 402 | testCases := []struct { | 
|  | 403 | moduleType string | 
|  | 404 | factory    android.ModuleFactory | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 405 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 406 | }{ | 
|  | 407 | { | 
|  | 408 | moduleType: "genrule", | 
|  | 409 | factory:    genrule.GenRuleFactory, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 410 | }, | 
|  | 411 | { | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 412 | moduleType: "cc_genrule", | 
|  | 413 | factory:    cc.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 414 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 415 | }, | 
|  | 416 | { | 
|  | 417 | moduleType: "java_genrule", | 
|  | 418 | factory:    java.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 419 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 420 | }, | 
|  | 421 | { | 
|  | 422 | moduleType: "java_genrule_host", | 
|  | 423 | factory:    java.GenRuleFactoryHost, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 424 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 425 | }, | 
|  | 426 | } | 
|  | 427 |  | 
|  | 428 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 429 | name: "foo", | 
|  | 430 | out: ["foo.out"], | 
|  | 431 | srcs: ["foo.in"], | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 432 | tool_files: [":foo.tool", ":other.tool"], | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 433 | cmd: "$(locations) -s $(out) $(in)", | 
|  | 434 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 435 | }` | 
|  | 436 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 437 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 438 | moduleAttrs := AttrNameToString{ | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 439 | "cmd":  `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, | 
|  | 440 | "outs": `["foo.out"]`, | 
|  | 441 | "srcs": `["foo.in"]`, | 
|  | 442 | "tools": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 443 | "//other:foo.tool", | 
|  | 444 | "//other:other.tool", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 445 | ]`, | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 446 | } | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 447 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 448 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 449 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 450 | } | 
|  | 451 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 452 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 453 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 454 | Bp2buildTestCase{ | 
|  | 455 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 456 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 457 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 458 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 459 | Filesystem:                 otherGenruleBp(tc.moduleType), | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 460 | StubbedBuildDefinitions:    []string{"//other:foo.tool", "//other:other.tool"}, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 461 | }) | 
|  | 462 | }) | 
|  | 463 | } | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | func TestGenruleWithoutToolsOrToolFiles(t *testing.T) { | 
|  | 467 | testCases := []struct { | 
|  | 468 | moduleType string | 
|  | 469 | factory    android.ModuleFactory | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 470 | hod        android.HostOrDeviceSupported | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 471 | }{ | 
|  | 472 | { | 
|  | 473 | moduleType: "genrule", | 
|  | 474 | factory:    genrule.GenRuleFactory, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 475 | }, | 
|  | 476 | { | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 477 | moduleType: "cc_genrule", | 
|  | 478 | factory:    cc.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 479 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 480 | }, | 
|  | 481 | { | 
|  | 482 | moduleType: "java_genrule", | 
|  | 483 | factory:    java.GenRuleFactory, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 484 | hod:        android.DeviceSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 485 | }, | 
|  | 486 | { | 
|  | 487 | moduleType: "java_genrule_host", | 
|  | 488 | factory:    java.GenRuleFactoryHost, | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 489 | hod:        android.HostSupported, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 490 | }, | 
|  | 491 | } | 
|  | 492 |  | 
|  | 493 | bp := `%s { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 494 | name: "foo", | 
|  | 495 | out: ["foo.out"], | 
|  | 496 | srcs: ["foo.in"], | 
|  | 497 | cmd: "cp $(in) $(out)", | 
|  | 498 | bazel_module: { bp2build_available: true }, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 499 | }` | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 500 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 501 | for _, tc := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 502 | moduleAttrs := AttrNameToString{ | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 503 | "cmd":  `"cp $(SRCS) $(OUTS)"`, | 
|  | 504 | "outs": `["foo.out"]`, | 
|  | 505 | "srcs": `["foo.in"]`, | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 506 | } | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 507 |  | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 508 | expectedBazelTargets := []string{ | 
| Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 509 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
| Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 510 | } | 
|  | 511 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 512 | t.Run(tc.moduleType, func(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 513 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 514 | Bp2buildTestCase{ | 
|  | 515 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 516 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 517 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 518 | ExpectedBazelTargets:       expectedBazelTargets, | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 519 | }) | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 520 | }) | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 521 | } | 
|  | 522 | } | 
|  | 523 |  | 
| Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 524 | func TestGenruleBp2BuildInlinesDefaults(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 525 | testCases := []Bp2buildTestCase{ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 526 | { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 527 | Description: "genrule applies properties from a genrule_defaults dependency if not specified", | 
|  | 528 | Blueprint: `genrule_defaults { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 529 | name: "gen_defaults", | 
|  | 530 | cmd: "do-something $(in) $(out)", | 
|  | 531 | } | 
|  | 532 | genrule { | 
|  | 533 | name: "gen", | 
|  | 534 | out: ["out"], | 
|  | 535 | srcs: ["in1"], | 
|  | 536 | defaults: ["gen_defaults"], | 
|  | 537 | bazel_module: { bp2build_available: true }, | 
|  | 538 | } | 
|  | 539 | `, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 540 | ExpectedBazelTargets: []string{ | 
|  | 541 | MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 542 | "cmd":  `"do-something $(SRCS) $(OUTS)"`, | 
|  | 543 | "outs": `["out"]`, | 
|  | 544 | "srcs": `["in1"]`, | 
|  | 545 | }), | 
|  | 546 | }, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 547 | }, | 
|  | 548 | { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 549 | Description: "genrule does merges properties from a genrule_defaults dependency, latest-first", | 
|  | 550 | Blueprint: `genrule_defaults { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 551 | name: "gen_defaults", | 
|  | 552 | out: ["out-from-defaults"], | 
|  | 553 | srcs: ["in-from-defaults"], | 
|  | 554 | cmd: "cmd-from-defaults", | 
|  | 555 | } | 
|  | 556 | genrule { | 
|  | 557 | name: "gen", | 
|  | 558 | out: ["out"], | 
|  | 559 | srcs: ["in1"], | 
|  | 560 | defaults: ["gen_defaults"], | 
|  | 561 | cmd: "do-something $(in) $(out)", | 
|  | 562 | bazel_module: { bp2build_available: true }, | 
|  | 563 | } | 
|  | 564 | `, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 565 | ExpectedBazelTargets: []string{ | 
|  | 566 | MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 567 | "cmd": `"do-something $(SRCS) $(OUTS)"`, | 
|  | 568 | "outs": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 569 | "out-from-defaults", | 
|  | 570 | "out", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 571 | ]`, | 
|  | 572 | "srcs": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 573 | "in-from-defaults", | 
|  | 574 | "in1", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 575 | ]`, | 
|  | 576 | }), | 
|  | 577 | }, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 578 | }, | 
|  | 579 | { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 580 | Description: "genrule applies properties from list of genrule_defaults", | 
|  | 581 | Blueprint: `genrule_defaults { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 582 | name: "gen_defaults1", | 
|  | 583 | cmd: "cp $(in) $(out)", | 
|  | 584 | } | 
|  | 585 |  | 
|  | 586 | genrule_defaults { | 
|  | 587 | name: "gen_defaults2", | 
|  | 588 | srcs: ["in1"], | 
|  | 589 | } | 
|  | 590 |  | 
|  | 591 | genrule { | 
|  | 592 | name: "gen", | 
|  | 593 | out: ["out"], | 
|  | 594 | defaults: ["gen_defaults1", "gen_defaults2"], | 
|  | 595 | bazel_module: { bp2build_available: true }, | 
|  | 596 | } | 
|  | 597 | `, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 598 | ExpectedBazelTargets: []string{ | 
|  | 599 | MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 600 | "cmd":  `"cp $(SRCS) $(OUTS)"`, | 
|  | 601 | "outs": `["out"]`, | 
|  | 602 | "srcs": `["in1"]`, | 
|  | 603 | }), | 
|  | 604 | }, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 605 | }, | 
|  | 606 | { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 607 | Description: "genrule applies properties from genrule_defaults transitively", | 
|  | 608 | Blueprint: `genrule_defaults { | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 609 | name: "gen_defaults1", | 
|  | 610 | defaults: ["gen_defaults2"], | 
|  | 611 | cmd: "cmd1 $(in) $(out)", // overrides gen_defaults2's cmd property value. | 
|  | 612 | } | 
|  | 613 |  | 
|  | 614 | genrule_defaults { | 
|  | 615 | name: "gen_defaults2", | 
|  | 616 | defaults: ["gen_defaults3"], | 
|  | 617 | cmd: "cmd2 $(in) $(out)", | 
|  | 618 | out: ["out-from-2"], | 
|  | 619 | srcs: ["in1"], | 
|  | 620 | } | 
|  | 621 |  | 
|  | 622 | genrule_defaults { | 
|  | 623 | name: "gen_defaults3", | 
|  | 624 | out: ["out-from-3"], | 
|  | 625 | srcs: ["srcs-from-3"], | 
|  | 626 | } | 
|  | 627 |  | 
|  | 628 | genrule { | 
|  | 629 | name: "gen", | 
|  | 630 | out: ["out"], | 
|  | 631 | defaults: ["gen_defaults1"], | 
|  | 632 | bazel_module: { bp2build_available: true }, | 
|  | 633 | } | 
|  | 634 | `, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 635 | ExpectedBazelTargets: []string{ | 
|  | 636 | MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 637 | "cmd": `"cmd1 $(SRCS) $(OUTS)"`, | 
|  | 638 | "outs": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 639 | "out-from-3", | 
|  | 640 | "out-from-2", | 
|  | 641 | "out", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 642 | ]`, | 
|  | 643 | "srcs": `[ | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 644 | "srcs-from-3", | 
|  | 645 | "in1", | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 646 | ]`, | 
|  | 647 | }), | 
|  | 648 | }, | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 649 | }, | 
|  | 650 | } | 
|  | 651 |  | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 652 | for _, testCase := range testCases { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 653 | t.Run(testCase.Description, func(t *testing.T) { | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 654 | runGenruleTestCase(t, testCase) | 
|  | 655 | }) | 
| Rupert Shuttleworth | c5fa306 | 2021-09-08 10:36:41 -0400 | [diff] [blame] | 656 | } | 
|  | 657 | } | 
| Yu Liu | d620101 | 2022-10-17 12:29:15 -0700 | [diff] [blame] | 658 |  | 
|  | 659 | func TestCcGenruleArchAndExcludeSrcs(t *testing.T) { | 
|  | 660 | name := "cc_genrule with arch" | 
|  | 661 | bp := ` | 
|  | 662 | cc_genrule { | 
|  | 663 | name: "foo", | 
|  | 664 | srcs: [ | 
|  | 665 | "foo1.in", | 
|  | 666 | "foo2.in", | 
|  | 667 | ], | 
|  | 668 | exclude_srcs: ["foo2.in"], | 
|  | 669 | arch: { | 
|  | 670 | arm: { | 
|  | 671 | srcs: [ | 
|  | 672 | "foo1_arch.in", | 
|  | 673 | "foo2_arch.in", | 
|  | 674 | ], | 
|  | 675 | exclude_srcs: ["foo2_arch.in"], | 
|  | 676 | }, | 
|  | 677 | }, | 
|  | 678 | cmd: "cat $(in) > $(out)", | 
|  | 679 | bazel_module: { bp2build_available: true }, | 
|  | 680 | }` | 
|  | 681 |  | 
|  | 682 | expectedBazelAttrs := AttrNameToString{ | 
|  | 683 | "srcs": `["foo1.in"] + select({ | 
| Jingwen Chen | 9c2e3ee | 2023-10-11 10:51:28 +0000 | [diff] [blame] | 684 | "//build/bazel_common_rules/platforms/arch:arm": ["foo1_arch.in"], | 
| Yu Liu | d620101 | 2022-10-17 12:29:15 -0700 | [diff] [blame] | 685 | "//conditions:default": [], | 
|  | 686 | })`, | 
|  | 687 | "cmd":                    `"cat $(SRCS) > $(OUTS)"`, | 
| Jingwen Chen | 9c2e3ee | 2023-10-11 10:51:28 +0000 | [diff] [blame] | 688 | "target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`, | 
| Yu Liu | d620101 | 2022-10-17 12:29:15 -0700 | [diff] [blame] | 689 | } | 
|  | 690 |  | 
|  | 691 | expectedBazelTargets := []string{ | 
|  | 692 | MakeBazelTargetNoRestrictions("genrule", "foo", expectedBazelAttrs), | 
|  | 693 | } | 
|  | 694 |  | 
|  | 695 | t.Run(name, func(t *testing.T) { | 
|  | 696 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 697 | Bp2buildTestCase{ | 
|  | 698 | ModuleTypeUnderTest:        "cc_genrule", | 
|  | 699 | ModuleTypeUnderTestFactory: cc.GenRuleFactory, | 
|  | 700 | Blueprint:                  bp, | 
|  | 701 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 702 | }) | 
|  | 703 | }) | 
|  | 704 | } | 
| Liz Kammer | 0db0e34 | 2023-07-18 11:39:30 -0400 | [diff] [blame] | 705 |  | 
|  | 706 | func TestGenruleWithExportIncludeDirs(t *testing.T) { | 
|  | 707 | testCases := []struct { | 
|  | 708 | moduleType string | 
|  | 709 | factory    android.ModuleFactory | 
|  | 710 | hod        android.HostOrDeviceSupported | 
|  | 711 | }{ | 
|  | 712 | { | 
|  | 713 | moduleType: "genrule", | 
|  | 714 | factory:    genrule.GenRuleFactory, | 
|  | 715 | }, | 
|  | 716 | { | 
|  | 717 | moduleType: "cc_genrule", | 
|  | 718 | factory:    cc.GenRuleFactory, | 
|  | 719 | hod:        android.DeviceSupported, | 
|  | 720 | }, | 
|  | 721 | { | 
|  | 722 | moduleType: "java_genrule", | 
|  | 723 | factory:    java.GenRuleFactory, | 
|  | 724 | hod:        android.DeviceSupported, | 
|  | 725 | }, | 
|  | 726 | { | 
|  | 727 | moduleType: "java_genrule_host", | 
|  | 728 | factory:    java.GenRuleFactoryHost, | 
|  | 729 | hod:        android.HostSupported, | 
|  | 730 | }, | 
|  | 731 | } | 
|  | 732 |  | 
|  | 733 | dir := "baz" | 
|  | 734 |  | 
|  | 735 | bp := `%s { | 
|  | 736 | name: "foo", | 
|  | 737 | out: ["foo.out.h"], | 
|  | 738 | srcs: ["foo.in"], | 
|  | 739 | cmd: "cp $(in) $(out)", | 
|  | 740 | export_include_dirs: ["foo", "bar", "."], | 
|  | 741 | bazel_module: { bp2build_available: true }, | 
|  | 742 | }` | 
|  | 743 |  | 
|  | 744 | for _, tc := range testCases { | 
|  | 745 | moduleAttrs := AttrNameToString{ | 
|  | 746 | "cmd":  `"cp $(SRCS) $(OUTS)"`, | 
|  | 747 | "outs": `["foo.out.h"]`, | 
|  | 748 | "srcs": `["foo.in"]`, | 
|  | 749 | } | 
|  | 750 |  | 
|  | 751 | expectedBazelTargets := []string{ | 
|  | 752 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
|  | 753 | makeBazelTargetHostOrDevice("cc_library_headers", "foo__header_library", AttrNameToString{ | 
|  | 754 | "hdrs": `[":foo"]`, | 
|  | 755 | "export_includes": `[ | 
|  | 756 | "foo", | 
|  | 757 | "baz/foo", | 
|  | 758 | "bar", | 
|  | 759 | "baz/bar", | 
|  | 760 | ".", | 
|  | 761 | "baz", | 
|  | 762 | ]`, | 
|  | 763 | }, | 
|  | 764 | tc.hod), | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | t.Run(tc.moduleType, func(t *testing.T) { | 
|  | 768 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, | 
|  | 769 | Bp2buildTestCase{ | 
|  | 770 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 771 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 772 | Filesystem: map[string]string{ | 
|  | 773 | filepath.Join(dir, "Android.bp"): fmt.Sprintf(bp, tc.moduleType), | 
|  | 774 | }, | 
|  | 775 | Dir:                  dir, | 
|  | 776 | ExpectedBazelTargets: expectedBazelTargets, | 
|  | 777 | }) | 
|  | 778 | }) | 
|  | 779 | } | 
|  | 780 | } | 
| Cole Faust | f0d4d4f | 2023-08-14 11:37:54 -0700 | [diff] [blame] | 781 |  | 
| Cole Faust | ed94000 | 2023-08-15 11:59:24 -0700 | [diff] [blame] | 782 | func TestGenruleWithSoongConfigVariableConfiguredCmd(t *testing.T) { | 
| Cole Faust | f0d4d4f | 2023-08-14 11:37:54 -0700 | [diff] [blame] | 783 | testCases := []struct { | 
|  | 784 | moduleType string | 
|  | 785 | factory    android.ModuleFactory | 
|  | 786 | hod        android.HostOrDeviceSupported | 
|  | 787 | }{ | 
|  | 788 | { | 
|  | 789 | moduleType: "genrule", | 
|  | 790 | factory:    genrule.GenRuleFactory, | 
|  | 791 | }, | 
|  | 792 | { | 
|  | 793 | moduleType: "cc_genrule", | 
|  | 794 | factory:    cc.GenRuleFactory, | 
|  | 795 | hod:        android.DeviceSupported, | 
|  | 796 | }, | 
|  | 797 | { | 
|  | 798 | moduleType: "java_genrule", | 
|  | 799 | factory:    java.GenRuleFactory, | 
|  | 800 | hod:        android.DeviceSupported, | 
|  | 801 | }, | 
|  | 802 | { | 
|  | 803 | moduleType: "java_genrule_host", | 
|  | 804 | factory:    java.GenRuleFactoryHost, | 
|  | 805 | hod:        android.HostSupported, | 
|  | 806 | }, | 
|  | 807 | } | 
|  | 808 |  | 
|  | 809 | bp := ` | 
|  | 810 | soong_config_module_type { | 
|  | 811 | name: "my_genrule", | 
|  | 812 | module_type: "%s", | 
|  | 813 | config_namespace: "my_namespace", | 
|  | 814 | bool_variables: ["my_variable"], | 
|  | 815 | properties: ["cmd"], | 
|  | 816 | } | 
|  | 817 |  | 
|  | 818 | my_genrule { | 
|  | 819 | name: "foo", | 
|  | 820 | out: ["foo.txt"], | 
|  | 821 | cmd: "echo 'no variable' > $(out)", | 
|  | 822 | soong_config_variables: { | 
|  | 823 | my_variable: { | 
|  | 824 | cmd: "echo 'with variable' > $(out)", | 
|  | 825 | }, | 
|  | 826 | }, | 
|  | 827 | bazel_module: { bp2build_available: true }, | 
|  | 828 | } | 
|  | 829 | ` | 
|  | 830 |  | 
|  | 831 | for _, tc := range testCases { | 
|  | 832 | moduleAttrs := AttrNameToString{ | 
|  | 833 | "cmd": `select({ | 
|  | 834 | "//build/bazel/product_config/config_settings:my_namespace__my_variable": "echo 'with variable' > $(OUTS)", | 
|  | 835 | "//conditions:default": "echo 'no variable' > $(OUTS)", | 
|  | 836 | })`, | 
|  | 837 | "outs": `["foo.txt"]`, | 
|  | 838 | } | 
|  | 839 |  | 
|  | 840 | expectedBazelTargets := []string{ | 
|  | 841 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
|  | 842 | } | 
|  | 843 |  | 
|  | 844 | t.Run(tc.moduleType, func(t *testing.T) { | 
|  | 845 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) }, | 
|  | 846 | Bp2buildTestCase{ | 
|  | 847 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 848 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 849 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 850 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 851 | }) | 
|  | 852 | }) | 
|  | 853 | } | 
|  | 854 | } | 
| Cole Faust | ed94000 | 2023-08-15 11:59:24 -0700 | [diff] [blame] | 855 |  | 
|  | 856 | func TestGenruleWithProductVariableConfiguredCmd(t *testing.T) { | 
|  | 857 | testCases := []struct { | 
|  | 858 | moduleType string | 
|  | 859 | factory    android.ModuleFactory | 
|  | 860 | hod        android.HostOrDeviceSupported | 
|  | 861 | }{ | 
|  | 862 | { | 
|  | 863 | moduleType: "genrule", | 
|  | 864 | factory:    genrule.GenRuleFactory, | 
|  | 865 | }, | 
|  | 866 | { | 
|  | 867 | moduleType: "cc_genrule", | 
|  | 868 | factory:    cc.GenRuleFactory, | 
|  | 869 | hod:        android.DeviceSupported, | 
|  | 870 | }, | 
|  | 871 | { | 
|  | 872 | moduleType: "java_genrule", | 
|  | 873 | factory:    java.GenRuleFactory, | 
|  | 874 | hod:        android.DeviceSupported, | 
|  | 875 | }, | 
|  | 876 | { | 
|  | 877 | moduleType: "java_genrule_host", | 
|  | 878 | factory:    java.GenRuleFactoryHost, | 
|  | 879 | hod:        android.HostSupported, | 
|  | 880 | }, | 
|  | 881 | } | 
|  | 882 |  | 
|  | 883 | bp := ` | 
|  | 884 |  | 
|  | 885 | %s { | 
|  | 886 | name: "foo", | 
|  | 887 | out: ["foo.txt"], | 
|  | 888 | cmd: "echo 'no variable' > $(out)", | 
|  | 889 | product_variables: { | 
|  | 890 | debuggable: { | 
|  | 891 | cmd: "echo 'with variable' > $(out)", | 
|  | 892 | }, | 
|  | 893 | }, | 
|  | 894 | bazel_module: { bp2build_available: true }, | 
|  | 895 | } | 
|  | 896 | ` | 
|  | 897 |  | 
|  | 898 | for _, tc := range testCases { | 
|  | 899 | moduleAttrs := AttrNameToString{ | 
|  | 900 | "cmd": `select({ | 
|  | 901 | "//build/bazel/product_config/config_settings:debuggable": "echo 'with variable' > $(OUTS)", | 
|  | 902 | "//conditions:default": "echo 'no variable' > $(OUTS)", | 
|  | 903 | })`, | 
|  | 904 | "outs": `["foo.txt"]`, | 
|  | 905 | } | 
|  | 906 |  | 
|  | 907 | expectedBazelTargets := []string{ | 
|  | 908 | makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod), | 
|  | 909 | } | 
|  | 910 |  | 
|  | 911 | t.Run(tc.moduleType, func(t *testing.T) { | 
|  | 912 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) }, | 
|  | 913 | Bp2buildTestCase{ | 
|  | 914 | Blueprint:                  fmt.Sprintf(bp, tc.moduleType), | 
|  | 915 | ModuleTypeUnderTest:        tc.moduleType, | 
|  | 916 | ModuleTypeUnderTestFactory: tc.factory, | 
|  | 917 | ExpectedBazelTargets:       expectedBazelTargets, | 
|  | 918 | }) | 
|  | 919 | }) | 
|  | 920 | } | 
|  | 921 | } | 
| Spandan Das | f62e80a | 2023-08-17 22:35:04 +0000 | [diff] [blame] | 922 |  | 
|  | 923 | func TestGenruleWithModulesInNamespaces(t *testing.T) { | 
|  | 924 | bp := ` | 
|  | 925 | genrule { | 
|  | 926 | name: "mygenrule", | 
|  | 927 | cmd: "echo $(location //mynamespace:mymodule) > $(out)", | 
|  | 928 | srcs: ["//mynamespace:mymodule"], | 
|  | 929 | out: ["myout"], | 
|  | 930 | } | 
|  | 931 | ` | 
|  | 932 | fs := map[string]string{ | 
|  | 933 | "mynamespace/Android.bp":     `soong_namespace {}`, | 
|  | 934 | "mynamespace/dir/Android.bp": `cc_binary {name: "mymodule"}`, | 
|  | 935 | } | 
|  | 936 | expectedBazelTargets := []string{ | 
|  | 937 | MakeBazelTargetNoRestrictions("genrule", "mygenrule", AttrNameToString{ | 
|  | 938 | // The fully qualified soong label is <namespace>:<module_name> | 
|  | 939 | // - here the prefix is mynamespace | 
|  | 940 | // The fully qualifed bazel label is <package>:<module_name> | 
|  | 941 | // - here the prefix is mynamespace/dir, since there is a BUILD file at each level of this FS path | 
|  | 942 | "cmd":  `"echo $(location //mynamespace/dir:mymodule) > $(OUTS)"`, | 
|  | 943 | "outs": `["myout"]`, | 
|  | 944 | "srcs": `["//mynamespace/dir:mymodule"]`, | 
|  | 945 | }), | 
|  | 946 | } | 
|  | 947 |  | 
|  | 948 | t.Run("genrule that uses module from a different namespace", func(t *testing.T) { | 
|  | 949 | runGenruleTestCase(t, Bp2buildTestCase{ | 
|  | 950 | Blueprint:                  bp, | 
|  | 951 | Filesystem:                 fs, | 
|  | 952 | ModuleTypeUnderTest:        "genrule", | 
|  | 953 | ModuleTypeUnderTestFactory: genrule.GenRuleFactory, | 
|  | 954 | ExpectedBazelTargets:       expectedBazelTargets, | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 955 | StubbedBuildDefinitions:    []string{"//mynamespace/dir:mymodule"}, | 
| Spandan Das | f62e80a | 2023-08-17 22:35:04 +0000 | [diff] [blame] | 956 | }) | 
|  | 957 | }) | 
|  | 958 |  | 
|  | 959 | } |