Skip to content

Commit 6aec550

Browse files
committed
use make --silent instead of '@'-prefixing to suppress make's default command code printing
1 parent ee050a3 commit 6aec550

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

runfile.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function print-file-smartcase() {
163163
}
164164

165165
function print-makefile() {
166-
sed -E "s!\t${at}make --makefile ${makefile} !\t${at}make !" "$@"
166+
sed -E "s!\tmake --makefile ${makefile} !\tmake !" "$@"
167167
}
168168

169169
function print-runfile-commands() {
@@ -403,7 +403,7 @@ function wizard() {
403403
}
404404

405405
function run() ( set -euo pipefail
406-
local makefile='' buffer='' at='' task=''
406+
local makefile='' buffer='' task=''
407407
local arg='' make_args=() named_args=() pos_args=() pos_arg_idx=0
408408

409409
local runfile_variables='' runfile_variable_re=''
@@ -469,13 +469,6 @@ function run() ( set -euo pipefail
469469
# Temporary Makefile which we will pass to make:
470470
makefile="$( mktemp )"
471471
472-
# @-prefix causes Make to execute tasks silently (without printing task code):
473-
at="@"
474-
[[ " $* " == *' --verbose '* ]] || \
475-
[[ "${RUNFILE_VERBOSE:-}" =~ ^(1|true|TRUE|True)$ ]] || \
476-
[[ " $* " == *' --make-dry-run '* ]] && \
477-
at="" # Remove @-prefix so that Make prints task code before executing tasks.
478-
479472
# Separate arguments into categories:
480473
# make_args · Arguments that will be passed on to Make.
481474
# named_args · name=value arguments interpolated into $(name) within task code.
@@ -558,14 +551,14 @@ $(
558551
| sed -E \
559552
-e 's/[[:space:]]*$//' \
560553
`# trim any trailing whitespace from lines` \
561-
-e "s!^[[:space:]]*([^[:space:]])!\t${at}\1!" \
562-
`# prefix every non-blank line with TAB-@ (or just TAB, if verbose)` \
563-
-e "s!^\t${at}${task_re}(.*)\$!\n.PHONY: \1\n\1:${subtask_re}\#\3!" \
564-
`# remove TAB (or TAB-@) prefix from lines that match task pattern` \
565-
-e "s!^\t${at}((then|do|else|elif|\||&&|\|\|)[[:space:]]+.*|fi|done)\$!\t\1!" \
566-
`# remove TAB (or TAB-@) prefix from bash-keyword lines` \
567-
-e "s!^\t(@?)(if|for|while|then|do|else|elif)[[:space:]](.*)\$!\t\1\2 \3; \\\\!" \
568-
`# automatically add backslashes to multiline statements` \
554+
-e "s!^[[:space:]]*([^[:space:]])!\t\1!" \
555+
`# prefix every non-blank line with TAB` \
556+
-e "s!^\t${task_re}(.*)\$!\n.PHONY: \1\n\1:${subtask_re}\#\3!" \
557+
`# remove TAB prefix from lines that match task pattern` \
558+
-e "s!^\t(if|elif|then|else|for|while)[[:space:]](.*;.*)\$!\t\1 \2 \\\\!" \
559+
-e "s!^\t(if|elif|then|else|for|while)[[:space:]]([^;]*)\$!\t\1 \2; \\\\!" \
560+
-e "s!^\t(then|do|else|elif)\$!\t\1 \\\\!" \
561+
`# automatically add backslashes to multiline statements (if, for, while)` \
569562
| cat -s
570563
)
571564
@@ -680,7 +673,7 @@ EOF
680673
then
681674
# If a specific runfile trap is being triggered, remove that trap's prefix
682675
# (eg. EXIT) from lines in makefile so they can be executed normally:
683-
buffer="$( sed -E "s!^\t${at}${RUNFILE_TRAP} !\t${at}!" "${makefile}" )"
676+
buffer="$( sed -E "s!^\t${RUNFILE_TRAP} !\t!" "${makefile}" )"
684677

685678
# Write buffer back to temporary makefile:
686679
echo "${buffer}" > "${makefile}"
@@ -692,7 +685,14 @@ EOF
692685
fi
693686

694687
# Main Path · Invoke Make with generated Makefile and prepared arguments:
695-
make --makefile "${makefile}" "${make_args[@]}"
688+
if [[ " $* " == *' --verbose '* ]] \
689+
|| [[ "${RUNFILE_VERBOSE:-}" =~ ^(1|true|TRUE|True)$ ]] \
690+
|| [[ " $* " == *' --make-dry-run '* ]]
691+
then
692+
make --makefile "${makefile}" "${make_args[@]}"
693+
else
694+
make --silent --makefile "${makefile}" "${make_args[@]}"
695+
fi
696696

697697
# Main Path · Clean up temporary Makefile and exit with success:
698698
rm "${makefile}"

tests/Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ _tasks: .tasks
33

44
.PHONY: start
55
start: stop # start app
6-
@run build env=dev # tasks can be run directly from other tasks
7-
@echo "starting app in 3 seconds"
8-
@loading
9-
@sleep 3
6+
run build env=dev # tasks can be run directly from other tasks
7+
echo "starting app in 3 seconds"
8+
loading
9+
sleep 3
1010

1111
.PHONY: stop
1212
stop: # stop app
13-
@echo "stopping app"
13+
echo "stopping app"
1414

1515
.PHONY: build
1616
build: lint # build app for environment [vars: env]
17-
@[[ -n $(env) ]] && echo "buiding app for $(env)" || echo "error: missing env"
17+
[[ -n $(env) ]] && echo "buiding app for $(env)" || echo "error: missing env"
1818

1919
.PHONY: test
2020
test: # run all tests or specific tests [vars: name1, name2, etc.]
21-
@run build env=test
22-
@[[ -n $(@) ]] && echo "running tests $(@)" || echo "running all tests"
21+
run build env=test
22+
[[ -n $(@) ]] && echo "running tests $(@)" || echo "running all tests"
2323

2424
.PHONY: lint
2525
lint: # lint all files or specific file [vars: file]
26-
@[[ -n $(1) ]] && echo "linting file $(1)" || echo "linting all files"
26+
[[ -n $(1) ]] && echo "linting file $(1)" || echo "linting all files"
2727

2828
.PHONY: .tasks
2929
.tasks:

tests/test.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ function test_makefile() {
7878

7979
function test_makefile_task_start() {
8080
execute_test_command
81-
assert_output -p "$( cat ./Makefile | grep "@" | head -4 | sed 's/^.*@//' )"
81+
assert_output -p "$( cat ./Makefile | grep '^\t' | head -4 | tr '\t' '' )"
8282
assert_success
8383
}
8484
@test "${BATS_TEST_NUMBER} run --makefile start" { test_makefile_task_start; }
8585
@test "${BATS_TEST_NUMBER} run -m start" { test_makefile_task_start; }
8686

8787
function test_makefile_task_stop() {
8888
execute_test_command
89-
assert_output -p "$( cat ./Makefile | grep "@" | head -5 | tail -1 | sed 's/^.*@//' )"
89+
assert_output -p "$( cat ./Makefile | grep '^\t' | head -5 | tail -1 | tr '\t' '' )"
9090
assert_success
9191
}
9292
@test "${BATS_TEST_NUMBER} run --makefile stop" { test_makefile_task_stop; }

0 commit comments

Comments
 (0)