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 | |
| 15 | package genrule |
| 16 | |
| 17 | import ( |
| 18 | "github.com/google/blueprint" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterModuleType("filegroup", fileGroupFactory) |
| 25 | } |
| 26 | |
| 27 | type fileGroupProperties struct { |
| 28 | // srcs lists files that will be included in this filegroup |
| 29 | Srcs []string |
| 30 | |
| 31 | Exclude_srcs []string |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame^] | 32 | |
| 33 | // The base path to the files. May be used by other modules to determine which portion |
| 34 | // of the path to use. For example, when a filegroup is used as data in a cc_test rule, |
| 35 | // the base path is stripped off the path and the remaining path is used as the |
| 36 | // installation directory. |
| 37 | Path string |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | type fileGroup struct { |
| 41 | android.ModuleBase |
| 42 | properties fileGroupProperties |
| 43 | srcs android.Paths |
| 44 | } |
| 45 | |
| 46 | var _ android.SourceFileProducer = (*fileGroup)(nil) |
| 47 | |
| 48 | // filegroup modules contain a list of files, and can be used to export files across package |
| 49 | // boundaries. filegroups (and genrules) can be referenced from srcs properties of other modules |
| 50 | // using the syntax ":module". |
| 51 | func fileGroupFactory() (blueprint.Module, []interface{}) { |
| 52 | module := &fileGroup{} |
| 53 | |
| 54 | return android.InitAndroidModule(module, &module.properties) |
| 55 | } |
| 56 | |
| 57 | func (fg *fileGroup) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 58 | android.ExtractSourcesDeps(ctx, fg.properties.Srcs) |
| 59 | } |
| 60 | |
| 61 | func (fg *fileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame^] | 62 | fg.srcs = ctx.ExpandSourcesSubDir(fg.properties.Srcs, fg.properties.Exclude_srcs, fg.properties.Path) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | func (fg *fileGroup) Srcs() android.Paths { |
| 66 | return fg.srcs |
| 67 | } |