|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | suffix=$1
|
| 4 | +# Find and replace the string in Cargo.toml |
| 5 | +sed -i.bak 's|https://github.com/trusted-programming/mate|https://github.com/trusted-programming/count_loop|' Cargo.toml |
4 | 6 |
|
5 |
| -#!/bin/bash |
6 |
| -rs_files=($(find -L . -type d \( -name target -o -name benches -o -name bench -o -name tests -o -name test \) -prune -o -type f -name '*.rs' -print | grep -vE "/benches?/|/bench/|/tests?/")) |
7 |
| - |
8 |
| -echo "### COUNTING FOR LOOPS ###" |
9 |
| -for_loop_count=0 # Initialize total count |
10 |
| -for file in "${rs_files[@]}"; do |
11 |
| - echo "Checking: $file" |
12 |
| - # First, use grep to exclude comment lines, then count for loops |
13 |
| - for_loop_count_in_file=$(grep -vE '^\s*(//|/\*|\*/)' "$file" | grep -oE 'for\s+(\([^)]+\)|\w+)\s+in\s+[^{]+' | wc -l) |
14 |
| - echo "Count in file: $for_loop_count_in_file" |
15 |
| - ((for_loop_count += for_loop_count_in_file)) |
16 |
| -done |
17 |
| -echo "Total for loop count: $for_loop_count" |
18 |
| - |
19 |
| -iter_count=0 |
20 |
| -iter_mut_count=0 |
21 |
| -into_iter_count=0 |
| 7 | +echo |
| 8 | +echo "### FILE OUTPUT ###" |
| 9 | +echo |
22 | 10 |
|
23 |
| -echo "### COUNTING ITERS ###" |
24 |
| -for file in "${rs_files[@]}"; do |
25 |
| - echo "Checking: $file" |
26 |
| - iter_count_in_file=$(grep -oE '\.iter\(\)' "$file" | wc -l) |
27 |
| - iter_mut_count_in_file=$(grep -oE '\.iter_mut\(\)' "$file" | wc -l) |
28 |
| - into_iter_count_in_file=$(grep -oE '\.into_iter\(\)' "$file" | wc -l) |
29 |
| - echo "iter_count_in_file: $iter_count_in_file" |
30 |
| - echo "iter_mut_count_in_file: $iter_mut_count_in_file" |
31 |
| - echo "into_iter_count_in_file: $into_iter_count_in_file" |
| 11 | +if ! dylint_output=$(cargo dylint --workspace --all 2>&1); then |
| 12 | + echo "Error running cargo dylint" >&2 |
| 13 | + exit 1 |
| 14 | +fi |
32 | 15 |
|
33 |
| - ((iter_count += iter_count_in_file)) |
34 |
| - ((iter_mut_count += iter_mut_count_in_file)) |
35 |
| - ((into_iter_count += into_iter_count_in_file)) |
36 |
| -done |
37 |
| -general_iter_count=$((iter_count + iter_mut_count + into_iter_count)) |
| 16 | +echo "$dylint_output" |
| 17 | +echo |
| 18 | +echo "### FILE OUTPUT END ###" |
38 | 19 |
|
39 |
| -par_iter_count=0 |
40 |
| -into_par_iter_count=0 |
41 |
| -par_iter_mut_count=0 |
42 | 20 |
|
43 |
| -echo "### COUNTING PAR ITERS ###" |
44 |
| -for file in "${rs_files[@]}"; do |
45 |
| - echo "Checking: $file" |
46 |
| - par_iter_count_in_file=$(grep -oE '\.par_iter\(\)' "$file" | wc -l) |
47 |
| - into_par_iter_count_in_file=$(grep -oE '\.into_par_iter\(\)' "$file" | wc -l) |
48 |
| - par_iter_mut_count_in_file=$(grep -oE '\.par_iter_mut\(\)' "$file" | wc -l) |
49 |
| - echo "par_iter_count_in_file: $par_iter_count_in_file" |
50 |
| - echo "into_par_iter_count_in_file: $into_par_iter_count_in_file" |
51 |
| - echo "par_iter_mut_count_in_file: $par_iter_mut_count_in_file" |
52 |
| - ((par_iter_count += par_iter_count_in_file)) |
53 |
| - ((into_par_iter_count += into_par_iter_count_in_file)) |
54 |
| - ((par_iter_mut_count += par_iter_mut_count_in_file)) |
55 |
| -done |
56 |
| -par_iter_total_count=$((par_iter_count + into_par_iter_count + par_iter_mut_count)) |
| 21 | +for_loop_count=$(echo "$dylint_output" | grep -c "warning: found for loop, code: 213423") |
| 22 | +iter_count=$(echo "$dylint_output" | grep -c "warning: found iterator, code: 213932") |
| 23 | +par_iter_count=$(echo "$dylint_output" | grep -c "warning: found par iterator, code: 213312") |
57 | 24 |
|
58 | 25 | echo
|
59 | 26 | echo "### FINAL RESULTS ###"
|
60 | 27 | echo
|
61 | 28 | echo "for loop occurrences: $for_loop_count"
|
62 |
| -echo ".iter() occurrences: $iter_count" |
63 |
| -echo ".iter_mut() occurrences: $iter_mut_count" |
64 |
| -echo ".into_iter() occurrences: $into_iter_count" |
65 |
| -echo "Total .iter*() occurrences: $general_iter_count" |
66 |
| -echo ".par_iter() occurrences: $par_iter_count" |
67 |
| -echo ".into_par_iter() occurrences: $into_par_iter_count" |
68 |
| -echo ".par_iter_mut() occurrences: $par_iter_mut_count" |
69 |
| -echo "Total .par_iter*() occurrences: $par_iter_total_count" |
| 29 | +echo "Total iter occurrences: $iter_count" |
| 30 | +echo "Total par iter occurrences: $par_iter_count" |
70 | 31 | echo
|
71 | 32 | echo "### ALL DONE ###"
|
72 | 33 |
|
73 | 34 | # Echo the variables with the suffix to set them in the GitHub environment
|
74 | 35 | echo "for_loop_count_${suffix}=$for_loop_count" >>$GITHUB_ENV
|
75 | 36 | echo "iter_count_${suffix}=$iter_count" >>$GITHUB_ENV
|
76 |
| -echo "iter_mut_count_${suffix}=$iter_mut_count" >>$GITHUB_ENV |
77 |
| -echo "into_iter_count_${suffix}=$into_iter_count" >>$GITHUB_ENV |
78 |
| -echo "general_iter_count_${suffix}=$((iter_count + iter_mut_count + into_iter_count))" >>$GITHUB_ENV |
79 | 37 | echo "par_iter_count_${suffix}=$par_iter_count" >>$GITHUB_ENV
|
80 |
| -echo "into_par_iter_count_${suffix}=$into_par_iter_count" >>$GITHUB_ENV |
81 |
| -echo "par_iter_mut_count_${suffix}=$par_iter_mut_count" >>$GITHUB_ENV |
82 |
| -echo "par_iter_total_count_${suffix}=$((par_iter_count + into_par_iter_count + par_iter_mut_count))" >>$GITHUB_ENV |
| 38 | + |
| 39 | +# Change the string back in Cargo.toml |
| 40 | +mv Cargo.toml.bak Cargo.toml |
0 commit comments