blob: c34a615e5cbd9d5a3527daa361d21ac7b49b4393 [file] [log] [blame]
Colin Cross068e0fe2016-12-13 15:23:47 -08001// 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 Nainar955dc492018-04-17 14:58:42 -070015package android
Colin Cross068e0fe2016-12-13 15:23:47 -080016
17import (
Vinh Tran16fe8e12022-08-16 16:45:44 -040018 "path/filepath"
Sam Delmerico97bd1272022-08-25 14:45:31 -040019 "regexp"
Colin Crossd91d7ac2017-09-12 22:52:12 -070020 "strings"
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux0d990452021-08-11 16:46:13 +000021
22 "android/soong/bazel"
Chris Parsonsf874e462022-05-10 13:50:12 -040023 "android/soong/bazel/cquery"
Chris Parsons39a16972023-06-08 14:28:51 +000024 "android/soong/ui/metrics/bp2build_metrics_proto"
Sam Delmericoc7681022022-02-04 21:01:20 +000025 "github.com/google/blueprint"
Spandan Dasdf3ec822023-08-04 02:19:53 +000026 "github.com/google/blueprint/proptools"
Colin Cross068e0fe2016-12-13 15:23:47 -080027)
28
29func init() {
Anton Hansson7d6dd8b2023-03-06 11:26:17 +000030 RegisterFilegroupBuildComponents(InitRegistrationContext)
Jingwen Chen32b4ece2021-01-21 03:20:18 -050031}
32
Paul Duffin35816122021-02-24 01:49:52 +000033var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) {
Anton Hansson7d6dd8b2023-03-06 11:26:17 +000034 RegisterFilegroupBuildComponents(ctx)
Paul Duffin35816122021-02-24 01:49:52 +000035})
36
Anton Hansson7d6dd8b2023-03-06 11:26:17 +000037func RegisterFilegroupBuildComponents(ctx RegistrationContext) {
38 ctx.RegisterModuleType("filegroup", FileGroupFactory)
39 ctx.RegisterModuleType("filegroup_defaults", FileGroupDefaultsFactory)
40}
41
Yu Liu2aa806b2022-09-01 11:54:47 -070042var convertedProtoLibrarySuffix = "_bp2build_converted"
43
Sam Delmericoc7681022022-02-04 21:01:20 +000044// IsFilegroup checks that a module is a filegroup type
45func IsFilegroup(ctx bazel.OtherModuleContext, m blueprint.Module) bool {
46 return ctx.OtherModuleType(m) == "filegroup"
47}
48
Sam Delmerico97bd1272022-08-25 14:45:31 -040049var (
50 // ignoring case, checks for proto or protos as an independent word in the name, whether at the
51 // beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
52 filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
Liz Kammer79ff08f2023-09-27 14:43:45 -040053 filegroupLikelyAidlPattern = regexp.MustCompile("(?i)(^|[^a-z])aidl(s)?([^a-z]|$)")
Sam Delmerico97bd1272022-08-25 14:45:31 -040054
55 ProtoSrcLabelPartition = bazel.LabelPartition{
56 Extensions: []string{".proto"},
57 LabelMapper: isFilegroupWithPattern(filegroupLikelyProtoPattern),
58 }
59 AidlSrcLabelPartition = bazel.LabelPartition{
60 Extensions: []string{".aidl"},
61 LabelMapper: isFilegroupWithPattern(filegroupLikelyAidlPattern),
62 }
63)
64
65func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper {
66 return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
67 m, exists := ctx.ModuleFromName(label.OriginalModuleName)
68 labelStr := label.Label
69 if !exists || !IsFilegroup(ctx, m) {
70 return labelStr, false
71 }
72 likelyMatched := pattern.MatchString(label.OriginalModuleName)
73 return labelStr, likelyMatched
74 }
75}
76
Jingwen Chen32b4ece2021-01-21 03:20:18 -050077// https://docs.bazel.build/versions/master/be/general.html#filegroup
78type bazelFilegroupAttributes struct {
Wei Li2c9e8d62023-05-05 01:07:15 -070079 Srcs bazel.LabelListAttribute
80 Applicable_licenses bazel.LabelListAttribute
Jingwen Chen32b4ece2021-01-21 03:20:18 -050081}
82
Vinh Tran444154d2022-08-16 13:10:31 -040083type bazelAidlLibraryAttributes struct {
84 Srcs bazel.LabelListAttribute
85 Strip_import_prefix *string
86}
87
Liz Kammerbe46fcc2021-11-01 15:32:43 -040088// ConvertWithBp2build performs bp2build conversion of filegroup
Chris Parsons637458d2023-09-19 20:09:00 +000089func (fg *fileGroup) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
Jingwen Chen07027912021-03-15 06:02:43 -040090 srcs := bazel.MakeLabelListAttribute(
91 BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs))
Jingwen Chen5146ac02021-09-02 11:44:42 +000092
93 // For Bazel compatibility, don't generate the filegroup if there is only 1
94 // source file, and that the source file is named the same as the module
95 // itself. In Bazel, eponymous filegroups like this would be an error.
96 //
97 // Instead, dependents on this single-file filegroup can just depend
98 // on the file target, instead of rule target, directly.
99 //
100 // You may ask: what if a filegroup has multiple files, and one of them
101 // shares the name? The answer: we haven't seen that in the wild, and
102 // should lock Soong itself down to prevent the behavior. For now,
103 // we raise an error if bp2build sees this problem.
104 for _, f := range srcs.Value.Includes {
105 if f.Label == fg.Name() {
106 if len(srcs.Value.Includes) > 1 {
107 ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name())
Chris Parsons2ef472b2023-09-27 22:39:45 +0000108 ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_SRC_NAME_COLLISION, "")
109 } else {
110 panic("This situation should have been handled by FileGroupFactory's call to InitBazelModuleAsHandcrafted")
Jingwen Chen5146ac02021-09-02 11:44:42 +0000111 }
112 return
113 }
114 }
115
Vinh Tran444154d2022-08-16 13:10:31 -0400116 // Convert module that has only AIDL files to aidl_library
117 // If the module has a mixed bag of AIDL and non-AIDL files, split the filegroup manually
118 // and then convert
119 if fg.ShouldConvertToAidlLibrary(ctx) {
Liz Kammer2b3f56e2023-03-23 11:51:49 -0400120 tags := []string{"apex_available=//apex_available:anyapex"}
Vinh Tran444154d2022-08-16 13:10:31 -0400121 attrs := &bazelAidlLibraryAttributes{
122 Srcs: srcs,
123 Strip_import_prefix: fg.properties.Path,
124 }
Jingwen Chen1fd14692021-02-05 03:01:50 -0500125
Vinh Tran444154d2022-08-16 13:10:31 -0400126 props := bazel.BazelTargetModuleProperties{
127 Rule_class: "aidl_library",
Sam Delmericoe55bf082023-03-31 09:47:28 -0400128 Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
Vinh Tran444154d2022-08-16 13:10:31 -0400129 }
Jingwen Chen1fd14692021-02-05 03:01:50 -0500130
Liz Kammer2b3f56e2023-03-23 11:51:49 -0400131 ctx.CreateBazelTargetModule(
132 props,
133 CommonAttributes{
134 Name: fg.Name(),
135 Tags: bazel.MakeStringListAttribute(tags),
136 },
137 attrs)
Vinh Tran444154d2022-08-16 13:10:31 -0400138 } else {
Yu Liu2aa806b2022-09-01 11:54:47 -0700139 if fg.ShouldConvertToProtoLibrary(ctx) {
Spandan Dasdf3ec822023-08-04 02:19:53 +0000140 pkgToSrcs := partitionSrcsByPackage(ctx.ModuleDir(), bazel.MakeLabelList(srcs.Value.Includes))
141 if len(pkgToSrcs) > 1 {
142 ctx.ModuleErrorf("TODO: Add bp2build support for multiple package .protosrcs in filegroup")
143 return
144 }
145 pkg := SortedKeys(pkgToSrcs)[0]
Yu Liu2aa806b2022-09-01 11:54:47 -0700146 attrs := &ProtoAttrs{
Spandan Dasdf3ec822023-08-04 02:19:53 +0000147 Srcs: bazel.MakeLabelListAttribute(pkgToSrcs[pkg]),
Yu Liu2aa806b2022-09-01 11:54:47 -0700148 Strip_import_prefix: fg.properties.Path,
149 }
150
Liz Kammer2b3f56e2023-03-23 11:51:49 -0400151 tags := []string{
152 "apex_available=//apex_available:anyapex",
153 // TODO(b/246997908): we can remove this tag if we could figure out a solution for this bug.
154 "manual",
155 }
Spandan Dasdf3ec822023-08-04 02:19:53 +0000156 if pkg != ctx.ModuleDir() {
157 // Since we are creating the proto_library in a subpackage, create an import_prefix relative to the current package
158 if rel, err := filepath.Rel(ctx.ModuleDir(), pkg); err != nil {
159 ctx.ModuleErrorf("Could not get relative path for %v %v", pkg, err)
160 } else if rel != "." {
161 attrs.Import_prefix = &rel
162 // Strip the package prefix
163 attrs.Strip_import_prefix = proptools.StringPtr("")
164 }
165 }
166
Yu Liu2aa806b2022-09-01 11:54:47 -0700167 ctx.CreateBazelTargetModule(
168 bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
Sam Delmericoe9b33f72022-11-21 15:38:54 -0500169 CommonAttributes{
Spandan Dasdf3ec822023-08-04 02:19:53 +0000170 Name: fg.Name() + "_proto",
171 Dir: proptools.StringPtr(pkg),
Sam Delmericoe9b33f72022-11-21 15:38:54 -0500172 Tags: bazel.MakeStringListAttribute(tags),
173 },
Yu Liu2aa806b2022-09-01 11:54:47 -0700174 attrs)
Spandan Dasdf3ec822023-08-04 02:19:53 +0000175
176 // Create an alias in the current dir. The actual target might exist in a different package, but rdeps
177 // can reliabily use this alias
178 ctx.CreateBazelTargetModule(
179 bazel.BazelTargetModuleProperties{Rule_class: "alias"},
180 CommonAttributes{
181 Name: fg.Name() + convertedProtoLibrarySuffix,
182 // TODO(b/246997908): we can remove this tag if we could figure out a solution for this bug.
183 Tags: bazel.MakeStringListAttribute(tags),
184 },
185 &bazelAliasAttributes{
186 Actual: bazel.MakeLabelAttribute("//" + pkg + ":" + fg.Name() + "_proto"),
187 },
188 )
Yu Liu2aa806b2022-09-01 11:54:47 -0700189 }
190
191 // TODO(b/242847534): Still convert to a filegroup because other unconverted
192 // modules may depend on the filegroup
Vinh Tran444154d2022-08-16 13:10:31 -0400193 attrs := &bazelFilegroupAttributes{
194 Srcs: srcs,
195 }
196
197 props := bazel.BazelTargetModuleProperties{
198 Rule_class: "filegroup",
199 Bzl_load_location: "//build/bazel/rules:filegroup.bzl",
200 }
201
202 ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs)
203 }
Colin Cross068e0fe2016-12-13 15:23:47 -0800204}
205
Alixb29a3cd2023-05-09 20:37:49 +0000206type FileGroupPath interface {
Chris Parsons637458d2023-09-19 20:09:00 +0000207 GetPath(ctx Bp2buildMutatorContext) string
Alixb29a3cd2023-05-09 20:37:49 +0000208}
209
Chris Parsons637458d2023-09-19 20:09:00 +0000210func (fg *fileGroup) GetPath(ctx Bp2buildMutatorContext) string {
Alixb29a3cd2023-05-09 20:37:49 +0000211 if fg.properties.Path != nil {
212 return *fg.properties.Path
213 }
214 return ""
215}
216
Colin Cross068e0fe2016-12-13 15:23:47 -0800217type fileGroupProperties struct {
218 // srcs lists files that will be included in this filegroup
Colin Cross27b922f2019-03-04 22:35:41 -0800219 Srcs []string `android:"path"`
Colin Cross068e0fe2016-12-13 15:23:47 -0800220
Colin Cross27b922f2019-03-04 22:35:41 -0800221 Exclude_srcs []string `android:"path"`
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800222
223 // The base path to the files. May be used by other modules to determine which portion
224 // of the path to use. For example, when a filegroup is used as data in a cc_test rule,
225 // the base path is stripped off the path and the remaining path is used as the
226 // installation directory.
Nan Zhangea568a42017-11-08 21:20:04 -0800227 Path *string
Colin Crossd91d7ac2017-09-12 22:52:12 -0700228
229 // Create a make variable with the specified name that contains the list of files in the
230 // filegroup, relative to the root of the source tree.
Nan Zhangea568a42017-11-08 21:20:04 -0800231 Export_to_make_var *string
Colin Cross068e0fe2016-12-13 15:23:47 -0800232}
233
234type fileGroup struct {
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700235 ModuleBase
Liz Kammerea6666f2021-02-17 10:17:28 -0500236 BazelModuleBase
Anton Hansson7d6dd8b2023-03-06 11:26:17 +0000237 DefaultableModuleBase
Yu Liu2aa806b2022-09-01 11:54:47 -0700238 FileGroupAsLibrary
Alixb29a3cd2023-05-09 20:37:49 +0000239 FileGroupPath
Colin Cross068e0fe2016-12-13 15:23:47 -0800240 properties fileGroupProperties
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700241 srcs Paths
Colin Cross068e0fe2016-12-13 15:23:47 -0800242}
243
Chris Parsonsf874e462022-05-10 13:50:12 -0400244var _ MixedBuildBuildable = (*fileGroup)(nil)
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700245var _ SourceFileProducer = (*fileGroup)(nil)
Yu Liu2aa806b2022-09-01 11:54:47 -0700246var _ FileGroupAsLibrary = (*fileGroup)(nil)
Alixb29a3cd2023-05-09 20:37:49 +0000247var _ FileGroupPath = (*fileGroup)(nil)
Colin Cross068e0fe2016-12-13 15:23:47 -0800248
Patrice Arruda8958a942019-03-12 10:06:00 -0700249// filegroup contains a list of files that are referenced by other modules
250// properties (such as "srcs") using the syntax ":<name>". filegroup are
251// also be used to export files across package boundaries.
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700252func FileGroupFactory() Module {
Colin Cross068e0fe2016-12-13 15:23:47 -0800253 module := &fileGroup{}
Colin Cross36242852017-06-23 15:06:31 -0700254 module.AddProperties(&module.properties)
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700255 InitAndroidModule(module)
Liz Kammerea6666f2021-02-17 10:17:28 -0500256 InitBazelModule(module)
Chris Parsons2ef472b2023-09-27 22:39:45 +0000257 AddBazelHandcraftedHook(module, func(ctx LoadHookContext) string {
258 // If there is a single src with the same name as the filegroup module name,
259 // then don't generate this filegroup. It will be OK for other targets
260 // to depend on this source file by name directly.
261 fg := ctx.Module().(*fileGroup)
262 if len(fg.properties.Srcs) == 1 && fg.Name() == fg.properties.Srcs[0] {
263 return fg.Name()
264 }
265 return ""
266 })
Anton Hansson7d6dd8b2023-03-06 11:26:17 +0000267 InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -0700268 return module
Colin Cross068e0fe2016-12-13 15:23:47 -0800269}
270
Liz Kammer5edc1412022-05-25 11:12:44 -0400271var _ blueprint.JSONActionSupplier = (*fileGroup)(nil)
272
273func (fg *fileGroup) JSONActions() []blueprint.JSONAction {
274 ins := make([]string, 0, len(fg.srcs))
275 outs := make([]string, 0, len(fg.srcs))
276 for _, p := range fg.srcs {
277 ins = append(ins, p.String())
278 outs = append(outs, p.Rel())
279 }
280 return []blueprint.JSONAction{
281 blueprint.JSONAction{
282 Inputs: ins,
283 Outputs: outs,
284 },
285 }
286}
287
Liz Kammer5bde22f2021-04-19 14:04:14 -0400288func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
Liz Kammer5bde22f2021-04-19 14:04:14 -0400289 fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs)
Colin Cross2fafa3e2019-03-05 12:39:51 -0800290 if fg.properties.Path != nil {
291 fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path))
292 }
Aditya Choudhary26df39f2023-11-29 16:42:42 +0000293 ctx.SetProvider(blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: fg.srcs.Strings()})
Colin Cross068e0fe2016-12-13 15:23:47 -0800294}
295
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700296func (fg *fileGroup) Srcs() Paths {
297 return append(Paths{}, fg.srcs...)
Colin Cross068e0fe2016-12-13 15:23:47 -0800298}
Colin Crossd91d7ac2017-09-12 22:52:12 -0700299
Dan Willemsen6a6478d2020-07-17 19:28:53 -0700300func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) {
301 if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" {
302 ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " "))
Colin Crossd91d7ac2017-09-12 22:52:12 -0700303 }
304}
Chris Parsonsf874e462022-05-10 13:50:12 -0400305
306func (fg *fileGroup) QueueBazelCall(ctx BaseModuleContext) {
307 bazelCtx := ctx.Config().BazelContext
308
309 bazelCtx.QueueBazelRequest(
310 fg.GetBazelLabel(ctx, fg),
311 cquery.GetOutputFiles,
Yu Liue4312402023-01-18 09:15:31 -0800312 configKey{arch: Common.String(), osType: CommonOS})
Chris Parsonsf874e462022-05-10 13:50:12 -0400313}
314
315func (fg *fileGroup) IsMixedBuildSupported(ctx BaseModuleContext) bool {
Liz Kammer748209c2022-10-24 10:43:27 -0400316 // TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups
317 return false
Chris Parsonsf874e462022-05-10 13:50:12 -0400318}
319
320func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
Vinh Tran16fe8e12022-08-16 16:45:44 -0400321 bazelCtx := ctx.Config().BazelContext
322 // This is a short-term solution because we rely on info from Android.bp to handle
323 // a converted module. This will block when we want to remove Android.bp for all
324 // converted modules at some point.
325 // TODO(b/242847534): Implement a long-term solution in which we don't need to rely
326 // on info form Android.bp for modules that are already converted to Bazel
327 relativeRoot := ctx.ModuleDir()
Chris Parsonsf874e462022-05-10 13:50:12 -0400328 if fg.properties.Path != nil {
Vinh Tran16fe8e12022-08-16 16:45:44 -0400329 relativeRoot = filepath.Join(relativeRoot, *fg.properties.Path)
Chris Parsonsf874e462022-05-10 13:50:12 -0400330 }
331
Yu Liue4312402023-01-18 09:15:31 -0800332 filePaths, err := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), configKey{arch: Common.String(), osType: CommonOS})
Chris Parsonsf874e462022-05-10 13:50:12 -0400333 if err != nil {
334 ctx.ModuleErrorf(err.Error())
335 return
336 }
337
338 bazelOuts := make(Paths, 0, len(filePaths))
339 for _, p := range filePaths {
Vinh Tran16fe8e12022-08-16 16:45:44 -0400340 bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, relativeRoot, p))
Chris Parsonsf874e462022-05-10 13:50:12 -0400341 }
Chris Parsonsf874e462022-05-10 13:50:12 -0400342 fg.srcs = bazelOuts
343}
Vinh Tran444154d2022-08-16 13:10:31 -0400344
345func (fg *fileGroup) ShouldConvertToAidlLibrary(ctx BazelConversionPathContext) bool {
Yu Liu2aa806b2022-09-01 11:54:47 -0700346 return fg.shouldConvertToLibrary(ctx, ".aidl")
347}
348
349func (fg *fileGroup) ShouldConvertToProtoLibrary(ctx BazelConversionPathContext) bool {
350 return fg.shouldConvertToLibrary(ctx, ".proto")
351}
352
353func (fg *fileGroup) shouldConvertToLibrary(ctx BazelConversionPathContext, suffix string) bool {
Vinh Tran444154d2022-08-16 13:10:31 -0400354 if len(fg.properties.Srcs) == 0 || !fg.ShouldConvertWithBp2build(ctx) {
355 return false
356 }
357 for _, src := range fg.properties.Srcs {
Yu Liu2aa806b2022-09-01 11:54:47 -0700358 if !strings.HasSuffix(src, suffix) {
Vinh Tran444154d2022-08-16 13:10:31 -0400359 return false
360 }
361 }
362 return true
363}
364
365func (fg *fileGroup) GetAidlLibraryLabel(ctx BazelConversionPathContext) string {
Yu Liu2aa806b2022-09-01 11:54:47 -0700366 return fg.getFileGroupAsLibraryLabel(ctx)
367}
368
369func (fg *fileGroup) GetProtoLibraryLabel(ctx BazelConversionPathContext) string {
370 return fg.getFileGroupAsLibraryLabel(ctx) + convertedProtoLibrarySuffix
371}
372
373func (fg *fileGroup) getFileGroupAsLibraryLabel(ctx BazelConversionPathContext) string {
Vinh Tran444154d2022-08-16 13:10:31 -0400374 if ctx.OtherModuleDir(fg.module) == ctx.ModuleDir() {
375 return ":" + fg.Name()
376 } else {
377 return fg.GetBazelLabel(ctx, fg)
378 }
379}
Sam Delmerico97bd1272022-08-25 14:45:31 -0400380
381// Given a name in srcs prop, check to see if the name references a filegroup
382// and the filegroup is converted to aidl_library
383func IsConvertedToAidlLibrary(ctx BazelConversionPathContext, name string) bool {
Yu Liu2aa806b2022-09-01 11:54:47 -0700384 if fg, ok := ToFileGroupAsLibrary(ctx, name); ok {
385 return fg.ShouldConvertToAidlLibrary(ctx)
386 }
387 return false
388}
389
390func ToFileGroupAsLibrary(ctx BazelConversionPathContext, name string) (FileGroupAsLibrary, bool) {
Sam Delmerico97bd1272022-08-25 14:45:31 -0400391 if module, ok := ctx.ModuleFromName(name); ok {
392 if IsFilegroup(ctx, module) {
Yu Liu2aa806b2022-09-01 11:54:47 -0700393 if fg, ok := module.(FileGroupAsLibrary); ok {
394 return fg, true
Sam Delmerico97bd1272022-08-25 14:45:31 -0400395 }
396 }
397 }
Yu Liu2aa806b2022-09-01 11:54:47 -0700398 return nil, false
Sam Delmerico97bd1272022-08-25 14:45:31 -0400399}
Anton Hansson7d6dd8b2023-03-06 11:26:17 +0000400
401// Defaults
402type FileGroupDefaults struct {
403 ModuleBase
404 DefaultsModuleBase
405}
406
407func FileGroupDefaultsFactory() Module {
408 module := &FileGroupDefaults{}
409 module.AddProperties(&fileGroupProperties{})
410 InitDefaultsModule(module)
411
412 return module
413}