Compare commits

..

No commits in common. "4fc62f65b46071fa90f7930026a7d848bb15e865" and "4b4794e253dc73f28f284159d533903d68784603" have entirely different histories.

7 changed files with 53 additions and 181 deletions

View File

@ -1,8 +1,7 @@
# v2.1.0 # NEXT: v2.1.0
+ **config**: no more `current.config` and `default.config`, just `project.config` + **config**: no more `current.config` and `default.config`, just `project.config`
+ improved version checking + improved version checking
+ `setup.sh` now installs each minor version in separate dicectory + `setup.sh` now installs each minor version in separate dicectory
+ added `bootstrap.sh` which automaticly selects cbuild version specified in project config
# v2.0.2 # v2.0.2
+ new dependency resolution system (see **config** and `example_dependency_configs`) + new dependency resolution system (see **config** and `example_dependency_configs`)

View File

@ -1,85 +0,0 @@
#!/usr/bin/env bash
CBUILD_BOOTSTRAP_VERSION=1.0.0
set -eo pipefail
function version_parse {
local value="$1"
var_name="$2"
IFS_backup="$IFS"
IFS='.'
local v_array=($value)
IFS="$IFS_backup"
eval ${var_name}_version_major=${v_array[0]}
eval ${var_name}_version_minor=${v_array[1]}
eval ${var_name}_version_patch=${v_array[2]}
}
function safeprint {
printf "%s" "$@"
}
function exec_script_line {
local script="$1"
local line_num="$2"
local line_str="$(sed $line_num'!d' $script)"
if [ -z "$line_str" ]; then
echo "script line is empty"
exit 1
fi
eval "$line_str"
}
# parse command line arguments
project_config_path="./project.config"
args=($@)
args_count=${#args[@]}
i=0
function get_next_arg {
i=$((i+1))
safeprint "${args[i]}"
}
while [ $i -lt $args_count ]
do
case "${args[i]}" in
'-v' | '--version')
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
;;
'-c' | '--config')
project_config_path="$(get_next_arg)"
;;
'-n' | '--new-project')
echo "enter project cbuild version (example: 2.1.0)"
read -r CBUILD_VERSION
;;
*)
;;
esac
i=$((i+1))
done
# read version from project config if not specified
if [ -z "$CBUILD_VERSION" ]; then
exec_script_line "$project_config_path" 2
fi
version_parse "$CBUILD_VERSION"
cbuild_ommand="cbuild${_version_major}.${_version_minor} $@"
LOG_FILE="$(realpath cbuild.log)"
set +eo pipefail
# enable logging stdout and stderr to file
$cbuild_ommand 2>&1 | tee "$LOG_FILE"
# log file can be deleted by clean task
if [ -f "$LOG_FILE" ]; then
# remove terminal escape codes
sed -e 's/[^[:blank:][:print:]]//g' \
-e 's/\[0;[0-9][0-9]m//g' \
-e 's/\[0;[0-9]m//g' \
-e 's/\[[0-9][0-9]m//g' \
-e 's/\[[0-9]m//g' \
-e 's/ H //g' \
-e 's/\[3gH //g' \
-i "$LOG_FILE"
fi

View File

@ -1,29 +1,27 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INSTALLED_CBUILD_VERSION=2.1.0
# set \t size to 4 spaces
tabs 4 tabs 4
# exit on errors # exit on errors
set -eo pipefail set -eo pipefail
INSTALLED_CBUILD_VERSION=2.1.0
function version_parse { function version_parse {
local value="$1" local v="$1"
var_name="$2"
IFS_backup="$IFS" IFS_backup="$IFS"
IFS='.' IFS='.'
local v_array=($value) v_array=($v)
IFS="$IFS_backup" IFS="$IFS_backup"
eval ${var_name}_version_major=${v_array[0]} version_major=${v_array[0]}
eval ${var_name}_version_minor=${v_array[1]} version_minor=${v_array[1]}
eval ${var_name}_version_patch=${v_array[2]} version_patch=${v_array[2]}
} }
version_parse $INSTALLED_CBUILD_VERSION installed version_parse $INSTALLED_CBUILD_VERSION
if [ -z "$CBUILD_INSTALL_DIR" ]; then if [ -z "$CBUILD_INSTALL_DIR" ]; then
CBUILD_INSTALL_DIR="$HOME/.local/share/cbuild/${installed_version_major}.${installed_version_minor}" CBUILD_INSTALL_DIR="~/.local/share/cbuild/${version_major}.${version_minor}"
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${installed_version_major}.${installed_version_minor}" CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${version_major}.${version_minor}"
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
echo "CBUILD_INSTALL_DIR '$CBUILD_INSTALL_DIR' doesn't exist" echo "CBUILD_INSTALL_DIR '$CBUILD_INSTALL_DIR' doesn't exist"
exit 1 exit 1
@ -54,7 +52,6 @@ function print_help {
myprint " -c, --config FILE Set project config file path (default=./project.config)" myprint " -c, --config FILE Set project config file path (default=./project.config)"
} }
# parse command line arguments
project_config_path="./project.config" project_config_path="./project.config"
args=($@) args=($@)
args_count=${#args[@]} args_count=${#args[@]}
@ -77,11 +74,14 @@ do
exit 0 exit 0
;; ;;
'-v' | '--version') '-v' | '--version')
myprint "cbuild v$INSTALLED_CBUILD_VERSION" myprint $INSTALLED_CBUILD_VERSION
exit 0 exit 0
;; ;;
'-c' | '--config') '-c' | '--config')
project_config_path="$(get_next_arg)" i=$((i+1))
project_config_path="${args[i]}"
myprint "<$project_config_path>"
exit 0
;; ;;
'-n' | '--new-project') '-n' | '--new-project')
new_project_dir="$(get_next_arg)" new_project_dir="$(get_next_arg)"

