diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-05-25 03:15:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-25 03:15:43 +0200 |
commit | eb65d88cd4ac6b0362517c7d718cbc9857c30ba3 (patch) | |
tree | 68a805c058287f6d2e494af62b9635daa7c48a5f | |
parent | e34000653bba6b7f8ec6f2c16dcd87d7a01a3d68 (diff) | |
parent | e8de07dbb15ef235fb76f72b5ef5247d59c56936 (diff) | |
download | fork-godot-webrtc-native-eb65d88cd4ac6b0362517c7d718cbc9857c30ba3.tar.gz fork-godot-webrtc-native-eb65d88cd4ac6b0362517c7d718cbc9857c30ba3.tar.bz2 fork-godot-webrtc-native-eb65d88cd4ac6b0362517c7d718cbc9857c30ba3.zip |
Merge pull request #96 from Faless/fix/black
[CI] Fix python black formatting.
-rw-r--r-- | .github/workflows/build_release.yml | 2 | ||||
-rw-r--r-- | SConstruct | 39 | ||||
-rwxr-xr-x | misc/scripts/black_format.sh | 30 | ||||
-rw-r--r-- | tools/cmake.py | 1 | ||||
-rw-r--r-- | tools/common.py | 5 | ||||
-rw-r--r-- | tools/rtc.py | 31 | ||||
-rw-r--r-- | tools/ssl.py | 50 |
7 files changed, 87 insertions, 71 deletions
diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index 9047da3..ec474e0 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -18,7 +18,7 @@ jobs: sudo apt-get install -qq dos2unix recode clang-format-11 sudo update-alternatives --remove-all clang-format sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100 - sudo pip3 install black==20.8b1 pygments + sudo pip3 install black==22.3.0 pygments - name: File formatting checks (file_format.sh) run: | @@ -28,12 +28,15 @@ if env["godot_version"] == "3": env = SConscript("godot-cpp-3.x/SConstruct") # Patch base env - replace_flags(env["CCFLAGS"], { - "-mios-simulator-version-min=10.0": "-mios-simulator-version-min=11.0", - "-miphoneos-version-min=10.0": "-miphoneos-version-min=11.0", - "/std:c++14": "/std:c++17", - "-std=c++14": "-std=c++17", - }) + replace_flags( + env["CCFLAGS"], + { + "-mios-simulator-version-min=10.0": "-mios-simulator-version-min=11.0", + "-miphoneos-version-min=10.0": "-miphoneos-version-min=11.0", + "/std:c++14": "/std:c++17", + "-std=c++14": "-std=c++17", + }, + ) env = env.Clone() @@ -87,7 +90,7 @@ else: # Then we prepend PATH to make it take precedence, while preserving SCons' own entries. env.PrependENVPath("PATH", os.getenv("PATH")) env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH")) -if "TERM" in os.environ: # Used for colored output. +if "TERM" in os.environ: # Used for colored output. env["ENV"]["TERM"] = os.environ["TERM"] # Patch mingw SHLIBSUFFIX. @@ -132,7 +135,9 @@ if mac_universal: benv = env.Clone() benv["arch"] = arch benv["CCFLAGS"] = SCons.Util.CLVar(str(benv["CCFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch)) - benv["LINKFLAGS"] = SCons.Util.CLVar(str(benv["LINKFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch)) + benv["LINKFLAGS"] = SCons.Util.CLVar( + str(benv["LINKFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch) + ) benv["suffix"] = benv["suffix"].replace("universal", arch) benv["SHOBJSUFFIX"] = benv["suffix"] + benv["SHOBJSUFFIX"] build_envs.append(benv) @@ -144,7 +149,7 @@ for benv in build_envs: benv.Tool(tool, toolpath=["tools"]) ssl = benv.BuildOpenSSL() - benv.NoCache(ssl) # Needs refactoring to properly cache generated headers. + benv.NoCache(ssl) # Needs refactoring to properly cache generated headers. rtc = benv.BuildLibDataChannel() benv.Depends(sources, [ssl, rtc]) @@ -159,17 +164,23 @@ Default(build_targets) # For macOS universal builds, join the libraries using lipo. if mac_universal: result_name = "libwebrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"]) - universal_target = env.Command(os.path.join(result_path, "lib", result_name), build_targets, "lipo $SOURCES -output $TARGETS -create") + universal_target = env.Command( + os.path.join(result_path, "lib", result_name), build_targets, "lipo $SOURCES -output $TARGETS -create" + ) Default(universal_target) # GDNativeLibrary if env["godot_version"] == "3": gdnlib = "webrtc" if target != "debug" else "webrtc_debug" ext = ".tres" - extfile = env.Substfile(os.path.join(result_path, gdnlib + ext), "misc/webrtc" + ext, SUBST_DICT={ - "{GDNATIVE_PATH}": gdnlib, - "{TARGET}": "template_" + env["target"], - }) + extfile = env.Substfile( + os.path.join(result_path, gdnlib + ext), + "misc/webrtc" + ext, + SUBST_DICT={ + "{GDNATIVE_PATH}": gdnlib, + "{TARGET}": "template_" + env["target"], + }, + ) else: extfile = env.InstallAs(os.path.join(result_path, "webrtc.gdextension"), "misc/webrtc.gdextension") diff --git a/misc/scripts/black_format.sh b/misc/scripts/black_format.sh index f6b7925..3a64284 100755 --- a/misc/scripts/black_format.sh +++ b/misc/scripts/black_format.sh @@ -6,29 +6,21 @@ set -uo pipefail # Apply black. echo -e "Formatting Python files..." -PY_FILES=$(find \( -path "./.git" \ - -o -path "./webrtc" \ - -o -path "./godot-cpp" \ - \) -prune \ - -o \( -name "SConstruct" \ - -o -name "SCsub" \ - -o -name "*.py" \ - \) -print) +PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*') black -l 120 $PY_FILES -git diff > patch.patch +diff=$(git diff --color) -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; then - printf "Files in this commit comply with the black style rules.\n" - rm -f patch.patch +# 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 patch has been created, notify the user, clean up, and exit. -printf "\n*** The following differences were found between the code " -printf "and the formatting rules:\n\n" -cat patch.patch -printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" -rm -f patch.patch +# 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 "$diff\n" | 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/tools/cmake.py b/tools/cmake.py index 0d6ee6b..2362312 100644 --- a/tools/cmake.py +++ b/tools/cmake.py @@ -1,4 +1,3 @@ - def exists(env): return True diff --git a/tools/common.py b/tools/common.py index aa99c5c..4bd5ada 100644 --- a/tools/common.py +++ b/tools/common.py @@ -1,8 +1,9 @@ - def exists(env): return True def generate(env): env["DEPS_SOURCE"] = env.Dir("#thirdparty").abspath - env["DEPS_BUILD"] = env.Dir("#bin/thirdparty").abspath + "/{}.{}.dir".format(env["suffix"][1:], "RelWithDebInfo" if env["debug_symbols"] else "Release") + env["DEPS_BUILD"] = env.Dir("#bin/thirdparty").abspath + "/{}.{}.dir".format( + env["suffix"][1:], "RelWithDebInfo" if env["debug_symbols"] else "Release" + ) diff --git a/tools/rtc.py b/tools/rtc.py index 0e7330c..34da8eb 100644 --- a/tools/rtc.py +++ b/tools/rtc.py @@ -1,5 +1,6 @@ import os + def rtc_cmake_config(env): config = { "USE_NICE": 0, @@ -30,7 +31,9 @@ def rtc_cmake_config(env): config["CMAKE_SYSTEM_VERSION"] = api config["CMAKE_ANDROID_ARCH_ABI"] = abi config["ANDROID_ABI"] = abi - config["CMAKE_TOOLCHAIN_FILE"] = "%s/build/cmake/android.toolchain.cmake" % os.environ.get("ANDROID_NDK_ROOT", "") + config["CMAKE_TOOLCHAIN_FILE"] = "%s/build/cmake/android.toolchain.cmake" % os.environ.get( + "ANDROID_NDK_ROOT", "" + ) config["CMAKE_ANDROID_STL_TYPE"] = "c++_static" elif env["platform"] == "linux": march = "-m32" if env["arch"] == "x86_32" else "-m64" @@ -49,7 +52,7 @@ def rtc_cmake_config(env): config["CMAKE_OSX_DEPLOYMENT_TARGET"] = "11.0" config["CMAKE_OSX_ARCHITECTURES"] = env["arch"] if env["ios_simulator"]: - config["CMAKE_OSX_SYSROOT"] = "iphonesimulator" + config["CMAKE_OSX_SYSROOT"] = "iphonesimulator" elif env["platform"] == "windows": config["CMAKE_SYSTEM_NAME"] = "Windows" config["BUILD_WITH_WARNINGS"] = "0" # Disables werror in libsrtp. @@ -58,7 +61,10 @@ def rtc_cmake_config(env): def rtc_emitter(target, source, env): env.Depends(env["RTC_LIBS"], env["SSL_LIBS"]) - env.Depends(env["RTC_LIBS"], [env.File(__file__), env.Dir(env["RTC_SOURCE"]), env.File(env["RTC_SOURCE"] + "/CMakeLists.txt")]) + env.Depends( + env["RTC_LIBS"], + [env.File(__file__), env.Dir(env["RTC_SOURCE"]), env.File(env["RTC_SOURCE"] + "/CMakeLists.txt")], + ) return env["RTC_LIBS"], env.Dir(env["RTC_SOURCE"]) @@ -80,15 +86,16 @@ def generate(env): env["RTC_SOURCE"] = env["DEPS_SOURCE"] + "/libdatachannel" env["RTC_BUILD"] = env["DEPS_BUILD"] + "/libdatachannel" env["RTC_INCLUDE"] = env["RTC_SOURCE"] + "/include" - env["RTC_LIBS"] = [env.File(env["RTC_BUILD"] + "/" + lib) for lib in [ - "libdatachannel-static.a", - "deps/libjuice/libjuice-static.a", - "deps/libsrtp/libsrtp2.a", - "deps/usrsctp/usrsctplib/libusrsctp.a" - ]] - env.Append(BUILDERS={ - "BuildLibDataChannel": env.Builder(action=rtc_action, emitter=rtc_emitter) - }) + env["RTC_LIBS"] = [ + env.File(env["RTC_BUILD"] + "/" + lib) + for lib in [ + "libdatachannel-static.a", + "deps/libjuice/libjuice-static.a", + "deps/libsrtp/libsrtp2.a", + "deps/usrsctp/usrsctplib/libusrsctp.a", + ] + ] + env.Append(BUILDERS={"BuildLibDataChannel": env.Builder(action=rtc_action, emitter=rtc_emitter)}) env.Append(LIBPATH=[env["RTC_BUILD"]]) env.Append(CPPPATH=[env["RTC_INCLUDE"]]) env.Prepend(LIBS=env["RTC_LIBS"]) diff --git a/tools/ssl.py b/tools/ssl.py index f62aca1..64436ec 100644 --- a/tools/ssl.py +++ b/tools/ssl.py @@ -1,6 +1,7 @@ import os from SCons.Defaults import Mkdir + def ssl_emitter(target, source, env): env.Depends(env["SSL_LIBS"], env.File(__file__)) return env["SSL_LIBS"], [env.Dir(env["SSL_SOURCE"]), env.File(env["SSL_SOURCE"] + "/VERSION.dat")] @@ -33,15 +34,17 @@ def ssl_action(target, source, env): elif env["platform"] == "android": api = env["android_api_level"] if int(env["android_api_level"]) > 28 else "28" - args.extend([ - { - "arm64": "android-arm64", - "arm32": "android-arm", - "x86_32": "android-x86", - "x86_64": "android-x86_64", - }[env["arch"]], - "-D__ANDROID_API__=%s" % api, - ]) + args.extend( + [ + { + "arm64": "android-arm64", + "arm32": "android-arm", + "x86_32": "android-x86", + "x86_64": "android-x86_64", + }[env["arch"]], + "-D__ANDROID_API__=%s" % api, + ] + ) # Setup toolchain path. ssl_env.PrependENVPath("PATH", os.path.dirname(env["CC"])) ssl_env["ENV"]["ANDROID_NDK_ROOT"] = os.environ.get("ANDROID_NDK_ROOT", "") @@ -56,7 +59,7 @@ def ssl_action(target, source, env): elif env["platform"] == "ios": if env["ios_simulator"]: - args.extend(["iossimulator-xcrun"]) + args.extend(["iossimulator-xcrun"]) elif env["arch"] == "arm32": args.extend(["ios-xcrun"]) elif env["arch"] == "arm64": @@ -67,23 +70,28 @@ def ssl_action(target, source, env): elif env["platform"] == "windows": if env["arch"] == "x86_32": if env["use_mingw"]: - args.extend([ - "mingw", - "--cross-compile-prefix=i686-w64-mingw32-", - ]) + args.extend( + [ + "mingw", + "--cross-compile-prefix=i686-w64-mingw32-", + ] + ) else: args.extend(["VC-WIN32"]) else: if env["use_mingw"]: - args.extend([ - "mingw64", - "--cross-compile-prefix=x86_64-w64-mingw32-", - ]) + args.extend( + [ + "mingw64", + "--cross-compile-prefix=x86_64-w64-mingw32-", + ] + ) else: args.extend(["VC-WIN64A"]) jobs = env.GetOption("num_jobs") - ssl_env.Execute([ + ssl_env.Execute( + [ Mkdir(build_dir), "cd %s && perl %s/Configure %s" % (build_dir, source_dir, " ".join(['"%s"' % a for a in args])), "make -C %s -j%s" % (build_dir, jobs), @@ -105,9 +113,7 @@ def generate(env): env["SSL_LIBRARY"] = env.File(env["SSL_BUILD"] + "/libssl.a") env["SSL_CRYPTO_LIBRARY"] = env.File(env["SSL_BUILD"] + "/libcrypto.a") env["SSL_LIBS"] = [env["SSL_LIBRARY"], env["SSL_CRYPTO_LIBRARY"]] - env.Append(BUILDERS={ - "BuildOpenSSL": env.Builder(action=ssl_action, emitter=ssl_emitter) - }) + env.Append(BUILDERS={"BuildOpenSSL": env.Builder(action=ssl_action, emitter=ssl_emitter)}) env.Prepend(CPPPATH=[env["SSL_INCLUDE"]]) env.Prepend(LIBPATH=[env["SSL_BUILD"]]) env.Append(LIBS=env["SSL_LIBS"]) |