xref: /aosp_15_r20/build/soong/android/dirgroup.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright 2024 Google Inc. All rights reserved.
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage android
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint"
19*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint/proptools"
20*333d2b36SAndroid Build Coastguard Worker)
21*333d2b36SAndroid Build Coastguard Worker
22*333d2b36SAndroid Build Coastguard Workerfunc init() {
23*333d2b36SAndroid Build Coastguard Worker	RegisterDirgroupBuildComponents(InitRegistrationContext)
24*333d2b36SAndroid Build Coastguard Worker}
25*333d2b36SAndroid Build Coastguard Worker
26*333d2b36SAndroid Build Coastguard Workerfunc RegisterDirgroupBuildComponents(ctx RegistrationContext) {
27*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("dirgroup", DirGroupFactory)
28*333d2b36SAndroid Build Coastguard Worker}
29*333d2b36SAndroid Build Coastguard Worker
30*333d2b36SAndroid Build Coastguard Workertype dirGroupProperties struct {
31*333d2b36SAndroid Build Coastguard Worker	// dirs lists directories that will be included in this dirgroup
32*333d2b36SAndroid Build Coastguard Worker	Dirs proptools.Configurable[[]string] `android:"path"`
33*333d2b36SAndroid Build Coastguard Worker}
34*333d2b36SAndroid Build Coastguard Worker
35*333d2b36SAndroid Build Coastguard Workertype dirGroup struct {
36*333d2b36SAndroid Build Coastguard Worker	ModuleBase
37*333d2b36SAndroid Build Coastguard Worker	DefaultableModuleBase
38*333d2b36SAndroid Build Coastguard Worker	properties dirGroupProperties
39*333d2b36SAndroid Build Coastguard Worker}
40*333d2b36SAndroid Build Coastguard Worker
41*333d2b36SAndroid Build Coastguard Workertype DirInfo struct {
42*333d2b36SAndroid Build Coastguard Worker	Dirs DirectoryPaths
43*333d2b36SAndroid Build Coastguard Worker}
44*333d2b36SAndroid Build Coastguard Worker
45*333d2b36SAndroid Build Coastguard Workervar DirProvider = blueprint.NewProvider[DirInfo]()
46*333d2b36SAndroid Build Coastguard Worker
47*333d2b36SAndroid Build Coastguard Worker// dirgroup contains a list of dirs that are referenced by other modules
48*333d2b36SAndroid Build Coastguard Worker// properties using the syntax ":<name>". dirgroup are also be used to export
49*333d2b36SAndroid Build Coastguard Worker// dirs across package boundaries. Currently the only allowed usage is genrule's
50*333d2b36SAndroid Build Coastguard Worker// dir_srcs property.
51*333d2b36SAndroid Build Coastguard Workerfunc DirGroupFactory() Module {
52*333d2b36SAndroid Build Coastguard Worker	module := &dirGroup{}
53*333d2b36SAndroid Build Coastguard Worker	module.AddProperties(&module.properties)
54*333d2b36SAndroid Build Coastguard Worker	InitAndroidModule(module)
55*333d2b36SAndroid Build Coastguard Worker	InitDefaultableModule(module)
56*333d2b36SAndroid Build Coastguard Worker	return module
57*333d2b36SAndroid Build Coastguard Worker}
58*333d2b36SAndroid Build Coastguard Worker
59*333d2b36SAndroid Build Coastguard Workerfunc (fg *dirGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
60*333d2b36SAndroid Build Coastguard Worker	dirs := DirectoryPathsForModuleSrc(ctx, fg.properties.Dirs.GetOrDefault(ctx, nil))
61*333d2b36SAndroid Build Coastguard Worker	SetProvider(ctx, DirProvider, DirInfo{Dirs: dirs})
62*333d2b36SAndroid Build Coastguard Worker}
63