Add OutputPath.ReplaceExtension()
Add a helper method that returns a new OutputPath with the extension replaced. Test: paths_test.go Change-Id: I7f93b3475031a19b53652022740488373a1b7d97
This commit is contained in:
@@ -697,6 +697,16 @@ func (p OutputPath) Join(ctx PathContext, paths ...string) OutputPath {
|
|||||||
return p.withRel(path)
|
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
|
// PathForIntermediates returns an OutputPath representing the top-level
|
||||||
// intermediates directory.
|
// intermediates directory.
|
||||||
func PathForIntermediates(ctx PathContext, paths ...string) OutputPath {
|
func PathForIntermediates(ctx PathContext, paths ...string) OutputPath {
|
||||||
|
@@ -691,3 +691,15 @@ func TestPathForSource(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleOutputPath_ReplaceExtension() {
|
||||||
|
ctx := &configErrorWrapper{
|
||||||
|
config: TestConfig("out", nil),
|
||||||
|
}
|
||||||
|
p := PathForOutput(ctx, "system/framework/boot.art")
|
||||||
|
p2 := p.ReplaceExtension(ctx, "oat")
|
||||||
|
fmt.Println(p, p2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// out/system/framework/boot.art out/system/framework/boot.oat
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user