Skip to main content
deleted 5 characters in body
Source Link
file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):\d+=[\ds]+\d+=\S+ (\S+).*|\$1% (\$2/\$length) -- \$3|" |
    perl -ne '$s'BEGIN{$|=1}$s{$_}++ or print')

The BEGIN{$|=1} on all but the last perl invocation areinvocations is necessary to ensure output gets flushed immediately.

file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):\d+=[\ds]+ (\S+).*|\$1% (\$2/\$length) -- \$3|" |
    perl -ne '$s{$_}++ or print')

The BEGIN{$|=1} on all but the last perl invocation are necessary to ensure output gets flushed immediately.

file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):\d+=\S+ (\S+).*|\$1% (\$2/\$length) -- \$3|" |
    perl -ne 'BEGIN{$|=1}$s{$_}++ or print')

The BEGIN{$|=1} on the perl invocations is necessary to ensure output gets flushed immediately.

added 814 characters in body
Source Link
file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):(\d+)=([\ds]+)\d+=[\ds]+ (\S+).*|\$1% (\$2/\$length) -- \$5|"\$3|" |
    perl -ne '$s{$_}++ or print')

The raw output from --bar looks something like this:

#   0 sec src/tuner/Utilities.h                                                                                                                                         
3.65853658536585
[7m3% 3:7[0m9=0s src/tuner/Utilities.h                                                                                                                                        [0m

(With escape sequences to print the progress bar.)

The successive commands processing that output perform the following transformations:

  • Transform carriage returns into newlines.
  • Find lines containing percentage output.
  • Strip out escape sequences.
  • Perform a regex replacement to extract and format the number of files processed, the completion percentage, and the name of the file being processed. It also includes the total number of files to be processed via a shell variable.
  • Print unique lines.

The BEGIN{$|=1} on all but the last perl invocation are necessary to ensure output gets flushed immediately.

The p option will run perl on each line of input and print the result. The n option runs on each line of input put does not automatically print. The e option provides the script as a CLI argument.

file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):(\d+)=([\ds]+) (\S+).*|\$1% (\$2/\$length) -- \$5|" |
    perl -ne '$s{$_}++ or print')
file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):\d+=[\ds]+ (\S+).*|\$1% (\$2/\$length) -- \$3|" |
    perl -ne '$s{$_}++ or print')

The raw output from --bar looks something like this:

#   0 sec src/tuner/Utilities.h                                                                                                                                         
3.65853658536585
[7m3% 3:7[0m9=0s src/tuner/Utilities.h                                                                                                                                        [0m

(With escape sequences to print the progress bar.)

The successive commands processing that output perform the following transformations:

  • Transform carriage returns into newlines.
  • Find lines containing percentage output.
  • Strip out escape sequences.
  • Perform a regex replacement to extract and format the number of files processed, the completion percentage, and the name of the file being processed. It also includes the total number of files to be processed via a shell variable.
  • Print unique lines.

The BEGIN{$|=1} on all but the last perl invocation are necessary to ensure output gets flushed immediately.

The p option will run perl on each line of input and print the result. The n option runs on each line of input put does not automatically print. The e option provides the script as a CLI argument.

added 814 characters in body
Source Link

Thanks to Ole Tange for pointing me in the right direction. Based on his solution and some AI-assisted coding I came up with this monstrosity:

file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):(\d+)=([\ds]+) (\S+).*|\$1% (\$2/\$length) -- \$5|" |
    perl -ne '$s{$_}++ or print')

It generates output similar to this:

Running clang-tidy on 82 files
1% (1/82) -- src/tuner/LoadPositions.h
2% (2/82) -- src/tuner/Main.cpp
2% (2/82) -- src/tuner/Utilities.h
3% (3/82) -- src/tuner/Utilities.h
...

I'm sure there's a better way to do those perl scripts (and not have 4 of them). But this works, and my perl-foo is very weak.


Thanks to Ole Tange for pointing me in the right direction. Based on his solution and some AI-assisted coding I came up with this monstrosity:

file_list=$(find src \
  ! -path "path/to/exclude/*" \
  -type f \( -name "*.cpp" -o -name "*.h" \))

length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files

echo "$file_list" |
  parallel --bar "clang-tidy-19 {}" \
  2> >(
    perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
    grep '%' |
    perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
    perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):(\d+)=([\ds]+) (\S+).*|\$1% (\$2/\$length) -- \$5|" |
    perl -ne '$s{$_}++ or print')

It generates output similar to this:

Running clang-tidy on 82 files
1% (1/82) -- src/tuner/LoadPositions.h
2% (2/82) -- src/tuner/Main.cpp
2% (2/82) -- src/tuner/Utilities.h
3% (3/82) -- src/tuner/Utilities.h
...

I'm sure there's a better way to do those perl scripts (and not have 4 of them). But this works, and my perl-foo is very weak.

Source Link
Loading