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 ( |
Jihoon Kang | 705e63e | 2024-03-13 01:21:16 +0000 | [diff] [blame] | 18 | "maps" |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 19 | "strings" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 20 | |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 21 | "github.com/google/blueprint" |
Cole Faust | fdec872 | 2024-05-22 11:38:29 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func init() { |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 26 | RegisterFilegroupBuildComponents(InitRegistrationContext) |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 27 | } |
| 28 | |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 29 | var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) { |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 30 | RegisterFilegroupBuildComponents(ctx) |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 31 | }) |
| 32 | |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 33 | func RegisterFilegroupBuildComponents(ctx RegistrationContext) { |
| 34 | ctx.RegisterModuleType("filegroup", FileGroupFactory) |
| 35 | ctx.RegisterModuleType("filegroup_defaults", FileGroupDefaultsFactory) |
| 36 | } |
| 37 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 38 | type fileGroupProperties struct { |
| 39 | // srcs lists files that will be included in this filegroup |
Cole Faust | fdec872 | 2024-05-22 11:38:29 -0700 | [diff] [blame] | 40 | Srcs proptools.Configurable[[]string] `android:"path"` |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 41 | |
Cole Faust | fdec872 | 2024-05-22 11:38:29 -0700 | [diff] [blame] | 42 | Exclude_srcs proptools.Configurable[[]string] `android:"path"` |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 43 | |
Cole Faust | 65cb40a | 2024-10-21 15:41:42 -0700 | [diff] [blame^] | 44 | // Sources the will be included in the filegroup, but any module dependencies will be added |
| 45 | // using the device os and the device's first architecture's variant. |
| 46 | Device_first_srcs proptools.Configurable[[]string] `android:"path_device_first"` |
| 47 | |
| 48 | // Sources the will be included in the filegroup, but any module dependencies will be added |
| 49 | // using the device os and the common architecture's variant. |
| 50 | Device_common_srcs proptools.Configurable[[]string] `android:"path_device_common"` |
| 51 | |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 52 | // The base path to the files. May be used by other modules to determine which portion |
| 53 | // of the path to use. For example, when a filegroup is used as data in a cc_test rule, |
| 54 | // the base path is stripped off the path and the remaining path is used as the |
| 55 | // installation directory. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 56 | Path *string |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 57 | |
| 58 | // Create a make variable with the specified name that contains the list of files in the |
| 59 | // filegroup, relative to the root of the source tree. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 60 | Export_to_make_var *string |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | type fileGroup struct { |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 64 | ModuleBase |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 65 | DefaultableModuleBase |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 66 | properties fileGroupProperties |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 67 | srcs Paths |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 70 | var _ SourceFileProducer = (*fileGroup)(nil) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 71 | |
Patrice Arruda | 8958a94 | 2019-03-12 10:06:00 -0700 | [diff] [blame] | 72 | // filegroup contains a list of files that are referenced by other modules |
| 73 | // properties (such as "srcs") using the syntax ":<name>". filegroup are |
| 74 | // also be used to export files across package boundaries. |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 75 | func FileGroupFactory() Module { |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 76 | module := &fileGroup{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 77 | module.AddProperties(&module.properties) |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 78 | InitAndroidModule(module) |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 79 | InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 80 | return module |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Liz Kammer | 5edc141 | 2022-05-25 11:12:44 -0400 | [diff] [blame] | 83 | var _ blueprint.JSONActionSupplier = (*fileGroup)(nil) |
| 84 | |
| 85 | func (fg *fileGroup) JSONActions() []blueprint.JSONAction { |
| 86 | ins := make([]string, 0, len(fg.srcs)) |
| 87 | outs := make([]string, 0, len(fg.srcs)) |
| 88 | for _, p := range fg.srcs { |
| 89 | ins = append(ins, p.String()) |
| 90 | outs = append(outs, p.Rel()) |
| 91 | } |
| 92 | return []blueprint.JSONAction{ |
| 93 | blueprint.JSONAction{ |
| 94 | Inputs: ins, |
| 95 | Outputs: outs, |
| 96 | }, |
| 97 | } |
| 98 | } |
| 99 | |
Liz Kammer | 5bde22f | 2021-04-19 14:04:14 -0400 | [diff] [blame] | 100 | func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) { |
Cole Faust | 65cb40a | 2024-10-21 15:41:42 -0700 | [diff] [blame^] | 101 | srcs := PathsForModuleSrcExcludes(ctx, fg.properties.Srcs.GetOrDefault(ctx, nil), fg.properties.Exclude_srcs.GetOrDefault(ctx, nil)) |
| 102 | srcs = append(srcs, PathsForModuleSrc(ctx, fg.properties.Device_first_srcs.GetOrDefault(ctx, nil))...) |
| 103 | srcs = append(srcs, PathsForModuleSrc(ctx, fg.properties.Device_common_srcs.GetOrDefault(ctx, nil))...) |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 104 | if fg.properties.Path != nil { |
Cole Faust | 65cb40a | 2024-10-21 15:41:42 -0700 | [diff] [blame^] | 105 | srcs = PathsWithModuleSrcSubDir(ctx, srcs, String(fg.properties.Path)) |
Colin Cross | 2fafa3e | 2019-03-05 12:39:51 -0800 | [diff] [blame] | 106 | } |
Cole Faust | 65cb40a | 2024-10-21 15:41:42 -0700 | [diff] [blame^] | 107 | SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcs.Strings()}) |
Jihoon Kang | 705e63e | 2024-03-13 01:21:16 +0000 | [diff] [blame] | 108 | |
| 109 | var aconfigDeclarations []string |
| 110 | var intermediateCacheOutputPaths Paths |
| 111 | var srcjars Paths |
| 112 | modeInfos := make(map[string]ModeInfo) |
| 113 | ctx.VisitDirectDeps(func(module Module) { |
| 114 | if dep, ok := OtherModuleProvider(ctx, module, CodegenInfoProvider); ok { |
| 115 | aconfigDeclarations = append(aconfigDeclarations, dep.AconfigDeclarations...) |
| 116 | intermediateCacheOutputPaths = append(intermediateCacheOutputPaths, dep.IntermediateCacheOutputPaths...) |
| 117 | srcjars = append(srcjars, dep.Srcjars...) |
| 118 | maps.Copy(modeInfos, dep.ModeInfos) |
| 119 | } |
| 120 | }) |
Cole Faust | 65cb40a | 2024-10-21 15:41:42 -0700 | [diff] [blame^] | 121 | |
| 122 | fg.srcs = srcs |
Jihoon Kang | 705e63e | 2024-03-13 01:21:16 +0000 | [diff] [blame] | 123 | SetProvider(ctx, CodegenInfoProvider, CodegenInfo{ |
| 124 | AconfigDeclarations: aconfigDeclarations, |
| 125 | IntermediateCacheOutputPaths: intermediateCacheOutputPaths, |
| 126 | Srcjars: srcjars, |
| 127 | ModeInfos: modeInfos, |
| 128 | }) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 131 | func (fg *fileGroup) Srcs() Paths { |
| 132 | return append(Paths{}, fg.srcs...) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 133 | } |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 134 | |
Dan Willemsen | 6a6478d | 2020-07-17 19:28:53 -0700 | [diff] [blame] | 135 | func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) { |
| 136 | if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" { |
| 137 | ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " ")) |
Colin Cross | d91d7ac | 2017-09-12 22:52:12 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 140 | |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 141 | // Defaults |
| 142 | type FileGroupDefaults struct { |
| 143 | ModuleBase |
| 144 | DefaultsModuleBase |
| 145 | } |
| 146 | |
| 147 | func FileGroupDefaultsFactory() Module { |
| 148 | module := &FileGroupDefaults{} |
| 149 | module.AddProperties(&fileGroupProperties{}) |
| 150 | InitDefaultsModule(module) |
| 151 | |
| 152 | return module |
| 153 | } |