blob: ecbfbab093925e1a1d93c9fd1e33db459b605ae5 [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"
Jiyong Park65b62242020-11-25 12:44:59 +090021
22 "github.com/google/blueprint"
Jiyong Park6f0f6882020-11-12 13:14:30 +090023)
24
25func init() {
26 android.RegisterModuleType("android_filesystem", filesystemFactory)
27}
28
29type filesystem struct {
30 android.ModuleBase
31 android.PackagingBase
32}
33
34func filesystemFactory() android.Module {
35 module := &filesystem{}
36 android.InitPackageModule(module)
37 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
38 return module
39}
40
Jiyong Park65b62242020-11-25 12:44:59 +090041var dependencyTag = struct{ blueprint.BaseDependencyTag }{}
42
Jiyong Park6f0f6882020-11-12 13:14:30 +090043func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +090044 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +090045}
46
47var pctx = android.NewPackageContext("android/soong/filesystem")
48
49func (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}