mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-04 11:55:51 +00:00
fix: Do not rewrite original file if it hasn't changed in fix-local-i… (#2109)
…ncludes.sh
This commit is contained in:
@@ -19,18 +19,23 @@ fi
|
||||
fix_includes() {
|
||||
file_path="$1"
|
||||
|
||||
if [[ "$GNU_SED" == "false" ]]; then # macOS sed
|
||||
# make all includes to be <...> style
|
||||
sed -i '' -E 's|#include "(.*)"|#include <\1>|g' "$file_path"
|
||||
file_path_all_global="${file_path}.tmp.global"
|
||||
file_path_fixed="${file_path}.tmp.fixed"
|
||||
|
||||
# make local includes to be "..." style
|
||||
sed -i '' -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g" "$file_path"
|
||||
# Make all includes to be <...> style
|
||||
sed -E 's|#include "(.*)"|#include <\1>|g' "$file_path" > "$file_path_all_global"
|
||||
|
||||
# Make local includes to be "..." style
|
||||
sed -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g" "$file_path_all_global" > "$file_path_fixed"
|
||||
rm "$file_path_all_global"
|
||||
|
||||
# Check if the temporary file is different from the original file
|
||||
if ! cmp -s "$file_path" "$file_path_fixed"; then
|
||||
# Replace the original file with the temporary file
|
||||
mv "$file_path_fixed" "$file_path"
|
||||
else
|
||||
# make all includes to be <...> style
|
||||
sed -i -E 's|#include "(.*)"|#include <\1>|g' "$file_path"
|
||||
|
||||
# make local includes to be "..." style
|
||||
sed -i -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g" "$file_path"
|
||||
# Remove the temporary file if it's the same as the original
|
||||
rm "$file_path_fixed"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user