xref: /aosp_15_r20/build/soong/android/dirgroup.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1// Copyright 2024 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 android
16
17import (
18	"github.com/google/blueprint"
19	"github.com/google/blueprint/proptools"
20)
21
22func init() {
23	RegisterDirgroupBuildComponents(InitRegistrationContext)
24}
25
26func RegisterDirgroupBuildComponents(ctx RegistrationContext) {
27	ctx.RegisterModuleType("dirgroup", DirGroupFactory)
28}
29
30type dirGroupProperties struct {
31	// dirs lists directories that will be included in this dirgroup
32	Dirs proptools.Configurable[[]string] `android:"path"`
33}
34
35type dirGroup struct {
36	ModuleBase
37	DefaultableModuleBase
38	properties dirGroupProperties
39}
40
41type DirInfo struct {
42	Dirs DirectoryPaths
43}
44
45var DirProvider = blueprint.NewProvider[DirInfo]()
46
47// dirgroup contains a list of dirs that are referenced by other modules
48// properties using the syntax ":<name>". dirgroup are also be used to export
49// dirs across package boundaries. Currently the only allowed usage is genrule's
50// dir_srcs property.
51func DirGroupFactory() Module {
52	module := &dirGroup{}
53	module.AddProperties(&module.properties)
54	InitAndroidModule(module)
55	InitDefaultableModule(module)
56	return module
57}
58
59func (fg *dirGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
60	dirs := DirectoryPathsForModuleSrc(ctx, fg.properties.Dirs.GetOrDefault(ctx, nil))
61	SetProvider(ctx, DirProvider, DirInfo{Dirs: dirs})
62}
63