From 90ba5f4e98a29c5ed3e6c1c9bb39118b9454e97b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 2 Oct 2019 11:10:58 -0700 Subject: [PATCH 1/3] Add InstallInRoot to allow modules to install into root partition If InstallInRoot() returns true the module will be installed to $OUT/root or $OUT/recovery/root. Bug: 141877526 Test: m checkbuild Test: no change to build.ninja or Android-${TARGET_PRODUCT}.mk Test: TestPathForModuleInstall Change-Id: Id6e435c6019f11eeb5806528fd464dbf220b88d9 --- android/module.go | 10 ++++++++++ android/paths.go | 11 +++++++++-- android/paths_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/android/module.go b/android/module.go index a1a01a5cf..2d0c20d8c 100644 --- a/android/module.go +++ b/android/module.go @@ -157,6 +157,7 @@ type ModuleContext interface { 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,6 +1528,10 @@ 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() } diff --git a/android/paths.go b/android/paths.go index 8bd2c61e7..e8b08b504 100644 --- a/android/paths.go +++ b/android/paths.go @@ -47,6 +47,7 @@ type ModuleInstallPathContext interface { InstallInTestcases() bool InstallInSanitizerDir() bool InstallInRecovery() bool + InstallInRoot() bool InstallBypassMake() bool } @@ -1159,8 +1160,12 @@ func modulePartition(ctx ModuleInstallPathContext) string { } else if ctx.InstallInTestcases() { partition = "testcases" } else if ctx.InstallInRecovery() { - // the layout of recovery partion is the same as that of system partition - partition = "recovery/root/system" + 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 +1174,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" } diff --git a/android/paths_test.go b/android/paths_test.go index b66eb1e91..2e67272e0 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -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", From 70dda7e3da7eed09c1c7e0a3ab8b2ed3c9934035 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 1 Oct 2019 22:05:35 -0700 Subject: [PATCH 2/3] Separate InstallPath from OutputPath Create a new type InstallPath that is similar to OutputPath to differentiate intermediates output paths from installed output paths. RelPathString is a poorly defined, undocumented function that is primarily used to get an install path relative to out/soong to generate an equivalent install path for Make relative to $(OUT_DIR). Move it to InstallPath for now, and fix the one remaining user on OutputPath. Add a method to create an NDK install path so that ndk_sysroot.go doesn't have to do it manually with PathForOutput. Bug: 141877526 Test: m checkbuild Change-Id: I83c5a0bd1fd6c3dba8d3b6d20d039f64f353ddd5 --- android/hooks.go | 8 ++--- android/module.go | 26 +++++++-------- android/notices.go | 2 +- android/paths.go | 60 ++++++++++++++++++++++++++++------ android/prebuilt_etc.go | 4 +-- apex/apex.go | 6 ++-- cc/installer.go | 4 +-- cc/library.go | 4 +-- cc/ndk_headers.go | 4 +-- cc/ndk_sysroot.go | 6 ++-- java/app.go | 4 +-- java/dexpreopt.go | 4 +-- java/java.go | 2 +- java/platform_compat_config.go | 2 +- python/installer.go | 4 +-- rust/compiler.go | 4 +-- 16 files changed, 91 insertions(+), 53 deletions(-) diff --git a/android/hooks.go b/android/hooks.go index 1e5ff2195..604cb9c28 100644 --- a/android/hooks.go +++ b/android/hooks.go @@ -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, diff --git a/android/module.go b/android/module.go index 2d0c20d8c..40b2b5753 100644 --- a/android/module.go +++ b/android/module.go @@ -147,10 +147,10 @@ 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 @@ -1536,7 +1536,7 @@ 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 } @@ -1561,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) @@ -1607,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) @@ -1636,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) diff --git a/android/notices.go b/android/notices.go index 7b61d65ba..bf273b544 100644 --- a/android/notices.go +++ b/android/notices.go @@ -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. diff --git a/android/paths.go b/android/paths.go index e8b08b504..b89edba33 100644 --- a/android/paths.go +++ b/android/paths.go @@ -793,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 } @@ -824,12 +824,12 @@ func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath { // 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 { +func pathForInstallInMakeDir(ctx PathContext, pathComponents ...string) InstallPath { path, err := validatePath(pathComponents...) if err != nil { reportPathError(ctx, err) } - return OutputPath{basePath{"../" + path, ctx.Config(), ""}} + return InstallPath{basePath{"../" + path, ctx.Config(), ""}} } // PathsForOutput returns Paths rooted from buildDir @@ -847,10 +847,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 { @@ -1119,9 +1115,39 @@ 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 +} + +func (p InstallPath) writablePath() {} + +func (p InstallPath) String() string { + return filepath.Join(p.config.buildDir, 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 +} + +func (p InstallPath) RelPathString() string { + return p.path +} + // 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) @@ -1144,10 +1170,24 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() { return pathForInstallInMakeDir(ctx, outPaths...) } - return PathForOutput(ctx, outPaths...) + + path, err := validatePath(outPaths...) + if err != nil { + reportPathError(ctx, err) + } + return InstallPath{basePath{path, ctx.Config(), ""}} } -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 diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go index d29ed16f6..3aeda1c6a 100644 --- a/android/prebuilt_etc.go +++ b/android/prebuilt_etc.go @@ -65,7 +65,7 @@ type PrebuiltEtc struct { installDirBase string // The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware. socInstallDirBase string - installDirPath OutputPath + installDirPath InstallPath additionalDependencies *Paths } @@ -91,7 +91,7 @@ func (p *PrebuiltEtc) SourceFilePath(ctx ModuleContext) Path { return PathForModuleSrc(ctx, String(p.properties.Src)) } -func (p *PrebuiltEtc) InstallDirPath() OutputPath { +func (p *PrebuiltEtc) InstallDirPath() InstallPath { return p.installDirPath } diff --git a/apex/apex.go b/apex/apex.go index aff8d50b6..1e5cf910b 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -561,8 +561,8 @@ type apexBundle struct { bundleModuleFile android.WritablePath outputFiles map[apexPackaging]android.WritablePath - flattenedOutput android.OutputPath - installDir android.OutputPath + flattenedOutput android.InstallPath + installDir android.InstallPath prebuiltFileToDelete string @@ -1840,7 +1840,7 @@ type Prebuilt struct { properties PrebuiltProperties inputApex android.Path - installDir android.OutputPath + installDir android.InstallPath installFilename string outputApex android.WritablePath } diff --git a/cc/installer.go b/cc/installer.go index a52ccf1fe..610252c9d 100644 --- a/cc/installer.go +++ b/cc/installer.go @@ -52,7 +52,7 @@ type baseInstaller struct { relative string location installLocation - path android.OutputPath + path android.InstallPath } var _ installer = (*baseInstaller)(nil) @@ -61,7 +61,7 @@ func (installer *baseInstaller) installerProps() []interface{} { return []interface{}{&installer.Properties} } -func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath { +func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath { dir := installer.dir if ctx.toolchain().Is64Bit() && installer.dir64 != "" { dir = installer.dir64 diff --git a/cc/library.go b/cc/library.go index a41ddc26a..d8c9b90f0 100644 --- a/cc/library.go +++ b/cc/library.go @@ -791,9 +791,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, // Optimize out relinking against shared libraries whose interface hasn't changed by // depending on a table of contents file instead of the library itself. - tocPath := outputFile.RelPathString() - tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc") - tocFile := android.PathForOutput(ctx, tocPath) + tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.ShlibSuffix()[1:]+".toc") library.tocFile = android.OptionalPathForPath(tocFile) TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags) diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 40651280d..b8423be1f 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -48,7 +48,7 @@ func init() { } // Returns the NDK base include path for use with sdk_version current. Usable with -I. -func getCurrentIncludePath(ctx android.ModuleContext) android.OutputPath { +func getCurrentIncludePath(ctx android.ModuleContext) android.InstallPath { return getNdkSysrootBase(ctx).Join(ctx, "usr/include") } @@ -94,7 +94,7 @@ type headerModule struct { } func getHeaderInstallDir(ctx android.ModuleContext, header android.Path, from string, - to string) android.OutputPath { + to string) android.InstallPath { // Output path is the sysroot base + "usr/include" + to directory + directory component // of the file without the leading from directory stripped. // diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go index e39bae559..f6de4ef6e 100644 --- a/cc/ndk_sysroot.go +++ b/cc/ndk_sysroot.go @@ -66,12 +66,12 @@ func init() { pctx.Import("android/soong/android") } -func getNdkInstallBase(ctx android.PathContext) android.OutputPath { - return android.PathForOutput(ctx, "ndk") +func getNdkInstallBase(ctx android.PathContext) android.InstallPath { + return android.PathForNdkInstall(ctx) } // Returns the main install directory for the NDK sysroot. Usable with --sysroot. -func getNdkSysrootBase(ctx android.PathContext) android.OutputPath { +func getNdkSysrootBase(ctx android.PathContext) android.InstallPath { return getNdkInstallBase(ctx).Join(ctx, "sysroot") } diff --git a/java/app.go b/java/app.go index 3ee8b8d1b..e03366174 100644 --- a/java/app.go +++ b/java/app.go @@ -126,7 +126,7 @@ type AndroidApp struct { // the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES. installApkName string - installDir android.OutputPath + installDir android.InstallPath onDeviceDir string @@ -773,7 +773,7 @@ type AndroidAppImport struct { usesLibrary usesLibrary - installPath android.OutputPath + installPath android.InstallPath } type AndroidAppImportProperties struct { diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 6214dac44..db6b45551 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -22,7 +22,7 @@ import ( type dexpreopter struct { dexpreoptProperties DexpreoptProperties - installPath android.OutputPath + installPath android.InstallPath uncompressedDex bool isSDKLibrary bool isTest bool @@ -94,7 +94,7 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool { return false } -func odexOnSystemOther(ctx android.ModuleContext, installPath android.OutputPath) bool { +func odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool { return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreoptGlobalConfig(ctx)) } diff --git a/java/java.go b/java/java.go index f7b0f53ba..4264ba908 100644 --- a/java/java.go +++ b/java/java.go @@ -1795,7 +1795,7 @@ type Binary struct { isWrapperVariant bool wrapperFile android.Path - binaryFile android.OutputPath + binaryFile android.InstallPath } func (j *Binary) HostToolPath() android.OptionalPath { diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 3d46077b5..0c973c5db 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -30,7 +30,7 @@ type platformCompatConfig struct { android.ModuleBase properties platformCompatConfigProperties - installDirPath android.OutputPath + installDirPath android.InstallPath configFile android.OutputPath } diff --git a/python/installer.go b/python/installer.go index 62f36f4b5..b0a25b9b7 100644 --- a/python/installer.go +++ b/python/installer.go @@ -33,7 +33,7 @@ type pythonInstaller struct { dir64 string relative string - path android.OutputPath + path android.InstallPath androidMkSharedLibs []string } @@ -47,7 +47,7 @@ func NewPythonInstaller(dir, dir64 string) *pythonInstaller { var _ installer = (*pythonInstaller)(nil) -func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.OutputPath { +func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.InstallPath { dir := installer.dir if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" { dir = installer.dir64 diff --git a/rust/compiler.go b/rust/compiler.go index 3bfef7693..76d5ad844 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -94,7 +94,7 @@ type baseCompiler struct { dir64 string subDir string relative string - path android.OutputPath + path android.InstallPath } var _ compiler = (*baseCompiler)(nil) @@ -173,7 +173,7 @@ func (compiler *baseCompiler) crateName() string { return compiler.Properties.Crate_name } -func (compiler *baseCompiler) installDir(ctx ModuleContext) android.OutputPath { +func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath { dir := compiler.dir if ctx.toolchain().Is64Bit() && compiler.dir64 != "" { dir = compiler.dir64 From ff6c33d885c8a8132728853a8bd2cfd73988b660 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 2 Oct 2019 16:01:35 -0700 Subject: [PATCH 3/3] Replace RelPathString() with ToMakePath() Add a ToMakePath() method that returns a new path that points out out/ instead of out/soong/, and replace the "$(OUT_DIR)/" + path.RelPathString() pattern with path.ToMakePath().String() Bug: 141877526 Test: m checkbuild Change-Id: I391b9f2ed78c83a58d905d48355ce9b01d610d16 --- android/paths.go | 35 ++++++++++++------------- android/prebuilt_etc.go | 2 +- android/prebuilt_etc_test.go | 22 ++++++++-------- apex/apex.go | 10 +++---- apex/apex_test.go | 5 ++-- cc/androidmk.go | 10 +++---- cc/vndk_prebuilt.go | 14 ++++++++++ java/platform_compat_config.go | 2 +- python/androidmk.go | 5 ++-- rust/androidmk.go | 5 ++-- xml/xml_test.go | 48 ++++++++++++++++++++-------------- 11 files changed, 88 insertions(+), 70 deletions(-) diff --git a/android/paths.go b/android/paths.go index b89edba33..8dbb08644 100644 --- a/android/paths.go +++ b/android/paths.go @@ -821,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) InstallPath { - path, err := validatePath(pathComponents...) - if err != nil { - reportPathError(ctx, err) - } - return InstallPath{basePath{"../" + path, ctx.Config(), ""}} -} - // PathsForOutput returns Paths rooted from buildDir func PathsForOutput(ctx PathContext, paths []string) WritablePaths { ret := make(WritablePaths, len(paths)) @@ -1118,12 +1107,14 @@ func PathForModuleRes(ctx ModuleContext, pathComponents ...string) ModuleResPath // 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.path) + return filepath.Join(p.config.buildDir, p.baseDir, p.path) } // Join creates a new InstallPath with paths... joined with the current path. The @@ -1141,8 +1132,11 @@ func (p InstallPath) withRel(rel string) InstallPath { return p } -func (p InstallPath) RelPathString() string { - return p.path +// 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 @@ -1167,15 +1161,18 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string outPaths = append([]string{"debug"}, outPaths...) } outPaths = append(outPaths, pathComponents...) - if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() { - return pathForInstallInMakeDir(ctx, outPaths...) - } path, err := validatePath(outPaths...) if err != nil { reportPathError(ctx, err) } - return InstallPath{basePath{path, ctx.Config(), ""}} + + ret := InstallPath{basePath{path, ctx.Config(), ""}, ""} + if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() { + ret = ret.ToMakePath() + } + + return ret } func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath { @@ -1184,7 +1181,7 @@ func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath { if err != nil { reportPathError(ctx, err) } - return InstallPath{basePath{path, ctx.Config(), ""}} + return InstallPath{basePath{path, ctx.Config(), ""}, ""} } func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string { diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go index 3aeda1c6a..6c4813bd1 100644 --- a/android/prebuilt_etc.go +++ b/android/prebuilt_etc.go @@ -158,7 +158,7 @@ func (p *PrebuiltEtc) AndroidMkEntries() AndroidMkEntries { ExtraEntries: []AndroidMkExtraEntriesFunc{ func(entries *AndroidMkEntries) { entries.SetString("LOCAL_MODULE_TAGS", "optional") - entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) + entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable())) if p.additionalDependencies != nil { diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go index 0a2c7a4f5..f675ea3c3 100644 --- a/android/prebuilt_etc_test.go +++ b/android/prebuilt_etc_test.go @@ -182,9 +182,9 @@ func TestPrebuiltUserShareInstallDirPath(t *testing.T) { `) p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc) - expected := "target/product/test_device/system/usr/share/bar" - if p.installDirPath.RelPathString() != expected { - t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString()) + expected := buildDir + "/target/product/test_device/system/usr/share/bar" + if p.installDirPath.String() != expected { + t.Errorf("expected %q, got %q", expected, p.installDirPath.String()) } } @@ -199,9 +199,9 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) { buildOS := BuildOs.String() p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc) - expected := filepath.Join("host", config.PrebuiltOS(), "usr", "share", "bar") - if p.installDirPath.RelPathString() != expected { - t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString()) + expected := filepath.Join(buildDir, "host", config.PrebuiltOS(), "usr", "share", "bar") + if p.installDirPath.String() != expected { + t.Errorf("expected %q, got %q", expected, p.installDirPath.String()) } } @@ -214,14 +214,14 @@ func TestPrebuiltFontInstallDirPath(t *testing.T) { `) p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc) - expected := "target/product/test_device/system/fonts" - if p.installDirPath.RelPathString() != expected { - t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString()) + expected := buildDir + "/target/product/test_device/system/fonts" + if p.installDirPath.String() != expected { + t.Errorf("expected %q, got %q", expected, p.installDirPath.String()) } } func TestPrebuiltFirmwareDirPath(t *testing.T) { - targetPath := "target/product/test_device" + targetPath := buildDir + "/target/product/test_device" tests := []struct { description string config string @@ -249,7 +249,7 @@ func TestPrebuiltFirmwareDirPath(t *testing.T) { t.Run(tt.description, func(t *testing.T) { ctx, _ := testPrebuiltEtc(t, tt.config) p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc) - if p.installDirPath.RelPathString() != tt.expectedPath { + if p.installDirPath.String() != tt.expectedPath { t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath) } }) diff --git a/apex/apex.go b/apex/apex.go index 1e5cf910b..a561cfafc 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1625,8 +1625,8 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apex proptools.StringDefault(a.properties.Apex_name, name), fi.installDir) if a.properties.Flattened && apexType.image() { // /system/apex//{lib|framework|...} - fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", - a.installDir.RelPathString(), name, fi.installDir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(), + name, fi.installDir)) if !a.isFlattenedVariant() { fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) } @@ -1735,7 +1735,7 @@ func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkD fmt.Fprintln(w, "LOCAL_MODULE :=", name) fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class? fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String()) - fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString())) + fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String()) fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix()) fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) if len(moduleNames) > 0 { @@ -1746,7 +1746,7 @@ func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkD } if a.prebuiltFileToDelete != "" { fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+ - filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete)) + filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete)) } fmt.Fprintln(w, "include $(BUILD_PREBUILT)") @@ -1987,7 +1987,7 @@ func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries { Include: "$(BUILD_PREBUILT)", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString())) + entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String()) entries.SetString("LOCAL_MODULE_STEM", p.installFilename) entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...) diff --git a/apex/apex_test.go b/apex/apex_test.go index ecfa46fa5..b4516bd23 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1382,6 +1382,7 @@ func TestVndkApexVersion(t *testing.T) { vndk: { enabled: true, }, + target_arch: "arm64", srcs: ["libvndk27.so"], } `, withFiles(map[string][]byte{ @@ -1864,8 +1865,8 @@ func TestApexInProductPartition(t *testing.T) { `) apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle) - expected := "target/product/test_device/product/apex" - actual := apex.installDir.RelPathString() + expected := buildDir + "/target/product/test_device/product/apex" + actual := apex.installDir.String() if actual != expected { t.Errorf("wrong install path. expected %q. actual %q", expected, actual) } diff --git a/cc/androidmk.go b/cc/androidmk.go index aab4edd93..f1d329f9c 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -350,11 +350,10 @@ func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.And } ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - path := installer.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(installer.path.ToMakePath().String()) stem, suffix, _ := android.SplitFileExt(file) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) }) } @@ -395,12 +394,11 @@ func (c *vndkPrebuiltLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *andr ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { c.libraryDecorator.androidMkWriteExportedFlags(w) - path := c.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(c.path.ToMakePath().String()) stem, suffix, ext := android.SplitFileExt(file) fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) }) } diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go index 8126e4aa9..2cebb6dcb 100644 --- a/cc/vndk_prebuilt.go +++ b/cc/vndk_prebuilt.go @@ -129,6 +129,18 @@ func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) andro func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { + + arches := ctx.DeviceConfig().Arches() + if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { + ctx.Module().SkipInstall() + return nil + } + + if ctx.DeviceConfig().BinderBitness() != p.binderBit() { + ctx.Module().SkipInstall() + return nil + } + if len(p.properties.Srcs) > 0 && p.shared() { p.libraryDecorator.exportIncludes(ctx) p.libraryDecorator.reexportSystemDirs(p.properties.Export_system_include_dirs...) @@ -136,6 +148,8 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, // current VNDK prebuilts are only shared libs. return p.singleSourcePath(ctx) } + + ctx.Module().SkipInstall() return nil } diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 0c973c5db..23ba2b01e 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -78,7 +78,7 @@ func (p *platformCompatConfig) AndroidMkEntries() android.AndroidMkEntries { Include: "$(BUILD_PREBUILT)", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) + entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) }, }, diff --git a/python/androidmk.go b/python/androidmk.go index 1e51e7b8a..aae7cedc9 100644 --- a/python/androidmk.go +++ b/python/androidmk.go @@ -89,12 +89,11 @@ func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMk ret.Required = append(ret.Required, "libc++") ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - path := installer.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(installer.path.ToMakePath().String()) stem := strings.TrimSuffix(file, filepath.Ext(file)) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " ")) }) diff --git a/rust/androidmk.go b/rust/androidmk.go index 107959f84..a6208dbcd 100644 --- a/rust/androidmk.go +++ b/rust/androidmk.go @@ -116,11 +116,10 @@ func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.Andro ret.OutputFile = android.OptionalPathForPath(compiler.path) } ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - path := compiler.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(compiler.path.ToMakePath().String()) stem, suffix, _ := android.SplitFileExt(file) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) }) } diff --git a/xml/xml_test.go b/xml/xml_test.go index ae3e9fe3c..f2a440f9a 100644 --- a/xml/xml_test.go +++ b/xml/xml_test.go @@ -15,15 +15,40 @@ package xml import ( - "android/soong/android" "io/ioutil" "os" "testing" + + "android/soong/android" ) +var buildDir string + +func setUp() { + var err error + buildDir, err = ioutil.TempDir("", "soong_xml_test") + if err != nil { + panic(err) + } +} + +func tearDown() { + os.RemoveAll(buildDir) +} + +func TestMain(m *testing.M) { + run := func() int { + setUp() + defer tearDown() + + return m.Run() + } + + os.Exit(run()) +} + func testXml(t *testing.T, bp string) *android.TestContext { - config, buildDir := setup(t) - defer teardown(buildDir) + config := android.TestArchConfig(buildDir, nil) ctx := android.NewTestArchContext() ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) ctx.RegisterModuleType("prebuilt_etc_xml", android.ModuleFactoryAdaptor(PrebuiltEtcXmlFactory)) @@ -45,21 +70,6 @@ func testXml(t *testing.T, bp string) *android.TestContext { return ctx } -func setup(t *testing.T) (config android.Config, buildDir string) { - buildDir, err := ioutil.TempDir("", "soong_xml_test") - if err != nil { - t.Fatal(err) - } - - config = android.TestArchConfig(buildDir, nil) - - return -} - -func teardown(buildDir string) { - os.RemoveAll(buildDir) -} - func assertEqual(t *testing.T, name, expected, actual string) { t.Helper() if expected != actual { @@ -103,5 +113,5 @@ func TestPrebuiltEtcXml(t *testing.T) { } m := ctx.ModuleForTests("foo.xml", "android_arm64_armv8-a").Module().(*prebuiltEtcXml) - assertEqual(t, "installDir", "target/product/test_device/system/etc", m.InstallDirPath().RelPathString()) + assertEqual(t, "installDir", buildDir+"/target/product/test_device/system/etc", m.InstallDirPath().String()) }