blob: 402913474960cd7c8d3188b29c564cd5765b33dc [file] [log] [blame]
Colin Cross068e0fe2016-12-13 15:23:47 -08001// 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
15package genrule
16
17import (
Colin Cross068e0fe2016-12-13 15:23:47 -080018 "android/soong/android"
19)
20
21func init() {
Colin Cross795c3772017-03-16 16:50:10 -070022 android.RegisterModuleType("filegroup", FileGroupFactory)
Colin Cross068e0fe2016-12-13 15:23:47 -080023}
24
25type fileGroupProperties struct {
26 // srcs lists files that will be included in this filegroup
27 Srcs []string
28
29 Exclude_srcs []string
Colin Crossfaeb7aa2017-02-01 14:12:44 -080030
31 // The base path to the files. May be used by other modules to determine which portion
32 // of the path to use. For example, when a filegroup is used as data in a cc_test rule,
33 // the base path is stripped off the path and the remaining path is used as the
34 // installation directory.
35 Path string
Colin Cross068e0fe2016-12-13 15:23:47 -080036}
37
38type fileGroup struct {
39 android.ModuleBase
40 properties fileGroupProperties
41 srcs android.Paths
42}
43
44var _ android.SourceFileProducer = (*fileGroup)(nil)
45
46// filegroup modules contain a list of files, and can be used to export files across package
47// boundaries. filegroups (and genrules) can be referenced from srcs properties of other modules
48// using the syntax ":module".
Colin Cross36242852017-06-23 15:06:31 -070049func FileGroupFactory() android.Module {
Colin Cross068e0fe2016-12-13 15:23:47 -080050 module := &fileGroup{}
Colin Cross36242852017-06-23 15:06:31 -070051 module.AddProperties(&module.properties)
52 android.InitAndroidModule(module)
53 return module
Colin Cross068e0fe2016-12-13 15:23:47 -080054}
55
56func (fg *fileGroup) DepsMutator(ctx android.BottomUpMutatorContext) {
57 android.ExtractSourcesDeps(ctx, fg.properties.Srcs)
58}
59
60func (fg *fileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossfaeb7aa2017-02-01 14:12:44 -080061 fg.srcs = ctx.ExpandSourcesSubDir(fg.properties.Srcs, fg.properties.Exclude_srcs, fg.properties.Path)
Colin Cross068e0fe2016-12-13 15:23:47 -080062}
63
64func (fg *fileGroup) Srcs() android.Paths {
65 return fg.srcs
66}