Inseob Kim | 76e1985 | 2024-10-10 17:57:22 +0900 | [diff] [blame] | 1 | // Copyright 2024 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 android |
| 16 | |
| 17 | import ( |
| 18 | "github.com/google/blueprint" |
| 19 | "github.com/google/blueprint/proptools" |
| 20 | ) |
| 21 | |
| 22 | func init() { |
| 23 | RegisterDirgroupBuildComponents(InitRegistrationContext) |
| 24 | } |
| 25 | |
| 26 | func RegisterDirgroupBuildComponents(ctx RegistrationContext) { |
| 27 | ctx.RegisterModuleType("dirgroup", DirGroupFactory) |
| 28 | } |
| 29 | |
| 30 | type dirGroupProperties struct { |
| 31 | // dirs lists directories that will be included in this dirgroup |
| 32 | Dirs proptools.Configurable[[]string] `android:"path"` |
| 33 | } |
| 34 | |
| 35 | type dirGroup struct { |
| 36 | ModuleBase |
| 37 | DefaultableModuleBase |
| 38 | properties dirGroupProperties |
| 39 | } |
| 40 | |
| 41 | type DirInfo struct { |
Inseob Kim | 93036a5 | 2024-10-25 17:02:21 +0900 | [diff] [blame] | 42 | Dirs DirectoryPaths |
Inseob Kim | 76e1985 | 2024-10-10 17:57:22 +0900 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | var DirProvider = blueprint.NewProvider[DirInfo]() |
| 46 | |
| 47 | // dirgroup contains a list of dirs that are referenced by other modules |
| 48 | // properties using the syntax ":<name>". dirgroup are also be used to export |
| 49 | // dirs across package boundaries. Currently the only allowed usage is genrule's |
| 50 | // dir_srcs property. |
| 51 | func DirGroupFactory() Module { |
| 52 | module := &dirGroup{} |
| 53 | module.AddProperties(&module.properties) |
| 54 | InitAndroidModule(module) |
| 55 | InitDefaultableModule(module) |
| 56 | return module |
| 57 | } |
| 58 | |
| 59 | func (fg *dirGroup) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 60 | dirs := DirectoryPathsForModuleSrc(ctx, fg.properties.Dirs.GetOrDefault(ctx, nil)) |
| 61 | SetProvider(ctx, DirProvider, DirInfo{Dirs: dirs}) |
| 62 | } |