Make PathForArbitraryOutput return an OutputPath
The only place basePath is used as a Path is when being returned from
PathForArbitraryOutput. Using it as a Path requires implementing the
RelativeToTop() method on it, which then allowed that method to be
inherited by SourcePath, breaking the contract on RelativeToTop that
specifies that the returned Path is of the same concrete type as the
input Path.
Make PathForArbitraryOutput return an OutputPath, and update OutputPath
to support base paths that are not out/soong. This also fixes
RelativeToTop, which was previously not working for PathForArbitraryOutput
paths.
Test: all soong tests pass
Flag: EXEMPT refactor
Change-Id: Ie8d8e2290961f35280e97137d2bd641c4d57ab87
diff --git a/android/testing.go b/android/testing.go
index e39a1a7..dae787b 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -822,15 +822,15 @@
// containing at most one instance of the temporary build directory at the start of the path while
// this assumes that there can be any number at any position.
func normalizeStringRelativeToTop(config Config, s string) string {
- // The soongOutDir usually looks something like: /tmp/testFoo2345/001
+ // The outDir usually looks something like: /tmp/testFoo2345/001
//
- // Replace any usage of the soongOutDir with out/soong, e.g. replace "/tmp/testFoo2345/001" with
+ // Replace any usage of the outDir with out/soong, e.g. replace "/tmp/testFoo2345/001" with
// "out/soong".
outSoongDir := filepath.Clean(config.soongOutDir)
re := regexp.MustCompile(`\Q` + outSoongDir + `\E\b`)
s = re.ReplaceAllString(s, "out/soong")
- // Replace any usage of the soongOutDir/.. with out, e.g. replace "/tmp/testFoo2345" with
+ // Replace any usage of the outDir/.. with out, e.g. replace "/tmp/testFoo2345" with
// "out". This must come after the previous replacement otherwise this would replace
// "/tmp/testFoo2345/001" with "out/001" instead of "out/soong".
outDir := filepath.Dir(outSoongDir)
@@ -1234,8 +1234,14 @@
}
if isRel {
- // The path is in the soong out dir so indicate that in the relative path.
- return filepath.Join("out/soong", rel)
+ if strings.HasSuffix(soongOutDir, testOutSoongSubDir) {
+ // The path is in the soong out dir so indicate that in the relative path.
+ return filepath.Join(TestOutSoongDir, rel)
+ } else {
+ // Handle the PathForArbitraryOutput case
+ return filepath.Join(testOutDir, rel)
+
+ }
}
// Check to see if the path is relative to the top level out dir.