Skip to content

Commit

Permalink
Allow run-script output to have comment-lines and blank lines.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gittup committed Jun 6, 2024
1 parent 9018985 commit 4247a52
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/tup/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,6 @@ int exec_run_script(struct tupfile *tf, const char *cmdline, int lno)
while(p[0]) {
char *newline;
rslno++;
if(p[0] != ':') {
fprintf(tf->f, "tup error: run-script line %i is not a :-rule - '%s'\n", rslno, p);
goto out_err;
}
newline = strchr(p, '\n');
if(!newline) {
fprintf(tf->f, "tup error: Missing newline from :-rule in run script: '%s'\n", p);
Expand All @@ -1044,8 +1040,18 @@ int exec_run_script(struct tupfile *tf, const char *cmdline, int lno)
*newline = 0;
if(debug_run)
fprintf(tf->f, "%s\n", p);
if(parse_rule(tf, p+1, lno) < 0) {
fprintf(tf->f, "tup error: Unable to parse :-rule from run script: '%s'\n", p);
if(p[0] == ':') {
if(parse_rule(tf, p+1, lno) < 0) {
fprintf(tf->f, "tup error: Unable to parse :-rule from run script: '%s'\n", p);
goto out_err;
}
} else if(p[0] == '#' || p[0] == 0) {
/* Skip comments and blank lines */
if(debug_run) {
fprintf(tf->f, "Skipping non :-rule line %i: %s\n", rslno, p);
}
} else {
fprintf(tf->f, "tup error: run-script line %i is not a :-rule - '%s'\n", rslno, p);
goto out_err;
}
p = newline + 1;
Expand Down
38 changes: 38 additions & 0 deletions test/t2247-run-blankline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /bin/sh -e
# tup - A file-based build system
#
# Copyright (C) 2024 Mike Shal <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Make sure run script can ignore blank lines.

. ./tup.sh
check_no_windows run-script

cat > gen.sh << HERE
#! /usr/bin/env bash
for i in *; do
echo ": |> echo \$i |>"
echo ""
done
HERE
chmod +x gen.sh

cat > Tupfile << HERE
run ./gen.sh
HERE
update

eotup
38 changes: 38 additions & 0 deletions test/t2248-run-comments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /bin/sh -e
# tup - A file-based build system
#
# Copyright (C) 2024 Mike Shal <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Make sure run script can ignore comments.

. ./tup.sh
check_no_windows run-script

cat > gen.sh << HERE
#! /usr/bin/env bash
for i in *; do
echo "# basic echo rule"
echo ": |> echo \$i |>"
done
HERE
chmod +x gen.sh

cat > Tupfile << HERE
run ./gen.sh
HERE
update

eotup

0 comments on commit 4247a52

Please sign in to comment.