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

Commit 4acb77e7 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes from topic "install"

* changes:
  Replace RelPathString() with ToMakePath()
  Separate InstallPath from OutputPath
  Add InstallInRoot to allow modules to install into root partition
parents 5ffade1e ff6c33d8
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ func (x *hooks) runArchHooks(ctx ArchHookContext, m *ModuleBase) {

type InstallHookContext interface {
	ModuleContext
	Path() OutputPath
	Path() InstallPath
	Symlink() bool
}

@@ -89,11 +89,11 @@ func AddInstallHook(m blueprint.Module, hook func(InstallHookContext)) {

type installHookContext struct {
	ModuleContext
	path    OutputPath
	path    InstallPath
	symlink bool
}

func (x *installHookContext) Path() OutputPath {
func (x *installHookContext) Path() InstallPath {
	return x.path
}

@@ -101,7 +101,7 @@ func (x *installHookContext) Symlink() bool {
	return x.symlink
}

func (x *hooks) runInstallHooks(ctx ModuleContext, path OutputPath, symlink bool) {
func (x *hooks) runInstallHooks(ctx ModuleContext, path InstallPath, symlink bool) {
	if len(x.install) > 0 {
		mctx := &installHookContext{
			ModuleContext: ctx,
+23 −13
Original line number Diff line number Diff line
@@ -147,16 +147,17 @@ type ModuleContext interface {
	ExpandSource(srcFile, prop string) Path
	ExpandOptionalSource(srcFile *string, prop string) OptionalPath

	InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
	InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
	InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
	InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
	InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
	InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
	InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
	InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
	CheckbuildFile(srcPath Path)

	InstallInData() bool
	InstallInTestcases() bool
	InstallInSanitizerDir() bool
	InstallInRecovery() bool
	InstallInRoot() bool
	InstallBypassMake() bool

	RequiredModuleNames() []string
@@ -196,6 +197,7 @@ type Module interface {
	InstallInTestcases() bool
	InstallInSanitizerDir() bool
	InstallInRecovery() bool
	InstallInRoot() bool
	InstallBypassMake() bool
	SkipInstall()
	ExportedToMake() bool
@@ -846,6 +848,10 @@ func (m *ModuleBase) InstallInRecovery() bool {
	return Bool(m.commonProperties.Recovery)
}

func (m *ModuleBase) InstallInRoot() bool {
	return false
}

func (m *ModuleBase) InstallBypassMake() bool {
	return false
}
@@ -1522,11 +1528,15 @@ func (m *moduleContext) InstallInRecovery() bool {
	return m.module.InstallInRecovery()
}

func (m *moduleContext) InstallInRoot() bool {
	return m.module.InstallInRoot()
}

func (m *moduleContext) InstallBypassMake() bool {
	return m.module.InstallBypassMake()
}

func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
	if m.module.base().commonProperties.SkipInstall {
		return true
	}
@@ -1551,18 +1561,18 @@ func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
	return false
}

func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
	deps ...Path) OutputPath {
func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
	deps ...Path) InstallPath {
	return m.installFile(installPath, name, srcPath, Cp, deps)
}

func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
	deps ...Path) OutputPath {
func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
	deps ...Path) InstallPath {
	return m.installFile(installPath, name, srcPath, CpExecutable, deps)
}

func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
	rule blueprint.Rule, deps []Path) OutputPath {
func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
	rule blueprint.Rule, deps []Path) InstallPath {

	fullInstallPath := installPath.Join(m, name)
	m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
@@ -1597,7 +1607,7 @@ func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath
	return fullInstallPath
}

func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
	fullInstallPath := installPath.Join(m, name)
	m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)

@@ -1626,7 +1636,7 @@ func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcP

// installPath/name -> absPath where absPath might be a path that is available only at runtime
// (e.g. /apex/...)
func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
	fullInstallPath := installPath.Join(m, name)
	m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)

+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ func MergeNotices(ctx ModuleContext, mergedNotice WritablePath, noticePaths []Pa
	})
}

func BuildNoticeOutput(ctx ModuleContext, installPath OutputPath, installFilename string,
func BuildNoticeOutput(ctx ModuleContext, installPath InstallPath, installFilename string,
	noticePaths []Path) NoticeOutputs {
	// Merge all NOTICE files into one.
	// TODO(jungjw): We should just produce a well-formatted NOTICE.html file in a single pass.
+66 −22
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ type ModuleInstallPathContext interface {
	InstallInTestcases() bool
	InstallInSanitizerDir() bool
	InstallInRecovery() bool
	InstallInRoot() bool
	InstallBypassMake() bool
}

@@ -792,7 +793,7 @@ func (p SourcePath) OverlayPath(ctx ModuleContext, path Path) OptionalPath {
	return OptionalPathForPath(PathForSource(ctx, relPath))
}

// OutputPath is a Path representing a file path rooted from the build directory
// OutputPath is a Path representing an intermediates file path rooted from the build directory
type OutputPath struct {
	basePath
}
@@ -820,17 +821,6 @@ func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
	return OutputPath{basePath{path, ctx.Config(), ""}}
}

// pathForInstallInMakeDir is used by PathForModuleInstall when the module returns true
// for InstallBypassMake to produce an OutputPath that installs to $OUT_DIR instead of
// $OUT_DIR/soong.
func pathForInstallInMakeDir(ctx PathContext, pathComponents ...string) OutputPath {
	path, err := validatePath(pathComponents...)
	if err != nil {
		reportPathError(ctx, err)
	}
	return OutputPath{basePath{"../" + path, ctx.Config(), ""}}
}

// PathsForOutput returns Paths rooted from buildDir
func PathsForOutput(ctx PathContext, paths []string) WritablePaths {
	ret := make(WritablePaths, len(paths))
@@ -846,10 +836,6 @@ func (p OutputPath) String() string {
	return filepath.Join(p.config.buildDir, p.path)
}

func (p OutputPath) RelPathString() string {
	return p.path
}

// Join creates a new OutputPath with paths... joined with the current path. The
// provided paths... may not use '..' to escape from the current path.
func (p OutputPath) Join(ctx PathContext, paths ...string) OutputPath {
@@ -1118,9 +1104,44 @@ func PathForModuleRes(ctx ModuleContext, pathComponents ...string) ModuleResPath
	return ModuleResPath{PathForModuleOut(ctx, "res", p)}
}

// InstallPath is a Path representing a installed file path rooted from the build directory
type InstallPath struct {
	basePath

	baseDir string // "../" for Make paths to convert "out/soong" to "out", "" for Soong paths
}

func (p InstallPath) writablePath() {}

func (p InstallPath) String() string {
	return filepath.Join(p.config.buildDir, p.baseDir, p.path)
}

// Join creates a new InstallPath with paths... joined with the current path. The
// provided paths... may not use '..' to escape from the current path.
func (p InstallPath) Join(ctx PathContext, paths ...string) InstallPath {
	path, err := validatePath(paths...)
	if err != nil {
		reportPathError(ctx, err)
	}
	return p.withRel(path)
}

func (p InstallPath) withRel(rel string) InstallPath {
	p.basePath = p.basePath.withRel(rel)
	return p
}

// ToMakePath returns a new InstallPath that points to Make's install directory instead of Soong's,
// i.e. out/ instead of out/soong/.
func (p InstallPath) ToMakePath() InstallPath {
	p.baseDir = "../"
	return p
}

// PathForModuleInstall returns a Path representing the install path for the
// module appended with paths...
func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) OutputPath {
func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
	var outPaths []string
	if ctx.Device() {
		partition := modulePartition(ctx)
@@ -1140,13 +1161,30 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string
		outPaths = append([]string{"debug"}, outPaths...)
	}
	outPaths = append(outPaths, pathComponents...)

	path, err := validatePath(outPaths...)
	if err != nil {
		reportPathError(ctx, err)
	}

	ret := InstallPath{basePath{path, ctx.Config(), ""}, ""}
	if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() {
		return pathForInstallInMakeDir(ctx, outPaths...)
		ret = ret.ToMakePath()
	}
	return PathForOutput(ctx, outPaths...)

	return ret
}

func InstallPathToOnDevicePath(ctx PathContext, path OutputPath) string {
func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {
	paths = append([]string{"ndk"}, paths...)
	path, err := validatePath(paths...)
	if err != nil {
		reportPathError(ctx, err)
	}
	return InstallPath{basePath{path, ctx.Config(), ""}, ""}
}

func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
	rel := Rel(ctx, PathForOutput(ctx, "target", "product", ctx.Config().DeviceName()).String(), path.String())

	return "/" + rel
@@ -1159,8 +1197,12 @@ func modulePartition(ctx ModuleInstallPathContext) string {
	} else if ctx.InstallInTestcases() {
		partition = "testcases"
	} else if ctx.InstallInRecovery() {
		if ctx.InstallInRoot() {
			partition = "recovery/root"
		} else {
			// the layout of recovery partion is the same as that of system partition
			partition = "recovery/root/system"
		}
	} else if ctx.SocSpecific() {
		partition = ctx.DeviceConfig().VendorPath()
	} else if ctx.DeviceSpecific() {
@@ -1169,6 +1211,8 @@ func modulePartition(ctx ModuleInstallPathContext) string {
		partition = ctx.DeviceConfig().ProductPath()
	} else if ctx.SystemExtSpecific() {
		partition = ctx.DeviceConfig().SystemExtPath()
	} else if ctx.InstallInRoot() {
		partition = "root"
	} else {
		partition = "system"
	}
+39 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ type moduleInstallPathContextImpl struct {
	inTestcases    bool
	inSanitizerDir bool
	inRecovery     bool
	inRoot         bool
}

func (moduleInstallPathContextImpl) Fs() pathtools.FileSystem {
@@ -232,6 +233,10 @@ func (m moduleInstallPathContextImpl) InstallInRecovery() bool {
	return m.inRecovery
}

func (m moduleInstallPathContextImpl) InstallInRoot() bool {
	return m.inRoot
}

func (m moduleInstallPathContextImpl) InstallBypassMake() bool {
	return false
}
@@ -313,6 +318,40 @@ func TestPathForModuleInstall(t *testing.T) {
			in:  []string{"bin", "my_test"},
			out: "target/product/test_device/system_ext/bin/my_test",
		},
		{
			name: "root binary",
			ctx: &moduleInstallPathContextImpl{
				baseModuleContext: baseModuleContext{
					target: deviceTarget,
				},
				inRoot: true,
			},
			in:  []string{"my_test"},
			out: "target/product/test_device/root/my_test",
		},
		{
			name: "recovery binary",
			ctx: &moduleInstallPathContextImpl{
				baseModuleContext: baseModuleContext{
					target: deviceTarget,
				},
				inRecovery: true,
			},
			in:  []string{"bin/my_test"},
			out: "target/product/test_device/recovery/root/system/bin/my_test",
		},
		{
			name: "recovery root binary",
			ctx: &moduleInstallPathContextImpl{
				baseModuleContext: baseModuleContext{
					target: deviceTarget,
				},
				inRecovery: true,
				inRoot:     true,
			},
			in:  []string{"my_test"},
			out: "target/product/test_device/recovery/root/my_test",
		},

		{
			name: "system native test binary",
Loading