Fixed stem termination and stem triple-expansion bugs.
authorBoris Kolpackov <boris@kolpackov.net>
Thu, 3 Mar 2005 17:39:48 +0000 (17:39 +0000)
committerBoris Kolpackov <boris@kolpackov.net>
Thu, 3 Mar 2005 17:39:48 +0000 (17:39 +0000)
ChangeLog
implicit.c
read.c
tests/ChangeLog
tests/scripts/features/se_implicit
tests/scripts/features/se_statpat
tests/scripts/features/statipattrules

index b0b25dcded3c1aae2ac9bdceb21e4c25a3ca196d..485fb56f3690c33b0447fff7de211e9c1589cef2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Thu Mar  3 18:28:15 2005  Boris Kolpackov  <boris@kolpackov.net>
+
+       * 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  <boris@kolpackov.net>
 
        * read.c (record_files): Add a check for the list of prerequisites
index b844419b741decb79a2eef58a5f40276af438f23..acf7c944aafb1d42443763f5b0c845556c17db98 100644 (file)
@@ -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 4103555a5fe6721b5b6efb7193dcd8855d0eef2f..c7ff6c680ba8ba7af64261f680151028184dffc8 100644 (file)
--- 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);
                }
index 2c5890067e697b2dffc34858764e10548e4cacf1..a371f89eba8a2d094098eff00e149d5c6d2a03b4 100644 (file)
@@ -1,6 +1,18 @@
+Thu Mar  3 18:34:06 2005  Boris Kolpackov  <boris@kolpackov.net>
+
+       * 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  <boris@kolpackov.net>
 
-       * tests/scripts/features/statipattrules: Add a test for
+       * scripts/features/statipattrules: Add a test for
        Savannah bug #12180.
 
 2005-02-28  Paul D. Smith  <psmith@gnu.org>
index b6b726c86a30c5e8e71f78d0c62ee76b432ab015..0c38c17dab883a53a24c49b5bafa44a38ae3c6f2 100644 (file)
@@ -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;
index 9f1b4a32154c0df1f841f7e0484500db3b9695d3..3c54622839f6cb9cb8a577ac4702b9dea0d3ce5d 100644 (file)
@@ -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;
index 7d35ec3aaac660ebaf0da69f3fa105c7fc5f6f0c..b5459b9e64a5b9e6cae5d02dbcd5b3fcb6ca3fa8 100644 (file)
@@ -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