blob: 4c324fb3f9e885d3f9f7715b7e8c4bf3019fb517 [file] [log] [blame]
Dan Willemsend32e6d12019-04-10 12:25:07 -07001// Copyright (C) 2019 The Android Open Source Project
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 fs_config
16
17import (
18 "android/soong/android"
19)
20
21var pctx = android.NewPackageContext("android/soong/fs_config")
22
23func init() {
24 android.RegisterModuleType("target_fs_config_gen_filegroup", targetFSConfigGenFactory)
25}
26
Dan Willemsen7f25f2a2019-04-18 10:10:34 -070027// target_fs_config_gen_filegroup is used to expose the files pointed to by TARGET_FS_CONFIG_GEN to
Dan Willemsend32e6d12019-04-10 12:25:07 -070028// genrules in Soong. If TARGET_FS_CONFIG_GEN is empty, it will export an empty file instead.
29func targetFSConfigGenFactory() android.Module {
30 module := &targetFSConfigGen{}
31 android.InitAndroidModule(module)
32 return module
33}
34
35var _ android.SourceFileProducer = (*targetFSConfigGen)(nil)
36
37type targetFSConfigGen struct {
38 android.ModuleBase
Dan Willemsen7f25f2a2019-04-18 10:10:34 -070039 paths android.Paths
Dan Willemsend32e6d12019-04-10 12:25:07 -070040}
41
42func (targetFSConfigGen) DepsMutator(ctx android.BottomUpMutatorContext) {}
43
44func (t *targetFSConfigGen) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsen7f25f2a2019-04-18 10:10:34 -070045 if ret := ctx.DeviceConfig().TargetFSConfigGen(); len(ret) != 0 {
46 t.paths = android.PathsForSource(ctx, ret)
Dan Willemsend32e6d12019-04-10 12:25:07 -070047 } else {
48 path := android.PathForModuleGen(ctx, "empty")
Dan Willemsen7f25f2a2019-04-18 10:10:34 -070049 t.paths = android.Paths{path}
Dan Willemsend32e6d12019-04-10 12:25:07 -070050
Colin Cross40c95132020-11-16 17:58:17 -080051 rule := android.NewRuleBuilder(pctx, ctx)
Dan Willemsend32e6d12019-04-10 12:25:07 -070052 rule.Command().Text("rm -rf").Output(path)
53 rule.Command().Text("touch").Output(path)
Colin Cross40c95132020-11-16 17:58:17 -080054 rule.Build("fs_config_empty", "create empty file")
Dan Willemsend32e6d12019-04-10 12:25:07 -070055 }
56}
57
58func (t *targetFSConfigGen) Srcs() android.Paths {
Dan Willemsen7f25f2a2019-04-18 10:10:34 -070059 return t.paths
Dan Willemsend32e6d12019-04-10 12:25:07 -070060}