-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathtos
executable file
·665 lines (601 loc) · 20 KB
/
tos
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
#!/usr/bin/env bash
OPEN_SDK_ROOT=$(cd "$(dirname "$0")" && pwd)
PROJECT_ROOT=$(pwd)
. $OPEN_SDK_ROOT/tools/util_tools.sh
LISTMENU=$OPEN_SDK_ROOT/tools/listmenu.sh
OPEN_BUILD=$(basename "$0")
PROJECT_INI=$PROJECT_ROOT/.build/cache/using.config
KCONFIG_TOOLS=$OPEN_SDK_ROOT/tools/kconfiglib
if [ x"$TOS_DEBUG" = x"1" ]; then
CMAKE_VERBOSE="-DCMAKE_VERBOSE_MAKEFILE=ON"
VERBOSE="--verbose"
else
CMAKE_VERBOSE=""
VERBOSE=""
fi
# ==============================================================================
# executing define
# ------------------------------------------------------------------------------
function check_ini()
{
if [ ! -f $PROJECT_INI ]; then
show "${fore[yellow]}" "Not found [$PROJECT_INI]."
show "${fore[green]}" "You could run [$OPEN_BUILD menuconfig]."
exit 0
fi
}
function check_hooks()
{
if [ -d $OPEN_SDK_ROOT/.git/hooks ]; then
if [ ! -f $OPEN_SDK_ROOT/.git/hooks/pre-commit ]; then
cp -rf $OPEN_SDK_ROOT/tools/hooks/pre-commit $OPEN_SDK_ROOT/.git/hooks/pre-commit
fi
fi
}
function check_submodules()
{
check_hooks
show "${fore[green]}" "Check submodules."
cd $OPEN_SDK_ROOT
submodules=($(grep "path" .gitmodules | sed 's/^[ \t]*path = //'))
for submodule in "${submodules[@]}"
do
if [ -z "$(ls -A $submodule)" ]; then
echo "$submodule is empty, initializing submodule..."
git submodule update --init $submodule
fi
done
cd - > /dev/null
}
function check_arduino()
{
ARDUINO_REPO="https://github.com/tuya/arduino-tuyaopen.git"
ARDUINO_PATH=$OPEN_SDK_ROOT/arduino-tuyaopen
cd $OPEN_SDK_ROOT
if [ -d $ARDUINO_PATH ]; then
show "" "Skip download, exist [$ARDUINO_PATH]."
show "${fore[yellow]}" "If you want to download it again, please remove it."
return 0
fi
git clone $ARDUINO_REPO
if [ ! "0" = "$?" ]; then
show "${fore[red]}" "Clone repo [$ARDUINO_REPO] failed, please try again."
if [ -d "$ARDUINO_PATH" ]; then
show "${fore[yellow]}" "Delete [$ARDUINO_PATH] first."
fi
exit 1
fi
cd $ARDUINO_PATH
TAG=`git describe --tags --abbrev=0`
git checkout $TAG
git submodule update --init
}
function version_exec()
{
show "" "2.0.0"
}
function check_base_tool()
{
exit_flag=0
check_command_version "bash" "4.0.0" "bash --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
check_command_version "grep" "3.0.0" "grep --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
check_command_version "sed" "4.0.0" "sed --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
check_command_version "python3" "3.6.0" "python3 --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
check_command_version "git" "2.0.0" "git --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
check_command_version "ninja" "1.6.0" "ninja --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
check_command_version "cmake" "3.16.0" "cmake --version"
if [ x"$?" != x"0" ]; then exit_flag=1; fi
# check_command_version "ccmake" "3.16.0" "ccmake --version" # sudo apt-get install cmake-curses-gui
# check_command_version "lcov" "1.14" "lcov --version"
if [ x"$exit_flag" = x"1" ]; then
show "${fore[red]}" "Error: Check the required tools and versions."
exit 1
fi
}
function check_exec()
{
show "" "Check command and version ..."
check_base_tool
check_submodules
which $OPEN_BUILD > /dev/null
if [ "1" = "$?" ]; then
show "${fore[yellow]}" "Select a way to configure the OpenSDK tool:"
show "${fore[yellow]}" "1. export PATH=\$PATH:$OPEN_SDK_ROOT"
show "${fore[yellow]}" "2. set step1 to .bashrc / .zshrc / .profile"
fi
}
function download_platform()
{
PLATFORMS_DIR=$OPEN_SDK_ROOT/platform
PLATFORM_PATH="${PLATFORMS_DIR}/${PLATFORM_NAME}"
if [ -d "$PLATFORM_PATH" ]; then
show "" "Update platform ..."
cd "$PLATFORM_PATH"
git checkout -q "$PLATFORM_COMMIT"
else
show "" "Download platform ..."
git clone "$PLATFORM_REPO" "$PLATFORM_PATH"
if [ ! "0" = "$?" ]; then
show "${fore[red]}" "Clone repo [$PLATFORM_REPO] failed, please try again."
if [ -d "$PLATFORM_PATH" ]; then
show "${fore[yellow]}" "Delete [$PLATFORM_PATH] first."
fi
exit 1
fi
cd "$PLATFORM_PATH"
git checkout -q "$PLATFORM_COMMIT"
fi
if [ -f "$PLATFORM_PATH/platform_prepare.sh" ]; then
show "" "Run [$PLATFORM_PATH/platform_prepare.sh]."
cd "$PLATFORM_PATH"
./platform_prepare.sh $PLATFORM_CHIP
fi
}
function download_platform_by_name()
{
PLATFORM_NAME=$1
PLATFORM_CHIP=$2
PLATFORMS_DIR=$OPEN_SDK_ROOT/platform
PLATFORM_YAML=$PLATFORMS_DIR/platform_config.yaml
PLATFORM_INFO=$(cat $PLATFORM_YAML | awk "/^- name: $PLATFORM_NAME[[:space:]]*$/{flag=1; next} /^- name:.*$/{flag=0} flag")
PLATFORM_REPO=$(echo "$PLATFORM_INFO" | grep -oP '(?<=repo: ).*(?=$)')
PLATFORM_COMMIT=$(echo "$PLATFORM_INFO" | grep -oP '(?<=commit: ).*(?=$)')
assert_non_null "$PLATFORM_NAME" "Can't find the [platform name]."
assert_non_null "$PLATFORM_REPO" "Can't find the [platform repo]."
assert_non_null "$PLATFORM_COMMIT" "Can't find the [platform commit]."
if [ -z $PLATFORM_NAME ] || [ -z $PLATFORM_REPO ] || [ -z $PLATFORM_COMMIT ]; then
exit 1
fi
download_platform PLATFORM_NAME=$PLATFORM_NAME PLATFORM_REPO=$PLATFORM_REPO PLATFORM_COMMIT=$PLATFORM_COMMIT PLATFORM_CHIP=$PLATFORM_CHIP
}
function new_exec()
{
TEMPLATE_NAME=$1
if [ -z "$TEMPLATE_NAME" ]; then
TEMPLATE_NAME="base"
fi
TEMPLATE_PATH=$OPEN_SDK_ROOT/tools/app_template/$TEMPLATE_NAME
if [ ! -d $TEMPLATE_PATH ]; then
NOTE="No template named [$TEMPLATE_NAME] exists."
show "${fore[red]}" "$NOTE"
exit 1
fi
read -p "Input project name: " PROJ_NAME
if [ -z "$PROJ_NAME" ]; then
NOTE="Project name is empty."
show "${fore[yellow]}" "$NOTE"
exit 1
fi
if [ -d $PROJECT_ROOT/$PROJ_NAME ]; then
NOTE="[$PROJ_NAME] already exists, rename new project or delete the directory."
show "${fore[yellow]}" "$NOTE"
exit 1
fi
cp -a $TEMPLATE_PATH $PROJECT_ROOT/$PROJ_NAME
NOTE="You can use [tos menuconfig] to configure the project."
show "${fore[green]}" "$NOTE"
}
function using_config()
{
DOT_CONFIG_DIR=$(dirname $PROJECT_INI)
KCONFIG_CATALOG="CatalogKconfig"
DOT_CONFIG="using.config"
BOARDS_DIR="$OPEN_SDK_ROOT/boards"
mkdir -p ${DOT_CONFIG_DIR}
cd ${DOT_CONFIG_DIR}
python3 $KCONFIG_TOOLS/set_catalog_config.py -b $BOARDS_DIR -s $OPEN_SDK_ROOT/src -a $PROJECT_ROOT -o $KCONFIG_CATALOG
if [ ! -f $DOT_CONFIG ]; then
APP_DEFAULT_CONFIG="$KCONFIG_TOOLS/app_default.config"
if [ -f "$PROJECT_ROOT/app_default.config" ]; then
APP_DEFAULT_CONFIG="$PROJECT_ROOT/app_default.config"
fi
python3 $KCONFIG_TOOLS/defconfig.py --kconfig "${KCONFIG_CATALOG}" --dconfig "${DOT_CONFIG}" "${APP_DEFAULT_CONFIG}"
fi
cd -
}
function build_exec()
{
PROJECT_FILE="$PROJECT_ROOT/CMakeLists.txt"
if [ ! -f "$PROJECT_FILE" ]; then
NOTE="Can't found [CMakeLists.txt]."
show "${fore[red]}" "$NOTE"
return 1
fi
using_config
check_ini
check_base_tool
check_submodules
PROJ=$(cat $PROJECT_INI | grep -oP '(?<=CONFIG_PROJECT_NAME=").*(?="$)')
if [ -z "$PROJ" ]; then
NOTE="Can't found [CONFIG_PROJECT_NAME] in $PROJECT_INI."
show "${fore[red]}" "$NOTE"
return 1
fi
PROJECT_PLATFORM=$(cat $PROJECT_INI | grep -oP '(?<=CONFIG_PLATFORM_CHOICE=").*(?="$)')
if [ -z "$PROJECT_PLATFORM" ]; then
NOTE="Can't found [CONFIG_PLATFORM_CHOICE] in $PROJECT_INI."
show "${fore[red]}" "$NOTE"
return 1
fi
PROJECT_FRAMEWORK=$(cat $PROJECT_INI | grep -oP '(?<=CONFIG_FRAMEWORK_CHOICE=").*(?="$)')
if [ -z "$PROJECT_PLATFORM" ]; then
NOTE="Can't found [PROJECT_FRAMEWORK] in $PROJECT_INI."
show "${fore[red]}" "$NOTE"
return 1
fi
PROJECT_CHIP=$(cat $PROJECT_INI | grep -oP '(?<=CONFIG_CHIP_CHOICE=").*(?="$)')
if [ "$PROJECT_FRAMEWORK" = "arduino" ]; then
check_arduino
fi
PLATFORM_PATH=$OPEN_SDK_ROOT/platform/$PROJECT_PLATFORM
if [ ! -d "$PLATFORM_PATH" ]; then
download_platform_by_name $PROJECT_PLATFORM $PROJECT_CHIP
if [ "0" != "$?" ]; then
NOTE="Download platform [$PROJECT_PLATFORM] failed."
show "${fore[red]}" "$NOTE"
return 1
fi
fi
mkdir -p $PROJECT_ROOT/.build
cd $PROJECT_ROOT/.build
if [ -f "$PLATFORM_PATH/build_setup.sh" ]; then
$PLATFORM_PATH/build_setup.sh "${PROJ}" "${PROJECT_PLATFORM}" "${PROJECT_FRAMEWORK}" "${PROJECT_CHIP}"
fi
cmake -G Ninja $CMAKE_VERBOSE $OPEN_SDK_ROOT -DTOS_PROJECT_NAME=$PROJ -DTOS_PROJECT_ROOT=$PROJECT_ROOT -DTOS_PROJECT_PLATFORM=$PROJECT_PLATFORM -DTOS_FRAMEWORK=$PROJECT_FRAMEWORK -DTOS_PROJECT_CHIP=$PROJECT_CHIP
ninja example $VERBOSE
if [ "0" != "$?" ]; then
return 1
fi
if [ -f "$PLATFORM_PATH/build_hock.sh" ]; then
$PLATFORM_PATH/build_hock.sh "${PROJ}" "${PROJECT_PLATFORM}" "${PROJECT_FRAMEWORK}" "${PROJECT_CHIP}"
fi
cd - > /dev/null
return 0
}
function clean_exec()
{
if [ ! -f "$PROJECT_ROOT/.build/build.ninja" ]; then
return 0
fi
cd $PROJECT_ROOT/.build
ninja clean_all
NOTE="Clean success."
show "${fore[green]}" "$NOTE"
}
function fullclean_exec()
{
clean_exec
rm -rf $PROJECT_ROOT/.build
NOTE="Fullclean success."
show "${fore[green]}" "$NOTE"
}
function menuconfig_exec()
{
PROJECT_FILE="$PROJECT_ROOT/CMakeLists.txt"
if [ ! -f "$PROJECT_FILE" ]; then
NOTE="Can't found [CMakeLists.txt]."
show "${fore[red]}" "$NOTE"
return 1
fi
using_config
DOT_CONFIG_DIR="$PROJECT_ROOT/.build/cache"
KCONFIG_CATALOG="CatalogKconfig"
DOT_CONFIG="using.config"
CMAKE_CONFIG="using.cmake"
HEADER_DIR="$PROJECT_ROOT/.build/include"
HEADER_FILE="tuya_kconfig.h"
HEADER_IN_PATH="${KCONFIG_TOOLS}/config.h.in"
APP_DEFAULT_CONFIG="$PROJECT_ROOT/app_default.config"
BOARDS_DIR="$OPEN_SDK_ROOT/boards"
mkdir -p $DOT_CONFIG_DIR
cd $DOT_CONFIG_DIR
bash ${KCONFIG_TOOLS}/run_menuconfig.sh "${KCONFIG_CATALOG}" "$DOT_CONFIG"
python3 ${KCONFIG_TOOLS}/conf2cmake.py -c "${DOT_CONFIG_DIR}/${DOT_CONFIG}" -o "${CMAKE_CONFIG}"
mkdir -p ${HEADER_DIR}
cd ${HEADER_DIR}
python3 ${KCONFIG_TOOLS}/conf2h.py -c "${DOT_CONFIG_DIR}/${DOT_CONFIG}" -o "${HEADER_FILE}" -i "${HEADER_IN_PATH}"
cd - > /dev/null
}
function savedef_exec()
{
DOT_CONFIG_DIR="$PROJECT_ROOT/.build/cache"
KCONFIG_CATALOG="CatalogKconfig"
DOT_CONFIG="using.config"
APP_DEFAULT_CONFIG="$PROJECT_ROOT/app_default.config"
BOARDS_DIR="$OPEN_SDK_ROOT/boards"
mkdir -p $DOT_CONFIG_DIR
cd $DOT_CONFIG_DIR
if [ ! -f "$DOT_CONFIG" ]; then
NOTE="Warning: No file [$DOT_CONFIG]."
show "${fore[yellow]}" "$NOTE"
fi
python3 $KCONFIG_TOOLS/set_catalog_config.py -b $BOARDS_DIR -s $OPEN_SDK_ROOT/src -a $PROJECT_ROOT -o $KCONFIG_CATALOG
python3 $KCONFIG_TOOLS/savedefconfig.py --kconfig "${KCONFIG_CATALOG}" --out "${APP_DEFAULT_CONFIG}" --dconfig "${DOT_CONFIG}"
cd - > /dev/null
}
function config_choice_exec()
{
PROJECT_FILE="$PROJECT_ROOT/CMakeLists.txt"
if [ ! -f "$PROJECT_FILE" ]; then
NOTE="Can't found [CMakeLists.txt]."
show "${fore[red]}" "$NOTE"
return 1
fi
APP_DEFAULT_CONFIG="$PROJECT_ROOT/app_default.config"
CONFIG_DIR="$PROJECT_ROOT/config"
CONFIG_CHOICE=$(ls "$CONFIG_DIR" | bash $LISTMENU "Configs" 20 60 13)
cp "$CONFIG_DIR/$CONFIG_CHOICE" "$APP_DEFAULT_CONFIG"
}
function set_example_exec()
{
NOW_PLATFORM_FILE=$OPEN_SDK_ROOT/.set_example
NOW_PLATFORM="None"
if [ -f $NOW_PLATFORM_FILE ]; then
NOW_PLATFORM=`cat $NOW_PLATFORM_FILE`
fi
show "${fore[green]}" "Now used: $NOW_PLATFORM"
PLATFORMS_DIR=$OPEN_SDK_ROOT/platform
PLATFORM_YAML=$PLATFORMS_DIR/platform_config.yaml
PLATFORM_NAMES=$(cat $PLATFORM_YAML | grep -oP '(?<=^- name: ).*(?=$)')
PLATFORM_NAME=$(echo "$PLATFORM_NAMES" | bash $LISTMENU "Platforms" 20 60 13)
if [ -z "$PLATFORM_NAME" ]; then
assert_non_null "$PLATFORM_NAME" "Can't find the [platform name]."
fi
PLATFORM_PATH="${PLATFORMS_DIR}/${PLATFORM_NAME}"
if [ ! -d "$PLATFORM_PATH" ]; then
download_platform_by_name $PLATFORM_NAME
if [ "0" != "$?" ]; then
NOTE="Download platform [$PLATFORM_NAME] failed."
show "${fore[red]}" "$NOTE"
exit 1
fi
fi
ROOT_EXAMPLE_DIR=$OPEN_SDK_ROOT/examples
PLATFORM_EXAMPLE_DIR=$PLATFORM_PATH/examples
rm -rf $ROOT_EXAMPLE_DIR
if [ ! -d "$PLATFORM_EXAMPLE_DIR" ]; then
NOTE="[$PLATFORM_NAME] has no examples."
show "${fore[red]}" "$NOTE"
exit 1
fi
ln -s $PLATFORM_EXAMPLE_DIR $ROOT_EXAMPLE_DIR
NOTE="
Set [$PLATFORM_NAME] example success.
Please check $ROOT_EXAMPLE_DIR
"
show "${fore[green]}" "$NOTE"
echo $PLATFORM_NAME > $NOW_PLATFORM_FILE
}
function new_platform_exec()
{
PLATFORM_NAME=$1
if [ -z "$PLATFORM_NAME" ]; then
NOTE="new_platform command need an argument [PLATFORM_NAME]"
show "${fore[yellow]}" "$NOTE"
exit 1
fi
${OPEN_SDK_ROOT}/tools/kernel_porting.sh ${PLATFORM_NAME}
}
function flash_exec()
{
DOWNLOAD_SCRIPT=${OPEN_SDK_ROOT}/tools/tyutool/download_tyutool.sh
TYUTOOL_DIR="${OPEN_SDK_ROOT}/tools/tyutool"
TYUTOOL="${TYUTOOL_DIR}/tyutool_cli"
${DOWNLOAD_SCRIPT} ${TYUTOOL_DIR}
if [ "$?" != "0" ]; then
show "${fore[red]}" "Error: Download tyutool failed."
exit 1
fi
shift
show "" "tyutool params: $*"
if [ -n "$*" ]; then
${TYUTOOL} $@
exit 0
fi
check_ini
. $PROJECT_ROOT/.build/cache/using.config
DEVICE=$CONFIG_PLATFORM_CHOICE
if [ -n "$CONFIG_CHIP_CHOICE" ]; then
DEVICE=$CONFIG_CHIP_CHOICE
fi
BIN_FILE=$PROJECT_ROOT/.build/bin/${CONFIG_PROJECT_NAME}_QIO_${CONFIG_PROJECT_VERSION}.bin
${TYUTOOL} write -d ${DEVICE} -f ${BIN_FILE}
}
function upgrade_exec()
{
show "" "Upgrading framework ..."
cd $OPEN_SDK_ROOT
git pull
if [ "$?" = "0" ]; then
show "${fore[green]}" "Framework success."
else
show "${fore[red]}" "Framework failed."
fi
show "" "Upgrading platform ..."
PLATFORMS_DIR=$OPEN_SDK_ROOT/platform
PLATFORM_YAML=$PLATFORMS_DIR/platform_config.yaml
PLATFORM_NAMES=$(cat $PLATFORM_YAML | grep -oP '(?<=^- name: ).*(?=$)')
for NAME in $PLATFORM_NAMES; do
PLATFORM_INFO=$(cat $PLATFORM_YAML | awk "/^- name: $NAME[[:space:]]*$/{flag=1; next} /^- name:.*$/{flag=0} flag")
PLATFORM_REPO=$(echo "$PLATFORM_INFO" | grep -oP '(?<=repo: ).*(?=$)')
PLATFORM_BRANCH=$(echo "$PLATFORM_INFO" | grep -oP '(?<=branch: ).*(?=$)')
PLATFORM_COMMIT=$(echo "$PLATFORM_INFO" | grep -oP '(?<=commit: ).*(?=$)')
PLATFORM_PATH="${PLATFORMS_DIR}/${NAME}"
if [ ! -d "$PLATFORM_PATH" ]; then
continue
fi
cd "$PLATFORM_PATH"
git checkout -q "$PLATFORM_BRANCH"
git pull
git checkout -q "$PLATFORM_COMMIT"
if [ "$?" = "0" ]; then
show "${fore[green]}" "$NAME success."
else
show "${fore[red]}" "$NAME failed."
fi
done
}
function help_exec()
{
NOTE="
Usage: $OPEN_BUILD COMMAND [ARGS]...
Commands:
version - Show TOS verson
check - Check command and version
new - New project [base(default) / auduino]
build - Build project
clean - Clean project
fullclean - Clean project and delete build path
menuconfig - Configuration project features
savedef - Saves minimal configuration file (app_default.config)
config_choice - Select the file in the config directory instead of app_defalut.config
set_example - Set examples from platform
new_platform - New platform [platform_name]
upgrade - Upgrade framework and platforms
help - Help information
"
show "" "$NOTE"
}
# ==============================================================================
# executing define finished
# ------------------------------------------------------------------------------
function _save_platform_config_exec()
{
PLATFORMS_DIR=$OPEN_SDK_ROOT/platform
PLATFORM_YAML=$PLATFORMS_DIR/platform_config.yaml
PLATFORM_NAMES=$(cat $PLATFORM_YAML | grep -oP '(?<=^- name: ).*(?=$)')
for NAME in $PLATFORM_NAMES; do
PLATFORM_INFO=$(cat $PLATFORM_YAML | awk "/^- name: $NAME[[:space:]]*$/{flag=1; next} /^- name:.*$/{flag=0} flag")
PLATFORM_REPO=$(echo "$PLATFORM_INFO" | grep -oP '(?<=repo: ).*(?=$)')
PLATFORM_BRANCH=$(echo "$PLATFORM_INFO" | grep -oP '(?<=branch: ).*(?=$)')
PLATFORM_PATH="${PLATFORMS_DIR}/${NAME}"
if [ ! -d "$PLATFORM_PATH" ]; then
show "" "Download platform ${NAME} ..."
git clone "$PLATFORM_REPO" "$PLATFORM_PATH"
fi
if [ ! -d "$PLATFORM_PATH" ]; then
show "${fore[red]}" "Download platform ${NAME} failed."
continue
fi
cd "$PLATFORM_PATH"
git checkout -q "$PLATFORM_BRANCH"
git pull
COMMIT=$(git log -1 --format="%H")
show "" "$NAME: $COMMIT"
sed -i "/^- name: $NAME/,/^ commit:/s/^ commit: .*/ commit: $COMMIT/" "$PLATFORM_YAML"
done
}
function _build_all()
{
if [ ! -d "$1" ]; then
NOTE="Path not exists: [$1]"
show "${fore[yellow]}" "$NOTE"
exit 1
fi
PROJECTS_DIR=$(cd "$1" && pwd)
MAX_DEEP=$(expr $2 - 1)
PROJECT_FILE="$PROJECTS_DIR/CMakeLists.txt"
if [ -f "$PROJECT_FILE" ]; then
PROJECT_ROOT=$PROJECTS_DIR
PROJECT_INI=$PROJECT_ROOT/.build/cache/using.config
PROJECT_NAME=$(basename $PROJECT_ROOT)
show "" "Building [$PROJECT_NAME] ..."
build_exec > /dev/null 2>&1
if [ "0" = "$?" ]; then
BUILD_INFORMATION+="\033[32mBuild Success [${PROJECT_NAME}].\033[0m\n"
else
BUILD_INFORMATION+="\033[31mBuild Failed [${PROJECT_NAME}].\033[0m\n"
fi
show "" "Cleaning [$PROJECT_NAME] ..."
fullclean_exec > /dev/null
elif [ "$MAX_DEEP" -gt "0" ]; then
SUB_DIRS=$(ls -d $PROJECTS_DIR/*/)
for dir in $SUB_DIRS; do
d=$(cd "$dir" && pwd)
_build_all "$d" "$MAX_DEEP"
done
fi
MAX_DEEP="$2"
}
function _check_example_build_exec()
{
ROOT_EXAMPLE_DIR=$OPEN_SDK_ROOT/examples
BUILD_INFORMATION="\n----------Build All Examples Result----------\n"
_build_all "$ROOT_EXAMPLE_DIR" "4"
printf "${BUILD_INFORMATION}"
}
function dev_exec()
{
CMD=$1
if [ "$CMD" = "spc" ]; then
_save_platform_config_exec
elif [ "$CMD" = "ceb" ]; then
_check_example_build_exec
else
NOTE="
Usage: $OPEN_BUILD dev COMMAND [ARGS]...
Commands:
scp - Save platforms config
ceb - Check examples build
"
show "" "$NOTE"
fi
}
case $1 in
version)
version_exec
;;
check)
check_exec
;;
new)
new_exec $2
;;
build)
build_exec
;;
clean)
clean_exec
;;
fullclean)
fullclean_exec
;;
menuconfig)
menuconfig_exec
;;
savedef)
savedef_exec
;;
config_choice)
config_choice_exec
;;
set_example)
set_example_exec
;;
new_platform)
new_platform_exec $2
;;
flash)
flash_exec $@
;;
upgrade)
upgrade_exec $@
;;
help)
help_exec
;;
dev)
dev_exec $2
;;
*)
show "${fore[yellow]}" "Unknow command [$1]"
help_exec
;;
esac
exit 0