Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 1 | // Copyright (C) 2020 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 filesystem |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | |
| 20 | "android/soong/android" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | android.RegisterModuleType("android_filesystem", filesystemFactory) |
| 27 | } |
| 28 | |
| 29 | type filesystem struct { |
| 30 | android.ModuleBase |
| 31 | android.PackagingBase |
| 32 | } |
| 33 | |
| 34 | func filesystemFactory() android.Module { |
| 35 | module := &filesystem{} |
| 36 | android.InitPackageModule(module) |
| 37 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 38 | return module |
| 39 | } |
| 40 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 41 | var dependencyTag = struct{ blueprint.BaseDependencyTag }{} |
| 42 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 43 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 44 | f.AddDeps(ctx, dependencyTag) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 48 | |
| 49 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 50 | zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath |
| 51 | f.CopyDepsToZip(ctx, zipFile) |
| 52 | |
| 53 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
| 54 | builder := android.NewRuleBuilder() |
| 55 | builder.Command(). |
| 56 | BuiltTool(ctx, "zipsync"). |
| 57 | FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear. |
| 58 | Input(zipFile) |
| 59 | |
| 60 | mkuserimg := ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs") |
| 61 | propFile := android.PathForModuleOut(ctx, "prop").OutputPath |
| 62 | // TODO(jiyong): support more filesystem types other than ext4 |
| 63 | propsText := fmt.Sprintf(`mount_point=system\n`+ |
| 64 | `fs_type=ext4\n`+ |
| 65 | `use_dynamic_partition_size=true\n`+ |
| 66 | `ext_mkuserimg=%s\n`, mkuserimg.String()) |
| 67 | builder.Command().Text("echo").Flag("-e").Flag(`"` + propsText + `"`). |
| 68 | Text(">").Output(propFile). |
| 69 | Implicit(mkuserimg) |
| 70 | |
| 71 | image := android.PathForModuleOut(ctx, "filesystem.img").OutputPath |
| 72 | builder.Command().BuiltTool(ctx, "build_image"). |
| 73 | Text(rootDir.String()). // input directory |
| 74 | Input(propFile). |
| 75 | Output(image). |
| 76 | Text(rootDir.String()) // directory where to find fs_config_files|dirs |
| 77 | |
| 78 | // rootDir is not deleted. Might be useful for quick inspection. |
| 79 | builder.Build(pctx, ctx, "build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
| 80 | } |