Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package fs_config |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | var pctx = android.NewPackageContext("android/soong/fs_config") |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterModuleType("target_fs_config_gen_filegroup", targetFSConfigGenFactory) |
| 25 | } |
| 26 | |
Dan Willemsen | 7f25f2a | 2019-04-18 10:10:34 -0700 | [diff] [blame] | 27 | // target_fs_config_gen_filegroup is used to expose the files pointed to by TARGET_FS_CONFIG_GEN to |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 28 | // genrules in Soong. If TARGET_FS_CONFIG_GEN is empty, it will export an empty file instead. |
| 29 | func targetFSConfigGenFactory() android.Module { |
| 30 | module := &targetFSConfigGen{} |
| 31 | android.InitAndroidModule(module) |
| 32 | return module |
| 33 | } |
| 34 | |
| 35 | var _ android.SourceFileProducer = (*targetFSConfigGen)(nil) |
| 36 | |
| 37 | type targetFSConfigGen struct { |
| 38 | android.ModuleBase |
Dan Willemsen | 7f25f2a | 2019-04-18 10:10:34 -0700 | [diff] [blame] | 39 | paths android.Paths |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | func (targetFSConfigGen) DepsMutator(ctx android.BottomUpMutatorContext) {} |
| 43 | |
| 44 | func (t *targetFSConfigGen) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Dan Willemsen | 7f25f2a | 2019-04-18 10:10:34 -0700 | [diff] [blame] | 45 | if ret := ctx.DeviceConfig().TargetFSConfigGen(); len(ret) != 0 { |
| 46 | t.paths = android.PathsForSource(ctx, ret) |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 47 | } else { |
| 48 | path := android.PathForModuleGen(ctx, "empty") |
Dan Willemsen | 7f25f2a | 2019-04-18 10:10:34 -0700 | [diff] [blame] | 49 | t.paths = android.Paths{path} |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 50 | |
Colin Cross | 40c9513 | 2020-11-16 17:58:17 -0800 | [diff] [blame] | 51 | rule := android.NewRuleBuilder(pctx, ctx) |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 52 | rule.Command().Text("rm -rf").Output(path) |
| 53 | rule.Command().Text("touch").Output(path) |
Colin Cross | 40c9513 | 2020-11-16 17:58:17 -0800 | [diff] [blame] | 54 | rule.Build("fs_config_empty", "create empty file") |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | func (t *targetFSConfigGen) Srcs() android.Paths { |
Dan Willemsen | 7f25f2a | 2019-04-18 10:10:34 -0700 | [diff] [blame] | 59 | return t.paths |
Dan Willemsen | d32e6d1 | 2019-04-10 12:25:07 -0700 | [diff] [blame] | 60 | } |