Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99c844b3 authored by Colin Cross's avatar Colin Cross Committed by android-build-merger
Browse files

Add OutputPath.ReplaceExtension() am: 8854a5a8

am: 7e071999

Change-Id: I6c9722838c27a7f9b64ed9da75409a98680f03bf
parents a6f57f52 7e071999
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -697,6 +697,16 @@ func (p OutputPath) Join(ctx PathContext, paths ...string) OutputPath {
	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 {
+12 −0
Original line number Diff line number Diff line
@@ -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
}