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

Boost Jam code cleanup - minor stylistic changes in the make1.c module.

[SVN r79058]
This commit is contained in:
Jurko Gospodnetić
2012-06-24 13:23:29 +00:00
parent 748a9cf5c3
commit e18ae50fb5

View File

@@ -13,38 +13,27 @@
/*
* make1.c - execute command to bring targets up to date
*
* This module contains make1(), the entry point called by make() to
* recursively decend the dependency graph executing update actions as
* marked by make0().
* This module contains make1(), the entry point called by make() to recursively
* descend the dependency graph executing update actions as marked by make0().
*
* External routines:
*
* make1() - execute commands to update a TARGET and all of its dependencies.
* make1() - execute commands to update a TARGET and all of its dependencies
*
* Internal routines, the recursive/asynchronous command executors:
*
* make1a() - recursively traverse dependency target tree, calling make1b().
* make1atail() - started processing all dependencies so go on to make1b().
* make1b() - when dependencies are up to date, build target with make1c().
* make1c() - launch target's next command, call parents' make1b() if none.
* make1d() - handle command execution completion and call back make1c().
* make1a() - recursively traverse dependency target tree, calling make1b()
* make1atail() - started processing all dependencies so go on to make1b()
* make1b() - when dependencies are up to date, build target with make1c()
* make1c() - launch target's next command, call parents' make1b() if none
* make1d() - handle command execution completion and call back make1c()
*
* Internal support routines:
*
* make1cmds() - turn ACTIONS into CMDs, grouping, splitting, etc.
* make1list() - turn a list of targets into a LIST, for $(<) and $(>).
* make1settings() - for vars that get bound values, build up replacement lists.
* make1bind() - bind targets that weren't bound in dependency analysis.
*
* 04/16/94 (seiwald) - Split from make.c.
* 04/21/94 (seiwald) - Handle empty "updated" actions.
* 05/04/94 (seiwald) - async multiprocess (-j) support.
* 06/01/94 (seiwald) - new 'actions existing' does existing sources.
* 12/20/94 (seiwald) - NOTIME renamed NOTFILE.
* 01/19/95 (seiwald) - distinguish between CANTFIND/CANTMAKE targets.
* 01/22/94 (seiwald) - pass per-target JAMSHELL down to exec_cmd().
* 02/28/95 (seiwald) - Handle empty "existing" actions.
* 03/10/95 (seiwald) - Fancy counts.
* make1list() - turn a list of targets into a LIST, for $(<) and $(>)
* make1settings() - for vars that get bound values, build up replacement lists
* make1bind() - bind targets that weren't bound in dependency analysis
*/
#include "jam.h"
@@ -70,12 +59,12 @@
#include <unistd.h> /* for unlink */
#endif
static CMD * make1cmds ( TARGET * );
static LIST * make1list ( LIST *, TARGETS *, int flags );
static SETTINGS * make1settings( struct module_t * module, LIST * vars );
static void make1bind ( TARGET * );
static TARGET * make1findcycle( TARGET * t );
static void make1breakcycle( TARGET * t, TARGET * cycle_root );
static CMD * make1cmds ( TARGET * );
static LIST * make1list ( LIST *, TARGETS *, int flags );
static SETTINGS * make1settings ( struct module_t *, LIST * vars );
static void make1bind ( TARGET * );
static TARGET * make1findcycle ( TARGET * );
static void make1breakcycle( TARGET *, TARGET * cycle_root );
/* Ugly static - it is too hard to carry it through the callbacks. */
@@ -85,21 +74,22 @@ static struct
int skipped;
int total;
int made;
} counts[ 1 ] ;
} counts[ 1 ];
/* Target state - remove recursive calls by just keeping track of state target
* is in.
*/
#define T_STATE_MAKE1A 0 /* make1a() should be called */
#define T_STATE_MAKE1ATAIL 1 /* make1atail() should be called */
#define T_STATE_MAKE1B 2 /* make1b() should be called */
#define T_STATE_MAKE1C 3 /* make1c() should be called */
#define T_STATE_MAKE1D 4 /* make1d() should be called */
typedef struct _state
{
struct _state * prev; /* previous state on stack */
TARGET * t; /* current target */
TARGET * parent; /* parent argument necessary for make1a() */
#define T_STATE_MAKE1A 0 /* make1a() should be called */
#define T_STATE_MAKE1ATAIL 1 /* make1atail() should be called */
#define T_STATE_MAKE1B 2 /* make1b() should be called */
#define T_STATE_MAKE1C 3 /* make1c() should be called */
#define T_STATE_MAKE1D 4 /* make1d() should be called */
int curstate; /* current state */
int status;
} state;
@@ -109,7 +99,8 @@ static void make1atail ( state * );
static void make1b ( state * );
static void make1c ( state * );
static void make1d ( state * );
static void make_closure( void * closure, int status, timing_info *, const char *, const char * );
static void make_closure( void * closure, int status, timing_info *,
char const *, char const * );
typedef struct _stack
{
@@ -123,14 +114,13 @@ static state * state_freelist = NULL;
static state * alloc_state()
{
if ( state_freelist != NULL )
if ( state_freelist )
{
state * pState = state_freelist;
state * const pState = state_freelist;
state_freelist = pState->prev;
memset( pState, 0, sizeof( state ) );
return pState;
}
return (state *)BJAM_MALLOC( sizeof( state ) );
}
@@ -144,9 +134,9 @@ static void free_state( state * pState )
static void clear_state_freelist()
{
while ( state_freelist != NULL )
while ( state_freelist )
{
state * pState = state_freelist;
state * const pState = state_freelist;
state_freelist = state_freelist->prev;
BJAM_FREE( pState );
}
@@ -161,9 +151,9 @@ static state * current_state( stack * pStack )
static void pop_state( stack * pStack )
{
if ( pStack->stack != NULL )
if ( pStack->stack )
{
state * pState = pStack->stack->prev;
state * const pState = pStack->stack->prev;
free_state( pStack->stack );
pStack->stack = pState;
}
@@ -172,15 +162,13 @@ static void pop_state( stack * pStack )
static state * push_state( stack * pStack, TARGET * t, TARGET * parent, int curstate )
{
state * pState = alloc_state();
state * const pState = alloc_state();
pState->t = t;
pState->parent = parent;
pState->prev = pStack->stack;
pState->curstate = curstate;
pStack->stack = pState;
return pStack->stack;
}
@@ -191,9 +179,9 @@ static state * push_state( stack * pStack, TARGET * t, TARGET * parent, int curs
static void push_stack_on_stack( stack * pDest, stack * pSrc )
{
while ( pSrc->stack != NULL )
while ( pSrc->stack )
{
state * pState = pSrc->stack;
state * const pState = pSrc->stack;
pSrc->stack = pSrc->stack->prev;
pState->prev = pDest->stack;
pDest->stack = pState;
@@ -218,7 +206,7 @@ int make1( TARGET * t )
do
{
while ( ( pState = current_state( &state_stack ) ) != NULL )
while ( ( pState = current_state( &state_stack ) ) )
{
if ( intr )
pop_state( &state_stack );
@@ -230,6 +218,8 @@ int make1( TARGET * t )
case T_STATE_MAKE1B : make1b ( pState ); break;
case T_STATE_MAKE1C : make1c ( pState ); break;
case T_STATE_MAKE1D : make1d ( pState ); break;
default:
assert( !"make1(): Invalid state detected." );
}
}
}
@@ -241,13 +231,13 @@ int make1( TARGET * t )
/* Talk about it. */
if ( counts->failed )
printf( "...failed updating %d target%s...\n", counts->failed,
counts->failed > 1 ? "s" : "" );
counts->failed > 1 ? "s" : "" );
if ( DEBUG_MAKE && counts->skipped )
printf( "...skipped %d target%s...\n", counts->skipped,
counts->skipped > 1 ? "s" : "" );
counts->skipped > 1 ? "s" : "" );
if ( DEBUG_MAKE && counts->made )
printf( "...updated %d target%s...\n", counts->made,
counts->made > 1 ? "s" : "" );
counts->made > 1 ? "s" : "" );
return counts->total != counts->made;
}
@@ -265,17 +255,15 @@ int make1( TARGET * t )
static void make1a( state * pState )
{
TARGET * t = pState->t;
TARGET * scc_root = target_scc( t );
TARGETS * c;
if ( pState->parent == NULL || target_scc( pState->parent ) != scc_root )
if ( !pState->parent || target_scc( pState->parent ) != scc_root )
pState->t = t = scc_root;
/* If the parent is the first to try to build this target or this target is
* in the make1c() quagmire, arrange for the parent to be notified when this
* target is built.
* target has been built.
*/
if ( pState->parent )
{
@@ -285,25 +273,22 @@ static void make1a( state * pState )
case T_MAKE_ACTIVE:
case T_MAKE_INIT:
case T_MAKE_RUNNING:
{
TARGET * parent_scc = target_scc( pState->parent );
if ( t != parent_scc )
{
TARGET * parent_scc = target_scc( pState->parent );
if( t != parent_scc )
{
t->parents = targetentry( t->parents, parent_scc );
++parent_scc->asynccnt;
}
t->parents = targetentry( t->parents, parent_scc );
++parent_scc->asynccnt;
}
}
}
}
/*
* If the target has been previously updated with -n in
* effect, and we're ignoring -n, update it for real.
/* If the target has been previously updated with -n in effect, and we are
* now ignoring -n, update it for real.
*/
if ( !globs.noexec && t->progress == T_MAKE_NOEXEC_DONE )
{
t->progress = T_MAKE_INIT;
}
/* If this target is already being processed then do nothing. There is no
* need to start processing the same target all over again.
@@ -318,7 +303,7 @@ static void make1a( state * pState )
* to make1b() for actual building. We start off with a count of 1 to
* prevent anything from happening until we can notify all dependencies that
* they are needed. This 1 is accounted for when we call make1b() ourselves,
* below. Without this if a a dependency gets built before we finish
* below. Without this if a dependency gets built before we finish
* processing all of our other dependencies our build might be triggerred
* prematurely.
*/
@@ -329,6 +314,7 @@ static void make1a( state * pState )
{
stack temp_stack = { NULL };
TARGETS * c;
for ( c = t->depends; c && !intr; c = c->next )
push_state( &temp_stack, c->target, t, T_STATE_MAKE1A );
@@ -365,10 +351,9 @@ static void make1atail( state * pState )
static void make1b( state * pState )
{
TARGET * t = pState->t;
TARGETS * c;
TARGET * failed = 0;
const char * failed_name = "dependencies";
TARGET * t = pState->t;
TARGET * failed = 0;
char const * failed_name = "dependencies";
/* If any dependencies are still outstanding, wait until they call make1b()
* to signal their completion.
@@ -380,7 +365,7 @@ static void make1b( state * pState )
}
/* Try to aquire a semaphore. If it is locked, wait until the target that
* locked it is built and signal completition.
* locked it is built and signals completition.
*/
#ifdef OPT_SEMAPHORE
if ( t->semaphore && t->semaphore->asynccnt )
@@ -406,6 +391,7 @@ static void make1b( state * pState )
*/
if ( !globs.noexec )
{
TARGETS * c;
for ( c = t->depends; c; c = c->next )
if ( c->target->status > t->status && !( c->target->flags & T_FLAG_NOCARE ) )
{
@@ -532,17 +518,17 @@ static void make1c( state * pState )
if ( cmd && ( pState->t->status == EXEC_CMD_OK ) )
{
const char * rule_name = 0;
const char * target = 0;
char const * rule_name = 0;
char const * target_name = 0;
if ( DEBUG_MAKEQ ||
( !( cmd->rule->actions->flags & RULE_QUIETLY ) && DEBUG_MAKE ) )
{
rule_name = object_str( cmd->rule->name );
target = object_str( list_front( lol_get( &cmd->args, 0 ) ) );
target_name = object_str( list_front( lol_get( &cmd->args, 0 ) ) );
if ( globs.noexec )
out_action( rule_name, target, cmd->buf->value, "", "", EXIT_OK
);
out_action( rule_name, target_name, cmd->buf->value, "", "",
EXIT_OK );
}
if ( globs.noexec )
@@ -555,12 +541,11 @@ static void make1c( state * pState )
/* Pop state first because exec_cmd() could push state. */
pop_state( &state_stack );
exec_cmd( cmd->buf, make_closure, pState->t, cmd->shell, rule_name,
target );
target_name );
}
}
else
{
TARGETS * c;
ACTIONS * actions;
/* Collect status from actions, and distribute it as well. */
@@ -575,12 +560,13 @@ static void make1c( state * pState )
if ( pState->t->progress == T_MAKE_RUNNING )
switch ( pState->t->status )
{
case EXEC_CMD_OK : ++counts->made ; break;
case EXEC_CMD_OK: ++counts->made; break;
case EXEC_CMD_FAIL: ++counts->failed; break;
}
/* Tell parents their dependency has been built. */
{
TARGETS * c;
stack temp_stack = { NULL };
TARGET * t = pState->t;
TARGET * additional_includes = NULL;
@@ -683,8 +669,10 @@ static void make1c( state * pState )
t->semaphore->parents = first->next;
if ( DEBUG_EXECCMD )
printf( "SEM: placing %s on stack\n", object_str( first->target->name ) );
push_state( &temp_stack, first->target, NULL, T_STATE_MAKE1B );
printf( "SEM: placing %s on stack\n", object_str(
first->target->name ) );
push_state( &temp_stack, first->target, NULL, T_STATE_MAKE1B
);
BJAM_FREE( first );
}
}
@@ -706,7 +694,7 @@ static void make1c( state * pState )
* timing_info.
*/
static void call_timing_rule( TARGET * target, timing_info * time )
static void call_timing_rule( TARGET * target, timing_info const * time )
{
LIST * timing_rule;
@@ -723,7 +711,8 @@ static void call_timing_rule( TARGET * target, timing_info * time )
frame_init( frame );
/* args * :: $(__TIMING_RULE__[2-]) */
lol_add( frame->args, list_copy_range( timing_rule, list_next( list_begin( timing_rule ) ), list_end( timing_rule ) ) );
lol_add( frame->args, list_copy_range( timing_rule, list_next(
list_begin( timing_rule ) ), list_end( timing_rule ) ) );
/* target :: the name of the target */
lol_add( frame->args, list_new( object_copy( target->name ) ) );
@@ -752,14 +741,14 @@ static void call_timing_rule( TARGET * target, timing_info * time )
static void call_action_rule
(
TARGET * target,
int status,
timing_info * time,
const char * executed_command,
const char * command_output
TARGET * target,
int status,
timing_info const * time,
char const * executed_command,
char const * command_output
)
{
LIST * action_rule;
LIST * action_rule;
pushsettings( root_module(), target->settings );
action_rule = var_get( root_module(), constant_ACTION_RULE );
@@ -778,7 +767,8 @@ static void call_action_rule
frame_init( frame );
/* args * :: $(__ACTION_RULE__[2-]) */
lol_add( frame->args, list_copy_range( action_rule, list_next( list_begin( action_rule ) ), list_end( action_rule ) ) );
lol_add( frame->args, list_copy_range( action_rule, list_next(
list_begin( action_rule ) ), list_end( action_rule ) ) );
/* target :: the name of the target */
lol_add( frame->args, list_new( object_copy( target->name ) ) );
@@ -815,11 +805,11 @@ static void call_action_rule
static void make_closure
(
void * closure,
int status,
void * closure,
int status,
timing_info * time,
const char * executed_command,
const char * command_output
char const * executed_command,
char const * command_output
)
{
TARGET * built = (TARGET *)closure;
@@ -845,22 +835,21 @@ static void make_closure
static void make1d( state * pState )
{
TARGET * t = pState->t;
CMD * cmd = (CMD *)t->cmds;
int status = pState->status;
TARGET * t = pState->t;
CMD * cmd = (CMD *)t->cmds;
int status = pState->status;
if ( t->flags & T_FLAG_FAIL_EXPECTED && !globs.noexec )
{
/* Invert execution result when FAIL_EXPECTED has been applied. */
switch ( status )
{
case EXEC_CMD_FAIL: status = EXEC_CMD_OK ; break;
case EXEC_CMD_OK: status = EXEC_CMD_FAIL; break;
case EXEC_CMD_FAIL: status = EXEC_CMD_OK; break;
case EXEC_CMD_OK: status = EXEC_CMD_FAIL; break;
}
}
if ( ( status == EXEC_CMD_FAIL ) &&
( cmd->rule->actions->flags & RULE_IGNORE ) )
if ( status == EXEC_CMD_FAIL && cmd->rule->actions->flags & RULE_IGNORE )
status = EXEC_CMD_OK;
/* On interrupt, set intr so _everything_ fails. */
@@ -868,7 +857,7 @@ static void make1d( state * pState )
++intr;
/* Print command text on failure. */
if ( ( status == EXEC_CMD_FAIL ) && DEBUG_MAKE )
if ( status == EXEC_CMD_FAIL && DEBUG_MAKE )
{
if ( !DEBUG_EXEC )
printf( "%s\n", cmd->buf->value );
@@ -881,7 +870,7 @@ static void make1d( state * pState )
/* Treat failed commands as interrupts in case we were asked to stop the
* build in case of any errors.
*/
if ( ( status == EXEC_CMD_FAIL ) && globs.quitquick )
if ( status == EXEC_CMD_FAIL && globs.quitquick )
++intr;
/* If the command was interrupted or failed and the target is not
@@ -890,16 +879,15 @@ static void make1d( state * pState )
if ( status != EXEC_CMD_OK )
{
LIST * targets = lol_get( &cmd->args, 0 );
LISTITER iter = list_begin( targets ), end = list_end( targets );
LISTITER iter = list_begin( targets );
LISTITER const end = list_end( targets );
for ( ; iter != end; iter = list_next( iter ) )
{
int need_unlink = 1;
TARGET* t = bindtarget ( list_item( iter ) );
if (t->flags & T_FLAG_PRECIOUS)
{
TARGET * t = bindtarget( list_item( iter ) );
if ( t->flags & T_FLAG_PRECIOUS )
need_unlink = 0;
}
if (need_unlink && !unlink( object_str( list_item( iter ) ) ) )
if ( need_unlink && !unlink( object_str( list_item( iter ) ) ) )
printf( "...removing %s\n", object_str( list_item( iter ) ) );
}
}
@@ -916,7 +904,7 @@ static void make1d( state * pState )
/*
* swap_settings() - replace the settings from the current module and target
* with those from the new module and target
* with those from the new module and target
*/
static void swap_settings
@@ -927,7 +915,8 @@ static void swap_settings
TARGET * new_target
)
{
if ( ( new_target == *current_target ) && ( new_module == *current_module ) )
if ( ( new_target == *current_target ) &&
( new_module == *current_module ) )
return;
if ( *current_target )
@@ -962,7 +951,7 @@ static CMD * make1cmds( TARGET * t )
/* Step through actions. Actions may be shared with other targets or grouped
* using RULE_TOGETHER, so actions already seen are skipped.
*/
for ( a0 = t->actions ; a0; a0 = a0->next )
for ( a0 = t->actions; a0; a0 = a0->next )
{
RULE * rule = a0->action->rule;
rule_actions * actions = rule->actions;
@@ -987,7 +976,8 @@ static CMD * make1cmds( TARGET * t )
ns = make1list( L0, a0->action->sources, actions->flags );
if ( actions->flags & RULE_TOGETHER )
for ( a1 = a0->next; a1; a1 = a1->next )
if ( a1->action->rule == rule && a1->action->running < running_flag )
if ( a1->action->rule == rule &&
a1->action->running < running_flag )
{
ns = make1list( ns, a1->action->sources, actions->flags );
a1->action->running = running_flag;
@@ -996,7 +986,8 @@ static CMD * make1cmds( TARGET * t )
/* If doing only updated (or existing) sources, but none have been
* updated (or exist), skip this action.
*/
if ( list_empty( ns ) && ( actions->flags & ( RULE_NEWSRCS | RULE_EXISTING ) ) )
if ( list_empty( ns ) &&
( actions->flags & ( RULE_NEWSRCS | RULE_EXISTING ) ) )
{
list_free( nt );
continue;
@@ -1037,7 +1028,7 @@ static CMD * make1cmds( TARGET * t )
do
{
CMD * cmd;
LIST * cmd_sources = list_sublist( ns, start, chunk );
LIST * const cmd_sources = list_sublist( ns, start, chunk );
/* Build cmd: cmd_new() consumes its lists if successful. */
if ( list_empty( cmd_targets ) ) cmd_targets = list_copy( nt );
@@ -1086,9 +1077,7 @@ static CMD * make1cmds( TARGET * t )
list_free( nt );
list_free( ns );
/* Free the variables whose values were bound by 'actions xxx bind
* vars'.
*/
/* Free variables with values bound by 'actions xxx bind vars'. */
popsettings( rule->module, boundvars );
freesettings( boundvars );
}
@@ -1113,22 +1102,26 @@ static LIST * make1list( LIST * l, TARGETS * targets, int flags )
if ( ( flags & RULE_EXISTING ) && ( flags & RULE_NEWSRCS ) )
{
if ( ( t->binding != T_BIND_EXISTS ) && ( t->fate <= T_FATE_STABLE ) )
if ( ( t->binding != T_BIND_EXISTS ) &&
( t->fate <= T_FATE_STABLE ) )
continue;
}
else
else if ( flags & RULE_EXISTING )
{
if ( ( flags & RULE_EXISTING ) && ( t->binding != T_BIND_EXISTS ) )
if ( t->binding != T_BIND_EXISTS )
continue;
if ( ( flags & RULE_NEWSRCS ) && ( t->fate <= T_FATE_STABLE ) )
}
else if ( flags & RULE_NEWSRCS )
{
if ( t->fate <= T_FATE_STABLE )
continue;
}
/* Prohibit duplicates for RULE_TOGETHER. */
if ( flags & RULE_TOGETHER )
{
LISTITER iter = list_begin( l ), end = list_end( l );
LISTITER iter = list_begin( l );
LISTITER const end = list_end( l );
for ( ; iter != end; iter = list_next( iter ) )
if ( object_equal( list_item( iter ), t->boundname ) )
break;
@@ -1152,16 +1145,18 @@ static SETTINGS * make1settings( struct module_t * module, LIST * vars )
{
SETTINGS * settings = 0;
LISTITER vars_iter = list_begin( vars ), vars_end = list_end( vars );
LISTITER vars_iter = list_begin( vars );
LISTITER const vars_end = list_end( vars );
for ( ; vars_iter != vars_end; vars_iter = list_next( vars_iter ) )
{
LIST * l = var_get( module, list_item( vars_iter ) );
LIST * nl = L0;
LISTITER iter = list_begin( l ), end = list_end( l );
LISTITER iter = list_begin( l );
LISTITER const end = list_end( l );
for ( ; iter != end; iter = list_next( iter ) )
{
TARGET * t = bindtarget( list_item( iter ) );
TARGET * const t = bindtarget( list_item( iter ) );
/* Make sure the target is bound. */
if ( t->binding == T_BIND_UNBOUND )