mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Format Python scripts with black (NFC) (#4325)
This commit is contained in:
@@ -3,75 +3,100 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches
|
||||
from upstream_utils import (
|
||||
setup_upstream_repo,
|
||||
comment_out_invalid_includes,
|
||||
walk_cwd_and_copy_if,
|
||||
am_patches,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
root, repo = setup_upstream_repo("https://github.com/RobotLocomotion/drake",
|
||||
"v1.3.0")
|
||||
root, repo = setup_upstream_repo(
|
||||
"https://github.com/RobotLocomotion/drake", "v1.3.0"
|
||||
)
|
||||
wpimath = os.path.join(root, "wpimath")
|
||||
|
||||
prefix = os.path.join(root, "upstream_utils/drake_patches")
|
||||
am_patches(repo, [
|
||||
os.path.join(prefix, "0001-Replace-Eigen-Dense-with-Eigen-Core.patch"),
|
||||
os.path.join(
|
||||
prefix,
|
||||
"0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch")
|
||||
])
|
||||
am_patches(
|
||||
repo,
|
||||
[
|
||||
os.path.join(prefix, "0001-Replace-Eigen-Dense-with-Eigen-Core.patch"),
|
||||
os.path.join(
|
||||
prefix, "0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch"
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Delete old install
|
||||
for d in [
|
||||
"src/main/native/thirdparty/drake/src",
|
||||
"src/main/native/thirdparty/drake/include",
|
||||
"src/test/native/cpp/drake", "src/test/native/include/drake"
|
||||
"src/main/native/thirdparty/drake/src",
|
||||
"src/main/native/thirdparty/drake/include",
|
||||
"src/test/native/cpp/drake",
|
||||
"src/test/native/include/drake",
|
||||
]:
|
||||
shutil.rmtree(os.path.join(wpimath, d), ignore_errors=True)
|
||||
|
||||
# Copy drake source files into allwpilib
|
||||
src_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: f in
|
||||
["drake_assert_and_throw.cc", "discrete_algebraic_riccati_equation.cc"],
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/src"))
|
||||
lambda dp, f: f
|
||||
in ["drake_assert_and_throw.cc", "discrete_algebraic_riccati_equation.cc"],
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/src"),
|
||||
)
|
||||
|
||||
# Copy drake header files into allwpilib
|
||||
include_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: f in [
|
||||
"drake_assert.h", "drake_assertion_error.h",
|
||||
"is_approx_equal_abstol.h", "never_destroyed.h", "drake_copyable.h",
|
||||
"drake_throw.h", "discrete_algebraic_riccati_equation.h"
|
||||
lambda dp, f: f
|
||||
in [
|
||||
"drake_assert.h",
|
||||
"drake_assertion_error.h",
|
||||
"is_approx_equal_abstol.h",
|
||||
"never_destroyed.h",
|
||||
"drake_copyable.h",
|
||||
"drake_throw.h",
|
||||
"discrete_algebraic_riccati_equation.h",
|
||||
],
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/include/drake"))
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/include/drake"),
|
||||
)
|
||||
|
||||
# Copy drake test source files into allwpilib
|
||||
os.chdir(os.path.join(repo, "math/test"))
|
||||
test_src_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: f == "discrete_algebraic_riccati_equation_test.cc",
|
||||
os.path.join(wpimath, "src/test/native/cpp/drake"))
|
||||
os.path.join(wpimath, "src/test/native/cpp/drake"),
|
||||
)
|
||||
os.chdir(repo)
|
||||
|
||||
# Copy drake test header files into allwpilib
|
||||
test_include_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: f == "eigen_matrix_compare.h",
|
||||
os.path.join(wpimath, "src/test/native/include/drake"))
|
||||
os.path.join(wpimath, "src/test/native/include/drake"),
|
||||
)
|
||||
|
||||
for f in src_files:
|
||||
comment_out_invalid_includes(
|
||||
f,
|
||||
[os.path.join(wpimath, "src/main/native/thirdparty/drake/include")])
|
||||
f, [os.path.join(wpimath, "src/main/native/thirdparty/drake/include")]
|
||||
)
|
||||
for f in include_files:
|
||||
comment_out_invalid_includes(
|
||||
f,
|
||||
[os.path.join(wpimath, "src/main/native/thirdparty/drake/include")])
|
||||
f, [os.path.join(wpimath, "src/main/native/thirdparty/drake/include")]
|
||||
)
|
||||
for f in test_src_files:
|
||||
comment_out_invalid_includes(f, [
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/include"),
|
||||
os.path.join(wpimath, "src/test/native/include")
|
||||
])
|
||||
comment_out_invalid_includes(
|
||||
f,
|
||||
[
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/include"),
|
||||
os.path.join(wpimath, "src/test/native/include"),
|
||||
],
|
||||
)
|
||||
for f in test_include_files:
|
||||
comment_out_invalid_includes(f, [
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/include"),
|
||||
os.path.join(wpimath, "src/test/native/include")
|
||||
])
|
||||
comment_out_invalid_includes(
|
||||
f,
|
||||
[
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/drake/include"),
|
||||
os.path.join(wpimath, "src/test/native/include"),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -4,7 +4,12 @@ import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches
|
||||
from upstream_utils import (
|
||||
setup_upstream_repo,
|
||||
comment_out_invalid_includes,
|
||||
walk_cwd_and_copy_if,
|
||||
am_patches,
|
||||
)
|
||||
|
||||
|
||||
def eigen_inclusions(dp, f):
|
||||
@@ -38,8 +43,12 @@ def eigen_inclusions(dp, f):
|
||||
|
||||
# Include architectures we care about
|
||||
if "Core/arch/" in abspath:
|
||||
return ("arch/AVX/" in abspath or "arch/Default" in abspath or
|
||||
"arch/NEON" in abspath or "arch/SSE" in abspath)
|
||||
return (
|
||||
"arch/AVX/" in abspath
|
||||
or "arch/Default" in abspath
|
||||
or "arch/NEON" in abspath
|
||||
or "arch/SSE" in abspath
|
||||
)
|
||||
|
||||
# Include the following modules
|
||||
modules = [
|
||||
@@ -87,8 +96,7 @@ def unsupported_inclusions(dp, f):
|
||||
|
||||
|
||||
def main():
|
||||
root, repo = setup_upstream_repo("https://gitlab.com/libeigen/eigen.git",
|
||||
"3.4.0")
|
||||
root, repo = setup_upstream_repo("https://gitlab.com/libeigen/eigen.git", "3.4.0")
|
||||
wpimath = os.path.join(root, "wpimath")
|
||||
|
||||
# Apply patches to original git repo
|
||||
@@ -97,29 +105,31 @@ def main():
|
||||
|
||||
# Delete old install
|
||||
for d in [
|
||||
"src/main/native/thirdparty/eigen/include/Eigen",
|
||||
"src/main/native/thirdparty/eigen/include/unsupported"
|
||||
"src/main/native/thirdparty/eigen/include/Eigen",
|
||||
"src/main/native/thirdparty/eigen/include/unsupported",
|
||||
]:
|
||||
shutil.rmtree(os.path.join(wpimath, d), ignore_errors=True)
|
||||
|
||||
# Copy Eigen headers into allwpilib
|
||||
eigen_files = walk_cwd_and_copy_if(
|
||||
eigen_inclusions,
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/eigen/include"))
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/eigen/include"),
|
||||
)
|
||||
|
||||
# Copy unsupported headers into allwpilib
|
||||
unsupported_files = walk_cwd_and_copy_if(
|
||||
unsupported_inclusions,
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/eigen/include"))
|
||||
os.path.join(wpimath, "src/main/native/thirdparty/eigen/include"),
|
||||
)
|
||||
|
||||
for f in eigen_files:
|
||||
comment_out_invalid_includes(
|
||||
f,
|
||||
[os.path.join(wpimath, "src/main/native/thirdparty/eigen/include")])
|
||||
f, [os.path.join(wpimath, "src/main/native/thirdparty/eigen/include")]
|
||||
)
|
||||
for f in unsupported_files:
|
||||
comment_out_invalid_includes(
|
||||
f,
|
||||
[os.path.join(wpimath, "src/main/native/thirdparty/eigen/include")])
|
||||
f, [os.path.join(wpimath, "src/main/native/thirdparty/eigen/include")]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches
|
||||
from upstream_utils import (
|
||||
setup_upstream_repo,
|
||||
comment_out_invalid_includes,
|
||||
walk_cwd_and_copy_if,
|
||||
am_patches,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -12,8 +17,7 @@ def main():
|
||||
|
||||
# Apply patches to original git repo
|
||||
prefix = os.path.join(root, "upstream_utils/fmt_patches")
|
||||
am_patches(
|
||||
repo, [os.path.join(prefix, "0001-Don-t-throw-on-write-failure.patch")])
|
||||
am_patches(repo, [os.path.join(prefix, "0001-Don-t-throw-on-write-failure.patch")])
|
||||
|
||||
# Delete old install
|
||||
for d in ["src/main/native/fmtlib/src", "src/main/native/fmtlib/include"]:
|
||||
@@ -21,20 +25,24 @@ def main():
|
||||
|
||||
# Copy fmt source files into allwpilib
|
||||
src_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: dp.endswith("src") and f.endswith(".cc") and f !=
|
||||
"fmt.cc", os.path.join(wpiutil, "src/main/native/fmtlib"))
|
||||
lambda dp, f: dp.endswith("src") and f.endswith(".cc") and f != "fmt.cc",
|
||||
os.path.join(wpiutil, "src/main/native/fmtlib"),
|
||||
)
|
||||
|
||||
# Copy fmt header files into allwpilib
|
||||
include_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: dp.endswith("include/fmt"),
|
||||
os.path.join(wpiutil, "src/main/native/fmtlib"))
|
||||
os.path.join(wpiutil, "src/main/native/fmtlib"),
|
||||
)
|
||||
|
||||
for f in src_files:
|
||||
comment_out_invalid_includes(
|
||||
f, [os.path.join(wpiutil, "src/main/native/fmtlib/include")])
|
||||
f, [os.path.join(wpiutil, "src/main/native/fmtlib/include")]
|
||||
)
|
||||
for f in include_files:
|
||||
comment_out_invalid_includes(
|
||||
f, [os.path.join(wpiutil, "src/main/native/fmtlib/include")])
|
||||
f, [os.path.join(wpiutil, "src/main/native/fmtlib/include")]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -4,27 +4,36 @@ import os
|
||||
import shutil
|
||||
import re
|
||||
|
||||
from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches, walk_if, copy_to
|
||||
from upstream_utils import (
|
||||
setup_upstream_repo,
|
||||
comment_out_invalid_includes,
|
||||
walk_cwd_and_copy_if,
|
||||
am_patches,
|
||||
walk_if,
|
||||
copy_to,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
root, repo = setup_upstream_repo("https://github.com/libuv/libuv",
|
||||
"v1.44.1")
|
||||
root, repo = setup_upstream_repo("https://github.com/libuv/libuv", "v1.44.1")
|
||||
wpinet = os.path.join(root, "wpinet")
|
||||
|
||||
# Apply patches to original git repo
|
||||
prefix = os.path.join(root, "upstream_utils/libuv_patches")
|
||||
am_patches(repo, [
|
||||
os.path.join(prefix, "0001-Fix-missing-casts.patch"),
|
||||
os.path.join(prefix, "0002-Fix-warnings.patch"),
|
||||
os.path.join(prefix, "0003-Preprocessor-cleanup.patch"),
|
||||
os.path.join(prefix, "0004-Cleanup-problematic-language.patch"),
|
||||
os.path.join(prefix, "0005-Use-roborio-time.patch"),
|
||||
os.path.join(prefix, "0006-Style-comments-cleanup.patch"),
|
||||
os.path.join(prefix, "0007-Squelch-GCC-12.1-warnings.patch"),
|
||||
os.path.join(prefix, "0008-Fix-Win32-warning-suppression-pragma.patch"),
|
||||
os.path.join(prefix, "0009-Avoid-unused-variable-warning-on-Mac.patch"),
|
||||
])
|
||||
am_patches(
|
||||
repo,
|
||||
[
|
||||
os.path.join(prefix, "0001-Fix-missing-casts.patch"),
|
||||
os.path.join(prefix, "0002-Fix-warnings.patch"),
|
||||
os.path.join(prefix, "0003-Preprocessor-cleanup.patch"),
|
||||
os.path.join(prefix, "0004-Cleanup-problematic-language.patch"),
|
||||
os.path.join(prefix, "0005-Use-roborio-time.patch"),
|
||||
os.path.join(prefix, "0006-Style-comments-cleanup.patch"),
|
||||
os.path.join(prefix, "0007-Squelch-GCC-12.1-warnings.patch"),
|
||||
os.path.join(prefix, "0008-Fix-Win32-warning-suppression-pragma.patch"),
|
||||
os.path.join(prefix, "0009-Avoid-unused-variable-warning-on-Mac.patch"),
|
||||
],
|
||||
)
|
||||
|
||||
# Delete old install
|
||||
for d in ["src/main/native/thirdparty/libuv"]:
|
||||
@@ -39,7 +48,8 @@ def main():
|
||||
|
||||
include_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: "include" in dp and f not in include_ignorelist,
|
||||
os.path.join(wpinet, "src/main/native/thirdparty/libuv"))
|
||||
os.path.join(wpinet, "src/main/native/thirdparty/libuv"),
|
||||
)
|
||||
|
||||
src_ignorelist = [
|
||||
"aix-common.c",
|
||||
@@ -58,9 +68,9 @@ def main():
|
||||
"sysinfo-memory.c",
|
||||
]
|
||||
src_files = walk_cwd_and_copy_if(
|
||||
lambda dp, f: "src" in dp and "docs" not in dp and f
|
||||
not in src_ignorelist,
|
||||
os.path.join(wpinet, "src/main/native/thirdparty/libuv"))
|
||||
lambda dp, f: "src" in dp and "docs" not in dp and f not in src_ignorelist,
|
||||
os.path.join(wpinet, "src/main/native/thirdparty/libuv"),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,7 +3,14 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches, walk_if, copy_to
|
||||
from upstream_utils import (
|
||||
setup_upstream_repo,
|
||||
comment_out_invalid_includes,
|
||||
walk_cwd_and_copy_if,
|
||||
am_patches,
|
||||
walk_if,
|
||||
copy_to,
|
||||
)
|
||||
|
||||
|
||||
def run_global_replacements(wpiutil_llvm_files):
|
||||
@@ -17,43 +24,39 @@ def run_global_replacements(wpiutil_llvm_files):
|
||||
content = content.replace("llvm::", "wpi::")
|
||||
|
||||
# Fix #includes
|
||||
content = content.replace("include \"llvm/ADT", "include \"wpi")
|
||||
content = content.replace("include \"llvm/Config", "include \"wpi")
|
||||
content = content.replace("include \"llvm/Support", "include \"wpi")
|
||||
content = content.replace('include "llvm/ADT', 'include "wpi')
|
||||
content = content.replace('include "llvm/Config', 'include "wpi')
|
||||
content = content.replace('include "llvm/Support', 'include "wpi')
|
||||
|
||||
# Remove unused headers
|
||||
content = content.replace("#include \"llvm-c/ErrorHandling.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Debug.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Error.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Format.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/FormatVariadic.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/NativeFormatting.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Threading.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/DataTypes.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/llvm-config.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/abi-breaking.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/config.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Signals.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Process.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Path.h\"\n", "")
|
||||
content = content.replace("#include \"wpi/Program.h\"\n", "")
|
||||
content = content.replace('#include "llvm-c/ErrorHandling.h"\n', "")
|
||||
content = content.replace('#include "wpi/Debug.h"\n', "")
|
||||
content = content.replace('#include "wpi/Error.h"\n', "")
|
||||
content = content.replace('#include "wpi/Format.h"\n', "")
|
||||
content = content.replace('#include "wpi/FormatVariadic.h"\n', "")
|
||||
content = content.replace('#include "wpi/NativeFormatting.h"\n', "")
|
||||
content = content.replace('#include "wpi/Threading.h"\n', "")
|
||||
content = content.replace('#include "wpi/DataTypes.h"\n', "")
|
||||
content = content.replace('#include "wpi/llvm-config.h"\n', "")
|
||||
content = content.replace('#include "wpi/abi-breaking.h"\n', "")
|
||||
content = content.replace('#include "wpi/config.h"\n', "")
|
||||
content = content.replace('#include "wpi/Signals.h"\n', "")
|
||||
content = content.replace('#include "wpi/Process.h"\n', "")
|
||||
content = content.replace('#include "wpi/Path.h"\n', "")
|
||||
content = content.replace('#include "wpi/Program.h"\n', "")
|
||||
|
||||
# Fix include guards
|
||||
content = content.replace("LLVM_ADT_", "WPIUTIL_WPI_")
|
||||
content = content.replace("LLVM_SUPPORT_", "WPIUTIL_WPI_")
|
||||
content = content.replace("LLVM_DEFINED_HAS_FEATURE",
|
||||
"WPI_DEFINED_HAS_FEATURE")
|
||||
content = content.replace("LLVM_DEFINED_HAS_FEATURE", "WPI_DEFINED_HAS_FEATURE")
|
||||
|
||||
content = content.replace("const std::string_view &",
|
||||
"std::string_view ")
|
||||
content = content.replace("sys::fs::openFileForRead",
|
||||
"fs::OpenFileForRead")
|
||||
content = content.replace("const std::string_view &", "std::string_view ")
|
||||
content = content.replace("sys::fs::openFileForRead", "fs::OpenFileForRead")
|
||||
content = content.replace("sys::fs::closeFile", "fs::CloseFile")
|
||||
content = content.replace("sys::fs::", "fs::")
|
||||
|
||||
# Replace wpi/FileSystem.h with wpi/fs.h
|
||||
content = content.replace("include \"wpi/FileSystem.h\"",
|
||||
"include \"wpi/fs.h\"")
|
||||
content = content.replace('include "wpi/FileSystem.h"', 'include "wpi/fs.h"')
|
||||
|
||||
# Replace llvm_unreachable() with wpi_unreachable()
|
||||
content = content.replace("llvm_unreachable", "wpi_unreachable")
|
||||
@@ -62,14 +65,10 @@ def run_global_replacements(wpiutil_llvm_files):
|
||||
content = content.replace("llvm_is_multithreaded()", "1")
|
||||
|
||||
# Revert message in copyright header
|
||||
content = content.replace("/// Defines the wpi::",
|
||||
"/// Defines the llvm::")
|
||||
content = content.replace("// end llvm namespace",
|
||||
"// end wpi namespace")
|
||||
content = content.replace("// end namespace llvm",
|
||||
"// end namespace wpi")
|
||||
content = content.replace("// End llvm namespace",
|
||||
"// End wpi namespace")
|
||||
content = content.replace("/// Defines the wpi::", "/// Defines the llvm::")
|
||||
content = content.replace("// end llvm namespace", "// end wpi namespace")
|
||||
content = content.replace("// end namespace llvm", "// end namespace wpi")
|
||||
content = content.replace("// End llvm namespace", "// End wpi namespace")
|
||||
|
||||
content = content.replace("fs::openFileForRead", "fs::OpenFileForRead")
|
||||
|
||||
@@ -93,8 +92,11 @@ def find_wpiutil_llvm_files(wpiutil_root, subfolder):
|
||||
|
||||
# These files have substantial changes, not worth managing with the patching process
|
||||
ignore_list = [
|
||||
"StringExtras.h", "StringExtras.cpp", "MemoryBuffer.cpp",
|
||||
"MemoryBuffer.h", "SmallVectorMemoryBuffer.h"
|
||||
"StringExtras.h",
|
||||
"StringExtras.cpp",
|
||||
"MemoryBuffer.cpp",
|
||||
"MemoryBuffer.h",
|
||||
"SmallVectorMemoryBuffer.h",
|
||||
]
|
||||
|
||||
wpiutil_files = []
|
||||
@@ -121,34 +123,40 @@ def overwrite_files(wpiutil_files, llvm_files):
|
||||
|
||||
|
||||
def overwrite_source(wpiutil_root, llvm_root):
|
||||
llvm_files = flattened_llvm_files(llvm_root, [
|
||||
"llvm/include/llvm/ADT/", "llvm/include/llvm/Config",
|
||||
"llvm/include/llvm/Support/", "llvm/lib/Support/"
|
||||
])
|
||||
llvm_files = flattened_llvm_files(
|
||||
llvm_root,
|
||||
[
|
||||
"llvm/include/llvm/ADT/",
|
||||
"llvm/include/llvm/Config",
|
||||
"llvm/include/llvm/Support/",
|
||||
"llvm/lib/Support/",
|
||||
],
|
||||
)
|
||||
wpi_files = find_wpiutil_llvm_files(
|
||||
wpiutil_root, "src/main/native/thirdparty/llvm/include/wpi"
|
||||
) + find_wpiutil_llvm_files(wpiutil_root,
|
||||
"src/main/native/thirdparty/llvm/cpp/llvm")
|
||||
) + find_wpiutil_llvm_files(
|
||||
wpiutil_root, "src/main/native/thirdparty/llvm/cpp/llvm"
|
||||
)
|
||||
|
||||
overwrite_files(wpi_files, llvm_files)
|
||||
run_global_replacements(wpi_files)
|
||||
|
||||
|
||||
def overwrite_tests(wpiutil_root, llvm_root):
|
||||
llvm_files = flattened_llvm_files(llvm_root, [
|
||||
"llvm/unittests/ADT/", "llvm/unittests/Config",
|
||||
"llvm/unittests/Support/"
|
||||
])
|
||||
wpi_files = find_wpiutil_llvm_files(wpiutil_root,
|
||||
"src/test/native/cpp/llvm")
|
||||
llvm_files = flattened_llvm_files(
|
||||
llvm_root,
|
||||
["llvm/unittests/ADT/", "llvm/unittests/Config", "llvm/unittests/Support/"],
|
||||
)
|
||||
wpi_files = find_wpiutil_llvm_files(wpiutil_root, "src/test/native/cpp/llvm")
|
||||
|
||||
overwrite_files(wpi_files, llvm_files)
|
||||
run_global_replacements(wpi_files)
|
||||
|
||||
|
||||
def main():
|
||||
root, repo = setup_upstream_repo("https://github.com/llvm/llvm-project",
|
||||
"llvmorg-13.0.0")
|
||||
root, repo = setup_upstream_repo(
|
||||
"https://github.com/llvm/llvm-project", "llvmorg-13.0.0"
|
||||
)
|
||||
wpiutil = os.path.join(root, "wpiutil")
|
||||
|
||||
patch_root = os.path.join(root, "upstream_utils/llvm_patches")
|
||||
|
||||
@@ -4,7 +4,14 @@ import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches, walk_if, copy_to
|
||||
from upstream_utils import (
|
||||
setup_upstream_repo,
|
||||
comment_out_invalid_includes,
|
||||
walk_cwd_and_copy_if,
|
||||
am_patches,
|
||||
walk_if,
|
||||
copy_to,
|
||||
)
|
||||
|
||||
|
||||
def crlf_to_lf(stackwalker_dir):
|
||||
@@ -15,11 +22,11 @@ def crlf_to_lf(stackwalker_dir):
|
||||
for fname in files:
|
||||
filename = os.path.join(root, fname)
|
||||
print(f"Converting CRLF -> LF for {filename}")
|
||||
with open(filename, 'rb') as f:
|
||||
with open(filename, "rb") as f:
|
||||
content = f.read()
|
||||
content = content.replace(b'\r\n', b'\n')
|
||||
content = content.replace(b"\r\n", b"\n")
|
||||
|
||||
with open(filename, 'wb') as f:
|
||||
with open(filename, "wb") as f:
|
||||
f.write(content)
|
||||
|
||||
subprocess.check_call(["git", "add", "-A"])
|
||||
@@ -30,7 +37,8 @@ def main():
|
||||
root, repo = setup_upstream_repo(
|
||||
"https://github.com/JochenKalmbach/StackWalker",
|
||||
"42e7a6e056a9e7aca911a7e9e54e2e4f90bc2652",
|
||||
shallow=False)
|
||||
shallow=False,
|
||||
)
|
||||
wpiutil = os.path.join(root, "wpiutil")
|
||||
|
||||
# Run CRLF -> LF before trying any patches
|
||||
@@ -38,19 +46,25 @@ def main():
|
||||
|
||||
# Apply patches to original git repo
|
||||
patch_dir = os.path.join(root, "upstream_utils/stack_walker_patches")
|
||||
am_patches(repo, [
|
||||
os.path.join(patch_dir, "0001-Apply-PR-35.patch"),
|
||||
os.path.join(patch_dir, "0002-Remove-_M_IX86-checks.patch"),
|
||||
os.path.join(patch_dir, "0003-Add-advapi-pragma.patch"),
|
||||
],
|
||||
ignore_whitespce=True)
|
||||
am_patches(
|
||||
repo,
|
||||
[
|
||||
os.path.join(patch_dir, "0001-Apply-PR-35.patch"),
|
||||
os.path.join(patch_dir, "0002-Remove-_M_IX86-checks.patch"),
|
||||
os.path.join(patch_dir, "0003-Add-advapi-pragma.patch"),
|
||||
],
|
||||
ignore_whitespce=True,
|
||||
)
|
||||
|
||||
shutil.copy(os.path.join("Main", "StackWalker", "StackWalker.h"),
|
||||
os.path.join(wpiutil, "src/main/native/windows/StackWalker.h"))
|
||||
shutil.copy(
|
||||
os.path.join("Main", "StackWalker", "StackWalker.h"),
|
||||
os.path.join(wpiutil, "src/main/native/windows/StackWalker.h"),
|
||||
)
|
||||
|
||||
shutil.copy(
|
||||
os.path.join("Main", "StackWalker", "StackWalker.cpp"),
|
||||
os.path.join(wpiutil, "src/main/native/windows/StackWalker.cpp"))
|
||||
os.path.join(wpiutil, "src/main/native/windows/StackWalker.cpp"),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -39,8 +39,7 @@ def clone_repo(url, treeish, shallow=True):
|
||||
# From https://gitlab.com/libeigen/eigen.git
|
||||
# 77c66e368c7e355f8be299659f57b0ffcaedb505 refs/heads/3.4
|
||||
# 3e006bfd31e4389e8c5718c30409cddb65a73b04 refs/heads/master
|
||||
ls_out = subprocess.check_output(["git", "ls-remote",
|
||||
"--heads"]).decode().rstrip()
|
||||
ls_out = subprocess.check_output(["git", "ls-remote", "--heads"]).decode().rstrip()
|
||||
heads = [x.split()[1] for x in ls_out.split("\n")[1:]]
|
||||
|
||||
if f"refs/heads/{treeish}" in heads:
|
||||
@@ -95,10 +94,7 @@ def walk_if(top, pred):
|
||||
True if the file should be included in the output list
|
||||
"""
|
||||
return [
|
||||
os.path.join(dp, f)
|
||||
for dp, dn, fn in os.walk(top)
|
||||
for f in fn
|
||||
if pred(dp, f)
|
||||
os.path.join(dp, f) for dp, dn, fn in os.walk(top) for f in fn if pred(dp, f)
|
||||
]
|
||||
|
||||
|
||||
@@ -175,14 +171,16 @@ def comment_out_invalid_includes(filename, include_roots):
|
||||
include = match.group(1)
|
||||
|
||||
# Write contents from before this match
|
||||
new_contents += old_contents[pos:match.span()[0]]
|
||||
new_contents += old_contents[pos : match.span()[0]]
|
||||
|
||||
# Comment out #include if the file doesn't exist in current directory or
|
||||
# include root
|
||||
if not os.path.exists(os.path.join(
|
||||
os.path.dirname(filename), include)) and not any(
|
||||
os.path.exists(os.path.join(include_root, include))
|
||||
for include_root in include_roots):
|
||||
if not os.path.exists(
|
||||
os.path.join(os.path.dirname(filename), include)
|
||||
) and not any(
|
||||
os.path.exists(os.path.join(include_root, include))
|
||||
for include_root in include_roots
|
||||
):
|
||||
new_contents += "// "
|
||||
|
||||
new_contents += match.group()
|
||||
|
||||
@@ -29,9 +29,11 @@ def main():
|
||||
dirname, _ = os.path.split(os.path.abspath(__file__))
|
||||
cmake_binary_dir = sys.argv[1]
|
||||
|
||||
env = Environment(loader=FileSystemLoader(f"{dirname}/src/generate"),
|
||||
autoescape=False,
|
||||
keep_trailing_newline=True)
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(f"{dirname}/src/generate"),
|
||||
autoescape=False,
|
||||
keep_trailing_newline=True,
|
||||
)
|
||||
|
||||
template = env.get_template("GenericNumber.java.jinja")
|
||||
rootPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/math/numbers"
|
||||
|
||||
@@ -7,9 +7,7 @@ import array
|
||||
import struct
|
||||
from typing import List, SupportsBytes
|
||||
|
||||
__all__ = [
|
||||
"StartRecordData", "MetadataRecordData", "DataLogRecord", "DataLogReader"
|
||||
]
|
||||
__all__ = ["StartRecordData", "MetadataRecordData", "DataLogRecord", "DataLogReader"]
|
||||
|
||||
floatStruct = struct.Struct("<f")
|
||||
doubleStruct = struct.Struct("<d")
|
||||
@@ -66,16 +64,25 @@ class DataLogRecord:
|
||||
return self.data[0]
|
||||
|
||||
def isStart(self) -> bool:
|
||||
return (self.entry == 0 and len(self.data) >= 17 and
|
||||
self._getControlType() == kControlStart)
|
||||
return (
|
||||
self.entry == 0
|
||||
and len(self.data) >= 17
|
||||
and self._getControlType() == kControlStart
|
||||
)
|
||||
|
||||
def isFinish(self) -> bool:
|
||||
return (self.entry == 0 and len(self.data) == 5 and
|
||||
self._getControlType() == kControlFinish)
|
||||
return (
|
||||
self.entry == 0
|
||||
and len(self.data) == 5
|
||||
and self._getControlType() == kControlFinish
|
||||
)
|
||||
|
||||
def isSetMetadata(self) -> bool:
|
||||
return (self.entry == 0 and len(self.data) >= 9 and
|
||||
self._getControlType() == kControlSetMetadata)
|
||||
return (
|
||||
self.entry == 0
|
||||
and len(self.data) >= 9
|
||||
and self._getControlType() == kControlSetMetadata
|
||||
)
|
||||
|
||||
def getStartData(self) -> StartRecordData:
|
||||
if not self.isStart():
|
||||
@@ -157,13 +164,13 @@ class DataLogRecord:
|
||||
return arr
|
||||
|
||||
def _readInnerString(self, pos: int) -> str:
|
||||
size = int.from_bytes(self.data[pos:pos + 4],
|
||||
byteorder="little",
|
||||
signed=False)
|
||||
size = int.from_bytes(
|
||||
self.data[pos : pos + 4], byteorder="little", signed=False
|
||||
)
|
||||
end = pos + 4 + size
|
||||
if end > len(self.data):
|
||||
raise TypeError("invalid string size")
|
||||
return str(self.data[pos + 4:end], encoding="utf-8"), end
|
||||
return str(self.data[pos + 4 : end], encoding="utf-8"), end
|
||||
|
||||
|
||||
class DataLogIterator:
|
||||
@@ -193,13 +200,14 @@ class DataLogIterator:
|
||||
raise StopIteration
|
||||
entry = self._readVarInt(self.pos + 1, entryLen)
|
||||
size = self._readVarInt(self.pos + 1 + entryLen, sizeLen)
|
||||
timestamp = self._readVarInt(self.pos + 1 + entryLen + sizeLen,
|
||||
timestampLen)
|
||||
timestamp = self._readVarInt(self.pos + 1 + entryLen + sizeLen, timestampLen)
|
||||
if len(self.buf) < (self.pos + headerLen + size):
|
||||
raise StopIteration
|
||||
record = DataLogRecord(
|
||||
entry, timestamp,
|
||||
self.buf[self.pos + headerLen:self.pos + headerLen + size])
|
||||
entry,
|
||||
timestamp,
|
||||
self.buf[self.pos + headerLen : self.pos + headerLen + size],
|
||||
)
|
||||
self.pos += headerLen + size
|
||||
return record
|
||||
|
||||
@@ -215,8 +223,11 @@ class DataLogReader:
|
||||
|
||||
def isValid(self) -> bool:
|
||||
"""Returns true if the data log is valid (e.g. has a valid header)."""
|
||||
return (len(self.buf) >= 12 and self.buf[0:6] == b"WPILOG" and
|
||||
self.getVersion() >= 0x0100)
|
||||
return (
|
||||
len(self.buf) >= 12
|
||||
and self.buf[0:6] == b"WPILOG"
|
||||
and self.getVersion() >= 0x0100
|
||||
)
|
||||
|
||||
def getVersion(self) -> int:
|
||||
"""Gets the data log version. Returns 0 if data log is invalid.
|
||||
@@ -235,12 +246,12 @@ class DataLogReader:
|
||||
if len(self.buf) < 12:
|
||||
return ""
|
||||
size = int.from_bytes(self.buf[8:12], byteorder="little", signed=False)
|
||||
return str(self.buf[12:12 + size], encoding="utf-8")
|
||||
return str(self.buf[12 : 12 + size], encoding="utf-8")
|
||||
|
||||
def __iter__(self) -> DataLogIterator:
|
||||
extraHeaderSize = int.from_bytes(self.buf[8:12],
|
||||
byteorder="little",
|
||||
signed=False)
|
||||
extraHeaderSize = int.from_bytes(
|
||||
self.buf[8:12], byteorder="little", signed=False
|
||||
)
|
||||
return DataLogIterator(self.buf, 12 + extraHeaderSize)
|
||||
|
||||
|
||||
@@ -287,9 +298,7 @@ if __name__ == "__main__":
|
||||
elif record.isSetMetadata():
|
||||
try:
|
||||
data = record.getSetMetadataData()
|
||||
print(
|
||||
f"SetMetadata({data.entry}, '{data.metadata}') [{timestamp}]"
|
||||
)
|
||||
print(f"SetMetadata({data.entry}, '{data.metadata}') [{timestamp}]")
|
||||
if data.entry not in entries:
|
||||
print("...ID not found")
|
||||
except TypeError as e:
|
||||
@@ -302,14 +311,12 @@ if __name__ == "__main__":
|
||||
if entry is None:
|
||||
print("<ID not found>")
|
||||
continue
|
||||
print(
|
||||
f"<name='{entry.name}', type='{entry.type}'> [{timestamp}]")
|
||||
print(f"<name='{entry.name}', type='{entry.type}'> [{timestamp}]")
|
||||
|
||||
try:
|
||||
# handle systemTime specially
|
||||
if entry.name == "systemTime" and entry.type == "int64":
|
||||
dt = datetime.fromtimestamp(record.getInteger() /
|
||||
1000000)
|
||||
dt = datetime.fromtimestamp(record.getInteger() / 1000000)
|
||||
print(" {:%Y-%m-%d %H:%M:%S.%f}".format(dt))
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user