View File

@ -4,6 +4,14 @@ include cbuild/myprint.sh
include cbuild/functions.sh include cbuild/functions.sh
include cbuild/detect_os.sh include cbuild/detect_os.sh
function myprint_quiet {
local quiet=$1
local text="$2"
if [ "$quiet" != true ]; then
myprint "$text"
fi
}
function load_config { function load_config {
local project_config_path="$1" local project_config_path="$1"
TASK="$2" TASK="$2"
@ -36,8 +44,14 @@ function load_config {
myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION" myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
# checking versions # checking versions
version_parse $INSTALLED_CBUILD_VERSION installed version_parse $INSTALLED_CBUILD_VERSION
version_parse $CBUILD_VERSION config installed_version_major=$version_major
installed_version_minor=$version_minor
installed_version_patch=$version_patch
version_parse $CBUILD_VERSION
config_version_major=$version_major
config_version_minor=$version_minor
config_version_patch=$version_patch
if [ "$installed_version_major.$installed_version_minor" != "$config_version_major.$config_version_minor" ]; then if [ "$installed_version_major.$installed_version_minor" != "$config_version_major.$config_version_minor" ]; then
error "config was created for cbuild$config_version_major.$config_version_minor, but loaded whith cbuild$installed_version_major.$installed_version_minor which is incompatible" error "config was created for cbuild$config_version_major.$config_version_minor, but loaded whith cbuild$installed_version_major.$installed_version_minor which is incompatible"
fi fi

View File

@ -8,9 +8,6 @@ function exec_script_line {
local quiet=$3 local quiet=$3
myprint_quiet $quiet "${BLUE}reading line $line_num from $script" myprint_quiet $quiet "${BLUE}reading line $line_num from $script"
local line_str="$(sed $line_num'!d' $script)" local line_str="$(sed $line_num'!d' $script)"
if [ -z "$line_str" ]; then
error "script line is empty"
fi
myprint_quiet $quiet "$line_str" myprint_quiet $quiet "$line_str"
eval "$line_str" eval "$line_str"
} }

View File

@ -21,14 +21,6 @@ function myprint {
printf "${GRAY}$@${GRAY}\n" printf "${GRAY}$@${GRAY}\n"
} }
function myprint_quiet {
local quiet=$1
local text="$2"
if [ "$quiet" != true ]; then
myprint "$text"
fi
}
# print message and exit # print message and exit
function error { function error {
myprint "${RED}$@" myprint "${RED}$@"
@ -44,16 +36,6 @@ function ask_yn {
return $([[ "$answ" = [Yy] ]]); return $([[ "$answ" = [Yy] ]]);
} }
function char_multiply {
local character="$1"
local length="$2"
i=0
while [ $i -lt $length ]; do
printf $character
i=$((i+1))
done
}
# prints horizontal line occupying whole terminal row # prints horizontal line occupying whole terminal row
# https://en.wikipedia.org/wiki/Box-drawing_characters # https://en.wikipedia.org/wiki/Box-drawing_characters
function print_hline { function print_hline {
@ -65,10 +47,7 @@ function print_hline {
if [ -z "$character" ]; then if [ -z "$character" ]; then
character="-"; character="-";
fi fi
local term_width=$(tput cols) printf "${color}%.s${character}" $(seq 2 $(tput cols))
local line_length=$((term_width - 1))
printf "${color}"
char_multiply "$character" $line_length
printf "${GRAY}\n" printf "${GRAY}\n"
} }
@ -86,11 +65,10 @@ function print_header {
local term_width=$(tput cols) local term_width=$(tput cols)
local label_length=${#label} local label_length=${#label}
local line_characters_count=$((term_width - label_length - 2)) local line_characters_count=$((term_width - label_length - 2))
local left_line_length=$(( line_characters_count / 2 )) local letf_line_length=$(( line_characters_count / 2 ))
local right_line_length=$(( left_line_length - 1 + line_characters_count % 2 )) local right_line_length=$(( letf_line_length + line_characters_count % 2 ))
printf "${color}" printf "${color}%.s${character}" $(seq 1 $letf_line_length)
char_multiply "$character" $left_line_length printf "[${label}]"
printf "[${label}]${color}" printf "${color}%.s${character}" $(seq 2 $right_line_length)
char_multiply "$character" $right_line_length
printf "${GRAY}\n" printf "${GRAY}\n"
} }

View File

@ -1,49 +1,33 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# USAGE: ./setup.sh install cbuild to /usr/local # USAGE: ./setup.sh install cbuild to /usr/local
# ./setup.sh --local install cbuild to $HOME/.local # ./setup.sh --local install cbuild to ~/.local
# exit on errors # exit on errors
set -xeo pipefail set -xeo pipefail
CBUILD_VERSION=2.1.0 CBUILD_VERSION=2.1.0
function version_parse { function version_parse {
local value="$1" local v="$1"
var_name="$2"
IFS_backup="$IFS" IFS_backup="$IFS"
IFS='.' IFS='.'
local v_array=($value) v_array=($v)
IFS="$IFS_backup" IFS="$IFS_backup"
eval ${var_name}_version_major=${v_array[0]} version_major=${v_array[0]}
eval ${var_name}_version_minor=${v_array[1]} version_minor=${v_array[1]}
eval ${var_name}_version_patch=${v_array[2]} version_patch=${v_array[2]}
} }
function exec_script_line { version_parse $CBUILD_VERSION
local script="$1"
local line_num="$2"
local line_str="$(sed $line_num'!d' $script)"
if [ -z "$line_str" ]; then
echo "script line is empty"
exit 1
fi
eval "$line_str"
}
version_parse $CBUILD_VERSION local
if [ -z "$CBUILD_INSTALL_DIR" ]; then if [ -z "$CBUILD_INSTALL_DIR" ]; then
if [ "$1" = "--local" ]; then if [ "$1" = "--local" ]; then
if [ ! -d "$HOME" ]; then CBUILD_INSTALL_DIR="~/.local/share/cbuild/${version_major}.${version_minor}"
echo "ERROR: home directory '$HOME' doesn't exist" CBUILD_BIN_DIR="~/.local/bin"
exit 1 mkdir -p "~/.local"
fi mkdir -p "~/.local/share"
CBUILD_INSTALL_DIR="$HOME/.local/share/cbuild/${local_version_major}.${local_version_minor}" mkdir -p "~/.local/share/cbuild"
CBUILD_BIN_DIR="$HOME/.local/bin" mkdir -p "~/.local/bin"
mkdir -p "$HOME/.local"
mkdir -p "$HOME/.local/share"
mkdir -p "$HOME/.local/share/cbuild"
mkdir -p "$HOME/.local/bin"
else else
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${local_version_major}.${local_version_minor}" CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${version_major}.${version_minor}"
CBUILD_BIN_DIR="/usr/local/bin" CBUILD_BIN_DIR="/usr/local/bin"
mkdir -p "/usr/local/share" mkdir -p "/usr/local/share"
mkdir -p "/usr/local/share/cbuild" mkdir -p "/usr/local/share/cbuild"
@ -54,21 +38,6 @@ fi
rm -rf "$CBUILD_INSTALL_DIR" rm -rf "$CBUILD_INSTALL_DIR"
cp -r ./ "$CBUILD_INSTALL_DIR" cp -r ./ "$CBUILD_INSTALL_DIR"
rm -rf "$CBUILD_INSTALL_DIR/.git" rm -rf "$CBUILD_INSTALL_DIR/.git"
ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "$CBUILD_BIN_DIR/cbuild${local_version_major}.${local_version_minor}" ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "$CBUILD_BIN_DIR/cbuild${version_major}.${version_minor}"
bootstrap_install_path="$CBUILD_INSTALL_DIR/../bootstrap.sh" ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "$CBUILD_BIN_DIR/cbuild"
if [ -f "$bootstrap_install_path" ]; then
exec_script_line "$bootstrap_install_path" 2
installed_bootstrap_version=$CBUILD_BOOTSTRAP_VERSION
installed_bootstrap_version_int=$(echo $installed_bootstrap_version | sed 's/\.//g')
exec_script_line "./bootstrap.sh" 2
local_bootstrap_version=$CBUILD_BOOTSTRAP_VERSION
local_bootstrap_version_int=$(echo $local_bootstrap_version | sed 's/\.//g')
if [[ $local_bootstrap_version_int > $installed_bootstrap_version_int ]]; then
ln -sf "$(realpath $CBUILD_INSTALL_DIR/bootstrap.sh)" -T "$bootstrap_install_path"
fi
else
ln -sf "$(realpath $CBUILD_INSTALL_DIR/bootstrap.sh)" -T "$bootstrap_install_path"
fi
ln -sf "$(realpath $bootstrap_install_path)" -T "$CBUILD_BIN_DIR/cbuild"