From 16d098fe3197461cb8d5c4e5f35ebfc54f85ccc5 Mon Sep 17 00:00:00 2001 From: Joseph Eng Date: Sun, 14 Jul 2024 19:31:53 -0700 Subject: [PATCH] Use Lib class --- upstream_utils/update_mpack.py | 89 ++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/upstream_utils/update_mpack.py b/upstream_utils/update_mpack.py index 974587dc872..f821f7cce58 100755 --- a/upstream_utils/update_mpack.py +++ b/upstream_utils/update_mpack.py @@ -12,37 +12,74 @@ git_am, ) -def get_repo_path(url, tempdir=None): - if tempdir is None: - tempdir = tempfile.gettempdir() - repo = os.path.basename(url) - dest = os.path.join(tempdir, repo) - dest = dest.removesuffix(".git") - return dest -def open_repo(url, *, err_msg_if_absent): - os.chdir(tempfile.gettempdir()) +class Lib: + def __init__( + self, + name, + url, + old_tag, + patch_list, + copy_upstream_src, + patch_options={}, + *, + pre_patch_hook=None, + pre_patch_commits=0, + ): + self.name = name + self.url = url + self.old_tag = old_tag + self.patch_list = patch_list + self.copy_upstream_src = copy_upstream_src + self.patch_options = patch_options + self.pre_patch_hook = pre_patch_hook + self.pre_patch_commits = pre_patch_commits + self.wpilib_root = get_repo_root() + + def get_repo_path(self, tempdir=None): + if tempdir is None: + tempdir = tempfile.gettempdir() + repo = os.path.basename(self.url) + dest = os.path.join(tempdir, repo) + dest = dest.removesuffix(".git") + return dest + + def open_repo(self, *, err_msg_if_absent): + os.chdir(tempfile.gettempdir()) + + dest = self.get_repo_path(os.getcwd()) + + print(f"INFO: Opening repository at {dest}") + + if not os.path.exists(dest): + if err_msg_if_absent is None: + subprocess.run(["git", "clone", "--filter=tree:0", self.url]) + else: + print(err_msg_if_absent, file=sys.stderr) + exit(1) + os.chdir(dest) + + def clone(self): + self.open_repo(err_msg_if_absent=None) + + subprocess.run(["git", "switch", "--detach", self.old_tag]) - dest = get_repo_path(url, os.getcwd()) - - print(f"INFO: Opening repository at {dest}") - - if not os.path.exists(dest): - if err_msg_if_absent is None: - subprocess.run(["git", "clone", "--filter=tree:0", url]) - else: - print(err_msg_if_absent, file=sys.stderr) - exit(1) - os.chdir(dest) +def main(): + name = "mpack" + url = "https://github.com/ludocode/mpack" + tag = "v1.1.1" -def clone(url, tag): - open_repo(url, err_msg_if_absent=None) + patch_list = [ + "0001-Don-t-emit-inline-defs.patch", + "0002-Update-amalgamation-script.patch", + "0003-Use-namespace-for-C.patch", + "0004-Group-doxygen-into-MPack-module.patch", + ] - subprocess.run(["git", "switch", "--detach", tag]) + mpack = Lib(name, url, tag, [], lambda: None) + mpack.clone() -def main(): - wpilib_root = get_repo_root() - clone("https://github.com/ludocode/mpack", "v1.1.1") + wpilib_root = mpack.wpilib_root upstream_root = os.getcwd() wpiutil = os.path.join(wpilib_root, "wpiutil")