Skip to content

Commit

Permalink
Allow @glob goals to be parameterized #155
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Jan 5, 2024
1 parent 2a05c13 commit 2b49b94
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
30 changes: 23 additions & 7 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions tests/29_glob_plus_pg.tush
Original file line number Diff line number Diff line change
@@ -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].

0 comments on commit 2b49b94

Please sign in to comment.