Skip to content

Make rbe_configs_gen more windows friendly. - #954

Merged
smukherj1 merged 1 commit into
bazelbuild:masterfrom
rubensf:winfix
Mar 1, 2021
Merged

smukherj1 merged 1 commit into
bazelbuild:masterfrom
rubensf:winfix

Conversation

@rubensf

@rubensf rubensf commented Feb 25, 2021

Copy link
Copy Markdown
Contributor

These non-exhaustive fixes address some of the more obvious problems:

  1. "find" works differently on windows.
  2. '/' -> ''
  3. There may be no symlinks on the local configs.

Comment thread pkg/rbeconfigsgen/rbeconfigsgen.go Outdated
return "", fmt.Errorf("failed to harden symlink %q in %q pointing to %q: %w", s, cppConfigDir, resolvedPath, err)
if err != nil {
log.Printf("WARNING: unable to list symlinks in the C++ config generation build output directory: %v", err)
} else {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't think this else is necessary. Set out to blank string if the command to list symlinks fails and you'll have an empty slice in symlinks and the for loop will never be entered. Avoids nesting the control flow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
if _, err := d.execCmd("ln", "-f", resolvedPath, s); err != nil {
return "", fmt.Errorf("failed to harden symlink %q in %q pointing to %q: %w", s, cppConfigDir, resolvedPath, err)
if err != nil {

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread pkg/rbeconfigsgen/rbeconfigsgen.go Outdated
defer resp.Body.Close()

localPath := path.Join(downloadDir, filename)
localPath := filepath.Join(downloadDir, filename)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Curious: What errors do you see when using path.Join on Windows?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't actually see an error for this - I changed this because I kept getting "file not found" when trying to dir the tools folder... When in reality it was simply because there were no symlinks to find, hah.

In any case, I think using filepath (which respects \) should be safer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nvm - PS > cmd /r /unix/style/path indeed doesn't work. I get errors eg Invalid Switch - "Users".

Running it directly from cmd seems to work, but IIUC the container could be using either cmd or PS.

I tweaked it so it only cleans uses windows filepath on the dir command so it doesn't potentially break eg bazel paths.

Comment thread pkg/rbeconfigsgen/rbeconfigsgen.go Outdated
switch o.ExecOS {
case "windows":
out = ""
log.Printf("WARNING: %s%v", errMsg, err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not a warning because it's not really actionable. Change to Ignoring error indicating no symlinks were found in the Bazel output directory: %v

No need to include errmsg because it would be confusing in the logs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

These non-exhaustive fixes address some of the more obvious problems:
1. "find" works differently on windows.
2. There may be no symlinks on the local configs.
@smukherj1
smukherj1 merged commit 883a619 into bazelbuild:master Mar 1, 2021
@rubensf
rubensf deleted the winfix branch March 1, 2021 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants