cpb- / yocto-cooker

Meta buildtool for Yocto Project based Linux embedded systems
GNU General Public License v2.0
43 stars 22 forks source link

Add support for executing a command in a poky-initialized shell (v2) #146

Closed ycongal-smile closed 1 year ago

ycongal-smile commented 1 year ago

PR initially from @amine-smile : https://github.com/cpb-/yocto-cooker/pull/145.

Updated the shell command to support executing a command within the poky-initialized shell. Introduced optional positional arguments, which allows users to specify a command to be executed (similar to what ssh does). When a command argument is provided, it is executed within the shell environment.

Example: cooker shell <cooker-build> 'bitbake -c cve_check <package-name>'

The unittest was added : Only check the generated command line with dry-run. Actually testing that the command run correctly would require cloning a poky environment.

And, also, a minor gitignore improvement.

pboettch commented 1 year ago

Does leaving out the single quotes also work? (Sorry to insist)

cooker shell <cooker-build> bitbake -c cve_check <package-name>

This is the reason I insisted on using nargs='*' .

Why, because I want to avoid extensive quote-escaping: cooker shell ... 'command \'arg with space in quote\'', but rather tell cooker shell to use all arguments after the build as sub-command and its arguments.

ycongal-smile commented 1 year ago

Does leaving out the single quotes also work? (Sorry to insist)

You're right to insist!

cooker shell <cooker-build> bitbake -c cve_check <package-name>

Forgot to remove the ' from the example... It definitively should work like this...

This is the reason I insisted on using nargs='*' .

Why, because I want to avoid extensive quote-escaping: cooker shell ... 'command \'arg with space in quote\'', but rather tell cooker shell to use all arguments after the build as sub-command and its arguments.

I've tested with a bunch of "echo test" :

 $ cooker shell qemu-x86-64 echo test "; echo test && echo titi" 
test
test
titi

=> This works well BUT (and here, you were especially right to insist)

 $ cooker shell qemu-x86-64 bitbake -e linux-yocto
usage: cooker [-h] [--debug] [--version] [-v] [-n] {cook,init,update,generate,show,build,shell,clean} ...
cooker: error: unrecognized arguments: -e linux-yocto

=> Does not work! My guess is that every arguments starting with - is interpreted by the main cooker command and not the shell subcommand. I'll look into this.

pboettch commented 1 year ago

It might be we have to use -- to separate args to cooker-shell and args for the sub-command.

ycongal-smile commented 1 year ago

It might be we have to use -- to separate args to cooker-shell and args for the sub-command.

It is :

 $ cooker shell qemu-x86-64 -- bitbake-getvar -r bash --value SUMMARY
An sh-compatible command language interpreter

I've updated the PR with a better (and working) example and a mention of this feature in the README.

cpb- commented 1 year ago

A useful example could also be

cooker shell qemu-x86-64 runqemu nographic

This is what I will use during training courses 🙂.

Le mer. 26 juil. 2023, 18:02, Yoann Congal @.***> a écrit :

It might be we have to use -- to separate args to cooker-shell and args for the sub-command.

It is :

$ cooker shell qemu-x86-64 -- bitbake-getvar -r bash --value SUMMARY An sh-compatible command language interpreter

I've updated the PR with a better (and working) example and a mention of this feature in the README.

— Reply to this email directly, view it on GitHub https://github.com/cpb-/yocto-cooker/pull/146#issuecomment-1652106024, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB5U3E2YSE6WEE4L5PB2I6TXSE5RRANCNFSM6AAAAAA2YJUAXE . You are receiving this because you commented.Message ID: @.***>

ycongal-smile commented 1 year ago

A useful example could also be

cooker shell qemu-x86-64 runqemu nographic

This is what I will use during training courses.

Added :)

ycongal-smile commented 1 year ago

Updated following @pboettch review

ycongal-smile commented 1 year ago

Removed Optional (https://github.com/cpb-/yocto-cooker/pull/146#discussion_r1279051000)