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