2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-17 13:42:14 +00:00

Boost Jam code cleanup - out_action() calls from different platform specific exec*.c modules now moved into the central make_closure() function in the main build state machine implementation. exec_cmd() callbacks fitted with additional parameters to make this work but this should be temporary. exec*.c modules no longer need to remember their original command string given to execute just so they could pass them back to their out_action() calls since the central make_closure() function already has this information.

[SVN r79113]
This commit is contained in:
Jurko Gospodnetić
2012-06-26 15:08:50 +00:00
parent 2072515cc7
commit c9fdc14f55
4 changed files with 33 additions and 59 deletions

View File

@@ -33,8 +33,11 @@ typedef void (* ExecCmdCallback)
void * const closure,
int const status,
timing_info const * const,
char const * const invoked_command,
char const * const command_output
char const * const cmd_stdout,
char const * const cmd_stderr,
int const cmd_exit_reason,
char const * const rule_name,
char const * const target_name
);
/* Status codes passed to ExecCmdCallback routines. */

View File

@@ -93,8 +93,6 @@ static void close_alerts();
static char const * prepare_command_file( string const * command, int slot );
/* invoke the actual external process using the given command line */
static void invoke_cmd( char const * const command, int const slot );
/* returns a string's value buffer if not empty or 0 if empty */
static char const * null_if_empty( string const * str );
/* find a free slot in the running commands table */
static int get_free_cmdtab_slot();
/* put together the final command string we are to run */
@@ -120,9 +118,8 @@ static int intr_installed;
/* The list of commands we run. */
static struct
{
string action[ 1 ]; /* buffer to hold action */
string target[ 1 ]; /* buffer to hold target */
string command[ 1 ]; /* buffer to hold command being invoked */
string action[ 1 ]; /* buffer to hold action */
string target[ 1 ]; /* buffer to hold target */
/* Temporary command file used to execute the action when needed. */
string command_file[ 1 ];
@@ -365,7 +362,6 @@ void exec_cmd
string_new( cmdtab[ slot ].action );
string_new( cmdtab[ slot ].target );
}
string_copy( cmdtab[ slot ].command, cmd_orig->value );
}
/* Invoke the actual external process using the constructed command line. */
@@ -428,27 +424,17 @@ void exec_wait()
else
rstat = EXEC_CMD_OK;
/* Output the action block. */
out_action(
null_if_empty( cmdtab[ i ].action ),
null_if_empty( cmdtab[ i ].target ),
null_if_empty( cmdtab[ i ].command ),
null_if_empty( cmdtab[ i ].buffer_out ),
null_if_empty( cmdtab[ i ].buffer_err ),
exit_reason );
/* Call the callback, may call back to jam rule land. Assume -p0 is in
* effect so only pass buffer containing merged output.
*/
/* Call the callback, may call back to jam rule land. */
(*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time,
cmdtab[ i ].command->value, cmdtab[ i ].buffer_out->value );
cmdtab[ i ].buffer_out->value, cmdtab[ i ].buffer_err->value,
exit_reason, cmdtab[ i ].action->size ? cmdtab[ i ].action->value :
0, cmdtab[ i ].target->size ? cmdtab[ i ].target->value : 0 );
/* Clean up our child process tracking data. No need to clear the
* temporary command file name as it gets reused.
*/
string_renew( cmdtab[ i ].action );
string_renew( cmdtab[ i ].target );
string_renew( cmdtab[ i ].command );
closeWinHandle( &cmdtab[ i ].pi.hProcess );
closeWinHandle( &cmdtab[ i ].pi.hThread );
closeWinHandle( &cmdtab[ i ].pipe_out[ 0 ] );
@@ -1313,16 +1299,6 @@ static char const * prepare_command_file( string const * command, int slot )
}
/*
* Returns a string's value buffer if not empty or 0 if empty.
*/
static char const * null_if_empty( string const * str )
{
return str->size ? str->value : 0;
}
/*
* Find a free slot in the running commands table.
*/

View File

