kaspar030 / laze

A fast, declarative build system for C/C++ projects, based on Ninja
Apache License 2.0
21 stars 1 forks source link

-v output is not shell-escaped #396

Open chrysn opened 8 months ago

chrysn commented 8 months ago

For running different cargo commands, I extracted what laze calls by running

$ laze -C examples/application build -v -b microbit-v2 -s probe-rs-run run
laze: project root: /home/chrysn/git/crates/RIOT-rs relpath: examples/application project_file: laze-project.yml
laze: building all for microbit-v2
laze: reading cache took 3.067268ms.
laze: executing task run for builder microbit-v2 bin application
+ cd examples/application
+ RIOTBASE=../../ BOARD=microbit-v2 USEMODULE= NEWLIB_ARCH=thumb/v7e-m/nofp CFLAGS= CFLAGS_OPT=-Os EXTERNAL_MODULE_DIRS= LTO=1 BUILDING_RIOT_RS=1 OPENOCD_ARGS=-f board/nordic_nrf52_dk.cfg SCRIPTS=../../scripts CARGO_BUILD_TARGET=thumbv7em-none-eabi CARGO_TARGET_THUMBV7EM_NONE_EABI_RUNNER=probe-rs run --chip nrf52840_xxAA CARGO_TARGET_THUMBV7EM_NONE_EABI_RUSTFLAGS=-Clink-arg=--nmagic -Clink-arg=-Tlinkme.x -Clink-arg=-Tlink.x -Clink-arg=-Tdevice.x -Clink-arg=--no-eh-frame-hdr --cfg builder="microbit-v2" -Clink-arg=-Tisr_stack.x --cfg context="cortex-m" -Ctarget-cpu=cortex-m4 --cfg armv7m --cfg context="nrf52" --cfg context="nrf52840" -Cembed-bitcode=yes -Clto=fat -Ccodegen-units=1 CARGO_TARGET_DIR=../../build/bin/microbit-v2/application/cargo cargo run --release --features=riot-rs-boards/microbit-v2,riot-rs/silent-panic,riot-rs/debug-console

... but cop-pasting the line starting with RIOTBASE=, my shell threw an error because escaping was off -- it says OPENOCD_ARGS=-f board/nordic_nrf52_dk.cfg which comes across to the shell as setting OPENOCD_ARGS to -f and then calling board/nordic_nrf52_dk.cfg. laze clearly has this right internally (the right command is called), but appears to naively print the shell arguments space-separated without extra escaping.

I'm too deep somewhere else in the stack to PR it, but I've found the shlex crate useful for escaping strings for shells when arguments can't be passed to an exec() call.

kaspar030 commented 8 months ago

Thanks! It's actually the shell that prints the commands, laze '-v' adds '-x' to the sh commandline (enabling the shell's own tracing). I'll look into printing within laze!

chrysn commented 8 months ago

Oooh ... then it sounds like laze is doing things right, and the shell is buggy, but admittedly the former is likely easier to fix.