From: Paul Smith Date: Tue, 15 Nov 2022 15:50:34 +0000 (-0500) Subject: Add specific hints for errors due to invalid conditionals X-Git-Tag: 4.4.0.90~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6c1a6dd77c55e7302ced47cdc293292ae9400d85;p=thirdparty%2Fmake.git Add specific hints for errors due to invalid conditionals * src/read.c (eval): If "missing separator" appears to be due to missing space after ifeq/ifneq, give a hint about the error. * tests/scripts/misc/failure: Check for these types of failures. * tests/scripts/variables/special: Move error checking unrelated to special variables, to misc/failure. --- diff --git a/src/read.c b/src/read.c index 07431240..15f58ecf 100644 --- a/src/read.c +++ b/src/read.c @@ -1140,20 +1140,29 @@ eval (struct ebuffer *ebuf, int set_default) p2 = next_token (variable_buffer); - /* If the word we're looking at is EOL, see if there's _anything_ - on the line. If not, a variable expanded to nothing, so ignore - it. If so, we can't parse this line so punt. */ + /* If we're at EOL we didn't find a separator so we don't know what + kind of line this is. */ if (wtype == w_eol) { + /* Ignore an empty line. */ if (*p2 == '\0') continue; - /* There's no need to be ivory-tower about this: check for - one of the most common bugs found in makefiles... */ + /* Check for spaces instead of TAB. */ if (cmd_prefix == '\t' && strneq (line, " ", 8)) O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)")); - else - O (fatal, fstart, _("missing separator")); + + /* Check for conditionals without whitespace afterward. + We don't check ifdef/ifndef because there's no real way to miss + whitespace there. */ + p2 = next_token (line); + if (strneq (p2, "if", 2) && + ((strneq (&p2[2], "neq", 3) && !STOP_SET (p2[5], MAP_BLANK)) + || (strneq (&p2[2], "eq", 2) && !STOP_SET (p2[4], MAP_BLANK)))) + O (fatal, fstart, _("missing separator (ifeq/ifneq must be followed by whitespace)")); + + /* No idea... */ + O (fatal, fstart, _("missing separator")); } { diff --git a/tests/scripts/misc/failure b/tests/scripts/misc/failure new file mode 100644 index 00000000..edd90fbb --- /dev/null +++ b/tests/scripts/misc/failure @@ -0,0 +1,49 @@ +# -*-perl-*- + +$description = "Test miscellaneous failures."; + + +# Test that the "did you mean TAB" message is printed properly + +run_make_test(q! +$x. +!, + '', '#MAKEFILE#:2: *** missing separator. Stop.', 512); + +run_make_test(q! +foo: + bar +!, + '', '#MAKEFILE#:3: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.', 512); + +run_make_test(q! +.RECIPEPREFIX = : +foo: + bar +!, + '', '#MAKEFILE#:4: *** missing separator. Stop.', 512); + +for my $kw ('eq', 'neq') { +run_make_test(qq! +if$kw(foo,bar) +\$(error ouch) +endif +!, + '', '#MAKEFILE#:2: *** missing separator (ifeq/ifneq must be followed by whitespace). Stop.', 512); + +run_make_test(qq! +if$kw +\$(error ouch) +endif +!, + '', '#MAKEFILE#:2: *** invalid syntax in conditional. Stop.', 512); + +run_make_test(qq! +if$kw blah +\$(error ouch) +endif +!, + '', '#MAKEFILE#:2: *** invalid syntax in conditional. Stop.', 512); +} + +1; diff --git a/tests/scripts/variables/special b/tests/scripts/variables/special index 68f3128c..abe9fc0c 100644 --- a/tests/scripts/variables/special +++ b/tests/scripts/variables/special @@ -122,26 +122,6 @@ reset-four \ : foo-three : foo-four'); -# Test that the "did you mean TAB" message is printed properly - -run_make_test(q! -$x. -!, - '', '#MAKEFILE#:2: *** missing separator. Stop.', 512); - -run_make_test(q! -foo: - bar -!, - '', '#MAKEFILE#:3: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.', 512); - -run_make_test(q! -.RECIPEPREFIX = : -foo: - bar -!, - '', '#MAKEFILE#:4: *** missing separator. Stop.', 512); - 1; ### Local Variables: