Skip to content

Commit 4247a52

Browse files
committed
Allow run-script output to have comment-lines and blank lines.
This makes the run-script output a little more lenient, so one could output blank lines or comments to make things more readable for debugging.
1 parent 9018985 commit 4247a52

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

src/tup/parser.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,6 @@ int exec_run_script(struct tupfile *tf, const char *cmdline, int lno)
10321032
while(p[0]) {
10331033
char *newline;
10341034
rslno++;
1035-
if(p[0] != ':') {
1036-
fprintf(tf->f, "tup error: run-script line %i is not a :-rule - '%s'\n", rslno, p);
1037-
goto out_err;
1038-
}
10391035
newline = strchr(p, '\n');
10401036
if(!newline) {
10411037
fprintf(tf->f, "tup error: Missing newline from :-rule in run script: '%s'\n", p);
@@ -1044,8 +1040,18 @@ int exec_run_script(struct tupfile *tf, const char *cmdline, int lno)
10441040
*newline = 0;
10451041
if(debug_run)
10461042
fprintf(tf->f, "%s\n", p);
1047-
if(parse_rule(tf, p+1, lno) < 0) {
1048-
fprintf(tf->f, "tup error: Unable to parse :-rule from run script: '%s'\n", p);
1043+
if(p[0] == ':') {
1044+
if(parse_rule(tf, p+1, lno) < 0) {
1045+
fprintf(tf->f, "tup error: Unable to parse :-rule from run script: '%s'\n", p);
1046+
goto out_err;
1047+
}
1048+
} else if(p[0] == '#' || p[0] == 0) {
1049+
/* Skip comments and blank lines */
1050+
if(debug_run) {
1051+
fprintf(tf->f, "Skipping non :-rule line %i: %s\n", rslno, p);
1052+
}
1053+
} else {
1054+
fprintf(tf->f, "tup error: run-script line %i is not a :-rule - '%s'\n", rslno, p);
10491055
goto out_err;
10501056
}
10511057
p = newline + 1;

test/t2247-run-blankline.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! /bin/sh -e
2+
# tup - A file-based build system
3+
#
4+
# Copyright (C) 2024 Mike Shal <marfey@gmail.com>
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License version 2 as
8+
# published by the Free Software Foundation.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License along
16+
# with this program; if not, write to the Free Software Foundation, Inc.,
17+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
19+
# Make sure run script can ignore blank lines.
20+
21+
. ./tup.sh
22+
check_no_windows run-script
23+
24+
cat > gen.sh << HERE
25+
#! /usr/bin/env bash
26+
for i in *; do
27+
echo ": |> echo \$i |>"
28+
echo ""
29+
done
30+
HERE
31+
chmod +x gen.sh
32+
33+
cat > Tupfile << HERE
34+
run ./gen.sh
35+
HERE
36+
update
37+
38+
eotup

test/t2248-run-comments.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! /bin/sh -e
2+
# tup - A file-based build system
3+
#
4+
# Copyright (C) 2024 Mike Shal <marfey@gmail.com>
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License version 2 as
8+
# published by the Free Software Foundation.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License along
16+
# with this program; if not, write to the Free Software Foundation, Inc.,
17+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
19+
# Make sure run script can ignore comments.
20+
21+
. ./tup.sh
22+
check_no_windows run-script
23+
24+
cat > gen.sh << HERE
25+
#! /usr/bin/env bash
26+
for i in *; do
27+
echo "# basic echo rule"
28+
echo ": |> echo \$i |>"
29+
done
30+
HERE
31+
chmod +x gen.sh
32+
33+
cat > Tupfile << HERE
34+
run ./gen.sh
35+
HERE
36+
update
37+
38+
eotup

0 commit comments

Comments
 (0)