* NEWS: Do not insert a space during '+=' if the value is empty.

* doc/make.texi (Appending): Document this behavior.
* variable.c (do_variable_definition): Only add a space if the variable
value is not empty.
* tests/scripts/variables/flavors: Test this behavior.
This commit is contained in:
Paul Smith 2017-05-27 20:07:30 -04:00
parent 816a867ff5
commit b90fabc8d6
4 changed files with 47 additions and 7 deletions

6
NEWS
View file

@ -29,6 +29,12 @@ http://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=108&set
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
* WARNING: Backward-incompatibility!
Previously appending using '+=' to an empty variable would result in a value
starting with a space. Now the initial space is only added if the variable
already contains some value. Similarly, appending an empty string does not
add a trailing space.
* The previous limit of 63 jobs under -jN on MS-Windows is now
increased to 4095. That limit includes the subprocess started by
the $(shell) function.

View file

@ -5720,7 +5720,8 @@ objects += another.o
@noindent
This takes the value of the variable @code{objects}, and adds the text
@samp{another.o} to it (preceded by a single space). Thus:
@samp{another.o} to it (preceded by a single space, if it has a value
already). Thus:
@example
objects = main.o foo.o bar.o utils.o

View file

@ -93,4 +93,23 @@ all: ; @echo $(foo)
',
'', "Goodbye\n");
# TEST 8: Append to empty
run_make_test(q!
recur =
recur += foo
simple :=
simple += bar
recur_empty = foo
recur_empty +=
simple_empty := bar
simple_empty +=
empty_recur =
empty_recur +=
empty_simple :=
empty_simple +=
all: ; @: $(info recur=/$(recur)/ simple=/$(simple)/ recure=/$(recur_empty)/ simplee=/$(simple_empty)/ erecur=/$(empty_recur)/ esimple=/$(empty_simple)/)
!,
'', "recur=/foo/ simple=/bar/ recure=/foo/ simplee=/bar/ erecur=// esimple=//\n");
1;

View file

@ -1197,7 +1197,7 @@ do_variable_definition (const floc *flocp, const char *varname,
The value is set IFF the variable is not defined yet. */
v = lookup_variable (varname, strlen (varname));
if (v)
return v->special ? set_special_var (v) : v;
goto done;
conditional = 1;
flavor = f_recursive;
@ -1253,15 +1253,29 @@ do_variable_definition (const floc *flocp, const char *varname,
buffer if we're looking at a target-specific variable. */
val = tp = allocated_variable_expand (val);
oldlen = strlen (v->value);
/* If the new value is empty, nothing to do. */
vallen = strlen (val);
if (!vallen)
{
alloc_value = tp;
goto done;
}
oldlen = strlen (v->value);
p = alloc_value = xmalloc (oldlen + 1 + vallen + 1);
memcpy (alloc_value, v->value, oldlen);
alloc_value[oldlen] = ' ';
memcpy (&alloc_value[oldlen + 1], val, vallen + 1);
if (oldlen)
{
memcpy (alloc_value, v->value, oldlen);
alloc_value[oldlen] = ' ';
++oldlen;
}
memcpy (&alloc_value[oldlen], val, vallen + 1);
free (tp);
}
break;
}
}
@ -1405,8 +1419,8 @@ do_variable_definition (const floc *flocp, const char *varname,
v->append = append;
v->conditional = conditional;
done:
free (alloc_value);
return v->special ? set_special_var (v) : v;
}