Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14199b07 authored by Inseob Kim's avatar Inseob Kim
Browse files

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
parent 2ce1b5dc
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -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