-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·133 lines (111 loc) · 4.2 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# MicroROS Build Action - Entrypoint script, this builds the library.
# Copyright 2024 Samyar Sadat Akhavi
# Written by Samyar Sadat Akhavi, 2024.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https: www.gnu.org/licenses/>.
set -e
export ROS_DISTRO="humble"
# Get arguments
MICROROS_DIR_PATH="$1"
MICROROS_SRC_PATH="$2"
MICROROS_SETUP_PATH="$3"
ENV_SETUP_SCRIPT="$4"
MICROROS_DO_CLONE="$5"
COLCON_META_NAME="$6"
TOOLCHAIN_CMAKE_NAME="$7"
EXTRA_BUILD_PACKAGES="$8"
# Split package names into array
IFS=" " read -r -a EXTRA_BUILD_PACKAGES <<< "$EXTRA_BUILD_PACKAGES"
# Make paths absolute
RELATIVE_MICROROS_DIR_PATH="$MICROROS_DIR_PATH"
MICROROS_DIR_PATH="$GITHUB_WORKSPACE/$MICROROS_DIR_PATH"
MICROROS_SRC_PATH="$MICROROS_DIR_PATH/$MICROROS_SRC_PATH"
MICROROS_SETUP_PATH="$MICROROS_SRC_PATH/$MICROROS_SETUP_PATH"
# Directory existance check function
check_directory_exists() {
local dir_path=$1
if [ ! -d "$dir_path" ]; then
echo "ERROR: $dir_path does not exist."
exit 1
fi
}
# File existance check function
check_file_exists() {
local file_path=$1
if [ ! -f "$file_path" ]; then
echo "ERROR: $file_path does not exist."
exit 1
fi
}
# Check if directories exist
check_directory_exists "$MICROROS_DIR_PATH"
check_directory_exists "$MICROROS_SRC_PATH"
for package in "${EXTRA_BUILD_PACKAGES[@]}"; do
check_directory_exists "$MICROROS_SRC_PATH/$package"
done
# Check if the toolchain, colcon meta, and environment setup files exist
check_file_exists "$MICROROS_DIR_PATH/$TOOLCHAIN_CMAKE_NAME"
check_file_exists "$MICROROS_DIR_PATH/$COLCON_META_NAME"
# Environment setup
if [ -n "$ENV_SETUP_SCRIPT" ]; then
check_file_exists "$ENV_SETUP_SCRIPT"
echo "Running provided environment setup script..."
source "$ENV_SETUP_SCRIPT"
else
echo "No environment setup script provided."
echo "Using default RP2040 setup..."
ENV_SETUP_SCRIPT="DEFAULT RP2040 SETUP"
source /rp2040_env_setup.sh
fi
cd "$GITHUB_WORKSPACE"
# Echo arguments
echo "Configuration:"
echo "MICROROS_DIR_PATH=$MICROROS_DIR_PATH"
echo "MICROROS_SRC_PATH=$MICROROS_SRC_PATH"
echo "MICROROS_SETUP_PATH=$MICROROS_SETUP_PATH"
echo "MICROROS_DO_CLONE=$MICROROS_DO_CLONE"
echo "COLCON_META_NAME=$COLCON_META_NAME"
echo "TOOLCHAIN_CMAKE_NAME=$TOOLCHAIN_CMAKE_NAME"
echo "EXTRA_BUILD_PACKAGES=${EXTRA_BUILD_PACKAGES[@]}"
echo "ENV_SETUP_SCRIPT=$ENV_SETUP_SCRIPT"
echo "ROS_DISTRO=$ROS_DISTRO"
# Install MicroROS tools
echo "Running tools setup script..."
export MICROROS_DIR_PATH="$MICROROS_DIR_PATH"
export MICROROS_SRC_PATH="$MICROROS_SRC_PATH"
export MICROROS_SETUP_PATH="$MICROROS_SETUP_PATH"
export MICROROS_DO_CLONE="$MICROROS_DO_CLONE"
/install_tools.sh
source /opt/ros/$ROS_DISTRO/setup.bash
# Build MicroROS and extra packages
cd "$MICROROS_DIR_PATH"
echo "Removing directories..."
rm -rf ./build && rm -rf ./firmware && rm -rf ./install && rm -rf ./log
for package in "${EXTRA_BUILD_PACKAGES[@]}"; do
echo "Building extra package: $package..."
colcon build --packages-select "$package"
done
source install/local_setup.bash
source "$MICROROS_SETUP_PATH/install/local_setup.bash"
sudo apt-get update
ros2 run micro_ros_setup create_firmware_ws.sh generate_lib
for package in "${EXTRA_BUILD_PACKAGES[@]}"; do
echo "Running workspace creation script for package: $package..."
ros2 run "$package" create_firmware_ws.sh
done
ros2 run micro_ros_setup build_firmware.sh "$MICROROS_DIR_PATH/$TOOLCHAIN_CMAKE_NAME" "$MICROROS_DIR_PATH/$COLCON_META_NAME"
echo "Build completed successfully (probably)!"
# Add output directory path to GITHUB_OUTPUT
echo "library_build_dir=$RELATIVE_MICROROS_DIR_PATH/firmware/build/" >> $GITHUB_OUTPUT