Skip to content

Commit 33c2836

Browse files
Added CMake stuff to the venv (#298)
1 parent 46c6ce1 commit 33c2836

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

dev/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ RUN echo "source /home/dev/scripts/alias.sh" >> ~/.bashrc
4242
RUN ln -sf /usr/lib/linux-tools-*/* /usr/bin/
4343

4444
# Install cross compiler
45-
RUN wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 | tar -xvj
45+
RUN wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz | tar -xJv
4646

47-
ENV PATH $PATH:/home/dev/gcc-arm-none-eabi-10.3-2021.10/bin
47+
ENV PATH $PATH:/home/dev/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin
4848

4949
WORKDIR /home/app
5050

5151
# Set up safe directory
5252
RUN git config --global --add safe.directory /home/app
53-

ner_environment/build_system/build_system.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@ def unsupported_option_cb(value:bool):
4747
# Build command
4848
# ==============================================================================
4949

50-
@app.command(help="Build the project with GCC ARM Toolchain and Make")
50+
@app.command(help="Build the project with GCC ARM Toolchain and Make/CMake")
5151
def build(profile: str = typer.Option(None, "--profile", "-p", callback=unsupported_option_cb, help="(planned) Specify the build profile (e.g., debug, release)", show_default=True),
5252
clean: bool = typer.Option(False, "--clean", help="Clean the build directory before building", show_default=True)):
53-
54-
if clean:
55-
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", "clean"]
56-
else:
57-
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", f"-j{os.cpu_count()}"]
58-
run_command(command, stream_output=True)
53+
is_cmake = os.path.exists("CMakeLists.txt")
54+
if is_cmake: # Repo uses CMake, so execute CMake commands.
55+
print("[#cccccc](ner build):[/#cccccc] [blue]CMake-based project detected.[/blue]")
56+
if clean:
57+
run_command_docker('cmake --build build --target clean ; find . -type d -name "build" -exec rm -rf {} +')
58+
print("[#cccccc](ner build):[/#cccccc] [green]Ran build-cleaning command.[/green]")
59+
else:
60+
run_command_docker("mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .", stream_output=True)
61+
else: # Repo uses Make, so execute Make commands.
62+
print("[#cccccc](ner build):[/#cccccc] [blue]Makefile-based project detected.[/blue]")
63+
if clean:
64+
run_command_docker("make clean", stream_output=True)
65+
else:
66+
run_command_docker(f"make -j{os.cpu_count()}", stream_output=True)
5967

6068
# ==============================================================================
6169
# Clang command
@@ -333,13 +341,20 @@ def run_command(command, stream_output=False, exit_on_fail=True):
333341
else:
334342
try:
335343
result = subprocess.run(command, check=True, capture_output=True, text=True)
336-
print(result.stdout)
344+
if result.stdout and result.stdout.strip(): # Only print if stdout is not empty or just whitespace
345+
print(result.stdout)
337346
except subprocess.CalledProcessError as e:
338347
print(f"Error occurred: {e}", file=sys.stderr)
339348
print(e.stderr, file=sys.stderr)
340349
if exit_on_fail:
341350
sys.exit(e.returncode)
342351

352+
def run_command_docker(command, stream_output=False):
353+
"""Run a command in the Docker container."""
354+
docker_command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "sh", "-c", command]
355+
print(f"[bold blue](ner-gcc-arm): Running command '{command}' in Docker container.")
356+
run_command(docker_command, stream_output=stream_output, exit_on_fail=True)
357+
343358
def disconnect_usbip():
344359
"""Disconnect the current USB device."""
345360
command = ["sudo", "usbip", "detach", "-p", "0"]

0 commit comments

Comments
 (0)