From 6ec8763eac52a5ed1fb607ce1095bf31233de800 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sat, 20 Jul 2024 07:00:13 -0700 Subject: [PATCH] [upstream_utils] Make .c file rename toggleable (#6858) --- upstream_utils/libuv.py | 1 + upstream_utils/mpack.py | 1 + upstream_utils/upstream_utils.py | 10 ++++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/upstream_utils/libuv.py b/upstream_utils/libuv.py index 9a2865838c..73ba5f6830 100755 --- a/upstream_utils/libuv.py +++ b/upstream_utils/libuv.py @@ -51,6 +51,7 @@ def copy_upstream_src(wpilib_root): src_files = walk_cwd_and_copy_if( lambda dp, f: dp.startswith("./src") and f not in src_ignorelist, os.path.join(wpinet, "src/main/native/thirdparty/libuv"), + rename_c_to_cpp=True, ) diff --git a/upstream_utils/mpack.py b/upstream_utils/mpack.py index ad395377a6..e0971f3079 100755 --- a/upstream_utils/mpack.py +++ b/upstream_utils/mpack.py @@ -39,6 +39,7 @@ def copy_upstream_src(wpilib_root): walk_cwd_and_copy_if( lambda dp, f: f.endswith(".c"), os.path.join(wpiutil, "src/main/native/thirdparty/mpack/src"), + rename_c_to_cpp=True, ) diff --git a/upstream_utils/upstream_utils.py b/upstream_utils/upstream_utils.py index 5851df11f9..7fc287ba0b 100644 --- a/upstream_utils/upstream_utils.py +++ b/upstream_utils/upstream_utils.py @@ -87,7 +87,7 @@ def walk_if(top, pred): ] -def copy_to(files, root): +def copy_to(files, root, rename_c_to_cpp=False): """Copies list of files to root by appending the relative paths of the files to root. @@ -96,6 +96,7 @@ def copy_to(files, root): Keyword arguments: files -- list of files to copy root -- destination + rename_c_to_cpp -- whether to rename .c files to .cpp (default: False) Returns: The list of files in their destination. @@ -110,7 +111,7 @@ def copy_to(files, root): # Rename .cc file to .cpp if dest_file.endswith(".cc"): dest_file = os.path.splitext(dest_file)[0] + ".cpp" - if dest_file.endswith(".c"): + if rename_c_to_cpp and dest_file.endswith(".c"): dest_file = os.path.splitext(dest_file)[0] + ".cpp" # Make leading directory @@ -123,7 +124,7 @@ def copy_to(files, root): return dest_files -def walk_cwd_and_copy_if(pred, root): +def walk_cwd_and_copy_if(pred, root, rename_c_to_cpp=False): """Walks the current directory, generates a list of files for which the given predicate is true, then copies that list to root by appending the relative paths of the files to root. @@ -134,12 +135,13 @@ def walk_cwd_and_copy_if(pred, root): pred -- a function that takes a directory path and a filename, then returns True if the file should be included in the output list root -- destination + rename_c_to_cpp -- whether to rename .c files to .cpp (default: False) Returns: The list of files in their destination. """ files = walk_if(".", pred) - files = copy_to(files, root) + files = copy_to(files, root, rename_c_to_cpp) return files