-
Notifications
You must be signed in to change notification settings - Fork 126
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
app: support alias commands #716
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.
Nice! Amazing how little code this requires.
Can you please submit a documentation PR for https://docs.zephyrproject.org/latest/develop/west/config.html#built-in-configuration-options ?
It sucks that it is a in different repo but that's just the way it is now.
I would like the interface design to be reviewed before the implementation. Please do mention that it's recursive. Also mention briefly that overriding/shadowing built-in commands is possible but please change the (commit messages) examples that do that: that looks like a sure support nightmare! I think it's fine if "advanced" users who know what they're doing override built-in commands but we really don't want beginners to do that and then have their friends, colleagues and support spend hours scratching their heads.
5ebbddd
to
6aec00d
Compare
Updated the PR to have |
f2195e6
to
c7234bf
Compare
Calling |
17df658
to
3fcad1f
Compare
5fa1280
to
fe632c5
Compare
@marc-hb Thanks for the review! |
I just did some interactive If we really wanted to test quoting more then we should check some pre-canned config file in git and avoid command line peculiarities entirely. But for now I think restricting tests to single quotes nested in double quotes is portable and plenty good enough. We just want to make sure no one breaks the most basic whitespace usage and then trust |
2524057
to
afa24da
Compare
@marc-hb I've handled all comments, I think. |
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.
Let me try getting rid of shlex in conftest.py first.
Stop using `shlex.split()` in conftest.py as a way to prepare test commands for subprocess.run() because it does not always work. When we have quoting issues, just avoid them entirely by passing the test command as a list. Replace shlex.split() with a simple str.split() for convenience in simple cases. This simple split() will immediately fail when trying to use quote which is working exactly as intended. This also makes the cmd() interface more similar to subprocess.run() and its many friends, which is good thing. This is similar to commit 4100764 ("Project.git(list/str): reduce reliance on shlex.split()") but applied to tests/ Before commit 624880e, shlex.split() was used unconditionally in conftest.py. As expected, this eventually broke on Windows: shlex is not compatible across all operating systems and shells. https://docs.python.org/3/library/subprocess.html#security-considerations > If the shell is invoked explicitly, via shell=True, it is the > application’s responsibility to ensure that all whitespace and > metacharacters are quoted appropriately to avoid shell injection > vulnerabilities. On _some_ platforms, it is possible to use shlex.quote() > for this escaping. (Emphasis mine) Then commit 624880e made the "interesting" decision to stop using shlex.split()... only on Windows. This was discussed in zephyrproject-rtos#266 (comment) So after this commit, parsing of test commands was delegated to the shell but... only on Windows! This worked for a long time but eventually broke testing white spaces for the new `west alias` zephyrproject-rtos#716. Rather than making that Windows-specific hack even more complex with a special case, finally do the right thing and ask more complex test commands to use a list. Now we can drop shlex. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
Just tried the latest 93f9715 and infinite loops do not seem handled well. From reading the code I would expect this to print
More tests needed maybe? I warned you recursion (and overriding built ins) was fraught with peril! :-) |
7883b31
to
b389b3c
Compare
Yes, the early argument handling does make it a bit more complicated, but I think I've managed to make it more robust now.
I added a test for the infinite recursion to contain "unknown command". |
Update: handle empty aliases and add a test |
|
Ugh, sorry about that, and thanks for all the testing efforts! Empty help strings seem to get stripped. I now set an |
Fixed typo 🤦 |
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.
A few questions and minor suggestions left.
Let the builtin help command handle the passed arguments. Signed-off-by: Pieter De Gendt <pieter.degendt@gmail.com>
Replace west commands with alias set in configuration files Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Add simple test cases to verify alias' functionality. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This PR allows to add
alias
west commands to a configuration, similar to how git aliases work.It can override existing commands to have default arguments, and iteratively replace alias commands.
Some examples:
After applying you can run: