From 2841fb1ffc0ce9fcfeb687068ad4c34dd62266c2 Mon Sep 17 00:00:00 2001 From: xonix Date: Sun, 19 Sep 2021 17:19:51 +0300 Subject: [PATCH] Improvement to `@goal @glob` #46 --- Makesurefile | 55 ++------------------------ makesure_stable | 100 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 79 insertions(+), 76 deletions(-) diff --git a/Makesurefile b/Makesurefile index bc939db..a214d27 100644 --- a/Makesurefile +++ b/Makesurefile @@ -92,68 +92,21 @@ echo $cnt } +@goal tested +@depends_on tests/*.tush + @goal @glob tests/*.tush @private @depends_on prepared4tests @use_lib testing_tush MAKESURE=makesure \ run_tush_file "$ITEM" -@goal test_stable_version @glob tests/*.tush @private +@goal tested_stable @glob tests/*.tush @private @depends_on prepared4tests @use_lib testing_tush MAKESURE=makesure_stable \ run_tush_file "$ITEM" -@goal tested -@doc runs all tests with default awk on './makesure' -@depends_on tests/0_basic.tush -@depends_on tests/1_goals.tush -@depends_on tests/2_mydir.tush -@depends_on tests/3_loop.tush -@depends_on tests/4_trace.tush -@depends_on tests/5_shell.tush -@depends_on tests/6_reached_if.tush -@depends_on tests/7_options.tush -@depends_on tests/8_timing.tush -@depends_on tests/9_prelude.tush -@depends_on tests/10_define.tush -@depends_on tests/11_goal_glob.tush -@depends_on tests/12_update.tush -@depends_on tests/13_errors.tush -@depends_on tests/14_doc.tush -@depends_on tests/15_private.tush -@depends_on tests/16_lib.tush -@depends_on tests/17_prelude_fail.tush -@depends_on tests/18_empty_prelude.tush -@depends_on tests/19_vars_priority.tush -@depends_on tests/20_optimize_goals.tush -@depends_on tests/21_list_goals.tush - -@goal tested_stable -@doc runs all tests with default awk on './makesure_stable' -@depends_on test_stable_version@tests/0_basic.tush -@depends_on test_stable_version@tests/1_goals.tush -@depends_on test_stable_version@tests/2_mydir.tush -@depends_on test_stable_version@tests/3_loop.tush -@depends_on test_stable_version@tests/4_trace.tush -@depends_on test_stable_version@tests/5_shell.tush -@depends_on test_stable_version@tests/6_reached_if.tush -@depends_on test_stable_version@tests/7_options.tush -@depends_on test_stable_version@tests/8_timing.tush -@depends_on test_stable_version@tests/9_prelude.tush -@depends_on test_stable_version@tests/10_define.tush -@depends_on test_stable_version@tests/11_goal_glob.tush -@depends_on test_stable_version@tests/12_update.tush -@depends_on test_stable_version@tests/13_errors.tush -@depends_on test_stable_version@tests/14_doc.tush -@depends_on test_stable_version@tests/15_private.tush -@depends_on test_stable_version@tests/16_lib.tush -@depends_on test_stable_version@tests/17_prelude_fail.tush -@depends_on test_stable_version@tests/18_empty_prelude.tush -@depends_on test_stable_version@tests/19_vars_priority.tush -@depends_on test_stable_version@tests/20_optimize_goals.tush -@depends_on test_stable_version@tests/21_list_goals.tush - @goal stable @doc rebuilds makesure_stable & README.md for release @depends_on makesure_stable diff --git a/makesure_stable b/makesure_stable index 5d44765..e7d2f7a 100755 --- a/makesure_stable +++ b/makesure_stable @@ -22,8 +22,9 @@ BEGIN { split("",DependenciesCnt) split("",Doc) split("",ReachedIf) + GlobCnt = 0 + GlobGoalName = "" split("",GlobFiles) - split("",GlobGoals) split("",LibNames) split("",Lib) split("",UseLibLineNo) @@ -162,8 +163,8 @@ function handleUseLib( goalName) { if ("goal" == Mode) registerUseLib(currentGoalName()) else { - for (i=0; i in GlobGoals; i++){ - registerUseLib(GlobGoals[i]) + for (i=0; i < GlobCnt; i++){ + registerUseLib(globGoal(i)) } } } @@ -187,16 +188,19 @@ function registerGoal(goalName, priv) { arrPush(GoalNames, goalName) GoalsByName[goalName] = priv } +function globGoal(i) { return (GlobGoalName ? GlobGoalName "@" : "") GlobFiles[i] } function calcGlob(goalName, pattern, script, file) { - split("",GlobGoals) + GlobCnt = 0 + GlobGoalName = goalName split("",GlobFiles) script = MyDirScript ";for f in ./" pattern ";do test -e \"$f\" && echo \"$f\";done" while ((script | getline file)>0) { + GlobCnt++ file = substr(file, 3) arrPush(GlobFiles,file) - arrPush(GlobGoals,(goalName ? goalName "@" : "") file) } close(script) + quicksort(GlobFiles,0,arrLen(GlobFiles)-1) } function parseGoalLine( priv) { if ($NF == "@private") { @@ -206,25 +210,35 @@ function parseGoalLine( priv) { $1 = "" return priv } -function handleGoalGlob( goalName,priv,i) { +function handleGoalGlob( goalName,globAllGoal,globSingle,priv,i,pattern) { started("goal_glob") priv = parseGoalLine() goalName = $2; $2 = "" if ("@glob" == goalName) { goalName = "" } else $3 = "" - calcGlob(goalName, trim($0)) - for (i=0; i in GlobGoals; i++){ - registerGoal(GlobGoals[i], priv) + calcGlob(goalName, pattern = trim($0)) + globAllGoal = goalName ? goalName : pattern + globSingle = GlobCnt == 1 && globAllGoal == globGoal(0) + for (i=0; i < GlobCnt; i++){ + registerGoal(globGoal(i), globSingle ? priv : 1) + } + if (!globSingle) { + registerGoal(globAllGoal, priv) + for (i=0; i < GlobCnt; i++){ + registerDependency(globAllGoal, globGoal(i)) + } } } function handleDoc( i) { checkGoalOnly() - if ("goal" == Mode) + if ("goal" == Mode) { registerDoc(currentGoalName()) - else { - for (i=0; i in GlobGoals; i++){ - registerDoc(GlobGoals[i]) + } else { + if (!(GlobCnt == 1 && currentGoalName() == globGoal(0))) + registerDoc(currentGoalName()) + for (i=0; i < GlobCnt; i++){ + registerDoc(globGoal(i)) } } } @@ -239,29 +253,31 @@ function handleDependsOn( i) { if ("goal" == Mode) registerDependsOn(currentGoalName()) else { - for (i=0; i in GlobGoals; i++){ - registerDependsOn(GlobGoals[i]) + for (i=0; i < GlobCnt; i++){ + registerDependsOn(globGoal(i)) } } } -function registerDependsOn(goalName, i,x) { - for (i=2; i<=NF; i++) { - Dependencies[x = goalName SUBSEP DependenciesCnt[goalName]++] = $i - DependenciesLineNo[x] = NR - } +function registerDependsOn(goalName, i) { + for (i=2; i<=NF; i++) + registerDependency(goalName, $i) +} +function registerDependency(goalName, depGoalName, x) { + Dependencies[x = goalName SUBSEP DependenciesCnt[goalName]++] = depGoalName + DependenciesLineNo[x] = NR } function handleReachedIf( i) { checkGoalOnly() if ("goal" == Mode) registerReachedIf(currentGoalName()) else { - for (i=0; i in GlobGoals; i++){ - registerReachedIf(GlobGoals[i], makeGlobVarsCode(i)) + for (i=0; i < GlobCnt; i++){ + registerReachedIf(globGoal(i), makeGlobVarsCode(i)) } } } function makeGlobVarsCode(i) { - return "ITEM=" quoteArg(GlobFiles[i]) ";INDEX=" i ";TOTAL=" arrLen(GlobGoals) ";" + return "ITEM=" quoteArg(GlobFiles[i]) ";INDEX=" i ";TOTAL=" GlobCnt ";" } function registerReachedIf(goalName, preScript) { if (goalName in ReachedIf) @@ -432,8 +448,8 @@ function handleCodeLine(line, goalName) { name = currentLibName() Lib[name] = addL(Lib[name], line) } else if ("goal_glob" == Mode) { - for (i=0; i in GlobGoals; i++){ - if (!Code[goalName = GlobGoals[i]]) + for (i=0; i < GlobCnt; i++){ + if (!Code[goalName = globGoal(i)]) addCodeLine(goalName, makeGlobVarsCode(i)) addCodeLine(goalName, line) } @@ -531,6 +547,40 @@ function dl(url, dest, verbose) { return "error with curl" } else return "wget/curl no found" } +function natOrder(s1,s2, i1,i2, c1, c2, n1,n2, l1, l2) { + l1 = length(s1); l2 = length(s2) + if (i1 == l1+1 || i2 == l2+1) + return _cmp(l1-i1, l2-i2) + while ((c1 = substr(s1,i1,1)) == (c2 = substr(s2,i2,1))) { + i1++; i2++ + if (i1>l1 || i2>l2) + return _cmp(l1-i1, l2-i2) + } + if (!_digit(c1) || !_digit(c2)) + return _cmp(c1, c2) + n1 = 0; while(_digit(c1 = substr(s1,i1++,1))) { n1 = n1 * 10 + c1 } + n2 = 0; while(_digit(c2 = substr(s2,i2++,1))) { n2 = n2 * 10 + c2 } + return n1 == n2 ? natOrder(s1, s2, i1, i2) : _cmp(n1, n2) +} +function _cmp(v1, v2) { return v1 > v2 ? 1 : v1 < v2 ? -1 : 0 } +function _digit(c) { return c >= "0" && c <= "9" } +function quicksort(data, left, right, i, last) { + if (left >= right) + return + quicksortSwap(data, left, int((left + right) / 2)) + last = left + for (i = left + 1; i <= right; i++) + if (natOrder(data[i], data[left]) < 1) + quicksortSwap(data, ++last, i) + quicksortSwap(data, left, last) + quicksort(data, left, last - 1) + quicksort(data, last + 1, right) +} +function quicksortSwap(data, i, j, temp) { + temp = data[i] + data[i] = data[j] + data[j] = temp +} function join(arr, startIncl, endExcl, sep, result, i) { result = arr[startIncl] for (i = startIncl + 1; i < endExcl; i++)