Page MenuHome

Avoid UUOC in install_deps.sh
ClosedPublic

Authored by Bastien Montagne (mont29) on Jan 23 2014, 10:10 AM.

Details

Summary

The file build_files/build_environment/install_deps.sh contains the following line:

THREADS=`cat /proc/cpuinfo | grep processor | wc -l`

The command within the backticks is a Useless Use Of Cat.

A more compact way of writing the same thing (saving two subprocesses) is

THREADS=`grep -c processor /proc/cpuinfo`

or (using POSIX-preferred command-substitution parentheses instead of backticks)

THREADS=$(grep -c processor /proc/cpuinfo)

But the most compact, and least Linux-specific, way is to use the nproc(1) command from the GNU coreutils package:

THREADS=$(nproc)

Diff Detail

Event Timeline

Lawrence D'Oliveiro (ldo) updated this revision to Unknown Object (????).Jan 23 2014, 10:14 AM

add related patch: cmake_linux_install.sh wasn’t doing multithreaded build.

Lawrence D'Oliveiro (ldo) updated this revision to Unknown Object (????).Jan 23 2014, 10:15 AM

add related patch: prepare_release_env.sh should really be using number of available threads rather than cores.

Hmmm ... should I have submitted them as separate patches? Or created a task instead?

This is a duplicate of T37004. Is it better handled there or here?

Didn't knew about nproc, neat…