diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e3739..6fa4aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.9.18 +- Optimizations and fixes to `@reached_if` handling in [#104](https://github.com/xonixx/makesure/issues/104) and [#29](https://github.com/xonixx/makesure/issues/29) (thanks @08d2) +- Added autocompletion script for bash in [#75](https://github.com/xonixx/makesure/issues/75) + ## v0.9.17 - Allows `@define` in any position in file [#95](https://github.com/xonixx/makesure/issues/95) diff --git a/Makesurefile b/Makesurefile index 510a36f..2de054e 100644 --- a/Makesurefile +++ b/Makesurefile @@ -1,7 +1,7 @@ # vim: syntax=bash @options timing -@define NEXT_VERSION='0.9.17' +@define NEXT_VERSION='0.9.18' @define GOAWK_VERSION='1.15.0' @define JUST_VERSION='0.10.5' @define GOAWK="goawk$GOAWK_VERSION" diff --git a/README.md b/README.md index 2fcd1c5..5854417 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ By default, all scripts inside goals are executed with `bash`. If you want to us ``` $ ./makesure -h -makesure ver. 0.9.17 +makesure ver. 0.9.18 Usage: makesure [options...] [-f buildfile] [goals...] -f,--file buildfile set buildfile to use (default Makesurefile) diff --git a/makesure b/makesure index 9fa23e5..ccf243e 100755 --- a/makesure +++ b/makesure @@ -1,6 +1,6 @@ #!/bin/sh if command -v gawk >/dev/null;then makesure_awk='gawk -ltime -v Gawk=1';makesure_pre='';else makesure_awk=awk;makesure_pre='function gettimeofday(){}';fi -exec $makesure_awk -v "Version=0.9.17" -v "Prog=$0" "$makesure_pre"' +exec $makesure_awk -v "Version=0.9.18" -v "Prog=$0" "$makesure_pre"' BEGIN { Shell = "bash" SupportedShells["bash"] @@ -296,8 +296,13 @@ function checkBeforeRun( i,j,dep,depCnt,goalName,visited) { } } } +function getPreludeCode( a) { + addLine(a, MyDirScript) + addLine(a, DefinesCode) + return a[0] +} function doWork(\ - i,j,goalName,gnLen,gnMaxLen,depCnt,dep,reachedIf,reachedGoals,emptyGoals,definesLine, + i,j,goalName,gnLen,gnMaxLen,depCnt,dep,reachedGoals,emptyGoals,preludeCode, body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) { started("end") checkBeforeRun() @@ -326,37 +331,35 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) { } else { if (timingOn()) t0 = currentTimeMillis() - addLine(definesLine, MyDirScript) - addLine(definesLine, DefinesCode) for (i = 0; i in GoalNames; i++) { - goalName = GoalNames[i] - body = trim(Code[goalName]) - reachedIf = ReachedIf[goalName] - reachedGoals[goalName] = reachedIf ? checkConditionReached(goalName, definesLine[0], reachedIf) : 0 - emptyGoals[goalName] = length(body) == 0 - depCnt = DependenciesCnt[goalName] + depCnt = DependenciesCnt[goalName = GoalNames[i]] for (j=0; j < depCnt; j++) { dep = Dependencies[goalName, j] - if (!reachedGoals[goalName]) { - topologicalSortAddConnection(goalName, dep) - } else { - } + topologicalSortAddConnection(goalName, dep) } + } + topologicalSort(0,GoalNames) + topologicalSort(1,ArgGoals,resolvedGoals,reachedGoals) + preludeCode = getPreludeCode() + for (i = 0; i in GoalNames; i++) { + goalName = GoalNames[i] + body = trim(Code[goalName]) + emptyGoals[goalName] = length(body) == 0 goalBody[0] = "" - addLine(goalBody, definesLine[0]) + addLine(goalBody, preludeCode) if (goalName in GoalToLib) addLine(goalBody, Lib[GoalToLib[goalName]]) addLine(goalBody, body) goalBodies[goalName] = goalBody[0] } - resolveGoalsToRun(resolvedGoals) if ("-d" in Args || "--resolved" in Args) { printf "Resolved goals to reach for" for (i = 0; i in ArgGoals; i++) printf " %s", quote2(ArgGoals[i],1) print ":" for (i = 0; i in resolvedGoals; i++) - print " " quote2(resolvedGoals[i]) + if (!reachedGoals[goalName=resolvedGoals[i]] && !emptyGoals[goalName]) + print " " quote2(goalName) } else { for (i = 0; i in resolvedGoals; i++) { goalName = resolvedGoals[i] @@ -382,15 +385,16 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) { } } } -function resolveGoalsToRun(result, i, goalName, loop) { - if (arrLen(ArgGoals) == 0) - arrPush(ArgGoals, "default") - for (i = 0; i in ArgGoals; i++) { - goalName = ArgGoals[i] +function topologicalSort(includeReachedIf,requestedGoals,result,reachedGoals, i,goalName,loop) { + topologicalSortReset() + if (arrLen(requestedGoals) == 0) + arrPush(requestedGoals, "default") + for (i = 0; i in requestedGoals; i++) { + goalName = requestedGoals[i] if (!(goalName in GoalsByName)) { die("Goal not found: " goalName) } - topologicalSortPerform(goalName, result, loop) + topologicalSortPerform(includeReachedIf,reachedGoals, goalName, result, loop) } if (loop[0] == 1) { die("There is a loop in goal dependencies via " loop[1] " -> " loop[2]) @@ -412,8 +416,8 @@ function die(msg, out) { close(out) realExit(1) } -function checkConditionReached(goalName, definesLine, conditionStr, script) { - script = definesLine +function checkConditionReached(goalName, conditionStr, script) { + script = getPreludeCode() if (goalName in GoalToLib) script = script "\n" Lib[GoalToLib[goalName]] script = script "\n" conditionStr @@ -455,16 +459,25 @@ function addCodeLine(line, goalName, name, i) { function addCodeLineToGoal(name, line) { Code[name] = addL(Code[name], line) } +function topologicalSortReset() { + split("",Visited) +} function topologicalSortAddConnection(from, to) { Slist[from, ++Scnt[from]] = to } -function topologicalSortPerform(node, result, loop, i, s) { +function topologicalSortPerform(includeReachedIf,reachedGoals, node, result, loop, i, s) { if (Visited[node] == 2) return + if (includeReachedIf && node in ReachedIf && checkConditionReached(node, ReachedIf[node])){ + Visited[node] = 2 + arrPush(result, node) + reachedGoals[node] = 1 + return + } Visited[node] = 1 for (i = 1; i <= Scnt[node]; i++) { if (Visited[s = Slist[node, i]] == 0) - topologicalSortPerform(s, result, loop) + topologicalSortPerform(includeReachedIf,reachedGoals, s, result, loop) else if (Visited[s] == 1) { loop[0] = 1 loop[1] = s diff --git a/makesure_candidate b/makesure_candidate index 91ea2b4..ccf243e 100755 --- a/makesure_candidate +++ b/makesure_candidate @@ -1,6 +1,6 @@ #!/bin/sh if command -v gawk >/dev/null;then makesure_awk='gawk -ltime -v Gawk=1';makesure_pre='';else makesure_awk=awk;makesure_pre='function gettimeofday(){}';fi -exec $makesure_awk -v "Version=0.9.17" -v "Prog=$0" "$makesure_pre"' +exec $makesure_awk -v "Version=0.9.18" -v "Prog=$0" "$makesure_pre"' BEGIN { Shell = "bash" SupportedShells["bash"]