Subst and word splitting
Matthew Ryan <[email protected]>
| Newsgroups | gmane.comp.programming.tools.scons.user |
|---|---|
| Message-ID | <CACDhJGHvrPvD=gJAB414iXLYdEP-f-Y4uNGtBg39mMJZvqyjUQ@mail.gmail.com> |
I've found that the following (a minimal simplification of a more
complex builder)
does not work:
Command('target', ['source'], [['sh', '-c', 'cat $SOURCES >$TARGET']])
It results in the following command being run:
sh -c "cat source >" target
It seems that no combination of space/no-space on either side of the '>'
works.
I've attached a patch that seems to work (it's actually been in use since
SCons 0.97 in the setup I inherited and I'm finally trying to upstream some
of our patches). I'm just not sure if the patch fixes the issue in the correct
location, given the comments in the affected function.
- Matt
_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users
scons-split.patch
(application/octet-stream, 3.3 KB)
# Without this patch, the following breaks:
# Command('target', ['source'], [['sh', '-c', 'cat $SOURCES >$TARGET']])
#
# In base SCons 0.97, for the commands which are an array, like the
# ['sh', '-c', 'cat $SOURCES >$TARGET'] construction, any shell
# redirection character ('>', '<', and '|') that is not followed by
# whitespace will result in that string being broken up, resulting,
# in this example, in the following command:
# sh -c "cat source >" "target"
# instead of the desired:
# sh -c "cat source > target"
#
# This patch is still needed in SCons 3.0.5 (as confirmed by trying
# the above test builder). Indeed, in 1.2.0+ (perhaps earlier), the
# above builder does not work, regardless of what combination of space
# and nospace you use.
#
# So we patch things so that, instead of breaking the string into
# separately quoted words, we insert a space.
diff -u -r old/engine/SCons/Subst.py new/engine/SCons/Subst.py
--- old/engine/SCons/Subst.py 2009-02-23 17:06:53.000000000 +0000
+++ new/engine/SCons/Subst.py 2009-04-22 23:13:32.000000000 +0100
@@ -768,25 +768,25 @@
except IndexError:
last_char = '\0'
if last_char in '<>|':
- self.add_new_word(x)
- else:
- y = current_word + x
+ current_word = current_word + ' '
+
+ y = current_word + x
- # We used to treat a word appended to a literal
- # as a literal itself, but this caused problems
- # with interpreting quotes around space-separated
- # targets on command lines. Removing this makes
- # none of the "substantive" end-to-end tests fail,
- # so we'll take this out but leave it commented
- # for now in case there's a problem not covered
- # by the test cases and we need to resurrect this.
- #literal1 = self.literal(self[-1][-1])
- #literal2 = self.literal(x)
- y = self.conv(y)
- if is_String(y):
- #y = CmdStringHolder(y, literal1 or literal2)
- y = CmdStringHolder(y, None)
- self[-1][-1] = y
+ # We used to treat a word appended to a literal
+ # as a literal itself, but this caused problems
+ # with interpreting quotes around space-separated
+ # targets on command lines. Removing this makes
+ # none of the "substantive" end-to-end tests fail,
+ # so we'll take this out but leave it commented
+ # for now in case there's a problem not covered
+ # by the test cases and we need to resurrect this.
+ #literal1 = self.literal(self[-1][-1])
+ #literal2 = self.literal(x)
+ y = self.conv(y)
+ if is_String(y):
+ #y = CmdStringHolder(y, literal1 or literal2)
+ y = CmdStringHolder(y, None)
+ self[-1][-1] = y
def add_new_word(self, x):
if not self.in_strip or self.mode != SUBST_SIG: