@@ -37,6 +37,24 @@ ProcessDepot ()
3737# rm -r "Protobufs"
3838 mkdir -p " Protobufs"
3939
40+ # Map the file extension to the binary format type for the strings dumper
41+ local file_type=" "
42+ case " $1 " in
43+ .dylib)
44+ file_type=" macho"
45+ ;;
46+ .so)
47+ file_type=" elf"
48+ ;;
49+ .dll|.exe)
50+ file_type=" pe"
51+ ;;
52+ * )
53+ echo " Unknown file type $1 "
54+ echo " ::endgroup::"
55+ return
56+ esac
57+
4058 # Find all files matching the given extension and process each one
4159 while IFS= read -r -d ' ' file
4260 do
@@ -51,26 +69,6 @@ ProcessDepot ()
5169 # Extract protobuf definitions from the binary
5270 " $PROTOBUF_DUMPER_PATH " " $file " " Protobufs/" > /dev/null
5371
54- # Map the file extension to the binary format type for the strings dumper
55- file_type=" "
56- case " $1 " in
57- .dylib)
58- file_type=" macho"
59- ;;
60- .so)
61- file_type=" elf"
62- ;;
63- .dll)
64- file_type=" pe"
65- ;;
66- .exe)
67- file_type=" pe"
68- ;;
69- * )
70- echo " Unknown file type $1 "
71- continue
72- esac
73-
7472 # Derive the output strings filename by replacing the extension with _strings.txt
7573 if [[ " $1 " == " .exe" ]]; then
7674 strings_file=" ${file} _strings.txt"
@@ -124,16 +122,9 @@ DeduplicateStringsFrom ()
124122 fi
125123 done
126124
127- # Build grep arguments to filter out lines found in any of the reference files
128- grep_args=(
129- --fixed-strings
130- --line-regexp
131- --invert-match
132- )
133-
134- for dedupe_file in " ${dedupe_files[@]} " ; do
135- grep_args+=(--file " $dedupe_file " )
136- done
125+ # Merge all reference files into a single sorted set
126+ merged_dedupe=" $( mktemp) "
127+ sort --unique --merge " ${dedupe_files[@]} " > " $merged_dedupe "
137128
138129 # Iterate over all binaries matching the suffix and process their strings files
139130 while IFS= read -r -d ' ' file
@@ -154,10 +145,12 @@ DeduplicateStringsFrom ()
154145 done
155146
156147 # Remove lines present in reference files and replace the original
157- grep " ${grep_args[@]} " " $target_file " > " $target_file .tmp" || true
148+ comm -23 " $target_file " " $merged_dedupe " > " $target_file .tmp"
158149 mv " $target_file .tmp" " $target_file "
159150 done < <( find . -type f -name " *$suffix " -print0)
160151
152+ rm -f " $merged_dedupe "
153+
161154 echo " ::endgroup::"
162155}
163156
0 commit comments