@@ -85,7 +85,6 @@ static struct
int target_length; /* length of target string */
char * action; /* buffer to hold the action name (if not quiet) */
char * target; /* buffer to hold the target name (if not quiet) */
char * command; /* buffer to hold the command */
char * buffer[ 2 ]; /* buffers to hold stdout and stderr, if any */
int buf_size[ 2 ]; /* buffer sizes in bytes */
time_t start_dt; /* start of command timestamp */
@@ -176,10 +175,6 @@ void exec_cmd
printf( " argv[%d] = '%s'\n", i, argv[ i ] );
}
/* Save off actual command string. */
cmdtab[ slot ].command = BJAM_MALLOC_ATOMIC( command->size + 1 );
strcpy( cmdtab[ slot ].command, command->value );
/* Create pipes from child to parent. */
if ( pipe( out ) < 0 || pipe( err ) < 0 )
{
@@ -525,11 +520,6 @@ void exec_wait()
? EXIT_FAIL
: EXIT_OK;
/* Print out the rule and target name. */
out_action( cmdtab[ i ].action, cmdtab[ i ].target,
cmdtab[ i ].command, cmdtab[ i ].buffer[ OUT ],
cmdtab[ i ].buffer[ ERR ], cmdtab[ i ].exit_reason );
times( &new_time );
time_info.system = (double)( new_time.tms_cstime - old_time.tms_cstime ) / CLOCKS_PER_SEC;
time_info.user = (double)( new_time.tms_cutime - old_time.tms_cutime ) / CLOCKS_PER_SEC;
@@ -545,12 +535,11 @@ void exec_wait()
else
rstat = EXEC_CMD_OK;
/* Call the callback, may call back to jam rule land. Assume -p0
* is in effect so only pass buffer[ OUT ] containing merged
* output.
*/
/* Call the callback, may call back to jam rule land. */
(*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time_info,
cmdtab[ i ].command, cmdtab[ i ].buffer[ OUT ] );
cmdtab[ i ].buffer[ OUT ], cmdtab[ i ].buffer[ ERR ],
cmdtab[ i ].exit_reason, cmdtab[ i ].action,
cmdtab[ i ].target );
BJAM_FREE( cmdtab[ i ].buffer[ OUT ] );
cmdtab[ i ].buffer[ OUT ] = 0;
@@ -560,9 +549,6 @@ void exec_wait()
cmdtab[ i ].buffer[ ERR ] = 0;
cmdtab[ i ].buf_size[ ERR ] = 0;
BJAM_FREE( cmdtab[ i ].command );
cmdtab[ i ].command = 0;
cmdtab[ i ].func = 0;
cmdtab[ i ].closure = 0;
cmdtab[ i ].start_time = 0;

View File

@@ -100,8 +100,9 @@ static void make1b ( state * );
static void make1c ( state * );
static void make1d ( state * );
static void make_closure( void * const closure, int const status,
timing_info const * const, char const * const invoked_command,
char const * const command_output );
timing_info const * const, char const * const cmd_stdout,
char const * const cmd_stderr, int const cmd_exit_reason,
char const * const rule_name, char const * const target_name );
typedef struct _stack
{
@@ -563,15 +564,14 @@ static void make1c( state * pState )
{
timing_info time_info = { 0 } ;
time_info.start = time_info.end = time( 0 );
out_action( rule_name, target_name, cmd->buf->value, "", "",
EXIT_OK );
make_closure( t, EXEC_CMD_OK, &time_info, cmd->buf->value, "" );
make_closure( t, EXEC_CMD_OK, &time_info, "", "", EXIT_OK,
rule_name, target_name );
}
else
{
exec_cmd( cmd->buf, make_closure, t, cmd->shell, rule_name,
target_name );
/* Wait until under the concurrent command count limit. */
assert( 0 < globs.jobs );
assert( globs.jobs <= MAXJOBS );
@@ -848,19 +848,28 @@ static void make_closure
void * const closure,
int const status,
timing_info const * const time,
char const * const invoked_command,
char const * const command_output
char const * const cmd_stdout,
char const * const cmd_stderr,
int const cmd_exit_reason,
char const * const rule_name,
char const * const target_name
)
{
TARGET * const t = (TARGET *)closure;
CMD const * const cmd = (CMD *)t->cmds;
assert( cmd );
--cmdsrunning;
out_action( rule_name, target_name, cmd->buf->value, cmd_stdout, cmd_stderr,
cmd_exit_reason );
call_timing_rule( t, time );
if ( DEBUG_EXECCMD )
printf( "%f sec system; %f sec user\n", time->system, time->user );
call_action_rule( t, status, time, invoked_command, command_output );
/* Assume -p0 is in effect so only pass buffer containing merged output. */
call_action_rule( t, status, time, cmd->buf->value, cmd_stdout );
push_state( &state_stack, t, NULL, T_STATE_MAKE1D )->status = status;
}