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 |
| 32 | } |
| 33 | |
| 34 | type fileGroup struct { |
| 35 | android.ModuleBase |
| 36 | properties fileGroupProperties |
| 37 | srcs android.Paths |
| 38 | } |
| 39 | |
| 40 | var _ android.SourceFileProducer = (*fileGroup)(nil) |
| 41 | |
| 42 | // filegroup modules contain a list of files, and can be used to export files across package |
| 43 | // boundaries. filegroups (and genrules) can be referenced from srcs properties of other modules |
| 44 | // using the syntax ":module". |
| 45 | func fileGroupFactory() (blueprint.Module, []interface{}) { |
| 46 | module := &fileGroup{} |
| 47 | |
| 48 | return android.InitAndroidModule(module, &module.properties) |
| 49 | } |
| 50 | |
| 51 | func (fg *fileGroup) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 52 | android.ExtractSourcesDeps(ctx, fg.properties.Srcs) |
| 53 | } |
| 54 | |
| 55 | func (fg *fileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 56 | fg.srcs = ctx.ExpandSources(fg.properties.Srcs, fg.properties.Exclude_srcs) |
| 57 | } |
| 58 | |
| 59 | func (fg *fileGroup) Srcs() android.Paths { |
| 60 | return fg.srcs |
| 61 | } |