Skip to content

Commit

Permalink
Consider the notion of private goals #31
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Aug 17, 2021
1 parent 6ab4aac commit 833aa75
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 50 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ makesure ver. 0.9.7.1
Usage: makesure [options...] [-f buildfile] [goals...]
-f,--file buildfile
set buildfile to use (default Makesurefile)
-l,--list list all available goals
-l,--list list non-@private available goals
-la,--list-all list all available goals
-d,--resolved list resolved dependencies to reach given goals
-D "var=val",--define "var=val"
override @define values
Expand Down Expand Up @@ -129,4 +130,4 @@ TODO
- **Tup** https://github.com/gittup/tup
- Tup is a file-based build system for Linux, OSX, and Windows.
- **Please** https://github.com/thought-machine/please
- Please is a cross-language build system with an emphasis on high performance, extensibility and reproducibility.
- Please is a cross-language build system with an emphasis on high performance, extensibility and reproducibility.
114 changes: 66 additions & 48 deletions makesure_stable
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ BEGIN {
split("",ArgGoals) # invoked goals
split("",Options)
split("",GoalNames) # list
split("",GoalsByName) # name -> ""
split("",GoalsByName) # name -> private
split("",Code) # name -> body
split("",DefineOverrides) # k -> v
DefinesFile=""
split("",Dependencies) # name,i -> dep goal
split("",Dependencies) # name,i -> dep goal
split("",DependenciesLineNo) # name,i -> line no.
split("",DependenciesCnt) # name -> dep cnd
split("",Doc) # name,i -> doc str
split("",DocCnt) # name -> doc lines cnt
split("",Doc) # name -> doc str
split("",ReachedIf) # name -> condition line
split("",GlobFiles) # list
Mode = "prelude" # prelude/goal/goal_glob
srand()
prepareArgs()
MyDirScript = "MYDIR=" quoteArg(getMyDir(ARGV[1])) "; export MYDIR; cd \"$MYDIR\""
MyDirScript = "MYDIR=" quoteArg(getMyDir(ARGV[1])) ";export MYDIR;cd \"$MYDIR\""
Error=""
}
{ Lines[NR]=$0 }
"@options" == $1 { handleOptions(); next }
Expand Down Expand Up @@ -67,7 +68,8 @@ function prepareArgs( i,arg) {
print "Usage: makesure [options...] [-f buildfile] [goals...]"
print " -f,--file buildfile"
print " set buildfile to use (default Makesurefile)"
print " -l,--list list all available goals"
print " -l,--list list non-@private available goals"
print " -la,--list-all list all available goals"
print " -d,--resolved list resolved dependencies to reach given goals"
print " -D \"var=val\",--define \"var=val\""
print " override @define values"
Expand Down Expand Up @@ -117,18 +119,17 @@ function handleOptions() {
for (i=2; i<=NF; i++) {
if (!($i in SupportedOptions))
die("Option " $i " is not supported")
addError("Option '\''" $i "'\'' is not supported")
Options[$i]
}
}
function handleDefine( line,kv) {
checkPreludeOnly()
$1 = ""
handleDefineLine($0)
}
function handleDefineLine(line, kv) {
checkPreludeOnly()
if (!DefinesFile)
DefinesFile = executeGetLine("mktemp " Tmp "/makesure.XXXXXXXXXX")
Expand All @@ -146,7 +147,7 @@ function handleShell() {
Shell = trim($2)
if (!(Shell in SupportedShells))
die("Shell '\''" Shell "'\'' is not supported")
addError("Shell '\''" Shell "'\'' is not supported")
}
function adjustOptions() {
Expand All @@ -159,39 +160,47 @@ function started(mode) {
Mode = mode
}
function handleGoal() {
function handleGoal( priv) {
started("goal")
registerGoal($2)
priv = parseGoalLine()
registerGoal($0, priv)
}
function registerGoal(goal_name) {
function registerGoal(goal_name, priv) {
goal_name = trim(goal_name)
if (length(goal_name) == 0) {
die("Goal must have a name")
}
if (goal_name in GoalsByName) {
die("Goal " goal_name " is already defined")
}
if (length(goal_name) == 0)
addError("Goal must have a name")
if (goal_name in GoalsByName)
addError("Goal '\''" goal_name "'\'' is already defined")
arrPush(GoalNames, goal_name)
GoalsByName[goal_name]
GoalsByName[goal_name] = priv
}
function calcGlob(pattern, script, file) {
split("",GlobFiles)
script = MyDirScript "; for f in ./" pattern " ; do test -e \"$f\" && echo \"$f\" ; done"
while (script | getline file) {
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)
}
close(script)
}
function handleGoalGlob( goal_name,i) {
started("goal_glob")
function parseGoalLine( priv) {
if ($NF == "@private") {
priv=1
NF--
}
$1 = ""
return 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])
registerGoal(GlobFiles[i], priv)
}
}
Expand All @@ -208,8 +217,10 @@ function handleDoc( i) {
}
function registerDoc(goal_name) {
if (goal_name in Doc)
addError("Multiple " $1 " not allowed for a goal")
$1 = ""
Doc[goal_name, DocCnt[goal_name]++] = trim($0)
Doc[goal_name] = trim($0)
}
function handleDependsOn( i) {
Expand All @@ -227,6 +238,7 @@ function handleDependsOn( i) {
function registerDependsOn(goal_name, i) {
for (i=2; i<=NF; i++) {
Dependencies[goal_name, DependenciesCnt[goal_name]++] = $i
DependenciesLineNo[goal_name, DependenciesCnt[goal_name]] = NR
}
}
Expand All @@ -243,33 +255,38 @@ function handleReachedIf( i) {
}
function makeGlobVarsCode(i) {
return "ITEM=" quoteArg(GlobFiles[i]) "; INDEX=" i "; TOTAL=" arrLen(GlobFiles) "; "
return "ITEM=" quoteArg(GlobFiles[i]) ";INDEX=" i ";TOTAL=" arrLen(GlobFiles) ";"
}
function registerReachedIf(goal_name, pre_script) {
if (goal_name in ReachedIf) {
die("Multiple " $1 " not allowed for a goal")
}
if (goal_name in ReachedIf)
addError("Multiple " $1 " not allowed for a goal")
$1 = ""
ReachedIf[goal_name] = pre_script trim($0)
}
function doWork(\
i,j,goal_name,dep_cnt,dep,reached_if,reached_goals,empty_goals,defines_line,
body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed) {
body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed, list) {
started("end") # end last directive
if ("-l" in Args || "--list" in Args) {
if (Error)
dieMsg(Error)
list="-l" in Args || "--list" in Args
if (list || "-la" in Args || "--list-all" in Args) {
print "Available goals:"
for (i = 0; i < arrLen(GoalNames); i++) {
goal_name = GoalNames[i]
print " " goal_name
if (goal_name in DocCnt) {
for (j = 0; j < DocCnt[goal_name]; j++)
print " " Doc[goal_name, j]
}
if (list && GoalsByName[goal_name]) # private
continue
printf " "
if (goal_name in Doc)
printf "%s - %s\n", goal_name, Doc[goal_name]
else
print goal_name
}
} else {
if ("timing" in Options)
Expand All @@ -285,9 +302,8 @@ body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed) {
realExit(exit_code)
addLine(defines_line, MyDirScript)
if (DefinesFile) {
if (DefinesFile)
addLine(defines_line, ". " DefinesFile)
}
for (i = 0; i < arrLen(GoalNames); i++) {
goal_name = GoalNames[i]
Expand All @@ -303,7 +319,7 @@ body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed) {
for (j=0; j < dep_cnt; j++) {
dep = Dependencies[goal_name, j]
if (!(dep in GoalsByName))
dieMsg("Goal '\''" goal_name "'\'' has unknown dependency '\''" dep "'\''") # TODO find a way to provide line reference
die("Goal '\''" goal_name "'\'' has unknown dependency '\''" dep "'\''", DependenciesLineNo[goal_name, j])
if (!reached_goals[goal_name]) {
# we only add a dependency to this goal if it'\''s not reached
#print " [not reached] " goal_name " -> " dep
Expand Down Expand Up @@ -376,7 +392,7 @@ function resolveGoalsToRun(result, i, goal_name, loop) {
for (i = 0; i < arrLen(ArgGoals); i++) {
goal_name = ArgGoals[i]
if (!(goal_name in GoalsByName)) {
dieMsg("Goal not found: " goal_name) # TODO can we show line number here?
dieMsg("Goal not found: " goal_name)
}
topologicalSortPerform(goal_name, result, loop)
}
Expand All @@ -387,16 +403,17 @@ function resolveGoalsToRun(result, i, goal_name, loop) {
}
function isPrelude() { return "prelude"==Mode }
function checkPreludeOnly() { if (!isPrelude()) die("Only use " $1 " in prelude") }
function checkGoalOnly() { if ("goal" != Mode && "goal_glob" != Mode) die("Only use " $1 " in goal/goal_glob") }
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 currentGoalName() { return isPrelude() ? "" : arrLast(GoalNames) }
function realExit(code, i) {
Died = 1
if (DefinesFile)
system("rm " DefinesFile)
rm(DefinesFile)
exit code
}
function addError(err) { Error=addL(Error, err ":\n" ARGV[1] ":" NR ": " Lines[NR]) }
function die(msg, n) { if (!n) n=NR; dieMsg(msg ":\n" ARGV[1] ":" n ": " Lines[n]) }
function dieMsg(msg, out) {
out = "cat 1>&2" # trick to write from awk to stderr
Expand All @@ -422,7 +439,7 @@ function shellExec(script, res) {
}
function getMyDir(makesurefilePath) {
return executeGetLine("cd \"$(dirname " quoteArg(makesurefilePath) ")\"; pwd")
return executeGetLine("cd \"$(dirname " quoteArg(makesurefilePath) ")\";pwd")
}
function handleCodeLine(line, goal_name) {
Expand Down Expand Up @@ -487,8 +504,8 @@ function selfUpdate( url, tmp, err, newVer) {
else print "updated " Version " -> " newVer
} else print "you have latest version " Version " installed"
}
system("rm " tmp)
if (err) dieMsg(err);
rm(tmp)
if (err) dieMsg(err)
}
function renderDuration(deltaMillis,\
Expand Down Expand Up @@ -562,6 +579,7 @@ 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; }
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
' Makesurefile "$@"

0 comments on commit 833aa75

Please sign in to comment.