rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

Problems when outputUserRoot has @-sign

Open mvukov opened this issue 2 years ago • 9 comments

The problematic line is https://github.com/bazelbuild/rules_foreign_cc/blob/0.7.1/foreign_cc/private/framework/toolchains/linux_commands.bzl#L77.

I found this out when building with remote cache turned on (gcloud in this use-case). Here, outputUserRoot looks like outputRoot/[email protected] and the substitution fails. It's tricky to debug as in the terminal you can only see something as

sed: -e expression #1, char 207: unknown option to `s'

A simple workaround is to define e.g. --output_base=/tmp/bazel/output.

mvukov avatar Jan 31 '22 18:01 mvukov

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_foreign_cc!

github-actions[bot] avatar Jul 30 '22 22:07 github-actions[bot]

I seem to have the same problem. I tried compiling with --output_base but still doesn't work image

MaleicAcid avatar Aug 16 '22 12:08 MaleicAcid

@MaleicAcid are you using bzlmod here? I see you're using some kind of wrapper bzl - could this be causing the issue? From the paths in your screenshot (BTW posting text snippets is preferrable to screenshots) I think you are using bzlmod where repo names can now have @ in them which wasn't previously the case. I suspect we need to use a different delimiter in the sed commands but I'm not sure there is a 100% safe character to use; I believe @ was previously chosen as @ wasn't valid in a repo name before bzlmod AFAIK.

jsharpe avatar Aug 16 '22 12:08 jsharpe

@jsharpe

are you using bzlmod here?

Yes, I use bzlmod in the right picture, which automatically use a repo name contains '@' and cause sed command failed. In the left picture I just use bazel traditionally.(alias bzl='bazel')

posting text snippets is preferrable to screenshots

I'll change it to text later. ;)

I suspect we need to use a different delimiter in the sed commands but I'm not sure there is a 100% safe character to use;

I think '#' can be considered. Also, is it possible to provide an option in the cmake macro that allows the user to specify the delimiter. When a delimiter conflict occurs, provide a friendly error to guide the user to specify the delimiter.

MaleicAcid avatar Aug 16 '22 14:08 MaleicAcid

For bash, this solution can be used: ${parameter//pattern/string}

Reference: https://stackoverflow.com/a/13210909

mkauf avatar Sep 08 '22 14:09 mkauf

Proposed bugfix: Use the character $'\001' (Hex 0x01) as the delimiter for sed. It's very unlikely that a filename contains this character.

  • Linux (linux_commands.bzl):

    sed -i 's'$'\001'"$2"$'\001'"$3"$'\001''g' "${file}"
    
  • FreeBSD and macOS (freebsd_commands.bzl, macos_commands.bzl):

    sed -i '' -e 's'$'\001'"$2"$'\001'"$3"$'\001''g' "${file}"
    
  • Windows (windows_commands.bzl):

    sed -i 's'$'\001'"${argv2}"$'\001'"${argv3}"$'\001''g' "${file}"
    

mkauf avatar Jan 19 '23 13:01 mkauf

Proposed bugfix: Use the character $'\001' (Hex 0x01) as the delimiter for sed. It's very unlikely that a filename contains this character.

  • Linux (linux_commands.bzl):
    sed -i 's'$'\001'"$2"$'\001'"$3"$'\001''g' "${file}"
    
  • FreeBSD and macOS (freebsd_commands.bzl, macos_commands.bzl):
    sed -i '' -e 's'$'\001'"$2"$'\001'"$3"$'\001''g' "${file}"
    
  • Windows (windows_commands.bzl):
    sed -i 's'$'\001'"${argv2}"$'\001'"${argv3}"$'\001''g' "${file}"
    

This feels like a reasonable workaround for most users; care to send a PR for this?

jsharpe avatar Jan 25 '23 21:01 jsharpe

This feels like a reasonable workaround for most users; care to send a PR for this?

Absolutely, but this needs some time because my employer needs to sign Google's Corporate CLA.

mkauf avatar Jan 27 '23 16:01 mkauf

@jsharpe : Can you create a pull request? My employer wants to sign the CLA but does not give it a high enough priority, so this gets postponed all the time.

mkauf avatar Feb 27 '23 12:02 mkauf

@jsharpe : Can you create a pull request? My employer wants to sign the CLA but does not give it a high enough priority, so this gets postponed all the time.

I'll add it to my todo list but I'm afraid it won't be very high in the priority list, so if anyone else wants to beat me to it then feel free!

jsharpe avatar Feb 28 '23 23:02 jsharpe