Add OutputPath.ReplaceExtension()
Add a helper method that returns a new OutputPath with the
extension replaced.
Test: paths_test.go
Change-Id: I7f93b3475031a19b53652022740488373a1b7d97
diff --git a/android/paths.go b/android/paths.go
index 0c65b83..31500ab 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -697,6 +697,16 @@
return p.withRel(path)
}
+// ReplaceExtension creates a new OutputPath with the extension replaced with ext.
+func (p OutputPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
+ if strings.Contains(ext, "/") {
+ reportPathErrorf(ctx, "extension %q cannot contain /", ext)
+ }
+ ret := PathForOutput(ctx, pathtools.ReplaceExtension(p.path, ext))
+ ret.rel = p.rel
+ return ret
+}
+
// PathForIntermediates returns an OutputPath representing the top-level
// intermediates directory.
func PathForIntermediates(ctx PathContext, paths ...string) OutputPath {