Browse Source

enable multiselect in the "Cross Toolchain Template Menu" to support batched builds of cross toolchains (v0.8.0)

optimization of temp path handling to support the execution of multiple instances of s3
correct path setting in config builder function
fix library version detection
beautifying details on some menus
pull/8/head
WXbet 5 years ago
parent
commit
34709f23d9
  1. 74
      support/functions/_plugin_update_toolchain

74
support/functions/_plugin_update_toolchain

@ -1,11 +1,11 @@
#!/bin/bash
#simplebuild_plugin tcupdate (s3.TUP) 0.7.0
#simplebuild_plugin tcupdate (s3.TUP) 0.8.0
tcupdate(){
clear && _check_bin;
pversion="0.7.0";
pversion="0.8.0";
pname="s3.TUP";
pdesc="Plugin $pname v$pversion";
configname="$configdir/plugin_update_toolchain.config";
@ -39,7 +39,6 @@ tcupdate(){
#check config
_check_config;
IFS="#";
if [ "$1" == "-c" ] || [ "$1" == "--create" ];then
_create_tc;
bye;
@ -51,14 +50,16 @@ tcupdate(){
for i in "${INST_TCLIST[@]}";do
if [ ! "$i" == "native" ];then
source "$tccfgdir/$i";
MENU_OPTIONS+="$_toolchainname#$_description#toolchain folder:"$tcdir/$i" | config file:"$tccfgdir/$i"#";
MENU_OPTIONS+=("$_toolchainname" "$_description" "toolchain folder:$tcdir/$i | config file:$tccfgdir/$i");
counter;
fi;
done;
fi;
[ $COUNT -eq 0 ] && MENU_OPTIONS+="#no toolchains found#no toolchains found#" && counter;
[ $COUNT -eq 0 ] && MENU_OPTIONS+=("" "no toolchains found" "no toolchains found") && counter;
fi;
out=$("$gui" "$st_" "$bt_" "$title_ - $pdesc" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Update" "--cancel-label" "Create" "--help-button" "--help-label" "Exit" "--extra-button" "--extra-label" "Copy" "--title" "-[ Toolchain Menu ]-" --menu "\nSelect one of the installed tool chains that you want to update:\n " "${COUNT+10}" 0 0 ${MENU_OPTIONS});
out=$("$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Update" "--cancel-label" "Create" "--help-button" "--help-label" "Exit" "--extra-button" "--extra-label" "Copy" "--title" "-[ Toolchain Menu ]-" \
--menu "\nSelect one of the installed tool chains that you want to update:\n " \
"${COUNT+10}" 0 0 "${MENU_OPTIONS[@]}");
ret="$?"
tc=$(echo "$out" | awk '{printf $1}');
@ -112,10 +113,9 @@ tcupdate(){
cd "$tcdir/$tc/$_sysroot"
fi;
prefixdir="$PWD"
pkg=$(find * | grep -m1 "/pkgconfig") && pkgdir="$prefixdir/$pkg";
pkg=$(find * | grep -m1 "/pkgconfig") && pkgdir="$prefixdir/$pkg" || pkgdir="$prefixdir";
#build menu items from config file
IFS=$OIFS;
unset MENU_OPTIONS;COUNT=0;unset libs;
for i in "${LIBS[@]}"
do
@ -140,9 +140,9 @@ tcupdate(){
lib=("$libkey" "$libname" "$libversion" "$libversioncheck" "$libcheck" "$libversioncurrent" "$liburl" "(${libtasks[*]@Q})");
libs+=("(${lib[*]@Q})");
done;
[ $COUNT -eq 0 ] && MENU_OPTIONS+="#no libraries found#no libraries found#" && counter;
[ $COUNT -eq 0 ] && MENU_OPTIONS+=("" "no libraries found" "no libraries found") && counter;
opts=$("$gui" "--item-help" "--help-tags" "$st_" "$bt_" "$title_ - $pdesc" "--default-item" "$3" "--ok-label" "Start" "--help-button" "--help-label" "Info" "--cancel-label" "$([ "$tc_menu" == "1" ] && echo "Back" || echo "Exit")" --title "-[ Library Update Menu - $tc ]-" "$cl_"\
opts=$("$gui" "--item-help" "--help-tags" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--default-item" "$3" "--ok-label" "Start" "--help-button" "--help-label" "Info" "--cancel-label" "$([ "$tc_menu" == "1" ] && echo "Back" || echo "Exit")" "--title" "-[ Library Update Menu - \Z2$tc\Zn ]-" "$cl_"\
"\nSelect all libraries to update in toolchain's SYSROOT folder:\n$prefixdir\n\n library version NEW CURRENT" \
"${COUNT+12}" 70 0 "${MENU_OPTIONS[@]}");
@ -159,19 +159,21 @@ tcupdate(){
bcd=$(cat "$configname" | grep ""$libkey"_tasks");
txt=$(echo -e "Toolchain: $tcdir/$tc\nCompiler: $compilername\nSysroot: $sr\nPrefix: $prefixdir\n$sp\n\nLibrary configuration:\n$txt\n\nBuild command:\n$(_replace_tokens "$(_tidy_tasks "$bcd" "$libkey")")");
tempfile=$(mktemp) && echo -e "$txt" > "$tempfile";
"$gui" "$st_" "$nc_" "$bt_" "$title_ - $pdesc" "--textbox" "$tempfile" 30 80;
"$gui" "$st_" "$nc_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--textbox" "$tempfile" 30 80;
rm "$tempfile" 2>/dev/null;
tcupdate $tc $tc_menu $libkey;
fi;
#BUILD section
ts=$(date +%F)_$(date +%T);
tmpdir="/tmp/lib_source/$ts";
icount=$(echo $opts | wc -w);i=0;
for o in $opts;do
unset buildtasks;
for l in "${libs[@]}";do
declare -a lib="${l[*]}"; #populate libs array element
[ ! "$o" == "${lib[0]}" ] && continue || ((i++));
logfile="$ldir/$(date +%F)_$(date +%T)_update_toolchain_"$_toolchainname"_"${lib[1]}"_"${lib[2]}".log"
logfile="$ldir/"$ts"_update_toolchain_"$_toolchainname"_"${lib[1]}"_"${lib[2]}".log"
#generate build command list
declare -a libtasks="${lib[7]}"; #populate tasks array element
@ -179,9 +181,10 @@ tcupdate(){
task=$(_replace_tokens "$task"); #replace tokens
buildtasks+=("$task");
done
_build "($i/$icount) ${lib[1]}" $(_extract $(_dl "${lib[6]}")) "$logfile" "${buildtasks[@]}";
_build "($i/$icount) $tc: library ${lib[1]} ${lib[2]}" $(_extract $(_dl "${lib[6]}" "${lib[1]} ${lib[2]}") "$tmpdir") "$logfile" "${buildtasks[@]}";
done;
done;
[ -d "$tmpdir" ] && rm -r "$tmpdir";
#Reopen update menu
if [ ${#opts} -gt 0 ];then
@ -214,23 +217,24 @@ _create_tc(){
desc=$(sed -n -e '/#toolchain template/ s/.*\: *//p' $t);
[ ! "$desc" ] && desc="no description available";
[ -d "$tcdir/$t" ] && [ -f "$tccfgdir/$t" ] && color="\Z1" || color="";
MENU_OPTIONS+="$t#$color$desc\Zn#template filename:"$cttpldir/$t"#";
MENU_OPTIONS+=("$t" "$color$desc\Zn" "off" "template filename:$cttpldir/$t");counter;
counter;
done;
fi;
[ $COUNT -eq 0 ] && MENU_OPTIONS+="#no templates found#no templates found#" && counter;
[ $COUNT -eq 0 ] && MENU_OPTIONS+=("" "no templates found" "no templates found") && counter;
opts=$("$gui" "$st_" "$bt_" "$title_ - $pdesc" "--colors" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Start" "--cancel-label" "Setup" "--help-button" "--help-label" "$([ $tc_menu ] && echo "Back" || echo "Exit")" "--title" "-[ Cross Toolchain Template Menu ]-" \
--menu "\nSelect on of the templates to create the cross toolchain you want:\n\n\Z1NOTE: If you create a cross toolchain from a template with a red colored description, an existing one with the same name will be replaced without asking!\Zn" \
"${COUNT+11}" 0 0 ${MENU_OPTIONS});
opts=$("$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Start" "--cancel-label" "Setup" "--help-button" "--help-label" "$([ $tc_menu ] && echo "Back" || echo "Exit")" "--title" "-[ Cross Toolchain Template Menu ]-" "$cl_"\
"\nSelect on of the templates to create the cross toolchain you want:\n\n\Z1NOTE: If you create a cross toolchain from a template with a red colored description, an existing one with the same name will be replaced without asking!\Zn" \
"${COUNT+11}" 0 0 "${MENU_OPTIONS[@]}");
ret="$?"
tpl=$(echo "$opts" | awk '{printf $1}');
case $ret in
0) #Start - Build cross toolchain
if [ -f "$ctsrcdir/ct-ng" ]; then
icount=$(echo $opts | wc -w);i=0;
for tpl in $opts;do
if [ -f "$cttpldir/$tpl" ]; then
#logfile="$ldir/$(date +%F)_$(date +%T)_update_toolchain_crosstoolchain_"$tpl".log"
logfile="$ldir/$(date +%F)_$(date +%T)_update_toolchain_crosstoolchain_"$tpl".log" && ((i++));
#copy template and patching them
cp --no-preserve=mode,ownership -f "$cttpldir/$tpl" "$ctsrcdir/.config";
@ -238,37 +242,41 @@ _create_tc(){
sed -i "s#.*CT_LOCAL_TARBALLS_DIR=.*#CT_LOCAL_TARBALLS_DIR=\"$dldir\"#g" "$ctsrcdir/.config";
#CT_PREFIX_DIR aka folder that contains the final toolchain
sed -i "s#.*CT_PREFIX_DIR=.*#CT_PREFIX_DIR=\"$tcdir/$tpl\"#g" "$ctsrcdir/.config";
#CT_PARALLEL_JOBS
#CT_PARALLEL_JOBS aka parallel build job count
sed -i "s#.*CT_PARALLEL_JOBS=.*#CT_PARALLEL_JOBS=$CTNG_PARALLEL_JOBS#g" "$ctsrcdir/.config";
clear;
#run build
#run build as $CTNG_USER
bcl=$(printf '%s\n' "${CTNG_BUILD_tasks[@]}");
sp=$(printf '%*s' 80 | tr ' ' '=')
echo -e "$sp\nbuild command list for cross toolchain $tpl (executed as user $CTNG_USER):\n$sp\ncd "$ctsrcdir"\n$(_replace_tokens "$bcl")\n$sp";
echo -e "$sp\nbuild ($i/$icount): command list for cross toolchain $tpl (executed as user $CTNG_USER):\n$sp\ncd "$ctsrcdir"\n$(_replace_tokens "$bcl")\n$sp";
sleep 2;
cd "$ctsrcdir";
cmd="${CTNG_BUILD_tasks[@]}";
sudo -u "$CTNG_USER" -H -- sh -c "$(_replace_tokens "$cmd")" 2>&1;
err=$(grep '\[ERROR\]' "$ctsrcdir/build.log" | wc -l)
#save build.log in logs
cp -f "$ctsrcdir/build.log" "$logfile";
if [ ! $err -gt 0 ]; then
#get target from build.log
target=$(sed -n -e '/target = / s/.*\= *//p' "$ctsrcdir/build.log");
#compress toolchain
_compress "$dldir/Toolchain-$tpl.tar.xz" "$tcdir/$tpl" | "$gui" "$st_" --colors --title " -[ Compress cross toolchain $tpl... ]- " "$pb_" "$_lines" "$_cols";
_compress "$dldir/Toolchain-$tpl.tar.xz" "$tcdir/$tpl" | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Compress cross toolchain $tpl... ]- " "$pb_" "$_lines" "$_cols";
#create toolchain.cfg
desc=$(sed -n -e '/#toolchain template/ s/.*\: *//p' "$cttpldir/$tpl");
_create_toolchaincfg "$tcdir/$tpl" "$tpl" "$target" "$desc" "$dldir/Toolchain-$tpl.tar.xz";
else
_paktc_timer;
_paktc_timer 10;
fi;
else
[ "$tpl" == "" ] && echo -e "$r_l $txt_error:$y_l $tc$w_l Template $txt_n_installed""$rs_";
sleep 2;
fi;
done;
else
echo -e "$r_l""CHECK -> crosstool-NG is not setup correctly. Please run 'Setup' from menu!\n""$re_";
_paktc_timer 10;
@ -302,8 +310,8 @@ _create_tc(){
cd "$ctsrcdir";
cmd="${CTNG_SETUP_tasks[@]}";
sudo -u "$CTNG_USER" -H -- sh -c "$(_replace_tokens "$cmd")" 2>&1;
) | tee "$logfile" | "$gui" "$st_" --colors --title " -[ Setup crosstool-NG... ]- " "$pb_" "$_lines" "$_cols";
_paktc_timer;
) | tee "$logfile" | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Setup crosstool-NG... ]- " "$pb_" "$_lines" "$_cols";
_paktc_timer 10;
_create_tc;;
2) #Exit
return;;
@ -324,7 +332,7 @@ _copy(){
#create toolchain.cfg
source "$tccfgdir/$1" && target="${_compiler%?}" && desc="$_description";
_create_toolchaincfg "$tcdir/$1" "$newtc" "$target" "$desc" "$xzfile";
) | "$gui" "$st_" --colors --title " -[ Copy $1 to $newtc ... ]- " "$pb_" "$_lines" "$_cols";
) | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Copy $1 to $newtc ... ]- " "$pb_" "$_lines" "$_cols";
[ -f "$newtccfgfile" ] && echo "$newtc";
};
_build(){
@ -344,7 +352,7 @@ _build(){
sleep 2;
cd "$libsrcdir";
( eval "${tasks[@]}" ) 2>&1 | tee -a "$lf"
) | "$gui" "$st_" --colors --title " -[ Build $desc ... ]- " "$pb_" "$_lines" "$_cols";sleep 2;
) | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Build $desc... ]- " "$pb_" "$_lines" "$_cols";sleep 2;
#build error message
error_on_build=$(grep -cw1 Error "$lf");
@ -359,7 +367,7 @@ _dl(){
[ -d "$dldir/#tmp" ] && rm --recursive --force "$dldir/#tmp"
mkdir --parents "$dldir/#tmp";
cd "$dldir/#tmp";
wget --content-disposition "$1" 2>&1 | stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | "$gui" "$st_" "$bt_" "$title_ - $pdesc" --title " -[ download ]- " --gauge " $txt_loading $fname $txt_wait" 6 74;
wget --content-disposition "$1" 2>&1 | stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ download $2 ]- " --gauge " $txt_loading $txt_wait" 6 74;
if [ $? -eq 0 ];then
fname="$(ls -t | head -n1)"; md5file="$fname.md5";
md5sum "$fname" > "$md5file";
@ -380,7 +388,7 @@ _extract(){
(($#)) || return;
edir=/tmp/lib_source;
edir="$2";
[ -d "$edir" ] && rm -r "$edir";
mkdir --parents "$edir";
@ -410,7 +418,7 @@ _extract(){
cd "$edir";
BEFORE=(.*/ */);
command "${c[@]}" "$i" |"$gui" "$st_" --title " -[ $txt_extracting ]- " "$pb_" 20 74;
command "${c[@]}" "$i" |"$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ $txt_extracting $i ]- " "$pb_" 20 74;
((e = e || $?));
AFTER=(.*/ */);
@ -563,7 +571,7 @@ _create_config(){
ctng_build_tasks=( "(\"./ct-ng build;\")" );
ctng_build_tasks_comment="#build command";
ctng_setup_tasks=( "(\"git clone --progress \"\$CTNG_REPO_URL\" \"@CTNGSOURCE@\";\")" "(\"./bootstrap;\")" "(\"./configure --enable-local;\")" "(\"make;\")" "(\"touch \"@CTNGSOURCE@\.config\";\")" );
ctng_setup_tasks=( "(\"git clone --progress \"\$CTNG_REPO_URL\" \"@CTNGSOURCE@\";\")" "(\"./bootstrap;\")" "(\"./configure --enable-local;\")" "(\"make;\")" "(\"touch \"@CTNGSOURCE@/.config\";\")" );
ctng_setup_tasks_comment="#setup command";
echo '#CROSS toolchain build settings' >"$configname";

Loading…
Cancel
Save