mirror of
https://github.com/boostorg/build.git
synced 2026-02-15 13:02:11 +00:00
Fix strip-eol for long command output
Previously, when shell command output exceeded the 1024 character buffer size, each chunk of output would be stripped. This had the undesirable effect of sometimes breaking compilation by splitting on whitespace boundaries. This patch addresses the issue by providing a string_rtrim function and utilizing the function on the output string instead of each buffered component.
This commit is contained in:
@@ -450,7 +450,7 @@ void load_builtins()
|
||||
char const * args [] = { "path", 0 };
|
||||
bind_builtin( "MAKEDIR", builtin_makedir, 0, args );
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
const char * args [] = { "path", 0 };
|
||||
bind_builtin( "READLINK", builtin_readlink, 0, args );
|
||||
@@ -1981,7 +1981,7 @@ LIST *builtin_readlink( FRAME * frame, int flags )
|
||||
bufsize *= 2;
|
||||
buf = BJAM_MALLOC( bufsize );
|
||||
}
|
||||
|
||||
|
||||
if ( buf != static_buf )
|
||||
BJAM_FREE( buf );
|
||||
|
||||
@@ -2460,15 +2460,6 @@ PyObject * bjam_caller( PyObject * self, PyObject * args )
|
||||
#endif /* defined(_MSC_VER) || defined(__BORLANDC__) */
|
||||
|
||||
|
||||
static char * rtrim( char * const s )
|
||||
{
|
||||
char * p = s;
|
||||
while ( *p ) ++p;
|
||||
for ( --p; p >= s && isspace( *p ); *p-- = 0 );
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
LIST * builtin_shell( FRAME * frame, int flags )
|
||||
{
|
||||
LIST * command = lol_get( frame->args, 0 );
|
||||
@@ -2515,8 +2506,6 @@ LIST * builtin_shell( FRAME * frame, int flags )
|
||||
buffer[ ret ] = 0;
|
||||
if ( !no_output_opt )
|
||||
{
|
||||
if ( strip_eol_opt )
|
||||
rtrim( buffer );
|
||||
string_append( &s, buffer );
|
||||
}
|
||||
|
||||
@@ -2524,6 +2513,9 @@ LIST * builtin_shell( FRAME * frame, int flags )
|
||||
if ( feof( p ) ) break;
|
||||
}
|
||||
|
||||
if ( strip_eol_opt )
|
||||
string_rtrim( &s );
|
||||
|
||||
exit_status = pclose( p );
|
||||
|
||||
/* The command output is returned first. */
|
||||
|
||||
@@ -189,6 +189,12 @@ char string_back( string * self )
|
||||
return self->value[ self->size - 1 ];
|
||||
}
|
||||
|
||||
void string_rtrim( string * self )
|
||||
{
|
||||
assert_invariants( self );
|
||||
char * p = self->value + self->size - 1;
|
||||
for ( p; p >= self->value && ( *p == '\0' || isspace( *p ) ); *p-- = 0 );
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void string_unit_test()
|
||||
@@ -219,5 +225,25 @@ void string_unit_test()
|
||||
assert( copy->size == strlen( original ) );
|
||||
string_free( copy );
|
||||
}
|
||||
|
||||
{
|
||||
char * const foo = "Foo ";
|
||||
string foo_copy[ 1 ];
|
||||
string_copy( foo_copy, foo );
|
||||
string_rtrim( foo_copy );
|
||||
assert( !strcmp( foo_copy->value, "Foo" ) );
|
||||
|
||||
string_rtrim( foo_copy );
|
||||
assert( !strcmp( foo_copy->value, "Foo" ) );
|
||||
|
||||
char * const bar = "Bar\0\0\0";
|
||||
string bar_copy[ 1 ];
|
||||
string_copy( bar_copy, bar );
|
||||
string_rtrim( bar_copy );
|
||||
assert( !strcmp( bar_copy->value, "Bar" ) );
|
||||
|
||||
string_rtrim( bar_copy );
|
||||
assert( !strcmp( bar_copy->value, "Bar" ) );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,7 @@ void string_reserve( string *, size_t );
|
||||
void string_truncate( string *, size_t );
|
||||
void string_pop_back( string * );
|
||||
char string_back( string * );
|
||||
void string_rtrim( string * );
|
||||
void string_unit_test();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user