blob: 869cb3de990e5ff6905cc506b1081fdb0ec40fa0 [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
27// target_fs_config_gen_filegroup is used to expose the file pointed to by TARGET_FS_CONFIG_GEN to
28// 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
39 path android.Path
40}
41
42func (targetFSConfigGen) DepsMutator(ctx android.BottomUpMutatorContext) {}
43
44func (t *targetFSConfigGen) GenerateAndroidBuildActions(ctx android.ModuleContext) {
45 if ret := ctx.DeviceConfig().TargetFSConfigGen(); ret != nil && *ret != "" {
46 t.path = android.PathForSource(ctx, *ret)
47 } else {
48 path := android.PathForModuleGen(ctx, "empty")
49 t.path = path
50
51 rule := android.NewRuleBuilder()
52 rule.Command().Text("rm -rf").Output(path)
53 rule.Command().Text("touch").Output(path)
54 rule.Build(pctx, ctx, "fs_config_empty", "create empty file")
55 }
56}
57
58func (t *targetFSConfigGen) Srcs() android.Paths {
59 return android.Paths{t.path}
60}