From 2b49b94d3f2568748565b7be7edb74bb4626838c Mon Sep 17 00:00:00 2001 From: xonix Date: Fri, 5 Jan 2024 17:20:41 +0200 Subject: [PATCH] Allow `@glob` goals to be parameterized #155 --- makesure.awk | 30 +++++++++++++----- tests/29_glob_plus_pg.tush | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/makesure.awk b/makesure.awk index d57eb06..22d7781 100755 --- a/makesure.awk +++ b/makesure.awk @@ -30,6 +30,7 @@ BEGIN { delete Lib # name -> code delete UseLibLineNo# name -> line no. delete GoalToLib # goal name -> lib name + delete GlobPgParams # TODO delete EMPTY Mode = "prelude" # prelude|define|goal|goal_glob|lib srand() @@ -242,27 +243,42 @@ function parsePriv() { NF-- return 1 } -function handleGoalGlob( goalName,globAllGoal,globSingle,priv,i,pattern,nfMax) { +function handleGoalGlob( goalName,globAllGoal,globSingle,priv,i,pattern,nfMax,gi,j,l) { started("goal_glob") + delete GlobPgParams priv = parsePriv() if ("@glob" == (goalName = $2)) { goalName = ""; pattern = $(nfMax = 3) } else pattern = $(nfMax = 4) - if (NF > nfMax) - addError("nothing allowed after glob pattern") + if (NF > nfMax && "@params" != $(nfMax + 1)) + addError("nothing allowed after glob pattern") # TODO adjust error else if (pattern == "") addError("absent glob pattern") else { + if ("@params" == $(nfMax + 1)) + for (i = nfMax + 2; i <= NF; i++) + arrPush(GlobPgParams, validateParamName($i)) calcGlob(goalName, pattern) globAllGoal = goalName ? goalName : pattern globSingle = GlobCnt == 1 && globAllGoal == globGoal(0) - for (i = 0; i < GlobCnt; i++) - registerGoal(globSingle ? priv : 1, globGoal(i)) - if (!globSingle) { # glob on single file + for (i = 0; i < GlobCnt; i++) { + registerGoal(globSingle ? priv : 1, gi = globGoal(i)) + for (j = 0; j in GlobPgParams; j++) + GoalParams[gi, GoalParamsCnt[gi]++] = GlobPgParams[j] + } if (!globSingle) { # glob on single file registerGoal(priv, globAllGoal) - for (i = 0; i < GlobCnt; i++) + for (j = 0; j in GlobPgParams; j++) + GoalParams[globAllGoal, GoalParamsCnt[globAllGoal]++] = GlobPgParams[j] + for (i = 0; i < GlobCnt; i++) { registerDependency(globAllGoal, globGoal(i)) + if (arrLen(GlobPgParams)) { + l = "@depends_on x @params" + for (j = 0; j in GlobPgParams; j++) + l = l " " GlobPgParams[j] + DependencyArgsL[globAllGoal, i] = l + } + } } } } diff --git a/tests/29_glob_plus_pg.tush b/tests/29_glob_plus_pg.tush index e2d161c..00ef160 100644 --- a/tests/29_glob_plus_pg.tush +++ b/tests/29_glob_plus_pg.tush @@ -1,16 +1,80 @@ $ ./$MAKESURE -f tests/29_glob_plus_pg_1.sh -l +| Available goals: +| g1 +| g2 +| g3 +| gpg@hello +| gpg@hi +| g3pg@salut +| gpg@salut $ ./$MAKESURE -f tests/29_glob_plus_pg_1.sh g1 +| goal 'gpg@glob_test/1.txt@hello' ... +| glob_test/1.txt hello +| goal 'gpg@glob_test/2.txt@hello' ... +| glob_test/2.txt hello +| goal 'gpg@hello' [empty]. +| goal 'g1' [empty]. $ ./$MAKESURE -f tests/29_glob_plus_pg_1.sh g2 +| goal 'gpg@glob_test/1.txt@hello' ... +| glob_test/1.txt hello +| goal 'gpg@glob_test/2.txt@hello' ... +| glob_test/2.txt hello +| goal 'gpg@hello' [empty]. +| goal 'gpg@glob_test/1.txt@hi' ... +| glob_test/1.txt hi +| goal 'gpg@glob_test/2.txt@hi' ... +| glob_test/2.txt hi +| goal 'gpg@hi' [empty]. +| goal 'g2' [empty]. $ ./$MAKESURE -f tests/29_glob_plus_pg_1.sh g3 +| goal 'gpg@glob_test/1.txt@salut' ... +| glob_test/1.txt salut +| goal 'gpg@glob_test/2.txt@salut' ... +| glob_test/2.txt salut +| goal 'gpg@salut' [empty]. +| goal 'g3pg@salut' [empty]. +| goal 'g3' [empty]. $ ./$MAKESURE -f tests/29_glob_plus_pg_2.sh -l +| Available goals: +| g1 +| g2 +| g3 +| 'glob_test/*.txt@hello' +| 'glob_test/*.txt@hi' +| g3pg@salut +| 'glob_test/*.txt@salut' $ ./$MAKESURE -f tests/29_glob_plus_pg_2.sh g1 +| goal 'glob_test/1.txt@hello' ... +| glob_test/1.txt hello +| goal 'glob_test/2.txt@hello' ... +| glob_test/2.txt hello +| goal 'glob_test/*.txt@hello' [empty]. +| goal 'g1' [empty]. $ ./$MAKESURE -f tests/29_glob_plus_pg_2.sh g2 +| goal 'glob_test/1.txt@hello' ... +| glob_test/1.txt hello +| goal 'glob_test/2.txt@hello' ... +| glob_test/2.txt hello +| goal 'glob_test/*.txt@hello' [empty]. +| goal 'glob_test/1.txt@hi' ... +| glob_test/1.txt hi +| goal 'glob_test/2.txt@hi' ... +| glob_test/2.txt hi +| goal 'glob_test/*.txt@hi' [empty]. +| goal 'g2' [empty]. $ ./$MAKESURE -f tests/29_glob_plus_pg_2.sh g3 +| goal 'glob_test/1.txt@salut' ... +| glob_test/1.txt salut +| goal 'glob_test/2.txt@salut' ... +| glob_test/2.txt salut +| goal 'glob_test/*.txt@salut' [empty]. +| goal 'g3pg@salut' [empty]. +| goal 'g3' [empty].