From 4247a523587df54bd4a65ec42c4247a8488c050e Mon Sep 17 00:00:00 2001 From: Mike Shal Date: Sun, 2 Jun 2024 07:32:27 -0700 Subject: [PATCH] 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. --- src/tup/parser.c | 18 ++++++++++++------ test/t2247-run-blankline.sh | 38 +++++++++++++++++++++++++++++++++++++ test/t2248-run-comments.sh | 38 +++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100755 test/t2247-run-blankline.sh create mode 100755 test/t2248-run-comments.sh diff --git a/src/tup/parser.c b/src/tup/parser.c index e9e7e1b79..19bb837d8 100644 --- a/src/tup/parser.c +++ b/src/tup/parser.c @@ -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); @@ -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; diff --git a/test/t2247-run-blankline.sh b/test/t2247-run-blankline.sh new file mode 100755 index 000000000..799815e08 --- /dev/null +++ b/test/t2247-run-blankline.sh @@ -0,0 +1,38 @@ +#! /bin/sh -e +# tup - A file-based build system +# +# Copyright (C) 2024 Mike Shal +# +# 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 diff --git a/test/t2248-run-comments.sh b/test/t2248-run-comments.sh new file mode 100755 index 000000000..d66385f16 --- /dev/null +++ b/test/t2248-run-comments.sh @@ -0,0 +1,38 @@ +#! /bin/sh -e +# tup - A file-based build system +# +# Copyright (C) 2024 Mike Shal +# +# 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