static void var_dump( OBJECT * symbol, LIST * value, char * what ) { printf( "%s %s = ", what, object_str( symbol ) ); list_print( value ); printf( "\n" ); }
/* binary search for the property value */ LIST * property_set_get( FRAME * frame, int flags ) { OBJECT * varname = object_new( "self.raw" ); LIST * props = var_get( frame->module, varname ); const char * name = object_str( list_front( lol_get( frame->args, 0 ) ) ); size_t name_len = strlen( name ); LISTITER begin, end; LIST * result = L0; object_free( varname ); /* Assumes random access */ begin = list_begin( props ), end = list_end( props ); while ( 1 ) { ptrdiff_t diff = (end - begin); LISTITER mid = begin + diff / 2; int res; if ( diff == 0 ) { return L0; } res = strncmp( object_str( list_item( mid ) ), name, name_len ); if ( res < 0 ) { begin = mid + 1; } else if ( res > 0 ) { end = mid; } else /* We've found the property */ { /* Find the beginning of the group */ LISTITER tmp = mid; while ( tmp > begin ) { --tmp; res = strncmp( object_str( list_item( tmp ) ), name, name_len ); if ( res != 0 ) { ++tmp; break; } } begin = tmp; /* Find the end of the group */ tmp = mid + 1; while ( tmp < end ) { res = strncmp( object_str( list_item( tmp ) ), name, name_len ); if ( res != 0 ) break; ++tmp; } end = tmp; break; } } for ( ; begin != end; ++begin ) { result = list_push_back( result, object_new( object_str( list_item( begin ) ) + name_len ) ); } return result; }
static #endif LIST * headers1( LIST * l, OBJECT * file, int rec, regexp * re[] ) { FILE * f; char buf[ 1024 ]; int i; static regexp * re_macros = 0; #ifdef OPT_IMPROVED_PATIENCE_EXT static int count = 0; ++count; if ( ( ( count == 100 ) || !( count % 1000 ) ) && DEBUG_MAKE ) { out_printf( "...patience...\n" ); out_flush(); } #endif /* The following regexp is used to detect cases where a file is included * through a line like "#include MACRO". */ if ( re_macros == 0 ) { OBJECT * const re_str = object_new( "#[ \t]*include[ \t]*([A-Za-z][A-Za-z0-9_]*).*$" ); re_macros = regex_compile( re_str ); object_free( re_str ); } if ( !( f = fopen( object_str( file ), "r" ) ) ) return l; while ( fgets( buf, sizeof( buf ), f ) ) { for ( i = 0; i < rec; ++i ) if ( regexec( re[ i ], buf ) && re[ i ]->startp[ 1 ] ) { ( (char *)re[ i ]->endp[ 1 ] )[ 0 ] = '\0'; if ( DEBUG_HEADER ) out_printf( "header found: %s\n", re[ i ]->startp[ 1 ] ); l = list_push_back( l, object_new( re[ i ]->startp[ 1 ] ) ); } /* Special treatment for #include MACRO. */ if ( regexec( re_macros, buf ) && re_macros->startp[ 1 ] ) { OBJECT * header_filename; OBJECT * macro_name; ( (char *)re_macros->endp[ 1 ] )[ 0 ] = '\0'; if ( DEBUG_HEADER ) out_printf( "macro header found: %s", re_macros->startp[ 1 ] ); macro_name = object_new( re_macros->startp[ 1 ] ); header_filename = macro_header_get( macro_name ); object_free( macro_name ); if ( header_filename ) { if ( DEBUG_HEADER ) out_printf( " resolved to '%s'\n", object_str( header_filename ) ); l = list_push_back( l, object_copy( header_filename ) ); } else { if ( DEBUG_HEADER ) out_printf( " ignored !!\n" ); } } } fclose( f ); return l; }
int file_collect_archive_content_( file_archive_info_t * const archive ) { #ifndef NO_AR struct ar_hdr ar_hdr; char * string_table = 0; char buf[ MAXJPATH ]; long offset; int fd; const char * path = object_str( archive->file->name ); if ( ! filelist_empty( archive->members ) ) filelist_free( archive->members ); if ( ( fd = open( path, O_RDONLY, 0 ) ) < 0 ) return -1; if ( read( fd, buf, SARMAG ) != SARMAG || strncmp( ARMAG, buf, SARMAG ) ) { close( fd ); return -1; } offset = SARMAG; if ( DEBUG_BINDSCAN ) out_printf( "scan archive %s\n", path ); while ( ( read( fd, &ar_hdr, SARHDR ) == SARHDR ) && !( memcmp( ar_hdr.ar_fmag, ARFMAG, SARFMAG ) #ifdef ARFZMAG /* OSF also has a compressed format */ && memcmp( ar_hdr.ar_fmag, ARFZMAG, SARFMAG ) #endif ) ) { char lar_name_[ 257 ]; char * lar_name = lar_name_ + 1; long lar_date; long lar_size; long lar_offset; char * c; char * src; char * dest; strncpy( lar_name, ar_hdr.ar_name, sizeof( ar_hdr.ar_name ) ); sscanf( ar_hdr.ar_date, "%ld", &lar_date ); sscanf( ar_hdr.ar_size, "%ld", &lar_size ); if ( ar_hdr.ar_name[ 0 ] == '/' ) { if ( ar_hdr.ar_name[ 1 ] == '/' ) { /* This is the "string table" entry of the symbol table, holding * filename strings longer than 15 characters, i.e. those that * do not fit into ar_name. */ string_table = (char *)BJAM_MALLOC_ATOMIC( lar_size ); lseek( fd, offset + SARHDR, 0 ); if ( read( fd, string_table, lar_size ) != lar_size ) out_printf("error reading string table\n"); } else if ( string_table && ar_hdr.ar_name[ 1 ] != ' ' ) { /* Long filenames are recognized by "/nnnn" where nnnn is the * offset of the string in the string table represented in ASCII * decimals. */ dest = lar_name; lar_offset = atoi( lar_name + 1 ); src = &string_table[ lar_offset ]; while ( *src != '/' ) *dest++ = *src++; *dest = '/'; } } c = lar_name - 1; while ( ( *++c != ' ' ) && ( *c != '/' ) ); *c = '\0'; if ( DEBUG_BINDSCAN ) out_printf( "archive name %s found\n", lar_name ); sprintf( buf, "%s", lar_name ); if ( strcmp( buf, "") != 0 ) { file_info_t * member = 0; archive->members = filelist_push_back( archive->members, object_new( buf ) ); member = filelist_back( archive->members ); member->is_file = 1; member->is_dir = 0; member->exists = 0; timestamp_init( &member->time, (time_t)lar_date, 0 ); } offset += SARHDR + ( ( lar_size + 1 ) & ~1 ); lseek( fd, offset, 0 ); } if ( string_table ) BJAM_FREE( string_table ); close( fd ); #endif /* NO_AR */ return 0; }
/* Checks whether the given shell list is actually a request to execute raw * commands without an external shell. */ int is_raw_command_request( LIST * shell ) { return !list_empty( shell ) && !strcmp( object_str( list_front( shell ) ), "%" ) && list_next( list_begin( shell ) ) == list_end( shell ); }
static void make1b( state * const pState ) { TARGET * const t = pState->t; TARGET * failed = 0; char const * failed_name = "dependencies"; pop_state( &state_stack ); /* If any dependencies are still outstanding, wait until they signal their * completion by pushing this same state for their parent targets. */ if ( --t->asynccnt ) { return; } /* Now ready to build target 't', if dependencies built OK. */ /* Collect status from dependencies. If -n was passed then act as though all * dependencies built correctly (the only way they can fail is if UPDATE_NOW * was called). If the dependencies can not be found or we got an interrupt, * we can not get here. */ 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 ) ) { failed = c->target; t->status = c->target->status; } } /* If an internal header node failed to build, we want to output the target * that it failed on. */ if ( failed ) failed_name = failed->flags & T_FLAG_INTERNAL ? failed->failed : object_str( failed->name ); t->failed = failed_name; /* If actions for building any of the dependencies have failed, bail. * Otherwise, execute all actions to make the current target. */ if ( ( t->status == EXEC_CMD_FAIL ) && t->actions ) { ++counts->skipped; if ( ( t->flags & ( T_FLAG_RMOLD | T_FLAG_NOTFILE ) ) == T_FLAG_RMOLD ) { if ( !unlink( object_str( t->boundname ) ) ) printf( "...removing outdated %s\n", object_str( t->boundname ) ); } else printf( "...skipped %s for lack of %s...\n", object_str( t->name ), failed_name ); } if ( t->status == EXEC_CMD_OK ) switch ( t->fate ) { case T_FATE_STABLE: case T_FATE_NEWER: break; case T_FATE_CANTFIND: case T_FATE_CANTMAKE: t->status = EXEC_CMD_FAIL; break; case T_FATE_ISTMP: if ( DEBUG_MAKE ) printf( "...using %s...\n", object_str( t->name ) ); break; case T_FATE_TOUCHED: case T_FATE_MISSING: case T_FATE_NEEDTMP: case T_FATE_OUTDATED: case T_FATE_UPDATE: case T_FATE_REBUILD: /* Prepare commands for executing actions scheduled for this target. * Commands have their embedded variables automatically expanded, * including making use of any "on target" variables. */ if ( t->actions ) { ++counts->total; if ( DEBUG_MAKE && !( counts->total % 100 ) ) printf( "...on %dth target...\n", counts->total ); t->cmds = (char *)make1cmds( t ); /* Update the target's "progress" so MAKE1C processing counts it * among its successes/failures. */ t->progress = T_MAKE_RUNNING; } break; /* All valid fates should have been accounted for by now. */ default: printf( "ERROR: %s has bad fate %d", object_str( t->name ), t->fate ); abort(); } /* Proceed to MAKE1C to begin executing the chain of commands prepared for * building the target. If we are not going to build the target (e.g. due to * dependency failures or no commands needing to be run) the chain will be * empty and MAKE1C processing will directly signal the target's completion. */ if ( t->cmds == NULL || --( ( CMD * )t->cmds )->asynccnt == 0 ) push_state( &state_stack, t, NULL, T_STATE_MAKE1C ); else if ( DEBUG_EXECCMD ) { CMD * cmd = ( CMD * )t->cmds; printf( "Delaying %s %s: %d targets not ready\n", object_str( cmd->rule->name ), object_str( t->boundname ), cmd->asynccnt ); } }
void hcache_init() { FILE * f; OBJECT * version = 0; int header_count = 0; const char * hcachename; if ( hcachehash ) return; hcachehash = hashinit( sizeof( HCACHEDATA ), "hcache" ); if ( !( hcachename = cache_name() ) ) return; if ( !( f = fopen( hcachename, "rb" ) ) ) return; version = read_netstring( f ); if ( !version || strcmp( object_str( version ), CACHE_FILE_VERSION ) ) goto bail; while ( 1 ) { HCACHEDATA cachedata; HCACHEDATA * c; OBJECT * record_type = 0; OBJECT * time_str = 0; OBJECT * age_str = 0; OBJECT * includes_count_str = 0; OBJECT * hdrscan_count_str = 0; int i; int count; LIST * l; int found; cachedata.boundname = 0; cachedata.includes = 0; cachedata.hdrscan = 0; record_type = read_netstring( f ); if ( !record_type ) { fprintf( stderr, "invalid %s\n", hcachename ); goto cleanup; } if ( !strcmp( object_str( record_type ), CACHE_RECORD_END ) ) { object_free( record_type ); break; } if ( strcmp( object_str( record_type ), CACHE_RECORD_HEADER ) ) { fprintf( stderr, "invalid %s with record separator <%s>\n", hcachename, record_type ? object_str( record_type ) : "<null>" ); goto cleanup; } cachedata.boundname = read_netstring( f ); time_str = read_netstring( f ); age_str = read_netstring( f ); includes_count_str = read_netstring( f ); if ( !cachedata.boundname || !time_str || !age_str || !includes_count_str ) { fprintf( stderr, "invalid %s\n", hcachename ); goto cleanup; } cachedata.time = atoi( object_str( time_str ) ); cachedata.age = atoi( object_str( age_str ) ) + 1; count = atoi( object_str( includes_count_str ) ); for ( l = L0, i = 0; i < count; ++i ) { OBJECT * s = read_netstring( f ); if ( !s ) { fprintf( stderr, "invalid %s\n", hcachename ); list_free( l ); goto cleanup; } l = list_push_back( l, s ); } cachedata.includes = l; hdrscan_count_str = read_netstring( f ); if ( !hdrscan_count_str ) { fprintf( stderr, "invalid %s\n", hcachename ); goto cleanup; } count = atoi( object_str( hdrscan_count_str ) ); for ( l = L0, i = 0; i < count; ++i ) { OBJECT * s = read_netstring( f ); if ( !s ) { fprintf( stderr, "invalid %s\n", hcachename ); list_free( l ); goto cleanup; } l = list_push_back( l, s ); } cachedata.hdrscan = l; c = (HCACHEDATA *)hash_insert( hcachehash, cachedata.boundname, &found ); if ( !found ) { c->boundname = cachedata.boundname; c->time = cachedata.time; c->includes = cachedata.includes; c->hdrscan = cachedata.hdrscan; c->age = cachedata.age; } else { fprintf( stderr, "can't insert header cache item, bailing on %s\n", hcachename ); goto cleanup; } c->next = hcachelist; hcachelist = c; ++header_count; object_free( record_type ); object_free( time_str ); object_free( age_str ); object_free( includes_count_str ); object_free( hdrscan_count_str ); continue; cleanup: if ( record_type ) object_free( record_type ); if ( time_str ) object_free( time_str ); if ( age_str ) object_free( age_str ); if ( includes_count_str ) object_free( includes_count_str ); if ( hdrscan_count_str ) object_free( hdrscan_count_str ); if ( cachedata.boundname ) object_free( cachedata.boundname ); if ( cachedata.includes ) list_free( cachedata.includes ); if ( cachedata.hdrscan ) list_free( cachedata.hdrscan ); goto bail; } if ( DEBUG_HEADER ) printf( "hcache read from file %s\n", hcachename ); bail: if ( version ) object_free( version ); fclose( f ); }
void make0 ( TARGET * t, TARGET * p, /* parent */ int depth, /* for display purposes */ COUNTS * counts, /* for reporting */ int anyhow, TARGET * rescanning ) /* forcibly touch all (real) targets */ { TARGETS * c; TARGET * ptime = t; TARGET * located_target = 0; timestamp last; timestamp leaf; timestamp hlast; int fate; char const * flag = ""; SETTINGS * s; #ifdef OPT_GRAPH_DEBUG_EXT int savedFate; int oldTimeStamp; #endif if ( DEBUG_MAKEPROG ) printf( "make\t--\t%s%s\n", spaces( depth ), object_str( t->name ) ); /* * Step 1: Initialize. */ if ( DEBUG_MAKEPROG ) printf( "make\t--\t%s%s\n", spaces( depth ), object_str( t->name ) ); t->fate = T_FATE_MAKING; t->depth = depth; /* * Step 2: Under the influence of "on target" variables, bind the target and * search for headers. */ /* Step 2a: Set "on target" variables. */ s = copysettings( t->settings ); pushsettings( root_module(), s ); /* Step 2b: Find and timestamp the target file (if it is a file). */ if ( ( t->binding == T_BIND_UNBOUND ) && !( t->flags & T_FLAG_NOTFILE ) ) { OBJECT * another_target; object_free( t->boundname ); t->boundname = search( t->name, &t->time, &another_target, t->flags & T_FLAG_ISFILE ); /* If it was detected that this target refers to an already existing and * bound target, we add a dependency so that every target depending on * us will depend on that other target as well. */ if ( another_target ) located_target = bindtarget( another_target ); t->binding = timestamp_empty( &t->time ) ? T_BIND_MISSING : T_BIND_EXISTS; } /* INTERNAL, NOTFILE header nodes have the time of their parents. */ if ( p && ( t->flags & T_FLAG_INTERNAL ) ) ptime = p; /* If temp file does not exist but parent does, use parent. */ if ( p && ( t->flags & T_FLAG_TEMP ) && ( t->binding == T_BIND_MISSING ) && ( p->binding != T_BIND_MISSING ) ) { t->binding = T_BIND_PARENTS; ptime = p; } #ifdef OPT_SEMAPHORE { LIST * var = var_get( root_module(), constant_JAM_SEMAPHORE ); if ( !list_empty( var ) ) { TARGET * const semaphore = bindtarget( list_front( var ) ); semaphore->progress = T_MAKE_SEMAPHORE; t->semaphore = semaphore; } } #endif /* Step 2c: If its a file, search for headers. */ if ( t->binding == T_BIND_EXISTS ) headers( t ); /* Step 2d: reset "on target" variables. */ popsettings( root_module(), s ); freesettings( s ); /* * Pause for a little progress reporting. */ if ( DEBUG_BIND ) { if ( !object_equal( t->name, t->boundname ) ) printf( "bind\t--\t%s%s: %s\n", spaces( depth ), object_str( t->name ), object_str( t->boundname ) ); switch ( t->binding ) { case T_BIND_UNBOUND: case T_BIND_MISSING: case T_BIND_PARENTS: printf( "time\t--\t%s%s: %s\n", spaces( depth ), object_str( t->name ), target_bind[ (int)t->binding ] ); break; case T_BIND_EXISTS: printf( "time\t--\t%s%s: %s\n", spaces( depth ), object_str( t->name ), timestamp_str( &t->time ) ); break; } } /* * Step 3: Recursively make0() dependencies & headers. */ /* Step 3a: Recursively make0() dependencies. */ for ( c = t->depends; c; c = c->next ) { int const internal = t->flags & T_FLAG_INTERNAL; /* Warn about circular deps, except for includes, which include each * other alot. */ if ( c->target->fate == T_FATE_INIT ) make0( c->target, ptime, depth + 1, counts, anyhow, rescanning ); else if ( c->target->fate == T_FATE_MAKING && !internal ) printf( "warning: %s depends on itself\n", object_str( c->target->name ) ); else if ( c->target->fate != T_FATE_MAKING && rescanning ) make0rescan( c->target, rescanning ); if ( rescanning && c->target->includes && c->target->includes->fate != T_FATE_MAKING ) make0rescan( target_scc( c->target->includes ), rescanning ); } if ( located_target ) { if ( located_target->fate == T_FATE_INIT ) make0( located_target, ptime, depth + 1, counts, anyhow, rescanning ); else if ( located_target->fate != T_FATE_MAKING && rescanning ) make0rescan( located_target, rescanning ); } /* Step 3b: Recursively make0() internal includes node. */ if ( t->includes ) make0( t->includes, p, depth + 1, counts, anyhow, rescanning ); /* Step 3c: Add dependencies' includes to our direct dependencies. */ { TARGETS * incs = 0; for ( c = t->depends; c; c = c->next ) if ( c->target->includes ) incs = targetentry( incs, c->target->includes ); t->depends = targetchain( t->depends, incs ); } if ( located_target ) t->depends = targetentry( t->depends, located_target ); /* Step 3d: Detect cycles. */ { int cycle_depth = depth; for ( c = t->depends; c; c = c->next ) { TARGET * scc_root = target_scc( c->target ); if ( scc_root->fate == T_FATE_MAKING && ( !scc_root->includes || scc_root->includes->fate != T_FATE_MAKING ) ) { if ( scc_root->depth < cycle_depth ) { cycle_depth = scc_root->depth; t->scc_root = scc_root; } } } } /* * Step 4: Compute time & fate. */ /* Step 4a: Pick up dependencies' time and fate. */ timestamp_clear( &last ); timestamp_clear( &leaf ); fate = T_FATE_STABLE; for ( c = t->depends; c; c = c->next ) { /* If we are in a different strongly connected component, pull * timestamps from the root. */ if ( c->target->scc_root ) { TARGET * const scc_root = target_scc( c->target ); if ( scc_root != t->scc_root ) { timestamp_max( &c->target->leaf, &c->target->leaf, &scc_root->leaf ); timestamp_max( &c->target->time, &c->target->time, &scc_root->time ); c->target->fate = max( c->target->fate, scc_root->fate ); } } /* If LEAVES has been applied, we only heed the timestamps of the leaf * source nodes. */ timestamp_max( &leaf, &leaf, &c->target->leaf ); if ( t->flags & T_FLAG_LEAVES ) { timestamp_copy( &last, &leaf ); continue; } timestamp_max( &last, &last, &c->target->time ); fate = max( fate, c->target->fate ); #ifdef OPT_GRAPH_DEBUG_EXT if ( DEBUG_FATE ) if ( fate < c->target->fate ) printf( "fate change %s from %s to %s by dependency %s\n", object_str( t->name ), target_fate[ (int)fate ], target_fate[ (int)c->target->fate ], object_str( c->target->name ) ); #endif } /* Step 4b: Pick up included headers time. */ /* * If a header is newer than a temp source that includes it, the temp source * will need building. */ if ( t->includes ) timestamp_copy( &hlast, &t->includes->time ); else timestamp_clear( &hlast ); /* Step 4c: handle NOUPDATE oddity. * * If a NOUPDATE file exists, mark it as having eternally old dependencies. * Do not inherit our fate from our dependencies. Decide fate based only on * other flags and our binding (done later). */ if ( t->flags & T_FLAG_NOUPDATE ) { #ifdef OPT_GRAPH_DEBUG_EXT if ( DEBUG_FATE ) if ( fate != T_FATE_STABLE ) printf( "fate change %s back to stable, NOUPDATE.\n", object_str( t->name ) ); #endif timestamp_clear( &last ); timestamp_clear( &t->time ); /* Do not inherit our fate from our dependencies. Decide fate based only * upon other flags and our binding (done later). */ fate = T_FATE_STABLE; } /* Step 4d: Determine fate: rebuild target or what? */ /* In English: If can not find or make child, can not make target. If children changed, make target. If target missing, make it. If children newer, make target. If temp's children newer than parent, make temp. If temp's headers newer than parent, make temp. If deliberately touched, make it. If up-to-date temp file present, use it. If target newer than non-notfile parent, mark target newer. Otherwise, stable! Note this block runs from least to most stable: as we make it further down the list, the target's fate gets more stable. */ #ifdef OPT_GRAPH_DEBUG_EXT savedFate = fate; oldTimeStamp = 0; #endif if ( fate >= T_FATE_BROKEN ) { fate = T_FATE_CANTMAKE; } else if ( fate >= T_FATE_SPOIL ) { fate = T_FATE_UPDATE; } else if ( t->binding == T_BIND_MISSING ) { fate = T_FATE_MISSING; } else if ( t->binding == T_BIND_EXISTS && timestamp_cmp( &last, &t->time ) > 0 ) { #ifdef OPT_GRAPH_DEBUG_EXT oldTimeStamp = 1; #endif fate = T_FATE_OUTDATED; } else if ( t->binding == T_BIND_PARENTS && timestamp_cmp( &last, &p->time ) > 0 ) { #ifdef OPT_GRAPH_DEBUG_EXT oldTimeStamp = 1; #endif fate = T_FATE_NEEDTMP; } else if ( t->binding == T_BIND_PARENTS && timestamp_cmp( &hlast, &p->time ) > 0 ) { fate = T_FATE_NEEDTMP; } else if ( t->flags & T_FLAG_TOUCHED ) { fate = T_FATE_TOUCHED; } else if ( anyhow && !( t->flags & T_FLAG_NOUPDATE ) ) { fate = T_FATE_TOUCHED; } else if ( t->binding == T_BIND_EXISTS && ( t->flags & T_FLAG_TEMP ) ) { fate = T_FATE_ISTMP; } else if ( t->binding == T_BIND_EXISTS && p && p->binding != T_BIND_UNBOUND && timestamp_cmp( &t->time, &p->time ) > 0 ) { #ifdef OPT_GRAPH_DEBUG_EXT oldTimeStamp = 1; #endif fate = T_FATE_NEWER; } else { fate = T_FATE_STABLE; } #ifdef OPT_GRAPH_DEBUG_EXT if ( DEBUG_FATE && ( fate != savedFate ) ) { if ( savedFate == T_FATE_STABLE ) printf( "fate change %s set to %s%s\n", object_str( t->name ), target_fate[ fate ], oldTimeStamp ? " (by timestamp)" : "" ); else printf( "fate change %s from %s to %s%s\n", object_str( t->name ), target_fate[ savedFate ], target_fate[ fate ], oldTimeStamp ? " (by timestamp)" : "" ); } #endif /* Step 4e: Handle missing files. */ /* If it is missing and there are no actions to create it, boom. */ /* If we can not make a target we do not care about it, okay. */ /* We could insist that there are updating actions for all missing */ /* files, but if they have dependencies we just pretend it is a NOTFILE. */ if ( ( fate == T_FATE_MISSING ) && !t->actions && !t->depends ) { if ( t->flags & T_FLAG_NOCARE ) { #ifdef OPT_GRAPH_DEBUG_EXT if ( DEBUG_FATE ) printf( "fate change %s to STABLE from %s, " "no actions, no dependencies and do not care\n", object_str( t->name ), target_fate[ fate ] ); #endif fate = T_FATE_STABLE; } else { printf( "don't know how to make %s\n", object_str( t->name ) ); fate = T_FATE_CANTFIND; } } /* Step 4f: Propagate dependencies' time & fate. */ /* Set leaf time to be our time only if this is a leaf. */ timestamp_max( &t->time, &t->time, &last ); timestamp_copy( &t->leaf, timestamp_empty( &leaf ) ? &t->time : &leaf ); /* This target's fate may have been updated by virtue of following some * target's rebuilds list, so only allow it to be increased to the fate we * have calculated. Otherwise, grab its new fate. */ if ( fate > t->fate ) t->fate = fate; else fate = t->fate; /* Step 4g: If this target needs to be built, force rebuild everything in * its rebuilds list. */ if ( ( fate >= T_FATE_BUILD ) && ( fate < T_FATE_BROKEN ) ) force_rebuilds( t ); /* * Step 5: Sort dependencies by their update time. */ if ( globs.newestfirst ) t->depends = make0sort( t->depends ); /* * Step 6: A little harmless tabulating for tracing purposes. */ /* Do not count or report interal includes nodes. */ if ( t->flags & T_FLAG_INTERNAL ) return; if ( counts ) { #ifdef OPT_IMPROVED_PATIENCE_EXT ++counts->targets; #else if ( !( ++counts->targets % 1000 ) && DEBUG_MAKE ) { printf( "...patience...\n" ); fflush(stdout); } #endif if ( fate == T_FATE_ISTMP ) ++counts->temp; else if ( fate == T_FATE_CANTFIND ) ++counts->cantfind; else if ( ( fate == T_FATE_CANTMAKE ) && t->actions ) ++counts->cantmake; else if ( ( fate >= T_FATE_BUILD ) && ( fate < T_FATE_BROKEN ) && t->actions ) ++counts->updating; } if ( !( t->flags & T_FLAG_NOTFILE ) && ( fate >= T_FATE_SPOIL ) ) flag = "+"; else if ( t->binding == T_BIND_EXISTS && p && timestamp_cmp( &t->time, &p->time ) > 0 ) flag = "*"; if ( DEBUG_MAKEPROG ) printf( "made%s\t%s\t%s%s\n", flag, target_fate[ (int)t->fate ], spaces( depth ), object_str( t->name ) ); }
LIST * hcache( TARGET * t, int rec, regexp * re[], LIST * hdrscan ) { HCACHEDATA cachedata; HCACHEDATA * c = &cachedata; LIST * l = 0; ++queries; c->boundname = t->boundname; if (hashcheck (hcachehash, (HASHDATA **) &c)) { if (c->time == t->time) { LIST *l1 = hdrscan, *l2 = c->hdrscan; while (l1 && l2) { if (l1->value != l2->value) { l1 = NULL; } else { l1 = list_next(l1); l2 = list_next(l2); } } if (l1 || l2) { if (DEBUG_HEADER) printf("HDRSCAN out of date in cache for %s\n", object_str( t->boundname )); printf("HDRSCAN out of date for %s\n", object_str( t->boundname ) ); printf(" real : "); list_print(hdrscan); printf("\n cached: "); list_print(c->hdrscan); printf("\n"); list_free(c->includes); list_free(c->hdrscan); c->includes = 0; c->hdrscan = 0; } else { if (DEBUG_HEADER) printf ("using header cache for %s\n", object_str( t->boundname ) ); c->age = 0; ++hits; l = list_copy (0, c->includes); return l; } } else { if (DEBUG_HEADER) printf ("header cache out of date for %s\n", object_str( t->boundname ) ); list_free (c->includes); list_free(c->hdrscan); c->includes = 0; c->hdrscan = 0; } } else { if (hashenter (hcachehash, (HASHDATA **)&c)) { c->boundname = object_copy( c->boundname ); c->next = hcachelist; hcachelist = c; } } /* 'c' points at the cache entry. Its out of date. */ l = headers1 (0, t->boundname, rec, re); c->time = t->time; c->age = 0; c->includes = list_copy (0, l); c->hdrscan = list_copy(0, hdrscan); return l; }
static int str_ptr_compare( void const * va, void const * vb ) { OBJECT * a = *( (OBJECT * *)va ); OBJECT * b = *( (OBJECT * *)vb ); return strcmp( object_str( a ), object_str( b ) ); }
void hcache_init() { HCACHEDATA cachedata; HCACHEDATA * c; FILE * f; OBJECT * version; int header_count = 0; const char * hcachename; if ( hcachehash ) return; hcachehash = hashinit( sizeof( HCACHEDATA ), "hcache" ); if ( !( hcachename = cache_name() ) ) return; if ( !( f = fopen( hcachename, "rb" ) ) ) return; version = read_netstring( f ); if ( !version || strcmp( object_str( version ), CACHE_FILE_VERSION ) ) { fclose( f ); return; } while ( 1 ) { OBJECT * record_type; OBJECT * time_str; OBJECT * age_str; OBJECT * includes_count_str; OBJECT * hdrscan_count_str; int i; int count; LIST * l; record_type = read_netstring( f ); if ( !record_type ) { fprintf( stderr, "invalid %s\n", hcachename ); goto bail; } if ( !strcmp( object_str( record_type ), CACHE_RECORD_END ) ) break; if ( strcmp( object_str( record_type ), CACHE_RECORD_HEADER ) ) { fprintf( stderr, "invalid %s with record separator <%s>\n", hcachename, record_type ? object_str( record_type ) : "<null>" ); goto bail; } c = &cachedata; c->boundname = read_netstring( f ); time_str = read_netstring( f ); age_str = read_netstring( f ); includes_count_str = read_netstring( f ); if ( !c->boundname || !time_str || !age_str || !includes_count_str ) { fprintf( stderr, "invalid %s\n", hcachename ); goto bail; } c->time = atoi( object_str( time_str ) ); c->age = atoi( object_str( age_str ) ) + 1; count = atoi( object_str( includes_count_str ) ); for ( l = 0, i = 0; i < count; ++i ) { OBJECT * s = read_netstring( f ); if ( !s ) { fprintf( stderr, "invalid %s\n", hcachename ); goto bail; } l = list_new( l, s ); } c->includes = l; hdrscan_count_str = read_netstring( f ); if ( !includes_count_str ) { list_free( c->includes ); fprintf( stderr, "invalid %s\n", hcachename ); goto bail; } count = atoi( object_str( hdrscan_count_str ) ); for ( l = 0, i = 0; i < count; ++i ) { OBJECT * s = read_netstring( f ); if ( !s ) { fprintf( stderr, "invalid %s\n", hcachename ); goto bail; } l = list_new( l, s ); } c->hdrscan = l; if ( !hashenter( hcachehash, (HASHDATA * *)&c ) ) { fprintf( stderr, "can't insert header cache item, bailing on %s\n", hcachename ); goto bail; } c->next = hcachelist; hcachelist = c; ++header_count; } if ( DEBUG_HEADER ) printf( "hcache read from file %s\n", hcachename ); bail: fclose( f ); }
void exec_cmd ( const char * command, void (* func)( void * closure, int status, timing_info *, const char * invoked_command, const char * command_output ), void * closure, LIST * shell, const char * action, const char * target ) { int slot; int raw_cmd = 0 ; const char * argv_static[ MAXARGC + 1 ]; /* +1 for NULL */ const char * * argv = argv_static; char * p; const char * command_orig = command; /* Check to see if we need to hack around the line-length limitation. Look * for a JAMSHELL setting of "%", indicating that the command should be * invoked directly. */ if ( !list_empty( shell ) && !strcmp( object_str( list_front( shell ) ), "%" ) && list_next( list_begin( shell ) ) == list_end( shell ) ) { raw_cmd = 1; shell = 0; } /* Find a slot in the running commands table for this one. */ for ( slot = 0; slot < MAXJOBS; ++slot ) if ( !cmdtab[ slot ].pi.hProcess ) break; if ( slot == MAXJOBS ) { printf( "no slots for child!\n" ); exit( EXITBAD ); } /* Compute the name of a temp batch file, for possible use. */ if ( !cmdtab[ slot ].tempfile_bat ) { char const * tempdir = path_tmpdir(); DWORD procID = GetCurrentProcessId(); /* SVA - allocate 64 bytes extra just to be safe. */ cmdtab[ slot ].tempfile_bat = BJAM_MALLOC_ATOMIC( strlen( tempdir ) + 64 ); sprintf( cmdtab[ slot ].tempfile_bat, "%s\\jam%d-%02d.bat", tempdir, procID, slot ); } /* Trim leading, -ending- white space */ while ( *( command + 1 ) && isspace( *command ) ) ++command; /* Write to .BAT file unless the line would be too long and it meets the * other spawnability criteria. */ if ( raw_cmd && ( can_spawn( command ) >= MAXLINE ) ) { if ( DEBUG_EXECCMD ) printf("Executing raw command directly\n"); } else { FILE * f = 0; int tries = 0; raw_cmd = 0; /* Write command to bat file. For some reason this open can fail * intermitently. But doing some retries works. Most likely this is due * to a previously existing file of the same name that happens to be * opened by an active virus scanner. Pointed out and fixed by Bronek * Kozicki. */ for ( ; !f && ( tries < 4 ); ++tries ) { f = fopen( cmdtab[ slot ].tempfile_bat, "w" ); if ( !f && ( tries < 4 ) ) Sleep( 250 ); } if ( !f ) { printf( "failed to write command file!\n" ); exit( EXITBAD ); } fputs( command, f ); fclose( f ); command = cmdtab[ slot ].tempfile_bat; if ( DEBUG_EXECCMD ) { if ( !list_empty( shell ) ) printf( "using user-specified shell: %s", object_str( list_front( shell ) ) ); else printf( "Executing through .bat file\n" ); } } /* Formulate argv; If shell was defined, be prepared for % and ! subs. * Otherwise, use stock cmd.exe. */ if ( shell ) { int i; char jobno[ 4 ]; int gotpercent = 0; LISTITER shell_iter = list_begin( shell ), shell_end = list_end( shell ); sprintf( jobno, "%d", slot + 1 ); for ( i = 0; shell_iter != shell_end && ( i < MAXARGC ); ++i, shell_iter = list_next( shell_iter ) ) { switch ( object_str( list_item( shell_iter ) )[ 0 ] ) { case '%': argv[ i ] = command; ++gotpercent; break; case '!': argv[ i ] = jobno; break; default : argv[ i ] = object_str( list_item( shell_iter ) ); } if ( DEBUG_EXECCMD ) printf( "argv[%d] = '%s'\n", i, argv[ i ] ); } if ( !gotpercent ) argv[ i++ ] = command; argv[ i ] = 0; } else if ( raw_cmd ) { argv = string_to_args( command ); } else { argv[ 0 ] = "cmd.exe"; argv[ 1 ] = "/Q/C"; /* anything more is non-portable */ argv[ 2 ] = command; argv[ 3 ] = 0; } /* Catch interrupts whenever commands are running. */ if ( !cmdsrunning++ ) istat = signal( SIGINT, onintr ); /* Start the command. */ { SECURITY_ATTRIBUTES sa = { sizeof( SECURITY_ATTRIBUTES ), 0, 0 }; SECURITY_DESCRIPTOR sd; STARTUPINFO si = { sizeof( STARTUPINFO ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; string cmd; /* Init the security data. */ InitializeSecurityDescriptor( &sd, SECURITY_DESCRIPTOR_REVISION ); SetSecurityDescriptorDacl( &sd, TRUE, NULL, FALSE ); sa.lpSecurityDescriptor = &sd; sa.bInheritHandle = TRUE; /* Create the stdout, which is also the merged out + err, pipe. */ if ( !CreatePipe( &cmdtab[ slot ].pipe_out[ 0 ], &cmdtab[ slot ].pipe_out[ 1 ], &sa, 0 ) ) { perror( "CreatePipe" ); exit( EXITBAD ); } /* Create the stdout, which is also the merged out+err, pipe. */ if ( globs.pipe_action == 2 ) { if ( !CreatePipe( &cmdtab[ slot ].pipe_err[ 0 ], &cmdtab[ slot ].pipe_err[ 1 ], &sa, 0 ) ) { perror( "CreatePipe" ); exit( EXITBAD ); } } /* Set handle inheritance off for the pipe ends the parent reads from. */ SetHandleInformation( cmdtab[ slot ].pipe_out[ 0 ], HANDLE_FLAG_INHERIT, 0 ); if ( globs.pipe_action == 2 ) SetHandleInformation( cmdtab[ slot ].pipe_err[ 0 ], HANDLE_FLAG_INHERIT, 0 ); /* Hide the child window, if any. */ si.dwFlags |= STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; /* Set the child outputs to the pipes. */ si.dwFlags |= STARTF_USESTDHANDLES; si.hStdOutput = cmdtab[ slot ].pipe_out[ 1 ]; if ( globs.pipe_action == 2 ) { /* Pipe stderr to the action error output. */ si.hStdError = cmdtab[ slot ].pipe_err[ 1 ]; } else if ( globs.pipe_action == 1 ) { /* Pipe stderr to the console error output. */ si.hStdError = GetStdHandle( STD_ERROR_HANDLE ); } else { /* Pipe stderr to the action merged output. */ si.hStdError = cmdtab[ slot ].pipe_out[ 1 ]; } /* Let the child inherit stdin, as some commands assume it's available. */ si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); /* Save the operation for exec_wait() to find. */ cmdtab[ slot ].func = func; cmdtab[ slot ].closure = closure; if ( action && target ) { string_copy( &cmdtab[ slot ].action, action ); string_copy( &cmdtab[ slot ].target, target ); } else { string_free( &cmdtab[ slot ].action ); string_new ( &cmdtab[ slot ].action ); string_free( &cmdtab[ slot ].target ); string_new ( &cmdtab[ slot ].target ); } string_copy( &cmdtab[ slot ].command, command_orig ); /* Put together the command we run. */ { const char * * argp = argv; string_new( &cmd ); string_copy( &cmd, *(argp++) ); while ( *argp ) { string_push_back( &cmd, ' ' ); string_append( &cmd, *(argp++) ); } } /* Create output buffers. */ string_new( &cmdtab[ slot ].buffer_out ); string_new( &cmdtab[ slot ].buffer_err ); /* Run the command by creating a sub-process for it. */ if ( ! CreateProcess( NULL , /* application name */ cmd.value , /* command line */ NULL , /* process attributes */ NULL , /* thread attributes */ TRUE , /* inherit handles */ CREATE_NEW_PROCESS_GROUP, /* create flags */ NULL , /* env vars, null inherits env */ NULL , /* current dir, null is our */ /* current dir */ &si , /* startup info */ &cmdtab[ slot ].pi /* child process info, if created */ ) ) { perror( "CreateProcess" ); exit( EXITBAD ); } /* Clean up temporary stuff. */ string_free( &cmd ); } /* Wait until we are under the limit of concurrent commands. Do not trust * globs.jobs alone. */ while ( ( cmdsrunning >= MAXJOBS ) || ( cmdsrunning >= globs.jobs ) ) if ( !exec_wait() ) break; if ( argv != argv_static ) free_argv( argv ); }
LIST * var_get( struct module_t * module, OBJECT * symbol ) { LIST * result = L0; #ifdef OPT_AT_FILES /* Some "fixed" variables... */ if ( object_equal( symbol, constant_TMPDIR ) ) { list_free( saved_var ); result = saved_var = list_new( object_new( path_tmpdir()->value ) ); } else if ( object_equal( symbol, constant_TMPNAME ) ) { list_free( saved_var ); result = saved_var = list_new( path_tmpnam() ); } else if ( object_equal( symbol, constant_TMPFILE ) ) { list_free( saved_var ); result = saved_var = list_new( path_tmpfile() ); } else if ( object_equal( symbol, constant_STDOUT ) ) { list_free( saved_var ); result = saved_var = list_new( object_copy( constant_STDOUT ) ); } else if ( object_equal( symbol, constant_STDERR ) ) { list_free( saved_var ); result = saved_var = list_new( object_copy( constant_STDERR ) ); } else #endif { VARIABLE * v; int n; if ( ( n = module_get_fixed_var( module, symbol ) ) != -1 ) { if ( DEBUG_VARGET ) var_dump( symbol, module->fixed_variables[ n ], "get" ); result = module->fixed_variables[ n ]; } else if ( module->variables && ( v = (VARIABLE *)hash_find( module->variables, symbol ) ) ) { if ( DEBUG_VARGET ) var_dump( v->symbol, v->value, "get" ); result = v->value; } #ifdef OS_VMS else if ( ( module->name && object_equal( module->name, constant_ENVIRON ) ) || root_module() == module ) { /* On VMS, when a variable from root or ENVIRON module is not found, * explicitly request it from the process. * By design, process variables (and logicals) are not made available * to C main(), and thus will not get loaded in bulk to root/ENVRON. * So we get around it by getting any such variable on first request. */ const char * val = getenv( object_str( symbol ) ); if ( val ) { struct module_t * environ_module = module; char * environ[ 2 ] = { 0 }; /* NULL-terminated */ string buf[ 1 ]; if ( root_module() == module ) { environ_module = bindmodule( constant_ENVIRON ); } string_copy( buf, object_str( symbol ) ); string_append( buf, "=" ); string_append( buf, val ); environ[ 0 ] = buf->value; /* Load variable to global module, with splitting, for backward * compatibility. Then to .ENVIRON, without splitting. */ var_defines( root_module(), environ, 1 ); var_defines( environ_module, environ, 0 ); string_free( buf ); if ( module->variables && ( v = (VARIABLE *)hash_find( module->variables, symbol ) ) ) { if ( DEBUG_VARGET ) var_dump( v->symbol, v->value, "get" ); result = v->value; } } } #endif } return result; }
OBJECT * search( OBJECT * target, timestamp * const time, OBJECT * * another_target, int const file ) { PATHNAME f[ 1 ]; LIST * varlist; string buf[ 1 ]; int found = 0; OBJECT * boundname = 0; if ( another_target ) *another_target = 0; if ( !explicit_bindings ) explicit_bindings = hashinit( sizeof( BINDING ), "explicitly specified " "locations" ); string_new( buf ); /* Parse the filename. */ path_parse( object_str( target ), f ); f->f_grist.ptr = 0; f->f_grist.len = 0; varlist = var_get( root_module(), constant_LOCATE ); if ( !list_empty( varlist ) ) { OBJECT * key; f->f_root.ptr = object_str( list_front( varlist ) ); f->f_root.len = strlen( object_str( list_front( varlist ) ) ); path_build( f, buf ); if ( DEBUG_SEARCH ) printf( "locate %s: %s\n", object_str( target ), buf->value ); key = object_new( buf->value ); timestamp_from_path( time, key ); object_free( key ); found = 1; } else if ( varlist = var_get( root_module(), constant_SEARCH ), !list_empty( varlist ) ) { LISTITER iter = list_begin( varlist ); LISTITER const end = list_end( varlist ); for ( ; iter != end; iter = list_next( iter ) ) { BINDING * ba; file_info_t * ff; OBJECT * key; OBJECT * test_path; f->f_root.ptr = object_str( list_item( iter ) ); f->f_root.len = strlen( object_str( list_item( iter ) ) ); string_truncate( buf, 0 ); path_build( f, buf ); if ( DEBUG_SEARCH ) printf( "search %s: %s\n", object_str( target ), buf->value ); test_path = object_new( buf->value ); key = path_as_key( test_path ); object_free( test_path ); ff = file_query( key ); timestamp_from_path( time, key ); if ( ( ba = (BINDING *)hash_find( explicit_bindings, key ) ) ) { if ( DEBUG_SEARCH ) printf(" search %s: found explicitly located target %s\n", object_str( target ), object_str( ba->target ) ); if ( another_target ) *another_target = ba->target; found = 1; object_free( key ); break; } else if ( ff ) { if ( !file || ff->is_file ) { found = 1; object_free( key ); break; } } object_free( key ); } } if ( !found ) { /* Look for the obvious. */ /* This is a questionable move. Should we look in the obvious place if * SEARCH is set? */ OBJECT * key; f->f_root.ptr = 0; f->f_root.len = 0; string_truncate( buf, 0 ); path_build( f, buf ); if ( DEBUG_SEARCH ) printf( "search %s: %s\n", object_str( target ), buf->value ); key = object_new( buf->value ); timestamp_from_path( time, key ); object_free( key ); } boundname = object_new( buf->value ); string_free( buf ); /* Prepare a call to BINDRULE if the variable is set. */ call_bind_rule( target, boundname ); return boundname; }
void hcache_done() { FILE * f; HCACHEDATA * c; int header_count = 0; const char * hcachename; int maxage; if ( !hcachehash ) return; if ( !( hcachename = cache_name() ) ) goto cleanup; if ( !( f = fopen( hcachename, "wb" ) ) ) goto cleanup; maxage = cache_maxage(); /* Print out the version. */ write_netstring( f, CACHE_FILE_VERSION ); c = hcachelist; for ( c = hcachelist; c; c = c->next ) { LISTITER iter, end; char time_str[ 30 ]; char age_str[ 30 ]; char includes_count_str[ 30 ]; char hdrscan_count_str[ 30 ]; if ( maxage == 0 ) c->age = 0; else if ( c->age > maxage ) continue; sprintf( includes_count_str, "%lu", (long unsigned) list_length( c->includes ) ); sprintf( hdrscan_count_str, "%lu", (long unsigned) list_length( c->hdrscan ) ); sprintf( time_str, "%lu", (long unsigned) c->time ); sprintf( age_str, "%lu", (long unsigned) c->age ); write_netstring( f, CACHE_RECORD_HEADER ); write_netstring( f, object_str( c->boundname ) ); write_netstring( f, time_str ); write_netstring( f, age_str ); write_netstring( f, includes_count_str ); for ( iter = list_begin( c->includes ), end = list_end( c->includes ); iter != end; iter = list_next( iter ) ) write_netstring( f, object_str( list_item( iter ) ) ); write_netstring( f, hdrscan_count_str ); for ( iter = list_begin( c->hdrscan ), end = list_end( c->hdrscan ); iter != end; iter = list_next( iter ) ) write_netstring( f, object_str( list_item( iter ) ) ); fputs( "\n", f ); ++header_count; } write_netstring( f, CACHE_RECORD_END ); if ( DEBUG_HEADER ) printf( "hcache written to %s. %d dependencies, %.0f%% hit rate\n", hcachename, header_count, queries ? 100.0 * hits / queries : 0 ); fclose ( f ); cleanup: for ( c = hcachelist; c; c = c->next ) { list_free( c->includes ); list_free( c->hdrscan ); object_free( c->boundname ); } hcachelist = 0; if ( hcachehash ) hashdone( hcachehash ); hcachehash = 0; }
void macro_headers( TARGET * t ) { static regexp *re = 0; FILE *f; char buf[ 1024 ]; if ( DEBUG_HEADER ) printf( "macro header scan for %s\n", object_str( t->name ) ); /* this regexp is used to detect lines of the form */ /* "#define MACRO <....>" or "#define MACRO "....." */ /* in the header macro files.. */ if ( re == 0 ) { OBJECT * re_str = object_new( "^[ ]*#[ ]*define[ ]*([A-Za-z][A-Za-z0-9_]*)[ ]*" "[<\"]([^\">]*)[\">].*$" ); re = regex_compile( re_str ); object_free( re_str ); } if ( !( f = fopen( object_str( t->boundname ), "r" ) ) ) return; while ( fgets( buf, sizeof( buf ), f ) ) { HEADER_MACRO var; HEADER_MACRO *v = &var; if ( regexec( re, buf ) && re->startp[1] ) { OBJECT * symbol; /* we detected a line that looks like "#define MACRO filename */ ((char *)re->endp[1])[0] = '\0'; ((char *)re->endp[2])[0] = '\0'; if ( DEBUG_HEADER ) printf( "macro '%s' used to define filename '%s' in '%s'\n", re->startp[1], re->startp[2], object_str( t->boundname ) ); /* add macro definition to hash table */ if ( !header_macros_hash ) header_macros_hash = hashinit( sizeof( HEADER_MACRO ), "hdrmacros" ); v->symbol = symbol = object_new( re->startp[1] ); v->filename = 0; if ( hashenter( header_macros_hash, (HASHDATA **)&v ) ) { v->filename = object_new( re->startp[2] ); /* never freed */ } else { object_free( symbol ); } /* XXXX: FOR NOW, WE IGNORE MULTIPLE MACRO DEFINITIONS !! */ /* WE MIGHT AS WELL USE A LIST TO STORE THEM.. */ } } fclose( f ); }
LIST * hcache( TARGET * t, int rec, regexp * re[], LIST * hdrscan ) { HCACHEDATA * c; LIST * l = 0; ++queries; if ( ( c = (HCACHEDATA *)hash_find( hcachehash, t->boundname ) ) ) { if ( c->time == t->time ) { LIST *l1 = hdrscan, *l2 = c->hdrscan; LISTITER iter1 = list_begin( l1 ), end1 = list_end( l1 ), iter2 = list_begin( l2 ), end2 = list_end( l2 ); while ( iter1 != end1 && iter2 != end2 ) { if ( !object_equal( list_item( iter1 ), list_item( iter2 ) ) ) { iter1 = end1; } else { iter1 = list_next( iter1 ); iter2 = list_next( iter2 ); } } if ( iter1 != end1 || iter2 != end2 ) { if (DEBUG_HEADER) printf( "HDRSCAN out of date in cache for %s\n", object_str( t->boundname ) ); printf( "HDRSCAN out of date for %s\n", object_str( t->boundname ) ); printf(" real : "); list_print( hdrscan ); printf( "\n cached: " ); list_print( c->hdrscan ); printf( "\n" ); list_free( c->includes ); list_free( c->hdrscan ); c->includes = L0; c->hdrscan = L0; } else { if (DEBUG_HEADER) printf( "using header cache for %s\n", object_str( t->boundname ) ); c->age = 0; ++hits; l = list_copy( c->includes ); return l; } } else { if (DEBUG_HEADER) printf ("header cache out of date for %s\n", object_str( t->boundname ) ); list_free( c->includes ); list_free( c->hdrscan ); c->includes = L0; c->hdrscan = L0; } } else { int found; c = (HCACHEDATA *)hash_insert( hcachehash, t->boundname, &found ); if ( !found ) { c->boundname = object_copy( t->boundname ); c->next = hcachelist; hcachelist = c; } } /* 'c' points at the cache entry. Its out of date. */ l = headers1( L0, t->boundname, rec, re ); c->time = t->time; c->age = 0; c->includes = list_copy( l ); c->hdrscan = list_copy( hdrscan ); return l; }
static void dependGraphOutput( TARGET * t, int depth ) { TARGETS * c; if ( ( t->flags & T_FLAG_VISITED ) || !t->name || !t->boundname ) return; t->flags |= T_FLAG_VISITED; switch ( t->fate ) { case T_FATE_TOUCHED: case T_FATE_MISSING: case T_FATE_OUTDATED: case T_FATE_UPDATE: printf( "->%s%2d Name: %s\n", spaces( depth ), depth, target_name( t ) ); break; default: printf( " %s%2d Name: %s\n", spaces( depth ), depth, target_name( t ) ); break; } if ( !object_equal( t->name, t->boundname ) ) printf( " %s Loc: %s\n", spaces( depth ), object_str( t->boundname ) ); switch ( t->fate ) { case T_FATE_STABLE: printf( " %s : Stable\n", spaces( depth ) ); break; case T_FATE_NEWER: printf( " %s : Newer\n", spaces( depth ) ); break; case T_FATE_ISTMP: printf( " %s : Up to date temp file\n", spaces( depth ) ); break; case T_FATE_NEEDTMP: printf( " %s : Temporary file, to be updated\n", spaces( depth ) ); break; case T_FATE_TOUCHED: printf( " %s : Been touched, updating it\n", spaces( depth ) ); break; case T_FATE_MISSING: printf( " %s : Missing, creating it\n", spaces( depth ) ); break; case T_FATE_OUTDATED: printf( " %s : Outdated, updating it\n", spaces( depth ) ); break; case T_FATE_REBUILD: printf( " %s : Rebuild, updating it\n", spaces( depth ) ); break; case T_FATE_UPDATE: printf( " %s : Updating it\n", spaces( depth ) ); break; case T_FATE_CANTFIND: printf( " %s : Can not find it\n", spaces( depth ) ); break; case T_FATE_CANTMAKE: printf( " %s : Can make it\n", spaces( depth ) ); break; } if ( t->flags & ~T_FLAG_VISITED ) { printf( " %s : ", spaces( depth ) ); if ( t->flags & T_FLAG_TEMP ) printf( "TEMPORARY " ); if ( t->flags & T_FLAG_NOCARE ) printf( "NOCARE " ); if ( t->flags & T_FLAG_NOTFILE ) printf( "NOTFILE " ); if ( t->flags & T_FLAG_TOUCHED ) printf( "TOUCHED " ); if ( t->flags & T_FLAG_LEAVES ) printf( "LEAVES " ); if ( t->flags & T_FLAG_NOUPDATE ) printf( "NOUPDATE " ); printf( "\n" ); } for ( c = t->depends; c; c = c->next ) { printf( " %s : Depends on %s (%s)", spaces( depth ), target_name( c->target ), target_fate[ (int)c->target->fate ] ); if ( !timestamp_cmp( &c->target->time, &t->time ) ) printf( " (max time)"); printf( "\n" ); } for ( c = t->depends; c; c = c->next ) dependGraphOutput( c->target, depth + 1 ); }
int var_string( const char * in, char * out, int outsize, LOL * lol ) { char * out0 = out; char * oute = out + outsize - 1; while ( *in ) { char * lastword; int dollar = 0; /* Copy white space. */ while ( isspace( *in ) ) { if ( out >= oute ) return -1; *out++ = *in++; } lastword = out; /* Copy non-white space, watching for variables. */ while ( *in && !isspace( *in ) ) { if ( out >= oute ) return -1; if ( ( in[ 0 ] == '$' ) && ( in[ 1 ] == '(' ) ) { ++dollar; *out++ = *in++; } #ifdef OPT_AT_FILES else if ( ( in[ 0 ] == '@' ) && ( in[ 1 ] == '(' ) ) { int depth = 1; const char * ine = in + 2; const char * split = 0; /* Scan the content of the response file @() section. */ while ( *ine && ( depth > 0 ) ) { switch ( *ine ) { case '(': ++depth; break; case ')': --depth; break; case ':': if ( ( depth == 1 ) && ( ine[ 1 ] == 'E' ) && ( ine[ 2 ] == '=' ) ) split = ine; break; } ++ine; } if ( !split ) { /* the @() reference doesn't match the @(foo:E=bar) format. hence we leave it alone by copying directly to output. */ int l = 0; if ( out + 2 >= oute ) return -1; *( out++ ) = '@'; *( out++ ) = '('; l = var_string( in + 2, out, oute - out, lol ); if ( l < 0 ) return -1; out += l; if ( out + 1 >= oute ) return -1; *( out++ ) = ')'; } else if ( depth == 0 ) { string file_name_v; OBJECT * file_name = 0; int file_name_l = 0; const char * file_name_s = 0; /* Expand the temporary file name var inline. */ #if 0 string_copy( &file_name_v, "$(" ); string_append_range( &file_name_v, in + 2, split ); string_push_back( &file_name_v, ')' ); #else string_new( &file_name_v ); string_append_range( &file_name_v, in + 2, split ); #endif file_name_l = var_string( file_name_v.value, out, oute - out + 1, lol ); string_free( &file_name_v ); if ( file_name_l < 0 ) return -1; file_name_s = out; /* For stdout/stderr we will create a temp file and generate * a command that outputs the content as needed. */ if ( ( strcmp( "STDOUT", out ) == 0 ) || ( strcmp( "STDERR", out ) == 0 ) ) { int err_redir = strcmp( "STDERR", out ) == 0; out[ 0 ] = '\0'; file_name = path_tmpfile(); file_name_s = object_str(file_name); file_name_l = strlen(file_name_s); #ifdef OS_NT if ( ( out + 7 + file_name_l + ( err_redir ? 5 : 0 ) ) >= oute ) return -1; sprintf( out,"type \"%s\"%s", file_name_s, err_redir ? " 1>&2" : "" ); #else if ( ( out + 6 + file_name_l + ( err_redir ? 5 : 0 ) ) >= oute ) return -1; sprintf( out,"cat \"%s\"%s", file_name_s, err_redir ? " 1>&2" : "" ); #endif /* We also make sure that the temp files created by this * get nuked eventually. */ file_remove_atexit( file_name ); } /* Expand the file value into the file reference. */ var_string_to_file( split + 3, ine - split - 4, file_name_s, lol ); if ( file_name ) { object_free( file_name ); } /* Continue on with the expansion. */ out += strlen( out ); } /* And continue with the parsing just past the @() reference. */ in = ine; } #endif else { *out++ = *in++; } } /* Add zero to 'out' so that 'lastword' is correctly zero-terminated. */ if ( out >= oute ) return -1; /* Do not increment, intentionally. */ *out = '\0'; /* If a variable encountered, expand it and and embed the * space-separated members of the list in the output. */ if ( dollar ) { LIST * l = var_expand( L0, lastword, out, lol, 0 ); LIST * saved = l; out = lastword; while ( l ) { int so = strlen( object_str( l->value ) ); if ( out + so >= oute ) return -1; strcpy( out, object_str( l->value ) ); out += so; l = list_next( l ); if ( l ) *out++ = ' '; } list_free( saved ); } } if ( out >= oute ) return -1; *out++ = '\0'; return out - out0; }
int main( int argc, char * * argv, char * * arg_environ ) { int n; char * s; struct bjam_option optv[N_OPTS]; char const * all = "all"; int status; int arg_c = argc; char * * arg_v = argv; char const * progname = argv[0]; module_t * environ_module; saved_argv0 = argv[0]; BJAM_MEM_INIT(); # ifdef OS_MAC InitGraf(&qd.thePort); # endif --argc; ++argv; if ( getoptions( argc, argv, "-:l:d:j:p:f:gs:t:ano:qv", optv ) < 0 ) { printf( "\nusage: %s [ options ] targets...\n\n", progname ); printf( "-a Build all targets, even if they are current.\n" ); printf( "-dx Set the debug level to x (0-9).\n" ); printf( "-fx Read x instead of Jambase.\n" ); /* printf( "-g Build from newest sources first.\n" ); */ printf( "-jx Run up to x shell commands concurrently.\n" ); printf( "-lx Limit actions to x number of seconds after which they are stopped.\n" ); printf( "-n Don't actually execute the updating actions.\n" ); printf( "-ox Write the updating actions to file x.\n" ); printf( "-px x=0, pipes action stdout and stderr merged into action output.\n" ); printf( "-q Quit quickly as soon as a target fails.\n" ); printf( "-sx=y Set variable x=y, overriding environment.\n" ); printf( "-tx Rebuild x, even if it is up-to-date.\n" ); printf( "-v Print the version of jam and exit.\n" ); printf( "--x Option is ignored.\n\n" ); exit( EXITBAD ); } /* Version info. */ if ( ( s = getoptval( optv, 'v', 0 ) ) ) { printf( "Boost.Jam " ); printf( "Version %s. %s.\n", VERSION, OSMINOR ); printf( " Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. \n" ); printf( " Copyright 2001 David Turner.\n" ); printf( " Copyright 2001-2004 David Abrahams.\n" ); printf( " Copyright 2002-2008 Rene Rivera.\n" ); printf( " Copyright 2003-2008 Vladimir Prus.\n" ); return EXITOK; } /* Pick up interesting options. */ if ( ( s = getoptval( optv, 'n', 0 ) ) ) globs.noexec++, globs.debug[2] = 1; if ( ( s = getoptval( optv, 'p', 0 ) ) ) { /* Undocumented -p3 (acts like both -p1 -p2) means separate pipe action * stdout and stderr. */ globs.pipe_action = atoi( s ); if ( ( 3 < globs.pipe_action ) || ( globs.pipe_action < 0 ) ) { printf( "Invalid pipe descriptor '%d', valid values are -p[0..3].\n", globs.pipe_action ); exit( EXITBAD ); } } if ( ( s = getoptval( optv, 'q', 0 ) ) ) globs.quitquick = 1; if ( ( s = getoptval( optv, 'a', 0 ) ) ) anyhow++; if ( ( s = getoptval( optv, 'j', 0 ) ) ) { globs.jobs = atoi( s ); if (globs.jobs == 0) { printf("Invalid value for the '-j' option.\n"); exit(EXITBAD); } } if ( ( s = getoptval( optv, 'g', 0 ) ) ) globs.newestfirst = 1; if ( ( s = getoptval( optv, 'l', 0 ) ) ) globs.timeout = atoi( s ); /* Turn on/off debugging */ for ( n = 0; ( s = getoptval( optv, 'd', n ) ); ++n ) { int i; /* First -d, turn off defaults. */ if ( !n ) for ( i = 0; i < DEBUG_MAX; ++i ) globs.debug[i] = 0; i = atoi( s ); if ( ( i < 0 ) || ( i >= DEBUG_MAX ) ) { printf( "Invalid debug level '%s'.\n", s ); continue; } /* n turns on levels 1-n. */ /* +n turns on level n. */ if ( *s == '+' ) globs.debug[i] = 1; else while ( i ) globs.debug[i--] = 1; } constants_init(); { PROFILE_ENTER( MAIN ); #ifdef HAVE_PYTHON { PROFILE_ENTER( MAIN_PYTHON ); Py_Initialize(); { static PyMethodDef BjamMethods[] = { {"call", bjam_call, METH_VARARGS, "Call the specified bjam rule."}, {"import_rule", bjam_import_rule, METH_VARARGS, "Imports Python callable to bjam."}, {"define_action", bjam_define_action, METH_VARARGS, "Defines a command line action."}, {"variable", bjam_variable, METH_VARARGS, "Obtains a variable from bjam's global module."}, {"backtrace", bjam_backtrace, METH_VARARGS, "Returns bjam backtrace from the last call into Python."}, {"caller", bjam_caller, METH_VARARGS, "Returns the module from which the last call into Python is made."}, {NULL, NULL, 0, NULL} }; Py_InitModule( "bjam", BjamMethods ); } PROFILE_EXIT( MAIN_PYTHON ); } #endif #ifndef NDEBUG run_unit_tests(); #endif #if YYDEBUG != 0 if ( DEBUG_PARSE ) yydebug = 1; #endif /* Set JAMDATE. */ var_set( root_module(), constant_JAMDATE, list_new( L0, outf_time(time(0)) ), VAR_SET ); /* Set JAM_VERSION. */ var_set( root_module(), constant_JAM_VERSION, list_new( list_new( list_new( L0, object_new( VERSION_MAJOR_SYM ) ), object_new( VERSION_MINOR_SYM ) ), object_new( VERSION_PATCH_SYM ) ), VAR_SET ); /* Set JAMUNAME. */ #ifdef unix { struct utsname u; if ( uname( &u ) >= 0 ) { var_set( root_module(), constant_JAMUNAME, list_new( list_new( list_new( list_new( list_new( L0, object_new( u.sysname ) ), object_new( u.nodename ) ), object_new( u.release ) ), object_new( u.version ) ), object_new( u.machine ) ), VAR_SET ); } } #endif /* unix */ /* Load up environment variables. */ /* First into the global module, with splitting, for backward * compatibility. */ var_defines( root_module(), use_environ, 1 ); environ_module = bindmodule( constant_ENVIRON ); /* Then into .ENVIRON, without splitting. */ var_defines( environ_module, use_environ, 0 ); /* * Jam defined variables OS & OSPLAT. We load them after environment, so * that setting OS in environment does not change Jam's notion of the * current platform. */ var_defines( root_module(), othersyms, 1 ); /* Load up variables set on command line. */ for ( n = 0; ( s = getoptval( optv, 's', n ) ); ++n ) { char *symv[2]; symv[ 0 ] = s; symv[ 1 ] = 0; var_defines( root_module(), symv, 1 ); var_defines( environ_module, symv, 0 ); } /* Set the ARGV to reflect the complete list of arguments of invocation. */ for ( n = 0; n < arg_c; ++n ) { var_set( root_module(), constant_ARGV, list_new( L0, object_new( arg_v[n] ) ), VAR_APPEND ); } /* Initialize built-in rules. */ load_builtins(); /* Add the targets in the command line to the update list. */ for ( n = 1; n < arg_c; ++n ) { if ( arg_v[ n ][ 0 ] == '-' ) { char * f = "-:l:d:j:f:gs:t:ano:qv"; for ( ; *f; ++f ) if ( *f == arg_v[ n ][ 1 ] ) break; if ( ( f[ 1 ] == ':' ) && ( arg_v[ n ][ 2 ] == '\0' ) ) ++n; } else { OBJECT * target = object_new( arg_v[ n ] ); mark_target_for_updating( target ); object_free( target ); } } if (!targets_to_update()) { mark_target_for_updating( constant_all ); } /* Parse ruleset. */ { FRAME frame[ 1 ]; frame_init( frame ); for ( n = 0; ( s = getoptval( optv, 'f', n ) ); ++n ) { OBJECT * filename = object_new( s ); parse_file( filename, frame ); object_free( filename ); } if ( !n ) { parse_file( constant_plus, frame ); } } status = yyanyerrors(); /* Manually touch -t targets. */ for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) { OBJECT * target = object_new( s ); touch_target( target ); object_free( target ); } /* If an output file is specified, set globs.cmdout to that. */ if ( ( s = getoptval( optv, 'o', 0 ) ) ) { if ( !( globs.cmdout = fopen( s, "w" ) ) ) { printf( "Failed to write to '%s'\n", s ); exit( EXITBAD ); } ++globs.noexec; } /* The build system may set the PARALLELISM variable to override -j options. */ { LIST *p = L0; p = var_get ( root_module(), constant_PARALLELISM ); if ( p ) { int j = atoi( object_str( p->value ) ); if ( j == -1 ) { printf( "Invalid value of PARALLELISM: %s\n", object_str( p->value ) ); } else { globs.jobs = j; } } } /* KEEP_GOING overrides -q option. */ { LIST *p = L0; p = var_get( root_module(), constant_KEEP_GOING ); if ( p ) { int v = atoi( object_str( p->value ) ); if ( v == 0 ) globs.quitquick = 1; else globs.quitquick = 0; } } /* Now make target. */ { PROFILE_ENTER( MAIN_MAKE ); LIST * targets = targets_to_update(); if (targets) { int targets_count = list_length( targets ); OBJECT * * targets2 = (OBJECT * *) BJAM_MALLOC( targets_count * sizeof( OBJECT * ) ); int n = 0; for ( ; targets; targets = list_next( targets ) ) targets2[ n++ ] = targets->value; status |= make( targets_count, targets2, anyhow ); BJAM_FREE( (void *)targets2 ); } else { status = last_update_now_status; } PROFILE_EXIT( MAIN_MAKE ); } PROFILE_EXIT( MAIN ); } if ( DEBUG_PROFILE ) profile_dump(); #ifdef OPT_HEADER_CACHE_EXT hcache_done(); #endif clear_targets_to_update(); /* Widely scattered cleanup. */ file_done(); rules_done(); stamps_done(); search_done(); class_done(); modules_done(); regex_done(); exec_done(); pwd_done(); path_done(); function_done(); list_done(); constants_done(); object_done(); /* Close cmdout. */ if ( globs.cmdout ) fclose( globs.cmdout ); #ifdef HAVE_PYTHON Py_Finalize(); #endif BJAM_MEM_CLOSE(); return status ? EXITBAD : EXITOK; }
void var_string_to_file( const char * in, int insize, const char * out, LOL * lol ) { char const * ine = in + insize; FILE * out_file = 0; int out_debug = DEBUG_EXEC ? 1 : 0; if ( globs.noexec ) { /* out_debug = 1; */ } else if ( strcmp( out, "STDOUT" ) == 0 ) { out_file = stdout; } else if ( strcmp( out, "STDERR" ) == 0 ) { out_file = stderr; } else { /* Handle "path to file" filenames. */ string out_name; if ( ( out[ 0 ] == '"' ) && ( out[ strlen( out ) - 1 ] == '"' ) ) { string_copy( &out_name, out + 1 ); string_truncate( &out_name, out_name.size - 1 ); } else { string_copy( &out_name,out ); } out_file = fopen( out_name.value, "w" ); if ( !out_file ) { printf( "failed to write output file '%s'!\n", out_name.value ); exit( EXITBAD ); } string_free( &out_name ); } if ( out_debug ) printf( "\nfile %s\n", out ); while ( *in && ( in < ine ) ) { int dollar = 0; const char * output_0 = in; const char * output_1 = in; /* Copy white space. */ while ( ( output_1 < ine ) && isspace( *output_1 ) ) ++output_1; if ( output_0 < output_1 ) { if ( out_file ) fwrite( output_0, output_1 - output_0, 1, out_file ); if ( out_debug ) fwrite( output_0, output_1 - output_0, 1, stdout ); } output_0 = output_1; /* Copy non-white space, watching for variables. */ while ( ( output_1 < ine ) && *output_1 && !isspace( *output_1 ) ) { if ( ( output_1[ 0 ] == '$' ) && ( output_1[ 1 ] == '(' ) ) ++dollar; ++output_1; } /* If a variable encountered, expand it and embed the space-separated * members of the list in the output. */ if ( dollar ) { LIST * l = var_expand( L0, (char *)output_0, (char *)output_1, lol, 0 ); LIST * saved = l; while ( l ) { if ( out_file ) fputs( object_str( l->value ), out_file ); if ( out_debug ) puts( object_str( l->value ) ); l = list_next( l ); if ( l ) { if ( out_file ) fputc( ' ', out_file ); if ( out_debug ) fputc( ' ', stdout ); } } list_free( saved ); } else if ( output_0 < output_1 ) { if ( out_file ) { const char * output_n = output_0; while ( output_n < output_1 ) { output_n += fwrite( output_n, 1, output_1-output_n, out_file ); } } if ( out_debug ) { const char * output_n = output_0; while ( output_n < output_1 ) { output_n += fwrite( output_n, 1, output_1-output_n, stdout ); } } } in = output_1; } if ( out_file && ( out_file != stdout ) && ( out_file != stderr ) ) { fflush( out_file ); fclose( out_file ); } if ( out_debug ) fputc( '\n', stdout ); }
static void make1c_closure ( void * const closure, int status_orig, timing_info const * const time, char const * const cmd_stdout, char const * const cmd_stderr, int const cmd_exit_reason ) { TARGET * const t = (TARGET *)closure; CMD * const cmd = (CMD *)t->cmds; char const * rule_name = 0; char const * target_name = 0; assert( cmd ); --cmdsrunning; /* Calculate the target's status from the cmd execution result. */ { /* Store the target's status. */ t->status = status_orig; /* Invert OK/FAIL target status when FAIL_EXPECTED has been applied. */ if ( t->flags & T_FLAG_FAIL_EXPECTED && !globs.noexec ) { switch ( t->status ) { case EXEC_CMD_FAIL: t->status = EXEC_CMD_OK; break; case EXEC_CMD_OK: t->status = EXEC_CMD_FAIL; break; } } /* Ignore failures for actions marked as 'ignore'. */ if ( t->status == EXEC_CMD_FAIL && cmd->rule->actions->flags & RULE_IGNORE ) t->status = EXEC_CMD_OK; } if ( DEBUG_MAKEQ || ( DEBUG_MAKE && !( cmd->rule->actions->flags & RULE_QUIETLY ) ) ) { rule_name = object_str( cmd->rule->name ); target_name = object_str( list_front( lol_get( (LOL *)&cmd->args, 0 ) ) ); } out_action( rule_name, target_name, cmd->buf->value, cmd_stdout, cmd_stderr, cmd_exit_reason ); if ( !globs.noexec ) { call_timing_rule( t, time ); if ( DEBUG_EXECCMD ) printf( "%f sec system; %f sec user\n", time->system, time->user ); /* Assume -p0 is in effect, i.e. cmd_stdout contains merged output. */ call_action_rule( t, status_orig, time, cmd->buf->value, cmd_stdout ); } /* Print command text on failure. */ if ( t->status == EXEC_CMD_FAIL && DEBUG_MAKE ) { if ( !DEBUG_EXEC ) printf( "%s\n", cmd->buf->value ); printf( "...failed %s ", object_str( cmd->rule->name ) ); list_print( lol_get( (LOL *)&cmd->args, 0 ) ); printf( "...\n" ); } /* On interrupt, set quit so _everything_ fails. Do the same for failed * commands if we were asked to stop the build in case of any errors. */ if ( t->status == EXEC_CMD_INTR ) { ++intr; ++quit; } if ( t->status == EXEC_CMD_FAIL && globs.quitquick ) ++quit; /* If the command was not successful remove all of its targets not marked as * "precious". */ if ( t->status != EXEC_CMD_OK ) { LIST * const targets = lol_get( (LOL *)&cmd->args, 0 ); LISTITER iter = list_begin( targets ); LISTITER const end = list_end( targets ); for ( ; iter != end; iter = list_next( iter ) ) { char const * const filename = object_str( list_item( iter ) ); TARGET const * const t = bindtarget( list_item( iter ) ); if ( !( t->flags & T_FLAG_PRECIOUS ) && !unlink( filename ) ) printf( "...removing %s\n", filename ); } } #ifdef OPT_SEMAPHORE /* Release any semaphores used by this action. */ cmd_sem_unlock( t ); #endif /* Free this command and push the MAKE1C state to execute the next one * scheduled for building this same target. */ t->cmds = NULL; push_cmds( cmd->next, t->status ); cmd_free( cmd ); }
OBJECT * search( OBJECT * target, time_t *time, OBJECT * * another_target, int file ) { PATHNAME f[1]; LIST * varlist; string buf[1]; int found = 0; /* Will be set to 1 if target location is specified via LOCATE. */ int explicitly_located = 0; OBJECT * boundname = 0; OBJECT * varname; if ( another_target ) *another_target = 0; if (! explicit_bindings ) explicit_bindings = hashinit( sizeof(BINDING), "explicitly specified locations"); string_new( buf ); /* Parse the filename */ path_parse( object_str( target ), f ); f->f_grist.ptr = 0; f->f_grist.len = 0; varname = object_new( "LOCATE" ); varlist = var_get( varname ); object_free( varname ); if ( varlist ) { OBJECT * key; f->f_root.ptr = object_str( varlist->value ); f->f_root.len = strlen( object_str( varlist->value ) ); path_build( f, buf, 1 ); if ( DEBUG_SEARCH ) printf( "locate %s: %s\n", object_str( target ), buf->value ); explicitly_located = 1; key = object_new( buf->value ); timestamp( key, time ); object_free( key ); found = 1; } else if ( ( varname = object_new( "SEARCH" ), varlist = var_get( varname ), object_free( varname ), varlist ) ) { while ( varlist ) { BINDING b, *ba = &b; file_info_t *ff; OBJECT * key; f->f_root.ptr = object_str( varlist->value ); f->f_root.len = strlen( object_str( varlist->value ) ); string_truncate( buf, 0 ); path_build( f, buf, 1 ); if ( DEBUG_SEARCH ) printf( "search %s: %s\n", object_str( target ), buf->value ); key = object_new( buf->value ); ff = file_query( key ); timestamp( key, time ); b.binding = key; if ( hashcheck( explicit_bindings, (HASHDATA**)&ba ) ) { if ( DEBUG_SEARCH ) printf(" search %s: found explicitly located target %s\n", object_str( target ), object_str( ba->target ) ); if ( another_target ) *another_target = ba->target; found = 1; object_free( key ); break; } else if ( ff && ff->time ) { if ( !file || ff->is_file ) { found = 1; object_free( key ); break; } } object_free( key ); varlist = list_next( varlist ); } } if ( !found ) { /* Look for the obvious */ /* This is a questionable move. Should we look in the */ /* obvious place if SEARCH is set? */ OBJECT * key; f->f_root.ptr = 0; f->f_root.len = 0; string_truncate( buf, 0 ); path_build( f, buf, 1 ); if ( DEBUG_SEARCH ) printf( "search %s: %s\n", object_str( target ), buf->value ); key = object_new( buf->value ); timestamp( key, time ); object_free( key ); } boundname = object_new( buf->value ); string_free( buf ); if ( explicitly_located ) { BINDING b; BINDING * ba = &b; b.binding = boundname; b.target = target; /* CONSIDER: we probably should issue a warning is another file is explicitly bound to the same location. This might break compatibility, though. */ if ( hashenter( explicit_bindings, (HASHDATA * *)&ba ) ) { ba->binding = object_copy( boundname ); } } /* prepare a call to BINDRULE if the variable is set */ call_bind_rule( target, boundname ); return boundname; }