diff --git a/docs/@call.md b/docs/@call.md index d9b0975..6e745bd 100644 --- a/docs/@call.md +++ b/docs/@call.md @@ -83,7 +83,9 @@ desugars to Do we need `--file 'path/to/Makesurefile'`? -No. Even if we run `./makesure path/to/Makesurefile` path resolution is relative to the `Makesurefile` location, so internal makesure invocation now doesn't need explicit Makesurefile reference. But let's add a test for this case. +~~No. Even if we run `./makesure -f path/to/Makesurefile` path resolution is relative to the `Makesurefile` location, so internal makesure invocation now doesn't need explicit Makesurefile reference. But let's add a test for this case.~~ + +Yes, we must add `--file` because it can be `./makesure -f path/to/anyname`. Are there other options to passthrough ([Usage](https://makesure.dev/Usage.html))? diff --git a/makesure.awk b/makesure.awk index 521670a..9854c12 100755 --- a/makesure.awk +++ b/makesure.awk @@ -34,6 +34,7 @@ BEGIN { Mode = "prelude" # prelude|define|goal|goal_glob|lib srand() prepareArgs() + ProgAbs = "" # absolute path to makesure executable MyDirScript = "MYDIR=" quoteArg(getMyDir(ARGV[1])) ";export MYDIR;cd \"$MYDIR\"" Error = "" makesure() @@ -52,6 +53,7 @@ function makesure( i) { else if ("@reached_if" == $1) handleReachedIf() else if ("@lib" == $1) handleLib() else if ("@use_lib" == $1) handleUseLib() + else if ("@calls" == $1) handleCalls() else if ($1 ~ /^@/) addError("Unknown directive: " $1) else handleCodeLine($0) for (i = 1; i < 10; i++) $i = "" # only for macos 10.15 awk version 20070501 @@ -185,6 +187,25 @@ function handleUseLib( i) { registerUseLib(globGoal(i)) } +function handleCalls( i) { + checkGoalOnly() + + if (NF < 2) + addError("Provide at least one dependency") + + if ("goal" == Mode) + processCalls() +# else TODO +# for (i = 0; i < GlobCnt; i++) +# registerDependsOn(globGoal(i)) +} + +function processCalls( i) { + for (i = 2; i <= NF; i++) + addCodeLine(quoteArg(ProgAbs) " " quoteArg($i)) +# addCodeLine("echo " quoteArg(ProgAbs) " " quoteArg($i)) +} + function registerUseLib(goalName) { if (goalName in GoalToLib) addError("You can only use one @lib in a @goal") @@ -549,8 +570,12 @@ function shellExec(script, comment, res) { return res } -function getMyDir(makesurefilePath) { - return executeGetLine("cd \"$(dirname " quoteArg(makesurefilePath) ")\";pwd") +function getMyDir(makesurefilePath, script,res,p) { + script = "echo \"$(cd \"$(dirname "(p=quoteArg(Prog))")\" && pwd)/$(basename "p")\";cd \"$(dirname " quoteArg(makesurefilePath) ")\";pwd" + script | getline ProgAbs + script | getline res + closeErr(script) + return res } function handleCodeLine(line) { @@ -952,6 +977,7 @@ function reparseCli( res,i,err) { } return 1 } +# bash-friendly (non-POSIX-compatible) quoting function quote2(s,force) { if (index(s, "'")) { gsub(/\\/, "\\\\", s) @@ -978,6 +1004,7 @@ function commandExists(cmd) { return ok("command -v " cmd " >/dev/null") } function ok(cmd) { return system(cmd) == 0 } function isFile(path) { return ok("test -f " quoteArg(path)) } function rm(f) { system("rm " quoteArg(f)) } +# POSIX-compatible quoting function quoteArg(a) { gsub("'", "'\\''", a); return "'" a "'" } function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s } function copyKey(keySrc,keyDst,arr) { if (keySrc in arr) arr[keyDst] = arr[keySrc] } \ No newline at end of file diff --git a/tests/32_calls.sh b/tests/32_calls.sh new file mode 100644 index 0000000..acd3ca2 --- /dev/null +++ b/tests/32_calls.sh @@ -0,0 +1,15 @@ + + +@goal 'x-created' +@reached_if test -f /tmp/x + echo 'running x-created' + touch /tmp/x + +@goal 'x-deleted' +@reached_if ! test -e /tmp/x + echo 'running x-deleted' + rm /tmp/x + +@goal 'x-updated' +@calls 'x-deleted' +@calls 'x-created' \ No newline at end of file diff --git a/tests/32_calls.tush b/tests/32_calls.tush new file mode 100644 index 0000000..ee7bbe5 --- /dev/null +++ b/tests/32_calls.tush @@ -0,0 +1,2 @@ + +$ ./$MAKESURE -f tests/32_calls.sh x-updated