Merge changes from topic "dexpreopt_bootjars" am: 49afb313ed
am: 7931d32a00
am: 538a7a2124
Change-Id: I6a4bc320e694354e0619430137f67f8576fc0288
This commit is contained in:
@@ -677,6 +677,15 @@ func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
|
|||||||
return OutputPath{basePath{path, ctx.Config(), ""}}
|
return OutputPath{basePath{path, ctx.Config(), ""}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PathsForOutput returns Paths rooted from buildDir
|
||||||
|
func PathsForOutput(ctx PathContext, paths []string) WritablePaths {
|
||||||
|
ret := make(WritablePaths, len(paths))
|
||||||
|
for i, path := range paths {
|
||||||
|
ret[i] = PathForOutput(ctx, path)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func (p OutputPath) writablePath() {}
|
func (p OutputPath) writablePath() {}
|
||||||
|
|
||||||
func (p OutputPath) String() string {
|
func (p OutputPath) String() string {
|
||||||
@@ -707,6 +716,18 @@ func (p OutputPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InSameDir creates a new OutputPath from the directory of the current OutputPath joined with the elements in paths.
|
||||||
|
func (p OutputPath) InSameDir(ctx PathContext, paths ...string) OutputPath {
|
||||||
|
path, err := validatePath(paths...)
|
||||||
|
if err != nil {
|
||||||
|
reportPathError(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := PathForOutput(ctx, filepath.Dir(p.path), path)
|
||||||
|
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 {
|
||||||
@@ -1019,6 +1040,14 @@ func (p testPath) String() string {
|
|||||||
return p.path
|
return p.path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type testWritablePath struct {
|
||||||
|
testPath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p testPath) writablePath() {}
|
||||||
|
|
||||||
|
// PathForTesting returns a Path constructed from joining the elements of paths with '/'. It should only be used from
|
||||||
|
// within tests.
|
||||||
func PathForTesting(paths ...string) Path {
|
func PathForTesting(paths ...string) Path {
|
||||||
p, err := validateSafePath(paths...)
|
p, err := validateSafePath(paths...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1027,7 +1056,8 @@ func PathForTesting(paths ...string) Path {
|
|||||||
return testPath{basePath{path: p, rel: p}}
|
return testPath{basePath{path: p, rel: p}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PathsForTesting(strs []string) Paths {
|
// PathsForTesting returns a Path constructed from each element in strs. It should only be used from within tests.
|
||||||
|
func PathsForTesting(strs ...string) Paths {
|
||||||
p := make(Paths, len(strs))
|
p := make(Paths, len(strs))
|
||||||
for i, s := range strs {
|
for i, s := range strs {
|
||||||
p[i] = PathForTesting(s)
|
p[i] = PathForTesting(s)
|
||||||
@@ -1036,6 +1066,45 @@ func PathsForTesting(strs []string) Paths {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WritablePathForTesting returns a Path constructed from joining the elements of paths with '/'. It should only be
|
||||||
|
// used from within tests.
|
||||||
|
func WritablePathForTesting(paths ...string) WritablePath {
|
||||||
|
p, err := validateSafePath(paths...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return testWritablePath{testPath{basePath{path: p, rel: p}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WritablePathsForTesting returns a Path constructed from each element in strs. It should only be used from within
|
||||||
|
// tests.
|
||||||
|
func WritablePathsForTesting(strs ...string) WritablePaths {
|
||||||
|
p := make(WritablePaths, len(strs))
|
||||||
|
for i, s := range strs {
|
||||||
|
p[i] = WritablePathForTesting(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type testPathContext struct {
|
||||||
|
config Config
|
||||||
|
fs pathtools.FileSystem
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testPathContext) Fs() pathtools.FileSystem { return x.fs }
|
||||||
|
func (x *testPathContext) Config() Config { return x.config }
|
||||||
|
func (x *testPathContext) AddNinjaFileDeps(...string) {}
|
||||||
|
|
||||||
|
// PathContextForTesting returns a PathContext that can be used in tests, for example to create an OutputPath with
|
||||||
|
// PathForOutput.
|
||||||
|
func PathContextForTesting(config Config, fs map[string][]byte) PathContext {
|
||||||
|
return &testPathContext{
|
||||||
|
config: config,
|
||||||
|
fs: pathtools.MockFs(fs),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rel performs the same function as filepath.Rel, but reports errors to a PathContext, and reports an error if
|
// Rel performs the same function as filepath.Rel, but reports errors to a PathContext, and reports an error if
|
||||||
// targetPath is not inside basePath.
|
// targetPath is not inside basePath.
|
||||||
func Rel(ctx PathContext, basePath string, targetPath string) string {
|
func Rel(ctx PathContext, basePath string, targetPath string) string {
|
||||||
|
@@ -703,3 +703,15 @@ func ExampleOutputPath_ReplaceExtension() {
|
|||||||
// Output:
|
// Output:
|
||||||
// out/system/framework/boot.art out/system/framework/boot.oat
|
// out/system/framework/boot.art out/system/framework/boot.oat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleOutputPath_FileInSameDir() {
|
||||||
|
ctx := &configErrorWrapper{
|
||||||
|
config: TestConfig("out", nil),
|
||||||
|
}
|
||||||
|
p := PathForOutput(ctx, "system/framework/boot.art")
|
||||||
|
p2 := p.InSameDir(ctx, "oat", "arm", "boot.vdex")
|
||||||
|
fmt.Println(p, p2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// out/system/framework/boot.art out/system/framework/oat/arm/boot.vdex
|
||||||
|
}
|
||||||
|
@@ -1039,7 +1039,7 @@ var splitListForSizeTestCases = []struct {
|
|||||||
|
|
||||||
func TestSplitListForSize(t *testing.T) {
|
func TestSplitListForSize(t *testing.T) {
|
||||||
for _, testCase := range splitListForSizeTestCases {
|
for _, testCase := range splitListForSizeTestCases {
|
||||||
out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size)
|
out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size)
|
||||||
|
|
||||||
var outStrings [][]string
|
var outStrings [][]string
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user