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

Make rbe_configs_gen more windows friendly. #954

Merged
merged 1 commit into from
Mar 1, 2021
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: 20 additions & 2 deletions pkg/rbeconfigsgen/rbeconfigsgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
"text/template"
Expand Down Expand Up @@ -496,12 +497,29 @@ func genCppConfigs(d *dockerRunner, o *Options, bazeliskPath string) (string, er
// 2. Harden each link.
// 3. Archive the contents of the config output directory into a tarball.
// 4. Copy the tarball from the container to the local temp directory.
out, err := d.execCmd("find", cppConfigDir, "-type", "l")
var out string
if o.ExecOS == "windows" {
out, err = d.execCmd("cmd", "/r", "dir", filepath.Clean(cppConfigDir), "/a:l", "/b")
} else {
out, err = d.execCmd("find", cppConfigDir, "-type", "l")
}
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if find returns an error if symlinks aren't found? If the command behaves similar on both platforms I suggest removing WARNING here and just saying "no symlinks were found in the Bazel output directory that needed hardening. Ignoring the error returned by the symlinks find command".

If the error is specific to windows, then we should only ignore the error on windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right. find on linux just returns no files but 0 exit status. Fixed.

return "", fmt.Errorf("unable to list symlinks in the C++ config generation build output directory: %w", err)
errMsg := fmt.Sprintf("unable to list symlinks in the C++ config generation build output directory: ")
// Windows `dir` has a non-zero exit status if no files are found.
// Linux just doesn't return any files but has a zero exit.
switch o.ExecOS {
case "windows":
out = ""
log.Printf("Ignoring error indicating no symlinks were found in the Bazel output directory: %v", err)
default:
return "", fmt.Errorf("%s%w", errMsg, err)
}
}
symlinks := strings.Split(out, "\n")
for _, s := range symlinks {
if s == "" {
continue
}
resolvedPath, err := d.execCmd("readlink", s)
if err != nil {
return "", fmt.Errorf("unable to determine what the symlink %q in %q in the toolchain container points to: %w", s, cppConfigDir, err)
Expand Down