Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 1 | // Copyright 2016 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 | |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 18 | "path/filepath" |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 19 | "regexp" |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 20 | "strings" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 21 | |
| 22 | "android/soong/bazel" |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 23 | "android/soong/bazel/cquery" |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint" |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func init() { |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 29 | RegisterModuleType("filegroup", FileGroupFactory) |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 32 | var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 33 | ctx.RegisterModuleType("filegroup", FileGroupFactory) |
| 34 | }) |
| 35 | |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 36 | var convertedProtoLibrarySuffix = "_bp2build_converted" |
| 37 | |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 38 | // IsFilegroup checks that a module is a filegroup type |
| 39 | func IsFilegroup(ctx bazel.OtherModuleContext, m blueprint.Module) bool { |
| 40 | return ctx.OtherModuleType(m) == "filegroup" |
| 41 | } |
| 42 | |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 43 | var ( |
| 44 | // ignoring case, checks for proto or protos as an independent word in the name, whether at the |
| 45 | // beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match |
| 46 | filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)") |
| 47 | filegroupLikelyAidlPattern = regexp.MustCompile("(?i)(^|[^a-z])aidl([^a-z]|$)") |
| 48 | |
| 49 | ProtoSrcLabelPartition = bazel.LabelPartition{ |
| 50 | Extensions: []string{".proto"}, |
| 51 | LabelMapper: isFilegroupWithPattern(filegroupLikelyProtoPattern), |
| 52 | } |
| 53 | AidlSrcLabelPartition = bazel.LabelPartition{ |
| 54 | Extensions: []string{".aidl"}, |
| 55 | LabelMapper: isFilegroupWithPattern(filegroupLikelyAidlPattern), |
| 56 | } |
| 57 | ) |
| 58 | |
| 59 | func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper { |
| 60 | return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) { |
| 61 | m, exists := ctx.ModuleFromName(label.OriginalModuleName) |
| 62 | labelStr := label.Label |
| 63 | if !exists || !IsFilegroup(ctx, m) { |
| 64 | return labelStr, false |
| 65 | } |
| 66 | likelyMatched := pattern.MatchString(label.OriginalModuleName) |
| 67 | return labelStr, likelyMatched |
| 68 | } |
| 69 | } |
| 70 | |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 71 | // https://docs.bazel.build/versions/master/be/general.html#filegroup |
| 72 | type bazelFilegroupAttributes struct { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 73 | Srcs bazel.LabelListAttribute |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 76 | type bazelAidlLibraryAttributes struct { |
| 77 | Srcs bazel.LabelListAttribute |
| 78 | Strip_import_prefix *string |
| 79 | } |
| 80 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 81 | // ConvertWithBp2build performs bp2build conversion of filegroup |
| 82 | func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 83 | srcs := bazel.MakeLabelListAttribute( |
| 84 | BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs)) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 85 | |
| 86 | // For Bazel compatibility, don't generate the filegroup if there is only 1 |
| 87 | // source file, and that the source file is named the same as the module |
| 88 | // itself. In Bazel, eponymous filegroups like this would be an error. |
| 89 | // |
| 90 | // Instead, dependents on this single-file filegroup can just depend |
| 91 | // on the file target, instead of rule target, directly. |
| 92 | // |
| 93 | // You may ask: what if a filegroup has multiple files, and one of them |
| 94 | // shares the name? The answer: we haven't seen that in the wild, and |
| 95 | // should lock Soong itself down to prevent the behavior. For now, |
| 96 | // we raise an error if bp2build sees this problem. |
| 97 | for _, f := range srcs.Value.Includes { |
| 98 | if f.Label == fg.Name() { |
| 99 | if len(srcs.Value.Includes) > 1 { |
| 100 | ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name()) |
| 101 | } |
| 102 | return |
| 103 | } |
| 104 | } |
| 105 | |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 106 | // Convert module that has only AIDL files to aidl_library |
| 107 | // If the module has a mixed bag of AIDL and non-AIDL files, split the filegroup manually |
| 108 | // and then convert |
| 109 | if fg.ShouldConvertToAidlLibrary(ctx) { |
| 110 | attrs := &bazelAidlLibraryAttributes{ |
| 111 | Srcs: srcs, |
| 112 | Strip_import_prefix: fg.properties.Path, |
| 113 | } |
Jingwen Chen | 1fd1469 | 2021-02-05 03:01:50 -0500 | [diff] [blame] | 114 | |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 115 | props := bazel.BazelTargetModuleProperties{ |
| 116 | Rule_class: "aidl_library", |
| 117 | Bzl_load_location: "//build/bazel/rules/aidl:library.bzl", |
| 118 | } |
Jingwen Chen | 1fd1469 | 2021-02-05 03:01:50 -0500 | [diff] [blame] | 119 | |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 120 | ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs) |
| 121 | } else { |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 122 | if fg.ShouldConvertToProtoLibrary(ctx) { |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 123 | // TODO(b/246997908): we can remove this tag if we could figure out a |
| 124 | // solution for this bug. |
| 125 | tags := []string{"manual"} |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 126 | attrs := &ProtoAttrs{ |
| 127 | Srcs: srcs, |
| 128 | Strip_import_prefix: fg.properties.Path, |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 129 | Tags: tags, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | ctx.CreateBazelTargetModule( |
| 133 | bazel.BazelTargetModuleProperties{Rule_class: "proto_library"}, |
| 134 | CommonAttributes{Name: fg.Name() + convertedProtoLibrarySuffix}, |
| 135 | attrs) |
| 136 | } |
| 137 | |
| 138 | // TODO(b/242847534): Still convert to a filegroup because other unconverted |
| 139 | // modules may depend on the filegroup |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 140 | attrs := &bazelFilegroupAttributes{ |
| 141 | Srcs: srcs, |
| 142 | } |
| 143 | |
| 144 | props := bazel.BazelTargetModuleProperties{ |
| 145 | Rule_class: "filegroup", |
| 146 | Bzl_load_location: "//build/bazel/rules:filegroup.bzl", |
| 147 | } |
| 148 | |
| 149 | ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs) |
| 150 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | type fileGroupProperties struct { |
| 154 | // srcs lists files that will be included in this filegroup |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 155 | Srcs []string `android:"path"` |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 156 | |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 157 | Exclude_srcs []string `android:"path"` |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 158 | |
| 159 | // The base path to the files. May be used by other modules to determine which portion |
| 160 | // of the path to use. For example, when a filegroup is used as data in a cc_test rule, |
| 161 | // the base path is stripped off the path and the remaining path is used as the |
| 162 | // installation directory. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 163 | Path *string |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 164 | |
| 165 | // Create a make variable with the specified name that contains the list of files in the |
| 166 | // filegroup, relative to the root of the source tree. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 167 | Export_to_make_var *string |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | type fileGroup struct { |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 171 | ModuleBase |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 172 | BazelModuleBase |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 173 | FileGroupAsLibrary |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 174 | properties fileGroupProperties |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 175 | srcs Paths |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 178 | var _ MixedBuildBuildable = (*fileGroup)(nil) |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 179 | var _ SourceFileProducer = (*fileGroup)(nil) |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 180 | var _ FileGroupAsLibrary = (*fileGroup)(nil) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 181 | |
Patrice Arruda | 8958a94 | 2019-03-12 10:06:00 -0700 | [diff] [blame] | 182 | // filegroup contains a list of files that are referenced by other modules |
| 183 | // properties (such as "srcs") using the syntax ":<name>". filegroup are |
| 184 | // also be used to export files across package boundaries. |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 185 | func FileGroupFactory() Module { |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 186 | module := &fileGroup{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 187 | module.AddProperties(&module.properties) |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 188 | InitAndroidModule(module) |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 189 | InitBazelModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 190 | return module |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Liz Kammer | 5edc141 | 2022-05-25 11:12:44 -0400 | [diff] [blame] | 193 | var _ blueprint.JSONActionSupplier = (*fileGroup)(nil) |
| 194 | |
| 195 | func (fg *fileGroup) JSONActions() []blueprint.JSONAction { |
| 196 | ins := make([]string, 0, len(fg.srcs)) |
| 197 | outs := make([]string, 0, len(fg.srcs)) |
| 198 | for _, p := range fg.srcs { |
| 199 | ins = append(ins, p.String()) |
| 200 | outs = append(outs, p.Rel()) |
| 201 | } |
| 202 | return []blueprint.JSONAction{ |
| 203 | blueprint.JSONAction{ |
| 204 | Inputs: ins, |
| 205 | Outputs: outs, |
| 206 | }, |
| 207 | } |
| 208 | } |
| 209 | |
Liz Kammer | 5bde22f | 2021-04-19 14:04:14 -0400 | [diff] [blame] | 210 | func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) { |
Liz Kammer | 5bde22f | 2021-04-19 14:04:14 -0400 | [diff] [blame] | 211 | fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs) |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 212 | if fg.properties.Path != nil { |
| 213 | fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path)) |
| 214 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 217 | func (fg *fileGroup) Srcs() Paths { |
| 218 | return append(Paths{}, fg.srcs...) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 219 | } |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 220 | |
Dan Willemsen | 6a6478d | 2020-07-17 19:28:53 -0700 | [diff] [blame] | 221 | func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) { |
| 222 | if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" { |
| 223 | ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " ")) |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 226 | |
| 227 | func (fg *fileGroup) QueueBazelCall(ctx BaseModuleContext) { |
| 228 | bazelCtx := ctx.Config().BazelContext |
| 229 | |
| 230 | bazelCtx.QueueBazelRequest( |
| 231 | fg.GetBazelLabel(ctx, fg), |
| 232 | cquery.GetOutputFiles, |
| 233 | configKey{Common.String(), CommonOS}) |
| 234 | } |
| 235 | |
| 236 | func (fg *fileGroup) IsMixedBuildSupported(ctx BaseModuleContext) bool { |
Liz Kammer | 748209c | 2022-10-24 10:43:27 -0400 | [diff] [blame^] | 237 | // TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups |
| 238 | return false |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) { |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 242 | bazelCtx := ctx.Config().BazelContext |
| 243 | // This is a short-term solution because we rely on info from Android.bp to handle |
| 244 | // a converted module. This will block when we want to remove Android.bp for all |
| 245 | // converted modules at some point. |
| 246 | // TODO(b/242847534): Implement a long-term solution in which we don't need to rely |
| 247 | // on info form Android.bp for modules that are already converted to Bazel |
| 248 | relativeRoot := ctx.ModuleDir() |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 249 | if fg.properties.Path != nil { |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 250 | relativeRoot = filepath.Join(relativeRoot, *fg.properties.Path) |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 253 | filePaths, err := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), configKey{Common.String(), CommonOS}) |
| 254 | if err != nil { |
| 255 | ctx.ModuleErrorf(err.Error()) |
| 256 | return |
| 257 | } |
| 258 | |
| 259 | bazelOuts := make(Paths, 0, len(filePaths)) |
| 260 | for _, p := range filePaths { |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 261 | bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, relativeRoot, p)) |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 262 | } |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 263 | fg.srcs = bazelOuts |
| 264 | } |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 265 | |
| 266 | func (fg *fileGroup) ShouldConvertToAidlLibrary(ctx BazelConversionPathContext) bool { |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 267 | return fg.shouldConvertToLibrary(ctx, ".aidl") |
| 268 | } |
| 269 | |
| 270 | func (fg *fileGroup) ShouldConvertToProtoLibrary(ctx BazelConversionPathContext) bool { |
| 271 | return fg.shouldConvertToLibrary(ctx, ".proto") |
| 272 | } |
| 273 | |
| 274 | func (fg *fileGroup) shouldConvertToLibrary(ctx BazelConversionPathContext, suffix string) bool { |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 275 | if len(fg.properties.Srcs) == 0 || !fg.ShouldConvertWithBp2build(ctx) { |
| 276 | return false |
| 277 | } |
| 278 | for _, src := range fg.properties.Srcs { |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 279 | if !strings.HasSuffix(src, suffix) { |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 280 | return false |
| 281 | } |
| 282 | } |
| 283 | return true |
| 284 | } |
| 285 | |
| 286 | func (fg *fileGroup) GetAidlLibraryLabel(ctx BazelConversionPathContext) string { |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 287 | return fg.getFileGroupAsLibraryLabel(ctx) |
| 288 | } |
| 289 | |
| 290 | func (fg *fileGroup) GetProtoLibraryLabel(ctx BazelConversionPathContext) string { |
| 291 | return fg.getFileGroupAsLibraryLabel(ctx) + convertedProtoLibrarySuffix |
| 292 | } |
| 293 | |
| 294 | func (fg *fileGroup) getFileGroupAsLibraryLabel(ctx BazelConversionPathContext) string { |
Vinh Tran | 444154d | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 295 | if ctx.OtherModuleDir(fg.module) == ctx.ModuleDir() { |
| 296 | return ":" + fg.Name() |
| 297 | } else { |
| 298 | return fg.GetBazelLabel(ctx, fg) |
| 299 | } |
| 300 | } |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 301 | |
| 302 | // Given a name in srcs prop, check to see if the name references a filegroup |
| 303 | // and the filegroup is converted to aidl_library |
| 304 | func IsConvertedToAidlLibrary(ctx BazelConversionPathContext, name string) bool { |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 305 | if fg, ok := ToFileGroupAsLibrary(ctx, name); ok { |
| 306 | return fg.ShouldConvertToAidlLibrary(ctx) |
| 307 | } |
| 308 | return false |
| 309 | } |
| 310 | |
| 311 | func ToFileGroupAsLibrary(ctx BazelConversionPathContext, name string) (FileGroupAsLibrary, bool) { |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 312 | if module, ok := ctx.ModuleFromName(name); ok { |
| 313 | if IsFilegroup(ctx, module) { |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 314 | if fg, ok := module.(FileGroupAsLibrary); ok { |
| 315 | return fg, true |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 319 | return nil, false |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 320 | } |