Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix #400 with trim path handling in profile report #409

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions profile/internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,20 +1015,20 @@ func abs64(i int64) int64 {
}

func trimPath(path, trimPath, searchPath string) string {
const gnarkRoot = "github.com/consensys/gnark/"
const gnarkRootCI = "home/runner/work/gnark/gnark/"
const gnarkCIRoot = "/gnark/gnark/"
const gnarkRoot = "/gnark/"

// Keep path variable intact as it's used below to form the return value.
sPath, searchPath := filepath.ToSlash(path), filepath.ToSlash(searchPath)
path, searchPath = filepath.ToSlash(path), filepath.ToSlash(searchPath)

if idx := strings.Index(sPath, gnarkRoot); idx != -1 {
sPath = sPath[idx+len(gnarkRoot):]
return sPath
if idx := strings.Index(path, gnarkCIRoot); idx != -1 {
path = path[idx+len(gnarkCIRoot):]
return path
}

if idx := strings.Index(sPath, gnarkRootCI); idx != -1 {
sPath = sPath[idx+len(gnarkRootCI):]
return sPath
if idx := strings.Index(path, gnarkRoot); idx != -1 {
path = path[idx+len(gnarkRoot):]
return path
}

if trimPath == "" {
Expand All @@ -1040,7 +1040,7 @@ func trimPath(path, trimPath, searchPath string) string {
// "/my/local/path/my-project/foo/bar.c".
for _, dir := range filepath.SplitList(searchPath) {
want := "/" + filepath.Base(dir) + "/"
if found := strings.Index(sPath, want); found != -1 {
if found := strings.Index(path, want); found != -1 {
return path[found+len(want):]
}
}
Expand All @@ -1051,7 +1051,7 @@ func trimPath(path, trimPath, searchPath string) string {
if !strings.HasSuffix(trimPath, "/") {
trimPath += "/"
}
if strings.HasPrefix(sPath, trimPath) {
if strings.HasPrefix(path, trimPath) {
return path[len(trimPath):]
}
}
Expand Down