Skip to content

Commit

Permalink
Stage Go sources in a directory named after the package.
Browse files Browse the repository at this point in the history
This is a workaround for the issue described at
cockroachdb/cockroach#64379 -- this is
unnecessarily inefficient, but it does work and avoids some regressions
`rules_go` would otherwise introduce.
  • Loading branch information
rickystewart committed May 12, 2021
1 parent 2fe8a62 commit a94a425
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions go/tools/builders/cgo2.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,19 @@ func cgo2(goenv *env, goSrcs, cgoSrcs, cSrcs, cxxSrcs, objcSrcs, objcxxSrcs, sSr

// Copy regular Go source files into the work directory so that we can
// use -trimpath=workDir.
goBases, err := gatherSrcs(workDir, goSrcs)
subDir := filepath.Join(workDir, packagePath)
err = os.MkdirAll(subDir, 0755)
if err != nil {
return "", nil, nil, err
}
goBases, err := gatherSrcs(subDir, goSrcs)
if err != nil {
return "", nil, nil, err
}

allGoSrcs = make([]string, len(goSrcs)+len(genGoSrcs))
for i := range goSrcs {
allGoSrcs[i] = filepath.Join(workDir, goBases[i])
allGoSrcs[i] = filepath.Join(subDir, goBases[i])
}
copy(allGoSrcs[len(goSrcs):], genGoSrcs)
return workDir, allGoSrcs, cObjs, nil
Expand Down
11 changes: 10 additions & 1 deletion go/tools/builders/compilepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,16 @@ func compileArchive(
return err
}
}
gcFlags = append(gcFlags, "-trimpath=.")
subDir := filepath.Join(workDir, packagePath)
err := os.MkdirAll(subDir, 0755)
if err != nil {
return err
}
goBases, err := gatherSrcs(subDir, goSrcs)
for i, base := range goBases {
goSrcs[i] = filepath.Join(subDir, base)
}
gcFlags = append(gcFlags, "-trimpath="+workDir)
}

// Check that the filtered sources don't import anything outside of
Expand Down

0 comments on commit a94a425

Please sign in to comment.