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