瀏覽代碼

Replace the script that formats the code

Panagiotis Christopoulos Charitos 3 年之前
父節點
當前提交
47b23c4db2
共有 3 個文件被更改,包括 56 次插入25 次删除
  1. 二進制
      ThirdParty/Bin/Windows64/clang-format.exe
  2. 56 0
      Tools/FormatSource.py
  3. 0 25
      Tools/FormatSource.sh

二進制
ThirdParty/Bin/Windows64/clang-format.exe


+ 56 - 0
Tools/FormatSource.py

@@ -0,0 +1,56 @@
+#!/usr/bin/python3
+
+# Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
+# All rights reserved.
+# Code licensed under the BSD License.
+# http://www.anki3d.org/LICENSE
+
+import glob
+import subprocess
+import threading
+import multiprocessing
+
+file_extensions = ["h", "hpp", "c", "cpp", "glsl", "ankiprog"]
+directories = ["AnKi", "Tests", "Sandbox", "Tools", "Samples"]
+
+
+def thread_callback(tid):
+    """ Call clang-format """
+    global mutex
+    global file_names
+
+    while True:
+        mutex.acquire()
+        if len(file_names) > 0:
+            file_name = file_names.pop()
+        else:
+            file_name = None
+        mutex.release()
+
+        if file_name is None:
+            break
+
+        subprocess.check_call(["./ThirdParty/Bin/Windows64/clang-format.exe", "-sort-includes=false", "-i", file_name])
+
+
+# Gather the filenames
+file_names = []
+for directory in directories:
+    for extension in file_extensions:
+        file_names.extend(glob.glob("./" + directory + "/**/*." + extension, recursive=True))
+file_name_count = len(file_names)
+
+# Start the threads
+mutex = threading.Lock()
+thread_count = multiprocessing.cpu_count()
+threads = []
+for i in range(0, thread_count):
+    thread = threading.Thread(target=thread_callback, args=(i,))
+    threads.append(thread)
+    thread.start()
+
+# Join the threads
+for i in range(0, thread_count):
+    threads[i].join()
+
+print("Done! Formatted %d files" % file_name_count)

+ 0 - 25
Tools/FormatSource.sh

@@ -1,25 +0,0 @@
-#!/bin/bash
-
-files=(`find ./AnKi ./Tests ./Sandbox ./Tools ./Samples -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.glsl' -o -name '*.glslp' -o -name '*.ankiprog'`)
-
-filecount=${#files[@]}
-
-count=0
-for f in ${files[@]}
-do
-	# Run it in parallel
-	echo -ne Formatting ${count}/${filecount}\\r
-	./ThirdParty/Bin/Linux64/clang-format -sort-includes=false -i ${f} &
-	count=$((${count}+1))
-
-	# Throttle the parallel commands
-	if !((count % 16)); then
-		wait
-	fi
-done
-
-wait
-
-echo Done! Formatted ${filecount} files
-
-