Skip to content

Commit 1890037

Browse files
authored
Merge pull request #248 from JdeRobot/cpp-exercises
Allow Cpp exercises
2 parents a4d9fe6 + 583b1e5 commit 1890037

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

manager/manager/manager.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def find_docker_console():
664664

665665
# Delete old files
666666
if os.path.exists("/workspace/code"):
667-
shutil.rmtree("/workspace/code")
667+
shutil.rmtree("/workspace/code", ignore_errors=False)
668668
os.mkdir("/workspace/code")
669669

670670
# Extract app config
@@ -685,6 +685,44 @@ def find_docker_console():
685685
LogManager.logger.info("User code not found")
686686
raise Exception("User code not found")
687687

688+
_, file_extension = os.path.splitext(entrypoint)
689+
690+
if file_extension == ".cpp":
691+
fds = os.listdir("/dev/pts/")
692+
console_fd = str(max(map(int, fds[:-1])))
693+
694+
compile_process = subprocess.Popen(
695+
[
696+
"cd /workspace/code && source /opt/ros/humble/setup.bash && colcon build && source install/setup.bash && cd ../.."
697+
],
698+
stdin=open("/dev/pts/" + console_fd, "r"),
699+
stdout=open("/dev/pts/" + console_fd, "w"),
700+
stderr=open("/dev/pts/" + console_fd, "w"),
701+
bufsize=1024,
702+
universal_newlines=True,
703+
shell=True,
704+
executable="/bin/bash",
705+
)
706+
returncode = compile_process.wait()
707+
print(returncode)
708+
if returncode != 0:
709+
raise Exception("Failed to compile")
710+
711+
self.application_process = subprocess.Popen(
712+
[
713+
"source /workspace/code/install/setup.bash && ros2 run academy academyCode"
714+
],
715+
stdin=open("/dev/pts/" + console_fd, "r"),
716+
stdout=sys.stdout,
717+
stderr=subprocess.STDOUT,
718+
bufsize=1024,
719+
universal_newlines=True,
720+
shell=True,
721+
executable="/bin/bash",
722+
)
723+
self.unpause_sim()
724+
return
725+
688726
# Pass the linter
689727
errors = self.linter.evaluate_source_code(to_lint)
690728
failed_linter = False
@@ -718,7 +756,6 @@ def find_docker_console():
718756

719757
LogManager.logger.info("Run application transition finished")
720758

721-
722759
def on_terminate_application(self, event):
723760
"""
724761
Handle the 'terminate_application' event.

0 commit comments

Comments
 (0)