diff --git a/bin/nuxfs b/bin/nuxfs index afc265f..9538338 100755 --- a/bin/nuxfs +++ b/bin/nuxfs @@ -13,6 +13,7 @@ nux.use nuxfs GIT_BIN=$(which git) +## check - Verifies that directory matches nuxfs specification task.check() { nuxfs.dsl.process "$@"; } @@ -36,7 +37,8 @@ nuxfs.dsl.process() { TARGET=$(pwd); fi; - nux.log debug Target: $TARGET + TARGET=$(realpath -Lms "$TARGET") + nux.log debug Target: $TARGET NUXFS_DEF=$(nuxfs.closest $SUFFIX "$TARGET"); # diff --git a/inc/dsl/nuxfs.apply.dsl b/inc/dsl/nuxfs.apply.dsl index bb127a5..851ab8a 100644 --- a/inc/dsl/nuxfs.apply.dsl +++ b/inc/dsl/nuxfs.apply.dsl @@ -6,8 +6,8 @@ dir.check.recover() { } link.check.recover() { nuxfs.info "$rel_path" "Creating link to '$3'"; - ln -s "$3" "$abs_path" + ln -s "$target" "$abs_path" } git.check.recover() { - $GIT_BIN clone "$3" "$abs_path" + $GIT_BIN clone "$origin" "$abs_path" } diff --git a/inc/dsl/nuxfs.check.dsl b/inc/dsl/nuxfs.check.dsl index 4e6920c..bcb2cc3 100644 --- a/inc/dsl/nuxfs.check.dsl +++ b/inc/dsl/nuxfs.check.dsl @@ -7,21 +7,20 @@ link.entered() { return fi local REAL_LINK=$(readlink "$abs_path") - local TARGET="$3"; - nux.log trace "Target is: $TARGET, real link: $REAL_LINK" - if test ! "$REAL_LINK" = "$TARGET"; then + nux.log trace "Target is: $target, real link: $REAL_LINK" + if test ! "$REAL_LINK" = "$target"; then MAT_REAL=$(realpath "$REAL_LINK") local cdir=$(dirname "$abs_path") - MAT_TARGET=$(realpath "$cdir/$TARGET") + MAT_TARGET=$(realpath "$cdir/$target") if test "$MAT_REAL" = "$MAT_TARGET"; then nuxfs.warning "$rel_path" "is using different definition for target '$3'" else - nuxfs.error "$rel_path" "links to $REAL_LINK instead of $TARGET" + nuxfs.error "$rel_path" "links to $REAL_LINK instead of $target" return fi fi if test ! -e "$abs_path"; then - nuxfs.warning "$rel_path" "target '$NC_White$TARGET$NC_No' does not exists." + nuxfs.warning "$rel_path" "target '$NC_White$target$NC_No' does not exists." fi } @@ -31,9 +30,9 @@ git.entered() { nuxfs.error "$rel_path" "is not git repository" return fi - local remotes=$(grep "$3" "$rel_path/.git/config" | wc -l) + local remotes=$(grep "$origin" "$rel_path/.git/config" | wc -l) if [ $remotes -eq 0 ]; then - nuxfs.error "$rel_path" "Does not refer git remote '$3'" + nuxfs.error "$rel_path" "Does not refer git remote '$origin'" return; fi } diff --git a/inc/dsl/nuxfs.dsl b/inc/dsl/nuxfs.dsl index 5344de9..a0efb6a 100644 --- a/inc/dsl/nuxfs.dsl +++ b/inc/dsl/nuxfs.dsl @@ -1,3 +1,5 @@ +#/bin/sh + .block dir name .keyword link name target .keyword git name origin @@ -5,6 +7,7 @@ .keyword name name .keyword template .keyword exists +.keyword should-not-exists directory() { dir @@ -25,8 +28,22 @@ sdir() { nux.check.file.exists "$abs_path" } +should-not-exists.check() { + nux.log trace "Checking existence of $NC_White$abs_path$NC_No" + if nux.check.file.exists "$abs_path"; then + return 1 + fi + return 0 +} + +should-not-exists.check.failed() { + for f in "$rel_path"; do + nux.dsl.error $f Should not exists, but is present. + done +} + .check.failed() { - nux.dsl.error "$abs_path" does not exists. + nux.dsl.error "$rel_path" does not exists. } dir.entered() { if nux.check.file.exists "$abs_path/.nuxfs"; then diff --git a/inc/nux-base.inc.sh b/inc/nux-base.inc.sh index 0dddf52..a25e8ba 100644 --- a/inc/nux-base.inc.sh +++ b/inc/nux-base.inc.sh @@ -69,3 +69,8 @@ function nux.check.function { function nux.check.file.exists { test -e "$1" -o -h "$1"; } + +function nux.eval { + nux.log trace Going to evaluate "$@" + eval "$@" +} diff --git a/inc/nux.dsl.inc.sh b/inc/nux.dsl.inc.sh index e56130a..2ff8348 100644 --- a/inc/nux.dsl.inc.sh +++ b/inc/nux.dsl.inc.sh @@ -26,14 +26,12 @@ function nux.dsl.block.push { local btype="$1" local value="$2" local parent=$(nux.dsl.block.path) - nux.log trace "Pushing $NC_White$btype '$value'$NC_No on stack." + #nux.log trace "Pushing $NC_White$btype '$value'$NC_No on stack." DSL_BLOCK_TYPE[${#DSL_BLOCK_TYPE[@]}]="$btype" DSL_BLOCK_ID[${#DSL_BLOCK_ID[@]}]="$value" DSL_BLOCK_PATH[${#DSL_BLOCK_PATH[@]}]="$parent/$value"; } - - function nux.dsl.error { local tag="$1"; shift; nux.echo.error "$tag"$NC_No: $*; @@ -41,12 +39,12 @@ function nux.dsl.error { function nux.dsl.warning { local tag="$1"; shift; - nux.echo.warning "$1"$NC_No: $*; + nux.echo.warning "$tag"$NC_No: $*; } function nux.dsl.info { local tag="$1"; shift; - echo -e $NC_White"$1"$NC_No: $*; + echo -e $NC_White"$tag"$NC_No: $*; } function nux.dsl.keyword.exec { @@ -54,15 +52,21 @@ function nux.dsl.keyword.exec { local keyword="$2"; local FUNC_NAME=$keyword$func; local DEFAULT_NAME=$func; + local ALLWAYS_NAME=.allways$func; + shift; shift; + if nux.check.function $ALLWAYS_NAME; then + nux.log trace Executing: $NC_White$ALLWAYS_NAME$NC_No "$@"; + $ALLWAYS_NAME "$@"; + fi if nux.check.function $FUNC_NAME; then nux.log trace Executing: $NC_White$FUNC_NAME$NC_No "$@"; $FUNC_NAME "$@"; - return; + return $?; elif nux.check.function $DEFAULT_NAME; then nux.log trace Executing: $NC_White$DEFAULT_NAME$NC_No "$@"; $DEFAULT_NAME "$@"; - return; + return $?; fi } @@ -77,7 +81,7 @@ function nux.dsl.block.start { id="$2"; path="$parent/$id"; - #nux.log trace Starting Block: "$keyword" ID: "$id" Parent: $parent + nux.log trace Starting Block: "$keyword" ID: "$id" Parent: $parent #nux.log debug "Skip is: $nux_dsl_skip, test should return $(test -z "$nux_dsl_skip")" nux.dsl.block.push "$keyword" "$id" if [[ $path == $nux_dsl_only_subtree* && -z "$nux_dsl_skip" ]]; then @@ -102,21 +106,32 @@ function nux.dsl.block.end { id=$(nux.dsl.block.id) path=$(nux.dsl.block.path) - nux.log trace Ending block $NC_White"$keyword" "'$id'" + #nux.log trace Ending block $NC_White"$keyword" "'$id'" + nux.dsl.block.pop "$1" + if [ "$path" = "$nux_dsl_skip" ];then nux_dsl_skip=""; fi - nux.dsl.block.pop "$1" if [[ $path == $nux_dsl_only_subtree* ]]; then nux.dsl.keyword.exec .exited "$keyword" "'$id'" - - nux.log trace Ending block $NC_White"$keyword" "'$id'" fi } -function nux.dsl.load { +function nux.dsl.execute { local language=$1 local script=$2 + local language_dir=$(dirname "$language"); + local script_dir=$(dirname "$script"); + function .use-dsl { + if nux.check.file.exists "$language_dir/$1.dsl"; then + source "$language_dir/$1.dsl"; + elif nux.check.file.exists "$script_dir/$1.dsl"; then + source "$script_dir/$1.dsl"; + else + nux.dsl.error $1 Language not found in $NC_White$language_dir$NC_No and $NC_White$script_dir$NC_No + exit 1; + fi + } function .entered { nux.log debug Keyword $NC_White$1$NC_No is noop. @@ -129,13 +144,28 @@ function nux.dsl.load { return 1 } + function .arg.parser { + keyword="$1"; shift; + offset=1; + echo """# Parsing arguments + + keyword=$keyword + id=\"\$1\"""" + for var in "$@"; do + echo " ${var}=\"\$$offset\"" + let offset=$offset+1 + done + } + + function .block { local keyword="$1" - nux.log trace Defining block named $NCWhite"$keyword" + nux.log trace Defining block keyword $NC_White"$keyword" #FIXME: Add aliasing of binary of same name. - eval """ + nux.eval """ $keyword() { - nux.dsl.block.start $keyword "\$@"; + $(.arg.parser "$@") + nux.dsl.block.start $keyword \"\$@\"; } end$keyword() { nux.dsl.block.end $keyword @@ -146,14 +176,37 @@ function nux.dsl.load { function .keyword { local keyword="$1" #FIXME: Add aliasing of binary of same name. - nux.log trace Defining block named $NCWhite"$keyword" - eval """ + nux.log trace Defining keyword $NC_White"$keyword" + nux.eval """ $keyword() { - nux.dsl.block.start $keyword "\$@"; + $(.arg.parser "$@") + nux.dsl.block.start $keyword \"\$@\"; nux.dsl.block.end $keyword; } """ } + + .keyword.virtual() { + local keyword=$1 + .keyword "$@" + nux.eval """ + ${keyword}.check() { + return 0; + } + """ + } + + .block.virtual() { + local keyword=$1 + .block "$@" + nux.eval """ + ${keyword}.check() { + return 0; + } + """ + } + nux.dsl.block.init - $language + source "$language.dsl" + source "$script" }