- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
Avoid arg limits for internal uses of Bazel #190
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach seems a bit unsafe to me.
Maybe it would be better to go through the command list and pull out only things that look like targets or queries, instead of relying on the order or the presence of a --. We can then write these targets or queries into a file and leave the rest of the command intact.
| return | ||
|  | ||
| try: | ||
| sep_index = command.index("--") | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is super safe - from my testing click does not include the -- in its command list.
If we disable the ignore_arg_limits context manager in src/dda/tools/bzl/__init__.py, and debug we get the following:
dda bzl --version -- build hello
...
print(command)
>>> ["--version", "build", "hello"]
Now I get that in most contexts commands passed directly from click will have __ignore_arg_limits == True, but it seems dangerous to me to rely on a part of the command that our CLI framework itself omits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally forgot about that, great catch, thanks! I added a new utility that does the proper thing. In a separate PR I'll apply the utility to any other existing commands that exclusively forward arguments.
| from tempfile import NamedTemporaryFile | ||
|  | ||
| with NamedTemporaryFile(mode="w", encoding="utf-8") as f: | ||
| f.write("\n".join(command[sep_index + 1 :])) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't think this approach will work for every possible invocation of bazel.
For example:
bazel build -- --color no //targetIs a valid invocation, but we don't want the --color no part to be included in the file containing
We need to enforce a stricter structure to the command, where anything after -- is only arguments to the command (i.e. targets or queries), and disallow passing flags there.
This is going to be a bit tricky tho:
- As mentioned above, click does not pass the --marker, so it will be hard to rely on it
- As seen in my example, some flags can themselves accept arguments, so we can't just rely on the presence of -at the beginning of the arg.
| 
 I considered this but in order to do that you need knowledge of every supported option to understand whether it's a flag or if it accepts a value (and flags can also accept values apparently). Relevant documentation: 
 As you can see in the latter link, targets may also begin with a hyphen to indicate negation. I went through various approaches over the weekend and realized any parser would be fraught with issues so I chose to enforce the separator for internal uses. | 
* Avoid arg limits for internal uses of Bazel * address review 87cab28
Bazel supports supplying arguments that may exceed length limits via files. This uses the
--target_pattern_fileoption for commands that accept targets and the--query_fileoption for commands that accept a query.An exception is made for users invoking Bazel through the wrapper since there is no need for checking what was already successful.
The command
bzlnow matches the name of our internal Bazel wrapper and satisfies a comment from the previous review.