added file_copy_default_if_not_present() and replace_var_value_in_script()
This commit is contained in:
parent
579dd5916e
commit
6bfc0f5e9a
@ -4,6 +4,9 @@
|
|||||||
+ **CONFIG:** Changed `cbuild/default_tasks` to `@cbuild/default_tasks`
|
+ **CONFIG:** Changed `cbuild/default_tasks` to `@cbuild/default_tasks`
|
||||||
+ Moved most scripts to `include/`
|
+ Moved most scripts to `include/`
|
||||||
+ Renamed default config to `./project.config.default`
|
+ Renamed default config to `./project.config.default`
|
||||||
|
+ Added functions:
|
||||||
|
+ `file_copy_default_if_not_present()`
|
||||||
|
+ `replace_var_value_in_script()`
|
||||||
|
|
||||||
## 2.2.4
|
## 2.2.4
|
||||||
+ *default config*: C standard changed to C99
|
+ *default config*: C standard changed to C99
|
||||||
|
|||||||
@ -7,6 +7,7 @@ include "@cbuild/include/detect_os.sh"
|
|||||||
function load_config {
|
function load_config {
|
||||||
local project_config_path="$1"
|
local project_config_path="$1"
|
||||||
TASK="$2"
|
TASK="$2"
|
||||||
|
#bool
|
||||||
local quiet=$3
|
local quiet=$3
|
||||||
|
|
||||||
myprint "${BLUE}loading ${WHITE}'$project_config_path'"
|
myprint "${BLUE}loading ${WHITE}'$project_config_path'"
|
||||||
@ -53,10 +54,7 @@ function load_config {
|
|||||||
|
|
||||||
# load project user config
|
# load project user config
|
||||||
local project_user_config_path="$project_config_path.user"
|
local project_user_config_path="$project_config_path.user"
|
||||||
if [ ! -f "$project_user_config_path" ]; then
|
file_copy_default_if_not_present "$project_user_config_path" "$project_user_config_path.default"
|
||||||
myprint "${YELLOW}creating default project user config ${WHITE}$project_user_config_path"
|
|
||||||
cp "$project_user_config_path.default" "$project_user_config_path"
|
|
||||||
fi
|
|
||||||
myprint "${BLUE}loading ${WHITE}'$project_user_config_path'"
|
myprint "${BLUE}loading ${WHITE}'$project_user_config_path'"
|
||||||
include "$project_user_config_path"
|
include "$project_user_config_path"
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,9 @@ include "@cbuild/include/myprint.sh"
|
|||||||
function exec_script_line {
|
function exec_script_line {
|
||||||
local script="$1"
|
local script="$1"
|
||||||
local line_num="$2"
|
local line_num="$2"
|
||||||
|
#bool
|
||||||
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
|
if [ -z "$line_str" ]; then
|
||||||
@ -15,6 +17,18 @@ function exec_script_line {
|
|||||||
eval "$line_str"
|
eval "$line_str"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replace_var_value_in_script(){
|
||||||
|
local script="$1"
|
||||||
|
local var_name="$2"
|
||||||
|
local new_value="$3"
|
||||||
|
|
||||||
|
myprint "${BLUE}setting $var_name to ${CYAN}'$new_value' in '$script'"
|
||||||
|
cp "$script" "$script.tmp"
|
||||||
|
sed "s,$var_name=\".*\",$var_name=\"$new_value\",g" \
|
||||||
|
"$script.tmp" > "$script"
|
||||||
|
rm "$script.tmp"
|
||||||
|
}
|
||||||
|
|
||||||
function clean_dir {
|
function clean_dir {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
myprint "${WHITE}cleaning $dir"
|
myprint "${WHITE}cleaning $dir"
|
||||||
@ -36,6 +50,15 @@ function try_delete_dir_or_file {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_copy_default_if_not_present(){
|
||||||
|
local file="$1"
|
||||||
|
local file_default="$2"
|
||||||
|
if [ ! -f "$file" ]; then
|
||||||
|
myprint "${YELLOW}creating default ${WHITE}$file"
|
||||||
|
cp -r "$file_default" "$file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function exec_command {
|
function exec_command {
|
||||||
local command="$@"
|
local command="$@"
|
||||||
if [ ! -z "$command" ]; then
|
if [ ! -z "$command" ]; then
|
||||||
|
|||||||
@ -22,6 +22,7 @@ function myprint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function myprint_quiet {
|
function myprint_quiet {
|
||||||
|
#bool
|
||||||
local quiet=$1
|
local quiet=$1
|
||||||
local text="$2"
|
local text="$2"
|
||||||
if [ "$quiet" != true ]; then
|
if [ "$quiet" != true ]; then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user