Hacker News new | ask | show | jobs
by lc5G 2198 days ago

  for crate in $(ls */Cargo.toml | xargs dirname); do
     cargo build
Why do this instead of

  cargo --workspace build
Is it so you can time the individual crates?
2 comments

Yeah it looks like they wanted to know how long each crate took to build individually.

But as long as we're nitpicking, nobody should just pipe `ls` into `xargs` like this, since it fails if anything has spaces in it.

Instead, do:

    for cargo_toml in */Cargo.toml; do
      crate="$(dirname "${cargo_toml}")"
      pushd $crate
      # ...
    done
Don't be that person who writes a script which won't tolerate spaces in filenames!
Alternatively: Don't be that person who clones the repo at a path with spaces in!
Not having spaces in your directory names is certainly a good idea, but I'll be damned if I let any of my code have issues with them. Just because something's a good idea doesn't mean it should be a requirement :)

(The main reason for the advice of "Don't put spaces in paths" is really only because it breaks lots of poorly-written software... but that's not an excuse for your software to be poorly-written!)

Yep!