From d08157b4738b180da5f01136a9d21053646dd6ef Mon Sep 17 00:00:00 2001 From: Kashiuchi Sotaro Date: Wed, 26 Jun 2024 23:42:48 +0900 Subject: [PATCH] change rebuild not to clone but to pull --- microros_utils/library_builder.py | 9 ++------- microros_utils/repositories.py | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/microros_utils/library_builder.py b/microros_utils/library_builder.py index 1077400..4924899 100644 --- a/microros_utils/library_builder.py +++ b/microros_utils/library_builder.py @@ -66,9 +66,6 @@ def run(self, meta, toolchain, user_meta = ""): self.build_mcu_environment(meta, toolchain, user_meta) self.package_mcu_library() - # Delete build folders - shutil.rmtree(self.build_folder, ignore_errors=True) - def ignore_package(self, name): for p in self.mcu_packages: if p.name == name: @@ -90,8 +87,7 @@ def check_env(self): self.env = os.environ.copy() def download_dev_environment(self): - shutil.rmtree(self.dev_src_folder, ignore_errors=True) - os.makedirs(self.dev_src_folder) + os.makedirs(self.dev_src_folder, exist_ok=True) print("Downloading micro-ROS dev dependencies") for repo in Sources.dev_environments[self.distro]: repo.clone(self.dev_src_folder) @@ -108,8 +104,7 @@ def build_dev_environment(self): sys.exit(1) def download_mcu_environment(self): - shutil.rmtree(self.mcu_src_folder, ignore_errors=True) - os.makedirs(self.mcu_src_folder) + os.makedirs(self.mcu_src_folder, exist_ok=True) print("Downloading micro-ROS library") for repo in Sources.mcu_environments[self.distro]: repo.clone(self.mcu_src_folder) diff --git a/microros_utils/repositories.py b/microros_utils/repositories.py index 3fc3cc5..5d9401a 100644 --- a/microros_utils/repositories.py +++ b/microros_utils/repositories.py @@ -27,6 +27,14 @@ def __init__(self, name, url, distribution, branch=None): def clone(self, folder): self.path = folder + "/" + self.name # TODO(pablogs) ensure that git is installed + if os.path.exists(self.path): + command = f"cd {self.path} && git pull {self.url} {self.branch}" + result = run_cmd(command) + if 0 != result.returncode: + print(f"{self.name} pull failed: \n{result.stderr.decode('utf-8')}") + sys.exit(1) + return + command = "git clone -b {} {} {}".format(self.branch, self.url, self.path) result = run_cmd(command)