xref: /aosp_15_r20/build/make/tools/fs_config/fs_config.go (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1*9e94795aSAndroid Build Coastguard Worker// Copyright (C) 2019 The Android Open Source Project
2*9e94795aSAndroid Build Coastguard Worker//
3*9e94795aSAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*9e94795aSAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*9e94795aSAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*9e94795aSAndroid Build Coastguard Worker//
7*9e94795aSAndroid Build Coastguard Worker//      http://www.apache.org/licenses/LICENSE-2.0
8*9e94795aSAndroid Build Coastguard Worker//
9*9e94795aSAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*9e94795aSAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*9e94795aSAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9e94795aSAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*9e94795aSAndroid Build Coastguard Worker// limitations under the License.
14*9e94795aSAndroid Build Coastguard Worker
15*9e94795aSAndroid Build Coastguard Workerpackage fs_config
16*9e94795aSAndroid Build Coastguard Worker
17*9e94795aSAndroid Build Coastguard Workerimport (
18*9e94795aSAndroid Build Coastguard Worker	"android/soong/android"
19*9e94795aSAndroid Build Coastguard Worker)
20*9e94795aSAndroid Build Coastguard Worker
21*9e94795aSAndroid Build Coastguard Workervar pctx = android.NewPackageContext("android/soong/fs_config")
22*9e94795aSAndroid Build Coastguard Worker
23*9e94795aSAndroid Build Coastguard Workerfunc init() {
24*9e94795aSAndroid Build Coastguard Worker	android.RegisterModuleType("target_fs_config_gen_filegroup", targetFSConfigGenFactory)
25*9e94795aSAndroid Build Coastguard Worker}
26*9e94795aSAndroid Build Coastguard Worker
27*9e94795aSAndroid Build Coastguard Worker// target_fs_config_gen_filegroup is used to expose the files pointed to by TARGET_FS_CONFIG_GEN to
28*9e94795aSAndroid Build Coastguard Worker// genrules in Soong. If TARGET_FS_CONFIG_GEN is empty, it will export an empty file instead.
29*9e94795aSAndroid Build Coastguard Workerfunc targetFSConfigGenFactory() android.Module {
30*9e94795aSAndroid Build Coastguard Worker	module := &targetFSConfigGen{}
31*9e94795aSAndroid Build Coastguard Worker	android.InitAndroidModule(module)
32*9e94795aSAndroid Build Coastguard Worker	return module
33*9e94795aSAndroid Build Coastguard Worker}
34*9e94795aSAndroid Build Coastguard Worker
35*9e94795aSAndroid Build Coastguard Workervar _ android.SourceFileProducer = (*targetFSConfigGen)(nil)
36*9e94795aSAndroid Build Coastguard Worker
37*9e94795aSAndroid Build Coastguard Workertype targetFSConfigGen struct {
38*9e94795aSAndroid Build Coastguard Worker	android.ModuleBase
39*9e94795aSAndroid Build Coastguard Worker	paths android.Paths
40*9e94795aSAndroid Build Coastguard Worker}
41*9e94795aSAndroid Build Coastguard Worker
42*9e94795aSAndroid Build Coastguard Workerfunc (targetFSConfigGen) DepsMutator(ctx android.BottomUpMutatorContext) {}
43*9e94795aSAndroid Build Coastguard Worker
44*9e94795aSAndroid Build Coastguard Workerfunc (t *targetFSConfigGen) GenerateAndroidBuildActions(ctx android.ModuleContext) {
45*9e94795aSAndroid Build Coastguard Worker	if ret := ctx.DeviceConfig().TargetFSConfigGen(); len(ret) != 0 {
46*9e94795aSAndroid Build Coastguard Worker		t.paths = android.PathsForSource(ctx, ret)
47*9e94795aSAndroid Build Coastguard Worker	} else {
48*9e94795aSAndroid Build Coastguard Worker		path := android.PathForModuleGen(ctx, "empty")
49*9e94795aSAndroid Build Coastguard Worker		t.paths = android.Paths{path}
50*9e94795aSAndroid Build Coastguard Worker
51*9e94795aSAndroid Build Coastguard Worker		rule := android.NewRuleBuilder(pctx, ctx)
52*9e94795aSAndroid Build Coastguard Worker		rule.Command().Text("rm -rf").Output(path)
53*9e94795aSAndroid Build Coastguard Worker		rule.Command().Text("touch").Output(path)
54*9e94795aSAndroid Build Coastguard Worker		rule.Build("fs_config_empty", "create empty file")
55*9e94795aSAndroid Build Coastguard Worker	}
56*9e94795aSAndroid Build Coastguard Worker}
57*9e94795aSAndroid Build Coastguard Worker
58*9e94795aSAndroid Build Coastguard Workerfunc (t *targetFSConfigGen) Srcs() android.Paths {
59*9e94795aSAndroid Build Coastguard Worker	return t.paths
60*9e94795aSAndroid Build Coastguard Worker}
61