2
0
Эх сурвалжийг харах

Style: Fix code format scripts compat with non-GNU Unices

It's too hard to get compatibility between GNU and BSD sed,
so let's just use perl oneliners.

And improve it to also remove trailing tabs, not just spaces.

(cherry picked from commit c71e189efd63b3875904d8fe2b8a030e68919aad)
Rémi Verschelde 5 жил өмнө
parent
commit
4b9bb50176

+ 1 - 3
misc/scripts/black_format.sh

@@ -16,11 +16,9 @@ PY_FILES=$(find \( -path "./.git" \
 black -l 120 $PY_FILES
 black -l 120 $PY_FILES
 
 
 git diff > patch.patch
 git diff > patch.patch
-FILESIZE="$(stat -c%s patch.patch)"
-MAXSIZE=5
 
 
 # If no patch has been generated all is OK, clean up, and exit.
 # If no patch has been generated all is OK, clean up, and exit.
-if (( FILESIZE < MAXSIZE )); then
+if [ ! -s patch.patch ] ; then
     printf "Files in this commit comply with the black style rules.\n"
     printf "Files in this commit comply with the black style rules.\n"
     rm -f patch.patch
     rm -f patch.patch
     exit 0
     exit 0

+ 1 - 3
misc/scripts/clang_format.sh

@@ -39,11 +39,9 @@ while IFS= read -rd '' f; do
 done
 done
 
 
 git diff > patch.patch
 git diff > patch.patch
-FILESIZE="$(stat -c%s patch.patch)"
-MAXSIZE=5
 
 
 # If no patch has been generated all is OK, clean up, and exit.
 # If no patch has been generated all is OK, clean up, and exit.
-if (( FILESIZE < MAXSIZE )); then
+if [ ! -s patch.patch ] ; then
     printf "Files in this commit comply with the clang-format style rules.\n"
     printf "Files in this commit comply with the clang-format style rules.\n"
     rm -f patch.patch
     rm -f patch.patch
     exit 0
     exit 0

+ 11 - 10
misc/scripts/file_format.sh

@@ -1,7 +1,13 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
 # This script ensures proper POSIX text file formatting and a few other things.
 # This script ensures proper POSIX text file formatting and a few other things.
-# This is supplementary to clang-black-format.sh, but should be run before it.
+# This is supplementary to clang_format.sh and black_format.sh, but should be
+# run before them.
+
+# We need dos2unix and recode.
+if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
+    printf "Install 'dos2unix' and 'recode' to use this script.\n"
+fi
 
 
 set -uo pipefail
 set -uo pipefail
 IFS=$'\n\t'
 IFS=$'\n\t'
@@ -29,22 +35,17 @@ while IFS= read -rd '' f; do
     recode UTF-8 "$f" 2> /dev/null
     recode UTF-8 "$f" 2> /dev/null
     # Ensures that files have LF line endings.
     # Ensures that files have LF line endings.
     dos2unix "$f" 2> /dev/null
     dos2unix "$f" 2> /dev/null
-    # Ensures that files do not contain a BOM.
-    sed -i '1s/^\xEF\xBB\xBF//' "$f"
-    # Ensures that files end with newline characters.
-    tail -c1 < "$f" | read -r _ || echo >> "$f";
     # Remove trailing space characters.
     # Remove trailing space characters.
-    sed -z -i 's/\x20\x0A/\x0A/g' "$f"
+    # -l option handles newlines conveniently and seems to also get rid of BOMs.
+    perl -i -ple 's/\s*$//g' "$f"
     # Remove the character sequence "== true" if it has a leading space.
     # Remove the character sequence "== true" if it has a leading space.
-    sed -z -i 's/\x20== true//g' "$f"
+    perl -i -pe 's/\x20== true//g' "$f"
 done
 done
 
 
 git diff > patch.patch
 git diff > patch.patch
-FILESIZE="$(stat -c%s patch.patch)"
-MAXSIZE=5
 
 
 # If no patch has been generated all is OK, clean up, and exit.
 # If no patch has been generated all is OK, clean up, and exit.
-if (( FILESIZE < MAXSIZE )); then
+if [ ! -s patch.patch ] ; then
     printf "Files in this commit comply with the formatting rules.\n"
     printf "Files in this commit comply with the formatting rules.\n"
     rm -f patch.patch
     rm -f patch.patch
     exit 0
     exit 0

+ 3 - 3
platform/windows/godot.natvis

@@ -19,7 +19,7 @@
 			</ArrayItems>
 			</ArrayItems>
 		</Expand>
 		</Expand>
 	</Type>
 	</Type>
-	
+
 	<Type Name="List&lt;*&gt;">
 	<Type Name="List&lt;*&gt;">
 		<Expand>
 		<Expand>
 			<Item Name="[size]">_data ? (_data->size_cache) : 0</Item>
 			<Item Name="[size]">_data ? (_data->size_cache) : 0</Item>
@@ -62,7 +62,7 @@
 		<DisplayString Condition="type == Variant::POOL_COLOR_ARRAY">{*(PoolColorArray *)_data._mem}</DisplayString>
 		<DisplayString Condition="type == Variant::POOL_COLOR_ARRAY">{*(PoolColorArray *)_data._mem}</DisplayString>
 
 
 		<StringView Condition="type == Variant::STRING &amp;&amp; ((String *)(_data._mem))->_cowdata._ptr">((String *)(_data._mem))->_cowdata._ptr,su</StringView>
 		<StringView Condition="type == Variant::STRING &amp;&amp; ((String *)(_data._mem))->_cowdata._ptr">((String *)(_data._mem))->_cowdata._ptr,su</StringView>
-		
+
 		<Expand>
 		<Expand>
 			<Item Name="[value]" Condition="type == Variant::BOOL">_data._bool</Item>
 			<Item Name="[value]" Condition="type == Variant::BOOL">_data._bool</Item>
 			<Item Name="[value]" Condition="type == Variant::INT">_data._int</Item>
 			<Item Name="[value]" Condition="type == Variant::INT">_data._int</Item>
@@ -143,7 +143,7 @@
 			<Item Name="alpha">a</Item>
 			<Item Name="alpha">a</Item>
 		</Expand>
 		</Expand>
 	</Type>
 	</Type>
-	
+
 	<Type Name="Node" Inheritable="false">
 	<Type Name="Node" Inheritable="false">
 		<Expand>
 		<Expand>
 			<Item Name="Object">(Object*)this</Item>
 			<Item Name="Object">(Object*)this</Item>