Project

General

Profile

1 8291 aaronmk
#!/bin/bash -e
2 8715 aaronmk
# runscripts: a bash-based replacement for make
3 8272 aaronmk
# unlike make, supports full bash functionality including multiline commands
4
# usage: path/to/dir/run cmd args
5
6
if false; then #### run script template:
7 8291 aaronmk
#!/bin/bash -e
8 8272 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/util.run or file_including_util.run
9 9854 aaronmk
.rel other_includes
10 8272 aaronmk
11 9074 aaronmk
cmd()
12 8272 aaronmk
{
13 8881 aaronmk
	echo_func
14 8272 aaronmk
	"$(dirname "${BASH_SOURCE[0]}")"/path_relative_to_self
15
	"$(dirname "${BASH_SOURCE[1]}")"/path_relative_to_caller
16
	"$top_dir"/path_relative_to_outermost_script
17
}
18
fi ####
19
20 9013 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/../sh/util.sh
21 9854 aaronmk
.rel ../sh/make.sh
22 8703 aaronmk
23 8714 aaronmk
if self_not_included; then
24 8703 aaronmk
25 10271 aaronmk
26
#### setup
27
28
run_args_cmd() # runs the command line args command
29
{
30
	eval set -- "$(reverse "${BASH_ARGV[@]}")"
31
	test $# -ge 1 || set -- all
32
	echo_cmd "$top_script" "$@"; time "$@"
33
}
34
35 8972 aaronmk
# users can override run_args_cmd to perform other commands (or no commands)
36 8464 aaronmk
# after the script is read
37 9298 aaronmk
on_exit() { test $? -eq 0 || return; run_args_cmd; }
38 8464 aaronmk
trap on_exit EXIT
39
40 9268 aaronmk
func_override set_paths__util_sh
41
set_paths()
42 9267 aaronmk
{
43 9268 aaronmk
	set_paths__util_sh "$@"
44 9267 aaronmk
	top_file="${top_script%[./]run}"; echo_vars top_file
45
	top_filename="$(basename "$top_file")"; echo_vars top_filename
46
}
47 9268 aaronmk
set_paths
48 8988 aaronmk
49 10271 aaronmk
50
#### utils
51
52 10272 aaronmk
,() # usage: .../run , cmd1 cmd2 ... (like `make cmd1 cmd2 ...`)
53
# treats each of the command-line args as commands the way make does
54
# (instead of as args to the same command, the way runscripts do)
55
{ echo_func; for cmd in "$@"; do time echo_run "$cmd"; done; }
56
57 10271 aaronmk
fwd() # usage: subdirs=(...); fwd "$FUNCNAME" "$@"
58
{
59
	echo_func
60
	: "${subdirs?}"
61
62
	for subdir in "${subdirs[@]}"; do "$top_dir"/"$subdir"/run "$@"; done
63
}
64
65 8704 aaronmk
fi