parse_version
This commit is contained in:
parent
7d60219c33
commit
4b4794e253
4
.gitignore
vendored
4
.gitignore
vendored
@ -9,10 +9,6 @@ obj/
|
|||||||
*.user
|
*.user
|
||||||
*.vcxproj.filters
|
*.vcxproj.filters
|
||||||
|
|
||||||
# local cbuild config giles
|
|
||||||
current.config
|
|
||||||
*.current.config
|
|
||||||
|
|
||||||
# other files
|
# other files
|
||||||
.old*/
|
.old*/
|
||||||
old/
|
old/
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
|
# NEXT: v2.1.0
|
||||||
|
+ **config**: no more `current.config` and `default.config`, just `project.config`
|
||||||
|
+ improved version checking
|
||||||
|
+ `setup.sh` now installs each minor version in separate dicectory
|
||||||
|
|
||||||
# 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`)
|
||||||
+ **config**: changed description of `OBJDIR`
|
+ **config**: changed description of `OBJDIR`
|
||||||
|
|||||||
68
cbuild.sh
68
cbuild.sh
@ -4,11 +4,29 @@ tabs 4
|
|||||||
|
|
||||||
# exit on errors
|
# exit on errors
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
INSTALLED_CBUILD_VERSION=2.1.0
|
||||||
|
|
||||||
INSTALLED_CBUILD_VERSION=2.0.2
|
function version_parse {
|
||||||
|
local v="$1"
|
||||||
|
IFS_backup="$IFS"
|
||||||
|
IFS='.'
|
||||||
|
v_array=($v)
|
||||||
|
IFS="$IFS_backup"
|
||||||
|
version_major=${v_array[0]}
|
||||||
|
version_minor=${v_array[1]}
|
||||||
|
version_patch=${v_array[2]}
|
||||||
|
}
|
||||||
|
|
||||||
|
version_parse $INSTALLED_CBUILD_VERSION
|
||||||
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
CBUILD_INSTALL_DIR="~/.local/share/cbuild/${version_major}.${version_minor}"
|
||||||
|
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
|
||||||
|
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${version_major}.${version_minor}"
|
||||||
|
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
|
||||||
|
echo "CBUILD_INSTALL_DIR '$CBUILD_INSTALL_DIR' doesn't exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function include {
|
function include {
|
||||||
@ -31,12 +49,10 @@ function print_help {
|
|||||||
myprint " -h, --help Show this message"
|
myprint " -h, --help Show this message"
|
||||||
myprint " -v, --version Shows version"
|
myprint " -v, --version Shows version"
|
||||||
myprint " -n, --new-project [PROJ_DIR] Initialize new cbuild project directory (default=./)"
|
myprint " -n, --new-project [PROJ_DIR] Initialize new cbuild project directory (default=./)"
|
||||||
myprint " -c, --current-config FILE Set current config file path (default=./current.config)"
|
myprint " -c, --config FILE Set project config file path (default=./project.config)"
|
||||||
myprint " -d, --default-config FILE Set default config file path (default=./current.config)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_config_path="./current.config"
|
project_config_path="./project.config"
|
||||||
default_config_path="./default.config"
|
|
||||||
args=($@)
|
args=($@)
|
||||||
args_count=${#args[@]}
|
args_count=${#args[@]}
|
||||||
selected_tasks_array=()
|
selected_tasks_array=()
|
||||||
@ -55,34 +71,35 @@ do
|
|||||||
case "${args[i]}" in
|
case "${args[i]}" in
|
||||||
'-h' | '--help')
|
'-h' | '--help')
|
||||||
print_help
|
print_help
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
'-v' | '--version')
|
'-v' | '--version')
|
||||||
myprint $INSTALLED_CBUILD_VERSION
|
myprint $INSTALLED_CBUILD_VERSION
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
'-c' | '--current-config')
|
'-c' | '--config')
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
current_config_path="${args[i]}"
|
project_config_path="${args[i]}"
|
||||||
myprint "<$current_config_path>"
|
myprint "<$project_config_path>"
|
||||||
exit
|
exit 0
|
||||||
;;
|
|
||||||
'-d' | '--default-config')
|
|
||||||
default_config_path="$(get_next_arg)"
|
|
||||||
;;
|
;;
|
||||||
'-n' | '--new-project')
|
'-n' | '--new-project')
|
||||||
new_project_dir="$(get_next_arg)"
|
new_project_dir="$(get_next_arg)"
|
||||||
if [ -z "$new_project_dir" ]; then
|
if [ -z "$new_project_dir" ]; then
|
||||||
new_project_dir="./"
|
new_project_dir="."
|
||||||
fi
|
fi
|
||||||
|
if ask_yn "create default cbuild project config?"; then
|
||||||
if ask_yn "create default.config?"; then
|
project_config_path="$new_project_dir/project.config"
|
||||||
cp "$CBUILD_INSTALL_DIR/default.config" "$new_project_dir"
|
cp "$CBUILD_INSTALL_DIR/default.config" "$project_config_path"
|
||||||
myprint "Enter project name: "
|
myprint "Enter project name: "
|
||||||
read -r project_name
|
read -r project_name
|
||||||
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "default.config"
|
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "$project_config_path"
|
||||||
|
myprint "${GREEN}created config at '$project_config_path'"
|
||||||
fi
|
fi
|
||||||
if ask_yn "Copy default .gitignore?"; then
|
if ask_yn "Copy default .gitignore?"; then
|
||||||
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir"
|
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir/"
|
||||||
fi
|
fi
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
selected_tasks_array+=(${args[i]})
|
selected_tasks_array+=(${args[i]})
|
||||||
@ -92,13 +109,12 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
function call_task {
|
function call_task {
|
||||||
local current_config_path="$1"
|
local project_config_path="$1"
|
||||||
local default_config_path="$2"
|
local task="$2"
|
||||||
local task="$3"
|
TASK_ARGS="$3"
|
||||||
TASK_ARGS="$4"
|
|
||||||
|
|
||||||
print_header "${CYAN}" "─" "$PROJECT/$task"
|
print_header "${CYAN}" "─" "$PROJECT/$task"
|
||||||
load_config "$current_config_path" "$default_config_path" "$task" true
|
load_config "$project_config_path" "$task" true
|
||||||
|
|
||||||
if [ ! -z "$PRE_TASK_SCRIPT" ]; then
|
if [ ! -z "$PRE_TASK_SCRIPT" ]; then
|
||||||
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
|
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
|
||||||
@ -116,7 +132,7 @@ function call_task {
|
|||||||
|
|
||||||
function call_tasks {
|
function call_tasks {
|
||||||
local tasks="$@"
|
local tasks="$@"
|
||||||
load_config "$current_config_path" "$default_config_path" "" false
|
load_config "$project_config_path" "" false
|
||||||
print_header "${WHITE}" "═" "$PROJECT"
|
print_header "${WHITE}" "═" "$PROJECT"
|
||||||
project_dir="$(pwd)"
|
project_dir="$(pwd)"
|
||||||
for task_str in $tasks ; do
|
for task_str in $tasks ; do
|
||||||
@ -126,7 +142,7 @@ function call_tasks {
|
|||||||
IFS=',;'
|
IFS=',;'
|
||||||
args_array=($args_str)
|
args_array=($args_str)
|
||||||
IFS="$IFS_backup"
|
IFS="$IFS_backup"
|
||||||
call_task "$current_config_path" "$default_config_path" "$task" "${args_array[@]}"
|
call_task "$project_config_path" "$task" "${args_array[@]}"
|
||||||
cd "$project_dir"
|
cd "$project_dir"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
73
config.sh
73
config.sh
@ -12,29 +12,18 @@ function myprint_quiet {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec_script_line {
|
|
||||||
local script="$1"
|
|
||||||
local line_num="$2"
|
|
||||||
local quiet=$3
|
|
||||||
myprint_quiet $quiet "${BLUE}reading line $line_num from $script"
|
|
||||||
local line_str="$(sed $line_num'!d' $script)"
|
|
||||||
myprint_quiet $quiet "$line_str"
|
|
||||||
eval "$line_str"
|
|
||||||
}
|
|
||||||
|
|
||||||
function load_config {
|
function load_config {
|
||||||
local current_config_path="$1"
|
local project_config_path="$1"
|
||||||
local default_config_path="$2"
|
TASK="$2"
|
||||||
TASK="$3"
|
local quiet=$3
|
||||||
local quiet=$4
|
|
||||||
|
|
||||||
myprint "${BLUE}loading config current='$(realpath $current_config_path)' default='$(realpath $default_config_path)'"
|
myprint "${BLUE}loading config '$(realpath $project_config_path)'"
|
||||||
|
|
||||||
if [ -z "$current_config_path" ]; then
|
if [ -z "$project_config_path" ]; then
|
||||||
error "current_config_path is null"
|
error "config path is null"
|
||||||
fi
|
fi
|
||||||
if [ -z "$default_config_path" ]; then
|
if [ ! -f "$project_config_path" ]; then
|
||||||
error "default_config_path is null"
|
error "${YELLOW}$project_config_path doesn't exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OS=$(detect_os)
|
OS=$(detect_os)
|
||||||
@ -45,42 +34,36 @@ function load_config {
|
|||||||
error "couldnt get current cbuild installation version"
|
error "couldnt get current cbuild installation version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# getting version of default config
|
|
||||||
exec_script_line "$default_config_path" 3 $quiet
|
|
||||||
DEFAULT_CONFIG_VERSION="$CONFIG_VERSION"
|
|
||||||
unset CONFIG_VERSION
|
|
||||||
|
|
||||||
# undefined task
|
# undefined task
|
||||||
[ -z "$TASK" ] && TASK="no_task"
|
[ -z "$TASK" ] && TASK="no_task"
|
||||||
|
|
||||||
# error on undefined
|
# getting cbuild version from config (CBUILD_VERSION declaration is at line 2)
|
||||||
set -u
|
exec_script_line "$project_config_path" 2 $quiet
|
||||||
|
|
||||||
# reading current config or creating default
|
myprint_quiet $quiet "${WHITE}${project_config_path} cbuild version: ${CYAN}$CBUILD_VERSION"
|
||||||
if [ ! -f "$current_config_path" ]; then
|
|
||||||
myprint "${YELLOW}$current_config_path doesn't exist"
|
|
||||||
cp "$default_config_path" "$current_config_path"
|
|
||||||
myprint "${YELLOW}Created copy (${current_config_path}) of default config (${default_config_path})"
|
|
||||||
fi
|
|
||||||
|
|
||||||
myprint_quiet $quiet "${BLUE}reading $current_config_path"
|
|
||||||
include "$current_config_path"
|
|
||||||
|
|
||||||
myprint_quiet $quiet "${WHITE}project: ${CYAN}$PROJECT"
|
|
||||||
|
|
||||||
myprint_quiet $quiet "${WHITE}${current_config_path} cbuild version: ${CYAN}$CBUILD_VERSION"
|
|
||||||
myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
||||||
myprint_quiet $quiet "${WHITE}${current_config_path} version: ${CYAN}$CONFIG_VERSION"
|
|
||||||
myprint_quiet $quiet "${WHITE}${default_config_path} version: ${CYAN}$DEFAULT_CONFIG_VERSION"
|
|
||||||
|
|
||||||
# checking versions
|
# checking versions
|
||||||
if [ "$CBUILD_VERSION" != "$INSTALLED_CBUILD_VERSION" ]; then
|
version_parse $INSTALLED_CBUILD_VERSION
|
||||||
error "config was created for outdated cbuild version"
|
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
|
||||||
|
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
|
||||||
if [ "$CONFIG_VERSION" != "$DEFAULT_CONFIG_VERSION" ]; then
|
if [[ $installed_version_patch < $config_version_patch ]]; then
|
||||||
error "current config version doesn't match default config version"
|
myprint "${YELLOW}New patch for cbuild$installed_version_major.$installed_version_minor is abaliable."
|
||||||
|
myprint "${YELLOW}Install it to get latest bugfixes."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# throw error on undefined variable usage
|
||||||
|
set -u
|
||||||
|
include "$project_config_path"
|
||||||
|
|
||||||
mkdir -p "$OUTDIR"
|
mkdir -p "$OUTDIR"
|
||||||
mkdir -p "$OBJDIR/objects"
|
mkdir -p "$OBJDIR/objects"
|
||||||
mkdir -p "$OBJDIR/static_libs"
|
mkdir -p "$OBJDIR/static_libs"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
CBUILD_VERSION=2.0.2
|
CBUILD_VERSION=2.1.0
|
||||||
CONFIG_VERSION=1
|
CONFIG_VERSION=1
|
||||||
|
|
||||||
PROJECT="%PROJECT_NAME%"
|
PROJECT="%PROJECT_NAME%"
|
||||||
|
|||||||
10
functions.sh
10
functions.sh
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
include "cbuild/myprint.sh"
|
include "cbuild/myprint.sh"
|
||||||
|
|
||||||
|
function exec_script_line {
|
||||||
|
local script="$1"
|
||||||
|
local line_num="$2"
|
||||||
|
local quiet=$3
|
||||||
|
myprint_quiet $quiet "${BLUE}reading line $line_num from $script"
|
||||||
|
local line_str="$(sed $line_num'!d' $script)"
|
||||||
|
myprint_quiet $quiet "$line_str"
|
||||||
|
eval "$line_str"
|
||||||
|
}
|
||||||
|
|
||||||
function clean_dir {
|
function clean_dir {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
myprint "${WHITE}cleaning $dir"
|
myprint "${WHITE}cleaning $dir"
|
||||||
|
|||||||
40
setup.sh
40
setup.sh
@ -1,15 +1,43 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# USAGE: ./setup.sh install cbuild to /usr/local
|
||||||
|
# ./setup.sh --local install cbuild to ~/.local
|
||||||
|
|
||||||
# exit on errors
|
# exit on errors
|
||||||
set -eo pipefail
|
set -xeo pipefail
|
||||||
set -x
|
CBUILD_VERSION=2.1.0
|
||||||
|
|
||||||
|
function version_parse {
|
||||||
|
local v="$1"
|
||||||
|
IFS_backup="$IFS"
|
||||||
|
IFS='.'
|
||||||
|
v_array=($v)
|
||||||
|
IFS="$IFS_backup"
|
||||||
|
version_major=${v_array[0]}
|
||||||
|
version_minor=${v_array[1]}
|
||||||
|
version_patch=${v_array[2]}
|
||||||
|
}
|
||||||
|
|
||||||
|
version_parse $CBUILD_VERSION
|
||||||
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
if [ "$1" = "--local" ]; then
|
||||||
|
CBUILD_INSTALL_DIR="~/.local/share/cbuild/${version_major}.${version_minor}"
|
||||||
|
CBUILD_BIN_DIR="~/.local/bin"
|
||||||
|
mkdir -p "~/.local"
|
||||||
|
mkdir -p "~/.local/share"
|
||||||
|
mkdir -p "~/.local/share/cbuild"
|
||||||
|
mkdir -p "~/.local/bin"
|
||||||
|
else
|
||||||
|
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${version_major}.${version_minor}"
|
||||||
|
CBUILD_BIN_DIR="/usr/local/bin"
|
||||||
|
mkdir -p "/usr/local/share"
|
||||||
|
mkdir -p "/usr/local/share/cbuild"
|
||||||
|
mkdir -p "/usr/local/bin"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$CBUILD_INSTALL_DIR" != "." ]; then
|
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"
|
||||||
fi
|
ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "$CBUILD_BIN_DIR/cbuild${version_major}.${version_minor}"
|
||||||
ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "/usr/local/bin/cbuild"
|
|
||||||
|
ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "$CBUILD_BIN_DIR/cbuild"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user