From 0db5568612385e014ad40832660a34d935aba954 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 5 Dec 2017 15:36:55 -0800 Subject: [PATCH] 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 --- android/paths.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/android/paths.go b/android/paths.go index e0cbd21b2..80863c969 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