summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Inseob Kim <inseob@google.com> 2021-02-09 21:18:31 +0900
committer Inseob Kim <inseob@google.com> 2021-02-17 14:05:12 +0900
commit14199b07f7403e021d439f3ff743e475d409810c (patch)
treea82428e586143f35691ed9531398c8db370e8642
parent2ce1b5dc3ab59d27ab85825d941d2e4c6bbeb654 (diff)
Add dirs and symlinks property to filesystem
Dirs and symlinks will be created under the root of the filesystem. Basic essential directories like "dev", "proc", "sys" and symlinks like "bin -> /system/bin", "init -> /system/bin/init" can be created with these properties. Bug: 179652970 Test: boot with aosp_cf_x86_64_only_phone, see adb works Change-Id: Ie06dc5a93635ea8b1e18be517ed8615b6c82fee6
-rw-r--r--filesystem/filesystem.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 69496c998..3bccde9eb 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -16,6 +16,8 @@ package filesystem
import (
"fmt"
+ "path/filepath"
+ "strings"
"android/soong/android"
@@ -37,6 +39,11 @@ type filesystem struct {
installDir android.InstallPath
}
+type symlinkDefinition struct {
+ Target *string
+ Name *string
+}
+
type filesystemProperties struct {
// When set to true, sign the image with avbtool. Default is false.
Use_avb *bool
@@ -58,6 +65,12 @@ type filesystemProperties struct {
// Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
// (root).
Base_dir *string
+
+ // Directories to be created under root. e.g. /dev, /proc, etc.
+ Dirs []string
+
+ // Symbolic links to be created under root with "ln -sf <target> <name>".
+ Symlinks []symlinkDefinition
}
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
@@ -135,7 +148,32 @@ func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath
builder.Command().Text("rm -rf").Text(rootDir.String())
builder.Command().Text("mkdir -p").Text(rootDir.String())
- // Currently root.zip is empty, and just a placeholder now. Dirs and symlinks will be added.
+ // create dirs and symlinks
+ for _, dir := range f.properties.Dirs {
+ // OutputPath.Join verifies dir
+ builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
+ }
+
+ for _, symlink := range f.properties.Symlinks {
+ name := strings.TrimSpace(proptools.String(symlink.Name))
+ target := strings.TrimSpace(proptools.String(symlink.Target))
+
+ if name == "" {
+ ctx.PropertyErrorf("symlinks", "Name can't be empty")
+ continue
+ }
+
+ if target == "" {
+ ctx.PropertyErrorf("symlinks", "Target can't be empty")
+ continue
+ }
+
+ // OutputPath.Join verifies name. don't need to verify target.
+ dst := rootDir.Join(ctx, name)
+
+ builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
+ builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
+ }
zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath