Add (String)Path(s)RelativeToTop and assert functions
The existing NormalizePathForTesting function does not handle make
install paths very well, as it returns a relative path with a leading
"../" which is very confusing. It also does not clearly differentiate
between the different paths.
These functions return paths that are basically what are seen in a
normal developer build, i.e.
* <source path>
* out/soong/<soong output path>
* out/<make output path>
That makes tests that use them easier to understand.
Follow up changes will clean up the existing usages of the
Normalize... functions.
Bug: 182885307
Test: m nothing
Change-Id: I17ddc996bef5bbbf4a62da8334ea6ce29e306109
diff --git a/android/paths_test.go b/android/paths_test.go
index 14a4773..3734ed2 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -1261,6 +1261,52 @@
}
}
+func TestPathRelativeToTop(t *testing.T) {
+ testConfig := pathTestConfig("/tmp/build/top")
+ deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}}
+
+ ctx := &testModuleInstallPathContext{
+ baseModuleContext: baseModuleContext{
+ os: deviceTarget.Os,
+ target: deviceTarget,
+ },
+ }
+ ctx.baseModuleContext.config = testConfig
+
+ t.Run("install for soong", func(t *testing.T) {
+ p := PathForModuleInstall(ctx, "install/path")
+ AssertPathRelativeToTopEquals(t, "install path for soong", "out/soong/target/product/test_device/system/install/path", p)
+ })
+ t.Run("install for make", func(t *testing.T) {
+ p := PathForModuleInstall(ctx, "install/path").ToMakePath()
+ AssertPathRelativeToTopEquals(t, "install path for make", "out/target/product/test_device/system/install/path", p)
+ })
+ t.Run("output", func(t *testing.T) {
+ p := PathForOutput(ctx, "output/path")
+ AssertPathRelativeToTopEquals(t, "output path", "out/soong/output/path", p)
+ })
+ t.Run("source", func(t *testing.T) {
+ p := PathForSource(ctx, "source/path")
+ AssertPathRelativeToTopEquals(t, "source path", "source/path", p)
+ })
+ t.Run("mixture", func(t *testing.T) {
+ paths := Paths{
+ PathForModuleInstall(ctx, "install/path"),
+ PathForModuleInstall(ctx, "install/path").ToMakePath(),
+ PathForOutput(ctx, "output/path"),
+ PathForSource(ctx, "source/path"),
+ }
+
+ expected := []string{
+ "out/soong/target/product/test_device/system/install/path",
+ "out/target/product/test_device/system/install/path",
+ "out/soong/output/path",
+ "source/path",
+ }
+ AssertPathsRelativeToTopEquals(t, "mixture", expected, paths)
+ })
+}
+
func ExampleOutputPath_ReplaceExtension() {
ctx := &configErrorWrapper{
config: TestConfig("out", nil, "", nil),