diff --git a/ChangeLog b/ChangeLog index b0b25dcd..485fb56f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Thu Mar 3 18:28:15 2005 Boris Kolpackov + + * read.c (record_files): Instead of substituting % with + actual stem value in dependency list replace it with $*. + This fixes stem triple expansion bug. + + * implicit.c (pattern_search): Copy stem to a separate + buffer and make it a properly terminated string. Assign + this buffer instead of STEM (which is not terminated) to + f->stem. Instead of substituting % with actual stem value + in dependency list replace it with $*. This fixes stem + triple expansion bug. + Tue Mar 1 10:12:20 2005 Boris Kolpackov * read.c (record_files): Add a check for the list of prerequisites diff --git a/implicit.c b/implicit.c index b844419b..acf7c944 100644 --- a/implicit.c +++ b/implicit.c @@ -271,6 +271,8 @@ pattern_search (struct file *file, int archive, struct idep **id_ptr; struct dep **d_ptr; + PATH_VAR (stem_str); /* @@ Need to get rid of stem, stemlen, etc. */ + #ifndef NO_ARCHIVES if (archive || ar_name (filename)) lastslash = 0; @@ -466,8 +468,11 @@ pattern_search (struct file *file, int archive, DBS (DB_IMPLICIT, (_("Trying pattern rule with stem `%.*s'.\n"), (int) stemlen, stem)); + strncpy (stem_str, stem, stemlen); + stem_str[stemlen] = '\0'; + /* Temporary assign STEM to file->stem and set file variables. */ - file->stem = stem; + file->stem = stem_str; set_file_variables (file); /* Try each dependency; see if it "exists". */ @@ -503,7 +508,18 @@ pattern_search (struct file *file, int archive, if (p == 0) break; /* No more words */ - /* If the dependency name has %, substitute the stem. */ + /* If the dependency name has %, substitute the stem. + Watch out, we are going to do something very smart + here. If we just replace % with the stem value, + later, when we do the second expansion, we will + re-expand this stem value once again. This is not + good especially if you have certain characters in + your setm (like $). + + Instead, we will replace % with $* and allow the + second expansion to take care of it for us. This + way (since $* is a simple variable) there won't + be additional re-expansion of the stem.*/ for (p2 = p; p2 < p + len && *p2 != '%'; ++p2); @@ -511,9 +527,9 @@ pattern_search (struct file *file, int archive, { register unsigned int i = p2 - p; bcopy (p, depname, i); - bcopy (stem, depname + i, stemlen); - bcopy (p2 + 1, depname + i + stemlen, len - i - 1); - depname[len + stemlen - 1] = '\0'; + bcopy ("$*", depname + i, 2); + bcopy (p2 + 1, depname + i + 2, len - i - 1); + depname[len + 2 - 1] = '\0'; if (check_lastslash) add_dir = 1; diff --git a/read.c b/read.c index 4103555a..c7ff6c68 100644 --- a/read.c +++ b/read.c @@ -1911,32 +1911,17 @@ record_files (struct nameseq *filenames, char *pattern, char *pattern_percent, } else { - /* We use patsubst_expand to do the work of translating - the target pattern, the target's name and the dependencies' - patterns into plain dependency names. */ + /* We use subst_expand to do the work of translating + % to $* in the dependency line. */ if (this != 0 && find_percent (this->name) != 0) { - PATH_VAR (stem); char *o; char *buffer = variable_expand (""); - o = patsubst_expand (buffer, name, pattern, "%", - pattern_percent + 1, 0); + o = subst_expand (buffer, this->name, "%", "$*", + 1, 2, 0); - - strncpy (stem, buffer, o - buffer); - stem[o - buffer] = '\0'; - - o = subst_expand (buffer, this->name, "%", stem, - 1, strlen (stem), 0); - - /* If the name expanded to the empty string, that's - illegal. */ - if (o == buffer) - fatal (flocp, - _("target `%s' leaves prerequisite pattern empty"), - name); free (this->name); this->name = savestring (buffer, o - buffer); } diff --git a/tests/ChangeLog b/tests/ChangeLog index 2c589006..a371f89e 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,6 +1,18 @@ +Thu Mar 3 18:34:06 2005 Boris Kolpackov + + * scripts/features/se_implicit: Add a test for stem + termination bug. Add a test for stem triple-expansion bug. + + * scripts/features/se_statpat: Add a test for stem + triple-expansion bug. + + * scripts/features/statipattrules: Change test #4 to reflect + new way empty prerequisite list is handled. + + Tue Mar 1 10:15:25 2005 Boris Kolpackov - * tests/scripts/features/statipattrules: Add a test for + * scripts/features/statipattrules: Add a test for Savannah bug #12180. 2005-02-28 Paul D. Smith diff --git a/tests/scripts/features/se_implicit b/tests/scripts/features/se_implicit index b6b726c8..0c38c17d 100644 --- a/tests/scripts/features/se_implicit +++ b/tests/scripts/features/se_implicit @@ -183,6 +183,42 @@ foo.c: ; @echo $@ foo.o: {foo.c} foo.c '); +# Test #7: Test stem from the middle of the name. +# +run_make_test(' +foobarbaz: + +foo%baz: % $$*.1 + @echo $* + +bar bar.1: + @echo $@ + +', +'', +'bar +bar.1 +bar +'); + +# Test #8: Make sure stem triple-expansion does not happen. +# +run_make_test(' +foo$$bar: + +f%r: % $$*.1 + @echo \'$*\' + +oo$$ba oo$$ba.1: + @echo \'$@\' + +', +'', +'oo$ba +oo$ba.1 +oo$ba +'); + # This tells the test driver that the perl test script executed properly. 1; diff --git a/tests/scripts/features/se_statpat b/tests/scripts/features/se_statpat index 9f1b4a32..3c546228 100644 --- a/tests/scripts/features/se_statpat +++ b/tests/scripts/features/se_statpat @@ -102,5 +102,23 @@ baz.a.1 baz.a.2 '); + +# Test #4: Make sure stem triple-expansion does not happen. +# +run_make_test(' +foo$$bar: f%r: % $$*.1 + @echo \'$*\' + +oo$$ba oo$$ba.1: + @echo \'$@\' + +', +'', +'oo$ba +oo$ba.1 +oo$ba +'); + + # This tells the test driver that the perl test script executed properly. 1; diff --git a/tests/scripts/features/statipattrules b/tests/scripts/features/statipattrules index 7d35ec3a..b5459b9e 100644 --- a/tests/scripts/features/statipattrules +++ b/tests/scripts/features/statipattrules @@ -55,11 +55,11 @@ unlink('foo.el', 'bar.c', 'lose.c'); $makefile2 = &get_tmpfile; open(MAKEFILE, "> $makefile2"); -print MAKEFILE "foo: foo%: % ; \@echo $@\n"; +print MAKEFILE "foo: foo%: % ; \@echo \$@\n"; close(MAKEFILE); -&run_make_with_options($makefile2, '', &get_logfile, 512); -$answer = "$makefile2:1: *** target `foo' leaves prerequisite pattern empty. Stop.\n"; +&run_make_with_options($makefile2, '', &get_logfile); +$answer = "foo\n"; &compare_output($answer, &get_logfile(1)); # TEST #5 -- bug #12180: core dump on a stat pattern rule with an empty