Skip to content

Commit

Permalink
For empty args don't produce @ in instantiated goal names #160 : at…
Browse files Browse the repository at this point in the history
…tempt
  • Loading branch information
xonixx committed Jan 6, 2024
1 parent 9d0d7a8 commit 5c38057
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
23 changes: 14 additions & 9 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function handleGoalGlob( goalName,globAllGoal,globSingle,priv,i,pattern,nfMax,
} else
pattern = $(nfMax = 4)
if (NF > nfMax && "@params" != $(nfMax + 1))
addError("nothing or @params allowed after glob pattern")
addError("nothing or @params allowed after glob pattern")
else if (pattern == "")
addError("absent glob pattern")
else {
Expand Down Expand Up @@ -627,7 +627,7 @@ function instantiateGoals( i,l,goalName) {
instantiate(goalName)
# should not be possible to list or invoke (non-instantiated) parameterized goals, so let's remove them
for (goalName in GoalsByName)
if (GoalParamsCnt[goalName] > 0) {
if (!(goalName in Instantiated)) {
arrDel(GoalNames, goalName)
delete GoalsByName[goalName]
}
Expand All @@ -637,7 +637,7 @@ function instantiateGoals( i,l,goalName) {
#
function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInstantiated,argsCnt,gi,gii,argsCode,reparsed) { # -> goalNameInstantiated
if (goal in Instantiated) return goal
# indent(IDepth++); print "instantiating " goal " { " renderArgs(args) "} ..."
indent(IDepth++); print "instantiating " goal " { " renderArgs(args) "} ..."

Instantiated[goalNameInstantiated = instantiateGoalName(goal, args)]

Expand Down Expand Up @@ -678,13 +678,13 @@ function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInst
if (dep in GoalsByName && argsCnt != GoalParamsCnt[dep])
addError("wrong args count for '" dep "'", DependenciesLineNo[gi])

# indent(IDepth); print ">dep=" dep ", argsCnt[" gi "]=" argsCnt
indent(IDepth); print ">dep=" dep ", argsCnt[" gi "]=" argsCnt

for (j = 0; j < argsCnt; j++) {
depArg = reparsed[j + 3]
depArgType = "u" == reparsed[j + 3, "quote"] ? "var" : "str"

# indent(IDepth); print ">>@ " depArg " " depArgType
indent(IDepth); print ">>@ " depArg " " depArgType

newArgs[GoalParams[dep, j]] = \
depArgType == "str" ? \
Expand All @@ -696,19 +696,24 @@ function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInst
}

gii = goalNameInstantiated SUBSEP i
dbgA("Instantiated",Instantiated)
Dependencies[gii] = instantiate(dep, newArgs)
DependenciesLineNo[gii] = DependenciesLineNo[gi]
}

# IDepth--
IDepth--
return goalNameInstantiated
}
function instantiateGoalName(goal, args, res,cnt,i) {
function instantiateGoalName(goal, args, res,cnt,i,a) {
if ((cnt = GoalParamsCnt[goal]) == 0) return goal
res = goal
for (i = 0; i < cnt; i++)
res = res "@" args[GoalParams[goal, i]]
# print "@@ " res
if (a = args[GoalParams[goal, i]])
res = res "@" a
# res = res "@" args[GoalParams[goal, i]]
# print "@@ " res
print "---instantiateGoalName "goal" -> "res
# dbgA("args",args)
return res
}

Expand Down
2 changes: 1 addition & 1 deletion tests/27_parameterized_goals.tush
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ $ ./$MAKESURE -f tests/27_parameterized_goals_6_loop_err2.sh a
? 1

$ ./$MAKESURE -f tests/27_parameterized_goals_5_ok.sh a
| goal 'b@' ...
| goal 'b' ...
| world from b
| goal 'a' [empty].

Expand Down
9 changes: 9 additions & 0 deletions tests/31_pg_names_for_empty_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

@goal @glob 'glob_test/*.txt' @params P Q
echo "$ITEM $P $Q."

@goal g1
@depends_on 'glob_test/*.txt' @args '' ''
@depends_on 'glob_test/*.txt' @args 'p' ''
@depends_on 'glob_test/*.txt' @args '' 'q'
@depends_on 'glob_test/*.txt' @args 'p' 'q'
39 changes: 39 additions & 0 deletions tests/31_pg_names_for_empty_args.tush
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

$ ./$MAKESURE -f tests/31_pg_names_for_empty_args.sh -la
| Available goals:
| g1
| 'glob_test/*.txt@@'
| glob_test/1.txt@@
| glob_test/2.txt@@
| 'glob_test/*.txt@p@'
| glob_test/1.txt@p@
| glob_test/2.txt@p@
| 'glob_test/*.txt@@q'
| glob_test/1.txt@@q
| glob_test/2.txt@@q
| 'glob_test/*.txt@p@q'
| glob_test/1.txt@p@q
| glob_test/2.txt@p@q

$ ./$MAKESURE -f tests/31_pg_names_for_empty_args.sh g1
| goal 'glob_test/1.txt@@' ...
| glob_test/1.txt .
| goal 'glob_test/2.txt@@' ...
| glob_test/2.txt .
| goal 'glob_test/*.txt@@' [empty].
| goal 'glob_test/1.txt@p@' ...
| glob_test/1.txt p .
| goal 'glob_test/2.txt@p@' ...
| glob_test/2.txt p .
| goal 'glob_test/*.txt@p@' [empty].
| goal 'glob_test/1.txt@@q' ...
| glob_test/1.txt q.
| goal 'glob_test/2.txt@@q' ...
| glob_test/2.txt q.
| goal 'glob_test/*.txt@@q' [empty].
| goal 'glob_test/1.txt@p@q' ...
| glob_test/1.txt p q.
| goal 'glob_test/2.txt@p@q' ...
| glob_test/2.txt p q.
| goal 'glob_test/*.txt@p@q' [empty].
| goal 'g1' [empty].

0 comments on commit 5c38057

Please sign in to comment.