-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvsetup.sh
More file actions
318 lines (266 loc) · 9.03 KB
/
envsetup.sh
File metadata and controls
318 lines (266 loc) · 9.03 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# #############################################################################
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2025 Ragab R. Hassan (r.elkattawy@gmail.com)
#
# #############################################################################
# Directories
ABS_ROOT_WD=$(realpath .)
ROOT_WD=$(pwd)
DEPENDENCIES_DIR=${ABS_ROOT_WD}/deps
CURRENT_PROJECT=
# Build Configs
ENABLE_SIGNAL_HANDLING=1
DEP_INSTALL_PATH=${ABS_ROOT_WD}/install_folder
DEP_LIBRARY_PATH=${DEP_INSTALL_PATH}/lib/
COMMONAPI_CONFIG="commonapi4someip.ini"
USE_INSTALLED_COMMONAPI=ON
################################ General Utils ################################
# it wraps a function call while preserving the working directory
function _callWrapper() {
TEMP_CWD=$(pwd)
"$@"
cd ${TEMP_CWD}
}
# this function will check the existence of a directory relative to
# the project root directory and cd to that directory
# Parameters:
# 1: path of interest
# 2: (optional) n -> don't create path
#
# if n is passed and the directory does't exist, cwd = root directory
#
# to avoid path corruption use it inside a wrapped function only
function _checkPath() {
# go to root
cd ${ABS_ROOT_WD}
ls $1 2> /dev/null > /dev/null
# path existing
if [[ $? -eq 0 ]]; then
cd $1
else #path doesn't exist
if [[ $2 = "n" ]] then
return 1
fi
mkdir -p $1 && cd $1
fi
}
# same as _checkPath but works with cwd
# feel free to use it in unwrapped functions
function _checkRelPath() {
ls $1 2> /dev/null > /dev/null
if [[ $? -eq 0 ]]; then
cd $(realpath $1)
else
if [[ $2 = "n" ]] then
return 1
fi
mkdir $1 && cd $(realpath $1)
fi
}
# go to the root directory
function goToRoot() {
cd ${ABS_ROOT_WD}
}
# go to the current project if set
function goToProject() {
if [[ -n ${CURRENT_PROJECT} ]]; then
cd ${CURRENT_PROJECT}
fi
}
function _wrapProjectFunction() {
if [[ -n ${CURRENT_PROJECT} ]]; then
_callWrapper "$@"
else
echo "Couldn't find project, please run workOn <projectName>"
fi
}
function nowWhat() {
echo "
Are you stuck? here's what you can do
General:
workOn <project> Setup the project work directory
goToRoot Go to the environment root directory
goToProject Jump to the project directory
Project:
genCoreApiFiles Generate CommonApi files, fidl and fdepl files are expected to be under projectName/fidl
buildProject Build the current project
runApp <target> cfg.ini Runs the target (Client or Service) app with the specified cfg.ini,
if cfg.ini not specified projectName/commonapi4someip.ini will be used
Dependencies:
cloneDeps Clone dependencies under deps
buildDeps Build all dependencies
buildCapi-core Build only capi-core-runtime lib and install it to install_folder
buildCapi-someip Build only capi-someip-runtime lib and install it to install_folder
buildVsomeip Build only vsomeip libs and install it to install_folder
Code Generators:
getGenTools Download and extract the code generators
"
}
########################## Dependencies Handling ##############################
# Libraries versions/tags
CAPI_CORE_REPO_NAME="capicxx-core-runtime"
CAPI_CORE_VER="3.2.4"
CAPI_CORE_PATCHES="../patches/core"
CAPI_VSOMEIP_REPO_NAME="capicxx-someip-runtime"
CAPI_VSOMEIP_VER="3.2.4"
VSOMEIP_REPO_NAME="vsomeip"
VSOMEIP_VER="3.5.5"
# used by the user to clone dependencies
function cloneDeps() {
_callWrapper _cloneDeps
}
# Implementation of cloning a dependency
# takes two arguments
# 1: repo name -> should match the name in the url
# 2: repo version -> the version tag of a repo
# 3: (optional) patch directories
function _cloneDep() {
local REPO_NAME=$1
local REPO_VERSION=$2
echo "============================================================="
echo "Cloning ${REPO_NAME}..."
echo "============================================================="
_checkPath ${DEPENDENCIES_DIR}
_checkRelPath ${REPO_NAME} n
if [[ $? -eq 1 ]]; then
git clone https://github.com/COVESA/${REPO_NAME}.git ${REPO_NAME}
cd ${REPO_NAME}
echo "Checking out Version ${REPO_VERSION}..."
git checkout ${REPO_VERSION}
echo "Cloning Succeeded!"
if [[ -n $3 ]]; then
if [[ $? -eq 0 ]]; then
echo "applying patches..."
git apply $3/*.patch
fi
fi
else
echo "Error: /deps/${REPO_NAME} already existing"
echo "Cloning Failed!"
fi
echo " "
}
#Clone the needed dependencies Dependencies
function _cloneDeps() {
_callWrapper _cloneDep ${CAPI_CORE_REPO_NAME} ${CAPI_CORE_VER} ${CAPI_CORE_PATCHES}
_callWrapper _cloneDep ${CAPI_VSOMEIP_REPO_NAME} ${CAPI_VSOMEIP_VER}
_callWrapper _cloneDep ${VSOMEIP_REPO_NAME} ${VSOMEIP_VER}
}
function buildCapi-core() {
_callWrapper _buildCapi-core
}
# build the CommonAPI-core
function _buildCapi-core() {
cd ${DEPENDENCIES_DIR}
_checkRelPath ${CAPI_CORE_REPO_NAME} n
if [[ $? -eq 1 ]]; then
echo "ERROR: ${CAPI_CORE_REPO_NAME} not found, please clone"
return 1
fi
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_PATH} .
cmake --build build/ --target install -j$(nproc)
}
function buildVsomeip() {
_callWrapper _buildVsomeip
}
# build the CommonAPI-someip
function _buildVsomeip() {
cd ${DEPENDENCIES_DIR}
_checkRelPath ${VSOMEIP_REPO_NAME}
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_PATH} -DENABLE_SIGNAL_HANDLING=${ENABLE_SIGNAL_HANDLING} -DDIAGNOSIS_ADDRESS=0x10 .
cmake --build build/ --target install -j$(nproc)
}
function buildCapi-someip() {
_callWrapper _buildCapi-someip
}
# build vsomeip
function _buildCapi-someip() {
cd ${DEPENDENCIES_DIR}
_checkRelPath ${CAPI_VSOMEIP_REPO_NAME}
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_PATH} -DCMAKE_PREFIX_PATH=${DEP_INSTALL_PATH} -DUSE_INSTALLED_COMMONAPI=${USE_INSTALLED_COMMONAPI} .
cmake --build build/ --target install -j$(nproc)
}
# build all dependencies
function buildDeps() {
echo "Building ${VSOMEIP_REPO_NAME}..."
buildVsomeip
echo "Building ${CAPI_CORE_REPO_NAME}..."
buildCapi-core
echo "Building ${CAPI_VSOMEIP_REPO_NAME}..."
buildCapi-someip
}
######################## Generation Tools Handling ############################
# Code generators
export CORE_CGEN=${ABS_ROOT_WD}/cgen/commonapi_core_generator/commonapi-core-generator-linux-x86_64
export SOMEIP_CGEN=${ABS_ROOT_WD}/cgen/commonapi_someip_generator/commonapi-someip-generator-linux-x86_64
CORE_GEN_VERSION="3.2.15"
CORE_GEN_ID="3.2.15"
SOMEIP_GEN_VERSION="3.2.15"
SOMEIP_GEN_ID="3.2.15"
SRC_GEN_DIR=src-gen
function getGenTools() {
_callWrapper _getGenTools
}
function _getGenTools() {
_checkPath cgen
echo "Downloading CommonAPI-core-tools.."
wget https://github.com/COVESA/capicxx-core-tools/releases/download/3.2.15/commonapi_core_generator.zip
unzip commonapi_core_generator.zip -d commonapi_core_generator/
echo "CommonAPI-someip-tools.."
wget https://github.com/COVESA/capicxx-someip-tools/releases/download/3.2.15/commonapi_someip_generator.zip
unzip commonapi_someip_generator.zip -d commonapi_someip_generator/
}
############################ Project Specifics ################################
PROJECT_NAME=
# specify the project to work on
function workOn() {
_callWrapper _workOn "$@"
}
function _workOn() {
_checkPath $1 n
if [[ $? -eq 1 ]]; then
echo "ERROR: Project $1 not found"
return 1
fi
PROJECT_NAME=$1
CURRENT_PROJECT=$(realpath $(pwd))
}
# 1: fidl file
# 2: fdepl file
# currently supporting single interface files
function genCoreApiFiles() {
_wrapProjectFunction _genCoreApiFiles "$@"
}
function _genCoreApiFiles() {
cd ${CURRENT_PROJECT}
$CORE_CGEN --skel --dest-common ./src-gen/core/common --dest-proxy ./src-gen/core/proxy --dest-stub ./src-gen/core/stub --dest-skel ./src-gen/core/skel -sp ./fidl
$SOMEIP_CGEN --dest-common ./src-gen/someip/common --dest-proxy ./src-gen/someip/proxy --dest-stub ./src-gen/someip/stub -sp ./fidl
}
function buildProject() {
_wrapProjectFunction _buildProject
}
function _buildProject() {
cd ${CURRENT_PROJECT}
cmake -Bbuild -DCMAKE_PREFIX_PATH=${DEP_INSTALL_PATH} -DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=ON .
cmake --build build
}
function runApp() {
_wrapProjectFunction _runApp "$@"
}
function _runApp() {
cd ${CURRENT_PROJECT}
pwd
export LD_LIBRARY_PATH=${DEP_LIBRARY_PATH}:$PWD/build/
local TARGET=$1
if [[ -n $2 ]]; then
export COMMONAPI_CONFIG=$2
else
export COMMONAPI_CONFIG="commonapi4someip.ini"
fi
local APP_NAME="${PROJECT_NAME}${TARGET}"
build/${APP_NAME}
}