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
diff --git a/android/paths.go b/android/paths.go
index b89edba..8dbb086 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -821,17 +821,6 @@
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 @@
// 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 @@
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 @@
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 @@
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 3aeda1c..6c4813b 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -158,7 +158,7 @@
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 0a2c7a4..f675ea3 100644
--- a/android/prebuilt_etc_test.go
+++ b/android/prebuilt_etc_test.go
@@ -182,9 +182,9 @@
`)
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 @@
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 @@
`)
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 @@
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)
}
})