summaryrefslogtreecommitdiffstats
path: root/misc/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'misc/scripts')
-rwxr-xr-xmisc/scripts/black_format.sh26
-rwxr-xr-xmisc/scripts/check_ci_log.py4
-rwxr-xr-xmisc/scripts/clang_format.sh53
-rwxr-xr-xmisc/scripts/copyright_headers.py99
-rw-r--r--misc/scripts/dotnet_format.py30
-rwxr-xr-xmisc/scripts/dotnet_format.sh37
6 files changed, 82 insertions, 167 deletions
diff --git a/misc/scripts/black_format.sh b/misc/scripts/black_format.sh
deleted file mode 100755
index 48dc14c734..0000000000
--- a/misc/scripts/black_format.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env bash
-
-# This script runs black on all Python files in the repo.
-
-set -uo pipefail
-
-# Apply black.
-echo -e "Formatting Python files..."
-PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*')
-black -l 120 $PY_FILES
-
-diff=$(git diff --color)
-
-# If no diff has been generated all is OK, clean up, and exit.
-if [ -z "$diff" ] ; then
- printf "\e[1;32m*** Files in this commit comply with the black style rules.\e[0m\n"
- exit 0
-fi
-
-# A diff has been created, notify the user, clean up, and exit.
-printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
-# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
-printf "%s\n" "$diff" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
-
-printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
-exit 1
diff --git a/misc/scripts/check_ci_log.py b/misc/scripts/check_ci_log.py
index 1e5a12eeb4..d024a3e375 100755
--- a/misc/scripts/check_ci_log.py
+++ b/misc/scripts/check_ci_log.py
@@ -9,8 +9,8 @@ if len(sys.argv) < 2:
fname = sys.argv[1]
-fileread = open(fname.strip(), "r")
-file_contents = fileread.read()
+with open(fname.strip(), "r", encoding="utf-8") as fileread:
+ file_contents = fileread.read()
# If find "ERROR: AddressSanitizer:", then happens invalid read or write
# This is critical bug, so we need to fix this as fast as possible
diff --git a/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh
deleted file mode 100755
index 8b59519606..0000000000
--- a/misc/scripts/clang_format.sh
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env bash
-
-# This script runs clang-format and fixes copyright headers on all relevant files in the repo.
-# This is the primary script responsible for fixing style violations.
-
-set -uo pipefail
-
-if [ $# -eq 0 ]; then
- # Loop through all code files tracked by Git.
- files=$(git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \
- ':!:.git/*' ':!:thirdparty/*' ':!:*/thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' \
- ':!:*-so_wrap.*' ':!:tests/python_build/*')
-else
- # $1 should be a file listing file paths to process. Used in CI.
- files=$(cat "$1" | grep -v "thirdparty/" | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc|java|glsl)$" | grep -v "platform/android/java/lib/src/com/google/" | grep -v "\-so_wrap\." | grep -v "tests/python_build/")
-fi
-
-if [ ! -z "$files" ]; then
- clang-format --Wno-error=unknown -i $files
-fi
-
-# Fix copyright headers, but not all files get them.
-for f in $files; do
- if [[ "$f" == *"inc" && "$f" != *"compat.inc" ]]; then
- continue
- elif [[ "$f" == *"glsl" ]]; then
- continue
- elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView"* ]]; then
- continue
- elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper"* ]]; then
- continue
- elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix"* ]]; then
- continue
- fi
-
- python misc/scripts/copyright_headers.py "$f"
-done
-
-diff=$(git diff --color)
-
-# If no diff has been generated all is OK, clean up, and exit.
-if [ -z "$diff" ] ; then
- printf "\e[1;32m*** Files in this commit comply with the clang-format style rules.\e[0m\n"
- exit 0
-fi
-
-# A diff has been created, notify the user, clean up, and exit.
-printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
-# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
-printf "%s\n" "$diff" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
-
-printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
-exit 1
diff --git a/misc/scripts/copyright_headers.py b/misc/scripts/copyright_headers.py
index a5e2f0c05d..2b1201b3c0 100755
--- a/misc/scripts/copyright_headers.py
+++ b/misc/scripts/copyright_headers.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+import os
import sys
header = """\
@@ -35,61 +36,61 @@ header = """\
/**************************************************************************/
"""
-fname = sys.argv[1]
+if len(sys.argv) < 2:
+ print("Invalid usage of copyright_headers.py, it should be called with a path to one or multiple files.")
+ sys.exit(1)
-# Handle replacing $filename with actual filename and keep alignment
-fsingle = fname.strip()
-if fsingle.find("/") != -1:
- fsingle = fsingle[fsingle.rfind("/") + 1 :]
-rep_fl = "$filename"
-rep_fi = fsingle
-len_fl = len(rep_fl)
-len_fi = len(rep_fi)
-# Pad with spaces to keep alignment
-if len_fi < len_fl:
- for x in range(len_fl - len_fi):
- rep_fi += " "
-elif len_fl < len_fi:
- for x in range(len_fi - len_fl):
- rep_fl += " "
-if header.find(rep_fl) != -1:
- text = header.replace(rep_fl, rep_fi)
-else:
- text = header.replace("$filename", fsingle)
-text += "\n"
+for f in sys.argv[1:]:
+ fname = f
-# We now have the proper header, so we want to ignore the one in the original file
-# and potentially empty lines and badly formatted lines, while keeping comments that
-# come after the header, and then keep everything non-header unchanged.
-# To do so, we skip empty lines that may be at the top in a first pass.
-# In a second pass, we skip all consecutive comment lines starting with "/*",
-# then we can append the rest (step 2).
+ # Handle replacing $filename with actual filename and keep alignment
+ fsingle = os.path.basename(fname.strip())
+ rep_fl = "$filename"
+ rep_fi = fsingle
+ len_fl = len(rep_fl)
+ len_fi = len(rep_fi)
+ # Pad with spaces to keep alignment
+ if len_fi < len_fl:
+ for x in range(len_fl - len_fi):
+ rep_fi += " "
+ elif len_fl < len_fi:
+ for x in range(len_fi - len_fl):
+ rep_fl += " "
+ if header.find(rep_fl) != -1:
+ text = header.replace(rep_fl, rep_fi)
+ else:
+ text = header.replace("$filename", fsingle)
+ text += "\n"
-fileread = open(fname.strip(), "r")
-line = fileread.readline()
-header_done = False
+ # We now have the proper header, so we want to ignore the one in the original file
+ # and potentially empty lines and badly formatted lines, while keeping comments that
+ # come after the header, and then keep everything non-header unchanged.
+ # To do so, we skip empty lines that may be at the top in a first pass.
+ # In a second pass, we skip all consecutive comment lines starting with "/*",
+ # then we can append the rest (step 2).
-while line.strip() == "": # Skip empty lines at the top
- line = fileread.readline()
+ with open(fname.strip(), "r", encoding="utf-8") as fileread:
+ line = fileread.readline()
+ header_done = False
-if line.find("/**********") == -1: # Godot header starts this way
- # Maybe starting with a non-Godot comment, abort header magic
- header_done = True
+ while line.strip() == "" and line != "": # Skip empty lines at the top
+ line = fileread.readline()
-while not header_done: # Handle header now
- if line.find("/*") != 0: # No more starting with a comment
- header_done = True
- if line.strip() != "":
- text += line
- line = fileread.readline()
+ if line.find("/**********") == -1: # Godot header starts this way
+ # Maybe starting with a non-Godot comment, abort header magic
+ header_done = True
-while line != "": # Dump everything until EOF
- text += line
- line = fileread.readline()
+ while not header_done: # Handle header now
+ if line.find("/*") != 0: # No more starting with a comment
+ header_done = True
+ if line.strip() != "":
+ text += line
+ line = fileread.readline()
-fileread.close()
+ while line != "": # Dump everything until EOF
+ text += line
+ line = fileread.readline()
-# Write
-filewrite = open(fname.strip(), "w")
-filewrite.write(text)
-filewrite.close()
+ # Write
+ with open(fname.strip(), "w", encoding="utf-8", newline="\n") as filewrite:
+ filewrite.write(text)
diff --git a/misc/scripts/dotnet_format.py b/misc/scripts/dotnet_format.py
new file mode 100644
index 0000000000..83265be7c5
--- /dev/null
+++ b/misc/scripts/dotnet_format.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import glob
+import os
+import sys
+
+# Create dummy generated files.
+for path in [
+ "modules/mono/SdkPackageVersions.props",
+]:
+ os.makedirs(os.path.dirname(path), exist_ok=True)
+ with open(path, "w", encoding="utf-8", newline="\n") as f:
+ f.write("<Project />")
+
+# Avoid importing GeneratedIncludes.props.
+os.environ["GodotSkipGenerated"] = "true"
+
+# Match all the input files to their respective C# project.
+input_files = [os.path.normpath(x) for x in sys.argv]
+projects = {
+ path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
+ for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
+}
+
+# Run dotnet format on all projects with more than 0 modified files.
+for path, files in projects.items():
+ if len(files) > 0:
+ command = f"dotnet format {path} --include {' '.join(files)}"
+ os.system(command)
diff --git a/misc/scripts/dotnet_format.sh b/misc/scripts/dotnet_format.sh
deleted file mode 100755
index e2b4ba5e43..0000000000
--- a/misc/scripts/dotnet_format.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env bash
-
-# This script runs dotnet format on all relevant files in the repo.
-# This is the primary script responsible for fixing style violations in C# files.
-
-set -uo pipefail
-
-# Create dummy generated files.
-echo "<Project />" > modules/mono/SdkPackageVersions.props
-mkdir -p modules/mono/glue/GodotSharp/GodotSharp/Generated
-echo "<Project />" > modules/mono/glue/GodotSharp/GodotSharp/Generated/GeneratedIncludes.props
-mkdir -p modules/mono/glue/GodotSharp/GodotSharpEditor/Generated
-echo "<Project />" > modules/mono/glue/GodotSharp/GodotSharpEditor/Generated/GeneratedIncludes.props
-
-# Loops through all C# projects tracked by Git.
-git ls-files -- '*.csproj' \
- ':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' |
-while read -r f; do
- # Run dotnet format.
- dotnet format "$f"
-done
-
-diff=$(git diff --color)
-
-# If no diff has been generated all is OK, clean up, and exit.
-if [ -z "$diff" ] ; then
- printf "\e[1;32m*** Files in this commit comply with the dotnet format style rules.\e[0m\n"
- exit 0
-fi
-
-# A diff has been created, notify the user, clean up, and exit.
-printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
-# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
-printf "%s\n" "$diff" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
-
-printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
-exit 1