blob: 68311e39a9012002725805c7b0a37068d834dfbf [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
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070015package android
Colin Cross068e0fe2016-12-13 15:23:47 -080016
17import (
Colin Crossd91d7ac2017-09-12 22:52:12 -070018 "strings"
Colin Cross068e0fe2016-12-13 15:23:47 -080019)
20
21func init() {
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070022 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
Colin Cross27b922f2019-03-04 22:35:41 -080027 Srcs []string `android:"path"`
Colin Cross068e0fe2016-12-13 15:23:47 -080028
Colin Cross27b922f2019-03-04 22:35:41 -080029 Exclude_srcs []string `android:"path"`
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.
Nan Zhangea568a42017-11-08 21:20:04 -080035 Path *string
Colin Crossd91d7ac2017-09-12 22:52:12 -070036
37 // Create a make variable with the specified name that contains the list of files in the
38 // filegroup, relative to the root of the source tree.
Nan Zhangea568a42017-11-08 21:20:04 -080039 Export_to_make_var *string
Colin Cross068e0fe2016-12-13 15:23:47 -080040}
41
42type fileGroup struct {
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070043 ModuleBase
Colin Cross068e0fe2016-12-13 15:23:47 -080044 properties fileGroupProperties
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070045 srcs Paths
Colin Cross068e0fe2016-12-13 15:23:47 -080046}
47
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070048var _ SourceFileProducer = (*fileGroup)(nil)
Colin Cross068e0fe2016-12-13 15:23:47 -080049
Patrice Arruda8958a942019-03-12 10:06:00 -070050// filegroup contains a list of files that are referenced by other modules
51// properties (such as "srcs") using the syntax ":<name>". filegroup are
52// also be used to export files across package boundaries.
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070053func FileGroupFactory() Module {
Colin Cross068e0fe2016-12-13 15:23:47 -080054 module := &fileGroup{}
Colin Cross36242852017-06-23 15:06:31 -070055 module.AddProperties(&module.properties)
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070056 InitAndroidModule(module)
Colin Cross36242852017-06-23 15:06:31 -070057 return module
Colin Cross068e0fe2016-12-13 15:23:47 -080058}
59
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070060func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
Colin Cross8a497952019-03-05 22:25:09 -080061 fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs)
Colin Cross2fafa3e2019-03-05 12:39:51 -080062
63 if fg.properties.Path != nil {
64 fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path))
65 }
Colin Cross068e0fe2016-12-13 15:23:47 -080066}
67
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070068func (fg *fileGroup) Srcs() Paths {
69 return append(Paths{}, fg.srcs...)
Colin Cross068e0fe2016-12-13 15:23:47 -080070}
Colin Crossd91d7ac2017-09-12 22:52:12 -070071
Dan Willemsen6a6478d2020-07-17 19:28:53 -070072func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) {
73 if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" {
74 ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " "))
Colin Crossd91d7ac2017-09-12 22:52:12 -070075 }
76}