Make (Source|Output)Path.Join("foo").Rel() return "foo"
This allows TestModule.Output("foo") to be used to find
a file called "foo" that was installed using ctx.InstallFile.
Test: soong tests
Change-Id: I04833c9ee8ac5baa6b6afd35715d1191c1622a78
diff --git a/android/paths.go b/android/paths.go
index e0cbd21..80863c9 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -92,7 +92,7 @@
// Rel returns the portion of the path relative to the directory it was created from. For
// example, Rel on a PathsForModuleSrc would return the path relative to the module source
- // directory.
+ // directory, and OutputPath.Join("foo").Rel() would return "foo".
Rel() string
}
@@ -456,6 +456,12 @@
return p.path
}
+func (p basePath) withRel(rel string) basePath {
+ p.path = filepath.Join(p.path, rel)
+ p.rel = rel
+ return p
+}
+
// SourcePath is a Path representing a file path rooted from SrcDir
type SourcePath struct {
basePath
@@ -463,6 +469,11 @@
var _ Path = SourcePath{}
+func (p SourcePath) withRel(rel string) SourcePath {
+ p.basePath = p.basePath.withRel(rel)
+ return p
+}
+
// safePathForSource is for paths that we expect are safe -- only for use by go
// code that is embedding ninja variables in paths
func safePathForSource(ctx PathContext, path string) SourcePath {
@@ -589,7 +600,7 @@
// provided paths... may not use '..' to escape from the current path.
func (p SourcePath) Join(ctx PathContext, paths ...string) SourcePath {
path := validatePath(ctx, paths...)
- return PathForSource(ctx, p.path, path)
+ return p.withRel(path)
}
// OverlayPath returns the overlay for `path' if it exists. This assumes that the
@@ -631,8 +642,7 @@
}
func (p OutputPath) withRel(rel string) OutputPath {
- p.basePath.path = filepath.Join(p.basePath.path, rel)
- p.basePath.rel = rel
+ p.basePath = p.basePath.withRel(rel)
return p
}
@@ -660,7 +670,7 @@
// provided paths... may not use '..' to escape from the current path.
func (p OutputPath) Join(ctx PathContext, paths ...string) OutputPath {
path := validatePath(ctx, paths...)
- return PathForOutput(ctx, p.path, path)
+ return p.withRel(path)
}
// PathForIntermediates returns an OutputPath representing the top-level