From 03f1749ec9e32e25b6c4d385dcbbc1732765714e Mon Sep 17 00:00:00 2001 From: xonix Date: Sat, 21 Jan 2023 01:59:44 +0200 Subject: [PATCH] Parameterized goals #115 --- makesure.awk | 32 ++++++++++++++++++++++++------- tests/27_parameterized_goals_2.sh | 3 ++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/makesure.awk b/makesure.awk index c2aa4b1..cc26cdf 100755 --- a/makesure.awk +++ b/makesure.awk @@ -119,6 +119,17 @@ function prepareArgs( i,arg) { function dbgA(name, arr, i) { print "--- " name ": "; for (i in arr) printf "%2s : %s\n", i, arr[i] } function dbgAO(name, arr, i) { print "--- " name ": "; for (i=0;i in arr;i++) printf "%2s : %s\n", i, arr[i] } +function indent(ind) { + printf "%" ind*2 "s", "" +} +function printDepsTree(goal,ind, i) { + if (!(goal in GoalsByName)) { die("unknown goal: " goal) } + indent(ind) + print quote2(goal) + for (i=0; i < DependenciesCnt[goal]; i++) { + printDepsTree(Dependencies[goal,i],ind+1) + } +} function splitKV(arg, kv, n) { n = index(arg, "=") @@ -400,20 +411,19 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) { if (timingOn()) t0 = currentTimeMillis() - for (i = 0; i in GoalNames; i++) { - depCnt = DependenciesCnt[goalName = GoalNames[i]] - for (j=0; j < depCnt; j++) - topologicalSortAddConnection(goalName, Dependencies[goalName, j]) - } - topologicalSort(0,GoalNames) # first do topological sort disregarding @reached_if to catch loops instantiateGoals() + printDepsTree("a") + topologicalSort(1,ArgGoals,resolvedGoals,reachedGoals) # now do topological sort including @reached_if to resolve goals to run + printDepsTree("a") + preludeCode = getPreludeCode() + # TODO looks like this loop should go inside else branch below for (i = 0; i in GoalNames; i++) { goalName = GoalNames[i] @@ -467,9 +477,15 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) { } } -function topologicalSort(includeReachedIf,requestedGoals,result,reachedGoals, i,goalName,loop) { +function topologicalSort(includeReachedIf,requestedGoals,result,reachedGoals, i,j,goalName,loop,depCnt) { topologicalSortReset() + for (i = 0; i in GoalNames; i++) { + depCnt = DependenciesCnt[goalName = GoalNames[i]] + for (j=0; j < depCnt; j++) + topologicalSortAddConnection(goalName, Dependencies[goalName, j]) + } + if (arrLen(requestedGoals) == 0) arrPush(requestedGoals, "default") @@ -563,6 +579,8 @@ function addCodeLineToGoal(name, line) { function topologicalSortReset() { split("",Visited) + split("",Slist) + split("",Scnt) } function topologicalSortAddConnection(from, to) { # Slist - list of successors by node diff --git a/tests/27_parameterized_goals_2.sh b/tests/27_parameterized_goals_2.sh index 1e51b28..e097dac 100644 --- a/tests/27_parameterized_goals_2.sh +++ b/tests/27_parameterized_goals_2.sh @@ -4,7 +4,8 @@ @goal b @params S @depends_on c @args S + echo "$S world from b" @goal c @params S1 - echo "$S1 world" + echo "$S1 world from c"