Skip to content

Commit

Permalink
Redesign @goal_glob #34
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Aug 23, 2021
1 parent d1eb63f commit dc8b5c4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makesurefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@goal prepared4tests @private
@depends_on tush_installed debug

@goal_glob tests/*.tush @private
@goal @glob tests/*.tush @private
@depends_on prepared4tests
f="$ITEM"

Expand Down
1 change: 1 addition & 0 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ BEGIN {
"@doc" == $1 { handleDoc(); next }
"@depends_on" == $1 { handleDependsOn(); next }
"@reached_if" == $1 { handleReachedIf(); next }
$1 ~ /^@/ { addError("Unknown directive: " $1); next }
{ handleCodeLine($0); next }

END { if (!Died) doWork() }
Expand Down
39 changes: 23 additions & 16 deletions makesure_stable
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ BEGIN {
split("",Doc) # name -> doc str
split("",ReachedIf) # name -> condition line
split("",GlobFiles) # list
split("",GlobGoals) # list
Mode = "prelude" # prelude/goal/goal_glob
srand()
prepareArgs()
Expand All @@ -36,11 +37,11 @@ BEGIN {
"@options" == $1 { handleOptions(); next }
"@define" == $1 { handleDefine(); next }
"@shell" == $1 { handleShell(); next }
"@goal" == $1 { handleGoal(); next }
"@goal_glob" == $1 { handleGoalGlob(); next }
"@goal" == $1 { if ("@glob" == $2 || "@glob" == $3) handleGoalGlob(); else handleGoal(); next }
"@doc" == $1 { handleDoc(); next }
"@depends_on" == $1 { handleDependsOn(); next }
"@reached_if" == $1 { handleReachedIf(); next }
$1 ~ /^@/ { addError("Unknown directive: " $1); next }
{ handleCodeLine($0); next }
END { if (!Died) doWork() }
Expand Down Expand Up @@ -176,12 +177,14 @@ function registerGoal(goal_name, priv) {
GoalsByName[goal_name] = priv
}
function calcGlob(pattern, script, file) {
function calcGlob(goal_name, pattern, script, file) {
split("",GlobGoals)
split("",GlobFiles)
script = MyDirScript ";for f in ./" pattern ";do test -e \"$f\" && echo \"$f\";done"
while ((script | getline file)>0) {
file = substr(file, 3)
arrPush(GlobFiles,file)
arrPush(GlobGoals,(goal_name ? goal_name "@" : "") file)
}
close(script)
}
Expand All @@ -198,9 +201,13 @@ function parseGoalLine( priv) {
function handleGoalGlob( goal_name,priv,i) {
started("goal_glob")
priv = parseGoalLine()
calcGlob(trim($0))
for (i=0; i<arrLen(GlobFiles); i++){
registerGoal(GlobFiles[i], priv)
goal_name = $2; $2 = ""
if ("@glob" == goal_name) {
goal_name = ""
} else $3 = ""
calcGlob(goal_name, trim($0))
for (i=0; i<arrLen(GlobGoals); i++){
registerGoal(GlobGoals[i], priv)
}
}
Expand All @@ -210,8 +217,8 @@ function handleDoc( i) {
if ("goal" == Mode)
registerDoc(currentGoalName())
else {
for (i=0; i<arrLen(GlobFiles); i++){
registerDoc(GlobFiles[i])
for (i=0; i<arrLen(GlobGoals); i++){
registerDoc(GlobGoals[i])
}
}
}
Expand All @@ -229,8 +236,8 @@ function handleDependsOn( i) {
if ("goal" == Mode)
registerDependsOn(currentGoalName())
else {
for (i=0; i<arrLen(GlobFiles); i++){
registerDependsOn(GlobFiles[i])
for (i=0; i<arrLen(GlobGoals); i++){
registerDependsOn(GlobGoals[i])
}
}
}
Expand All @@ -248,14 +255,14 @@ function handleReachedIf( i) {
if ("goal" == Mode)
registerReachedIf(currentGoalName())
else {
for (i=0; i<arrLen(GlobFiles); i++){
registerReachedIf(GlobFiles[i], makeGlobVarsCode(i))
for (i=0; i<arrLen(GlobGoals); i++){
registerReachedIf(GlobGoals[i], makeGlobVarsCode(i))
}
}
}
function makeGlobVarsCode(i) {
return "ITEM=" quoteArg(GlobFiles[i]) ";INDEX=" i ";TOTAL=" arrLen(GlobFiles) ";"
return "ITEM=" quoteArg(GlobFiles[i]) ";INDEX=" i ";TOTAL=" arrLen(GlobGoals) ";"
}
function registerReachedIf(goal_name, pre_script) {
Expand Down Expand Up @@ -404,7 +411,7 @@ function resolveGoalsToRun(result, i, goal_name, loop) {
function isPrelude() { return "prelude"==Mode }
function checkPreludeOnly() { if (!isPrelude()) addError("Only use " $1 " in prelude") }
function checkGoalOnly() { if ("goal" != Mode && "goal_glob" != Mode) addError("Only use " $1 " in @goal/@goal_glob") }
function checkGoalOnly() { if ("goal" != Mode && "goal_glob" != Mode) addError("Only use " $1 " in @goal") }
function currentGoalName() { return isPrelude() ? "" : arrLast(GoalNames) }
function realExit(code, i) {
Expand Down Expand Up @@ -444,8 +451,8 @@ function getMyDir(makesurefilePath) {
function handleCodeLine(line, goal_name) {
if ("goal_glob" == Mode) {
for (i=0; i<arrLen(GlobFiles); i++){
if (!Code[goal_name = GlobFiles[i]])
for (i=0; i<arrLen(GlobGoals); i++){
if (!Code[goal_name = GlobGoals[i]])
addCodeLine(goal_name, makeGlobVarsCode(i))
addCodeLine(goal_name, line)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/13_errors.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

@reached_if true
@depend_on g1
@depends_on g1
@doc Doc in prelude
@options usupported
@shell usupported
Expand All @@ -9,7 +9,7 @@
echo Goal without name

@goal g1
@depend_on unknown
@depends_on unknown

@goal g1
@reached_if false
Expand All @@ -24,3 +24,4 @@
@doc doc1
@doc doc2
@options timing
@unknown_directive arg
4 changes: 4 additions & 0 deletions tests/13_errors.tush
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
$ cd "$MYDIR"; ./makesure -f tests/13_errors.sh
@ Only use @reached_if in @goal:
@ tests/13_errors.sh:2: @reached_if true
@ Only use @depends_on in @goal:
@ tests/13_errors.sh:3: @depends_on g1
@ Only use @doc in @goal:
@ tests/13_errors.sh:4: @doc Doc in prelude
@ Option 'usupported' is not supported:
Expand All @@ -22,4 +24,6 @@ $ cd "$MYDIR"; ./makesure -f tests/13_errors.sh
@ tests/13_errors.sh:25: @doc doc2
@ Only use @options in prelude:
@ tests/13_errors.sh:26: @options timing
@ Unknown directive: @unknown_directive:
@ tests/13_errors.sh:27: @unknown_directive arg
? 1

0 comments on commit dc8b5c4

Please sign in to comment.