diff options
author | Colin Cross <ccross@android.com> | 2017-12-05 15:36:55 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-12-06 04:16:00 +0000 |
commit | 0db5568612385e014ad40832660a34d935aba954 (patch) | |
tree | 46fe5ed7d8cf6e444aace06ccf9cc3126bc36268 /android | |
parent | 5425090a4f006fb0de0a98fbd0dad66706e1638e (diff) | |
download | build_soong-0db5568612385e014ad40832660a34d935aba954.tar.gz build_soong-0db5568612385e014ad40832660a34d935aba954.tar.bz2 build_soong-0db5568612385e014ad40832660a34d935aba954.zip |
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
Diffstat (limited to 'android')
-rw-r--r-- | android/paths.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/android/paths.go b/android/paths.go index e0cbd21b..80863c96 100644 --- a/android/paths.go +++ b/android/paths.go @@ -92,7 +92,7 @@ type Path interface { // 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 @@ func (p basePath) String() string { 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 @@ type SourcePath struct { 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 @@ func (p SourcePath) String() string { // 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 @@ type OutputPath struct { } 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 @@ func (p OutputPath) RelPathString() string { // 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 |