-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/internal/objabi: expand -trimpath syntax
This CL affects the low-level -trimpath flag provided by both cmd/asm and cmd/compile. Previously, the flag took the name of a single directory that would be trimmed from recorded paths in the resulting object file. This CL makes the flag take a semicolon-separated list of paths. Further, each path can now end in an optional "=>replacement" to specify what to replace that leading path prefix with, instead of only dropping it. A followup CL will add a mode to cmd/go that uses this richer -trimpath to build binaries that do not contain any local path names. For #16860. Change-Id: I246811750f37607c7f7a8fbecd56c5475ebe1ea5 Reviewed-on: https://go-review.googlesource.com/c/go/+/173344 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
- Loading branch information
Showing
2 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2019 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package objabi | ||
|
||
import ( | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
// On Windows, "/foo" is reported as a relative path | ||
// (it is relative to the current drive letter), | ||
// so we need add a drive letter to test absolute path cases. | ||
func drive() string { | ||
if runtime.GOOS == "windows" { | ||
return "c:" | ||
} | ||
return "" | ||
} | ||
|
||
var absFileTests = []struct { | ||
dir string | ||
file string | ||
rewrites string | ||
abs string | ||
}{ | ||
{"/d", "f", "", "/d/f"}, | ||
{"/d", drive() + "/f", "", drive() + "/f"}, | ||
{"/d", "f/g", "", "/d/f/g"}, | ||
{"/d", drive() + "/f/g", "", drive() + "/f/g"}, | ||
|
||
{"/d", "f", "/d/f", "??"}, | ||
{"/d", "f/g", "/d/f", "g"}, | ||
{"/d", "f/g", "/d/f=>h", "h/g"}, | ||
{"/d", "f/g", "/d/f=>/h", "/h/g"}, | ||
{"/d", "f/g", "/d/f=>/h;/d/e=>/i", "/h/g"}, | ||
{"/d", "e/f", "/d/f=>/h;/d/e=>/i", "/i/f"}, | ||
} | ||
|
||
func TestAbsFile(t *testing.T) { | ||
for _, tt := range absFileTests { | ||
abs := filepath.FromSlash(AbsFile(filepath.FromSlash(tt.dir), filepath.FromSlash(tt.file), tt.rewrites)) | ||
want := filepath.FromSlash(tt.abs) | ||
if abs != want { | ||
t.Errorf("AbsFile(%q, %q, %q) = %q, want %q", tt.dir, tt.file, tt.rewrites, abs, want) | ||
} | ||
} | ||
} |