Skip to content

Commit

Permalink
Diminish the notion of prelude #84 : fix for candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 10, 2021
1 parent 7ab9b06 commit 7316ce5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makesurefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return
in_begin && /^}/ { in_begin=0 }
in_begin && $1 ~ /^split/ { next }
/^function gettimeofday/ { next }
{ if (!/"#"/) gsub("\\s*#.+$", ""); gsub(Q, Q "\\" Q Q); if (trim($0)) print}' makesure.awk
{ if (!/"#"/ && !/\*\#\//) gsub("\\s*#.+$", ""); gsub(Q, Q "\\" Q Q); if (trim($0)) print}' makesure.awk
echo \'' Makesurefile "$@"'
} > "$F"
chmod +x "$F"
Expand Down
50 changes: 19 additions & 31 deletions makesure_candidate
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ BEGIN {
SupportedOptions["tracing"]
SupportedOptions["silent"]
SupportedOptions["timing"]
Tmp = isDir("/dev/shm") ? "/dev/shm" : "/tmp"
DefinesFile=""
DefinesCode=""
GlobCnt = 0
GlobGoalName = ""
Mode = "prelude"
Expand Down Expand Up @@ -116,14 +115,10 @@ function handleDefine() {
$1 = ""
handleDefineLine($0)
}
function handleDefineLine(line, kv,l) {
if (!DefinesFile)
DefinesFile = executeGetLine("mktemp " Tmp "/makesure.XXXXXXXXXX")
function handleDefineLine(line, kv) {
splitKV(line, kv)
if (!(kv[0] in DefineOverrides)) {
handleCodeLine(l = line "; export " kv[0])
handleCodeLine("echo " quoteArg(l) " >> " DefinesFile)
}
if (!(kv[0] in DefineOverrides))
DefinesCode = addL(DefinesCode, line "\nexport " kv[0])
}
function handleShell() {
checkPreludeOnly()
Expand Down Expand Up @@ -325,20 +320,8 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) {
} else {
if ("timing" in Options)
t0 = currentTimeMillis()
if (length(body = trim(Code[""])) > 0) {
goalBody[0] = MyDirScript
if ("tracing" in Options)
addLine(goalBody, "set -x")
addLine(goalBody, body)
exitCode = shellExec(goalBody[0])
if (exitCode != 0) {
print " prelude failed"
realExit(exitCode)
}
}
addLine(definesLine, MyDirScript)
if (DefinesFile)
addLine(definesLine, ". " DefinesFile)
addLine(definesLine, DefinesCode)
for (i = 0; i in GoalNames; i++) {
goalName = GoalNames[i]
body = trim(Code[goalName])
Expand Down Expand Up @@ -412,11 +395,9 @@ function resolveGoalsToRun(result, i, goalName, 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") }
function currentGoalName() { return isPrelude() ? "" : arrLast(GoalNames) }
function currentGoalName() { return arrLast(GoalNames) }
function currentLibName() { return arrLast(LibNames) }
function realExit(code) {
if (DefinesFile)
rm(DefinesFile)
exit code
}
function addError(err, n) { if (!n) n=NR; Error=addL(Error, err ":\n" ARGV[1] ":" n ": " Lines[n]) }
Expand All @@ -435,26 +416,34 @@ function checkConditionReached(goalName, definesLine, conditionStr, script) {
}
function shellExec(script, res) {
script = Shell " -e -c " quoteArg(script)
script = "trap '\''exit 7'\'' INT;" script
res = system(script)
return res
}
function getMyDir(makesurefilePath) {
return executeGetLine("cd \"$(dirname " quoteArg(makesurefilePath) ")\";pwd")
}
function handleCodeLine(line, goalName, name, i) {
function handleCodeLine(line) {
if (isPrelude() && line !~ /^[ \t]*#/ && trim(line) != "") {
if (!ShellInPreludeErrorShown++)
addError("Shell code is not allowed in prelude area")
} else
addCodeLine(line)
}
function addCodeLine(line, goalName, name, i) {
if ("lib" == Mode) {
name = currentLibName()
Lib[name] = addL(Lib[name], line)
} else if ("goal_glob" == Mode) {
for (i=0; i < GlobCnt; i++){
if (!Code[goalName = globGoal(i)])
addCodeLine(goalName, makeGlobVarsCode(i))
addCodeLine(goalName, line)
addCodeLineToGoal(goalName, makeGlobVarsCode(i))
addCodeLineToGoal(goalName, line)
}
} else
addCodeLine(currentGoalName(), line)
addCodeLineToGoal(currentGoalName(), line)
}
function addCodeLine(name, line) {
function addCodeLineToGoal(name, line) {
Code[name] = addL(Code[name], line)
}
function topologicalSortAddConnection(from, to) {
Expand Down Expand Up @@ -633,7 +622,6 @@ function arrLast(arr) { return arr[arrLen(arr)-1] }
function commandExists(cmd) { return ok("command -v " cmd " >/dev/null") }
function ok(cmd) { return system(cmd) == 0 }
function isFile(path) { return ok("test -f " quoteArg(path)) }
function isDir(path) { return ok("test -d " quoteArg(path)) }
function rm(f) { system("rm " quoteArg(f)) }
function quoteArg(a) { gsub("'\''", "'\''\\'\'''\''", a); return "'\''" a "'\''" }
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
Expand Down

0 comments on commit 7316ce5

Please sign in to comment.