Skip to content

Commit

Permalink
Add @lib for code reuse #36
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Aug 24, 2021
1 parent 1d52cb1 commit 4b89a47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function handleLib() {
if (libName in Lib) {
die("Lib '" libName "' is already defined")
}
arrPush(LibNames, script_name)
arrPush(LibNames, libName)
Lib[libName]
}

Expand Down Expand Up @@ -334,7 +334,7 @@ body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed, list)
if ("tracing" in Options)
addLine(goal_body, "set -x")
addLine(goal_body, trim(Code[""]))
exit_code = shellExec(goal_body[0])
exit_code = shellExec(goal_body[0]) # TODO optimize : don't exec empty prelude
if (exit_code != 0)
realExit(exit_code)

Expand Down Expand Up @@ -381,6 +381,8 @@ body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed, list)
addLine(goal_body, "exit 0")

addLine(goal_body, defines_line[0])
if (goal_name in GoalToLib)
addLine(goal_body, Lib[GoalToLib[goal_name]]) # TODO handle unknown lib

if ("tracing" in Options)
addLine(goal_body, "set -x")
Expand Down
2 changes: 1 addition & 1 deletion tests/16_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ f1 World

@goal g2
@use_lib lib_name
f1 World
f2 World
8 changes: 6 additions & 2 deletions tests/16_lib.tush
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

$ cd "$MYDIR"; ./makesure -f tests/16_lib.sh -l
| Available goals:
| a
| 15_private.sh
| g1
| g2

$ cd "$MYDIR"; ./makesure -f tests/16_lib.sh g1
| goal 'g1' ...
| Hello World

$ cd "$MYDIR"; ./makesure -f tests/16_lib.sh g2
| goal 'g2' ...
| Hello lib_name World


0 comments on commit 4b89a47

Please sign in to comment.