Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update extra_script.py and library_builder.py to speed up the build #141

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ def clean_microros_callback(*args, **kwargs):
if "clean_microros" not in global_env.get("__PIO_TARGETS", {}):
global_env.AddCustomTarget("clean_microros", None, clean_microros_callback, title="Clean Micro-ROS", description="Clean Micro-ROS build environment")

def clean_libmicroros_callback(*args, **kwargs):
library_path = main_path + '/libmicroros'

# Delete libmicroros folder
shutil.rmtree(library_path, ignore_errors=True)

print("libmicroros cleaned")
os._exit(0)

if "clean_libmicroros" not in global_env.get("__PIO_TARGETS", {}):
global_env.AddCustomTarget("clean_libmicroros", None, clean_libmicroros_callback, title="Clean libmicroros", description="Clean libmicroros")


def build_microros(*args, **kwargs):
##############################
#### Install dependencies ####
Expand Down Expand Up @@ -154,7 +167,7 @@ def update_env():
from SCons.Script import COMMAND_LINE_TARGETS

# Do not build library on clean_microros target or when IDE fetches C/C++ project metadata
if set(["clean_microros", "_idedata", "idedata"]).isdisjoint(set(COMMAND_LINE_TARGETS)):
if set(["clean_microros", "clean_libmicroros", "_idedata", "idedata"]).isdisjoint(set(COMMAND_LINE_TARGETS)):
build_microros()

update_env()
9 changes: 2 additions & 7 deletions microros_utils/library_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions microros_utils/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading