/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ /* * make.c - bring a target up to date, once rules are in place * * This modules controls the execution of rules to bring a target and * its dependencies up to date. It is invoked after the targets, rules, * et. al. described in rules.h are created by the interpreting of the * jam files. * * This file contains the main make() entry point and the first pass * make0(). The second pass, make1(), which actually does the command * execution, is in make1.c. * * External routines: * make() - make a target, given its name * * Internal routines: * make0() - bind and scan everything to make a TARGET * * 12/26/93 (seiwald) - allow NOTIME targets to be expanded via $(<), $(>) * 01/04/94 (seiwald) - print all targets, bounded, when tracing commands * 04/08/94 (seiwald) - progress report now reflects only targets with actions * 04/11/94 (seiwald) - Combined deps & headers into deps[2] in TARGET. * 12/20/94 (seiwald) - NOTIME renamed NOTFILE. * 12/20/94 (seiwald) - make0() headers after determining fate of target, so * that headers aren't seen as dependents on themselves. * 01/19/95 (seiwald) - distinguish between CANTFIND/CANTMAKE targets. * 02/02/95 (seiwald) - propagate leaf source time for new LEAVES rule. * 02/14/95 (seiwald) - NOUPDATE rule means don't update existing target. * 08/22/95 (seiwald) - NOUPDATE targets immune to anyhow (-a) flag. * 09/06/00 (seiwald) - NOCARE affects targets with sources/actions. * 03/02/01 (seiwald) - reverse NOCARE change. */ # include "jam.h" # include "lists.h" # include "parse.h" # include "variable.h" # include "rules.h" # include "search.h" # include "newstr.h" # include "make.h" # include "headers.h" # include "command.h" # ifndef max # define max( a,b ) ((a)>(b)?(a):(b)) # endif typedef struct { int temp; int updating; int cantfind; int cantmake; int targets; int made; } COUNTS ; static void make0( TARGET *t, int pbinding, time_t ptime, int depth, COUNTS *counts, int anyhow ); #ifdef OPT_BUILTIN_IFUSED_EXT static void makeifused0( TARGET *t, int depth ); static void makeifused( TARGET *t, int depth ); #endif #ifdef OPT_GRAPH_DEBUG_EXT static void dependGraphOutput( TARGET *t, int depth ); #endif static char *target_fate[] = { "init", /* T_FATE_INIT */ "making", /* T_FATE_MAKING */ "stable", /* T_FATE_STABLE */ "newer", /* T_FATE_NEWER */ "temp", /* T_FATE_ISTMP */ "touched", /* T_FATE_TOUCHED */ "missing", /* T_FATE_MISSING */ "old", /* T_FATE_OUTDATED */ "update", /* T_FATE_UPDATE */ "nofind", /* T_FATE_CANTFIND */ "nomake" /* T_FATE_CANTMAKE */ } ; static char *target_bind[] = { "unbound", "missing", "parents", "exists", } ; # define spaces(x) ( " " + 16 - ( x > 16 ? 16 : x ) ) /* * make() - make a target, given its name */ int make( int n_targets, char **targets, int anyhow ) { int i; COUNTS counts[1]; int status = 0; /* 1 if anything fails */ #ifdef OPT_HEADER_CACHE_EXT hcache_init(); #endif memset( (char *)counts, 0, sizeof( *counts ) ); for( i = 0; i < n_targets; i++ ) { TARGET *t = bindtarget( targets[i] ); make0( t, T_BIND_UNBOUND, (time_t)0, 0, counts, anyhow ); } #ifdef OPT_GRAPH_DEBUG_EXT if( DEBUG_GRAPH ) { for( i = 0; i < n_targets; i++ ) { TARGET *t = bindtarget( targets[i] ); dependGraphOutput( t, 0 ); } } #endif if( DEBUG_MAKE ) { if( counts->targets ) printf( "...found %d target(s)...\n", counts->targets ); if( counts->temp ) printf( "...using %d temp target(s)...\n", counts->temp ); if( counts->updating ) printf( "...updating %d target(s)...\n", counts->updating ); if( counts->cantfind ) printf( "...can't find %d target(s)...\n", counts->cantfind ); if( counts->cantmake ) printf( "...can't make %d target(s)...\n", counts->cantmake ); } #ifdef OPT_HEADER_CACHE_EXT hcache_done(); #endif status = counts->cantfind || counts->cantmake; for( i = 0; i < n_targets; i++ ) status |= make1( bindtarget( targets[i] ) ); return status; } #ifdef OPT_BUILTIN_IFUSED_EXT /* * makeifused0() - checks if this target is not being built but marked * ifused and if so, touches the target so it does * get built. */ static void makeifused0( TARGET *t, int depth ) { TARGETS *c; int i; /* * Step 1: don't bother if we are already being processed */ if (t->fate <= T_FATE_MAKING) return; /* * Step 2: don't bother if we're already being built */ if (t->fate >= T_FATE_SPOIL) return; /* * Step 3: don't bother if we're not ifused */ if ( !(t->flags & T_FLAG_IFUSED) ) return; /* * Step 4: say change our fate to "touched" */ #ifdef OPT_GRAPH_DEBUG_EXT if (DEBUG_FATE) printf("fate change %s from %s to %s by ifused touch\n", t->name, target_fate[t->fate], target_fate[T_FATE_TOUCHED]); #endif t->fate = T_FATE_TOUCHED; /* * Step 5: check our dependents for laziness. */ for (i = T_DEPS_DEPENDS; i <= T_DEPS_INCLUDES; i++) for (c = t->deps[i]; c; c = c->next) makeifused0(c->target, depth + 1); } /* * makeifused() - make the dependents of this target lazily * * makeifused() checks if this target is being built and if so * changes the fate of any ifused dependents so that they * are built as well. */ static void makeifused( TARGET *t, int depth ) { TARGETS *c; int i; /* * Step 1: don't bother if we're not being rebuilt */ if (t->fate < T_FATE_SPOIL) return; /* * Step 2: check our dependents for lazines. */ for (i = T_DEPS_DEPENDS; i <= T_DEPS_INCLUDES; i++) for (c = t->deps[i]; c; c = c->next) makeifused0(c->target, depth); } #endif /* * make0() - bind and scan everything to make a TARGET * * Make0() recursively binds a target, searches for #included headers, * calls itself on those headers, and calls itself on any dependents. */ static void make0( TARGET *t, int pbinding, /* parent target's binding */ time_t ptime, /* parent target's timestamp */ int depth, /* for display purposes */ COUNTS *counts, /* for reporting */ int anyhow ) /* forcibly touch all (real) targets */ { TARGETS *c; int fate, hfate; time_t last, leaf, hlast, hleaf; char *flag = ""; #ifdef OPT_FIX_TARGET_VARIABLES_EXT SETTINGS *saved; #endif #ifdef OPT_GRAPH_DEBUG_EXT int savedFate, oldTimeStamp; #endif if( DEBUG_MAKEPROG ) printf( "make\t--\t%s%s\n", spaces( depth ), t->name ); /* * Step 1: don't remake if already trying or tried */ switch( t->fate ) { case T_FATE_MAKING: printf( "warning: %s depends on itself\n", t->name ); return; default: return; case T_FATE_INIT: break; } t->fate = T_FATE_MAKING; /* * Step 2: under the influence of "on target" variables, * bind the target and search for headers. */ /* Step 2a: set "on target" variables. */ #ifdef OPT_FIX_TARGET_VARIABLES_EXT /* we must make a copy of the target's settings before pushing since calling the target's HDRRULE can change these settings. */ saved = copysettings( t->settings ); pushsettings( saved ); #else pushsettings( t->settings ); #endif /* Step 2b: find and timestamp the target file (if it's a file). */ if( t->binding == T_BIND_UNBOUND && !( t->flags & T_FLAG_NOTFILE ) ) { t->boundname = search( t->name, &t->time ); t->binding = t->time ? T_BIND_EXISTS : T_BIND_MISSING; } /* If temp file doesn't exist, use parent */ if( t->binding == T_BIND_MISSING && t->flags & T_FLAG_TEMP && ptime ) { t->time = ptime; t->binding = t->time ? T_BIND_PARENTS : T_BIND_MISSING; } /* Step 2c: If its a file, search for headers. */ if( t->binding == T_BIND_EXISTS ) headers( t ); /* Step 2d: reset "on target" variables */ #ifdef OPT_FIX_TARGET_VARIABLES_EXT popsettings( saved ); freesettings( saved ); #else popsettings( t->settings ); #endif /* * Pause for a little progress reporting */ if( DEBUG_BIND ) { if( strcmp( t->name, t->boundname ) ) { printf( "bind\t--\t%s%s: %s\n", spaces( depth ), t->name, 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 ), t->name, target_bind[ t->binding ] ); break; case T_BIND_EXISTS: printf( "time\t--\t%s%s: %s", spaces( depth ), t->name, ctime( &t->time ) ); break; } } /* * Step 3: recursively make0() dependents */ last = 0; leaf = 0; fate = T_FATE_STABLE; for( c = t->deps[ T_DEPS_DEPENDS ]; c; c = c->next ) { make0( c->target, t->binding, t->time, depth + 1, counts, anyhow ); leaf = max( leaf, c->target->leaf ); leaf = max( leaf, c->target->hleaf ); /* If LEAVES has been applied, we only heed the timestamps of */ /* the leaf source nodes. */ if( t->flags & T_FLAG_LEAVES ) { last = leaf; continue; } last = max( last, c->target->time ); last = max( last, c->target->htime ); #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", t->name, target_fate[fate], target_fate[c->target->fate], c->target->name); #endif fate = max( fate, c->target->fate ); #ifdef OPT_GRAPH_DEBUG_EXT if( DEBUG_FATE ) if( fate < c->target->hfate ) printf( "fate change %s from %s to %s by headers in %s\n", t->name, target_fate[fate], target_fate[c->target->hfate], c->target->name); #endif fate = max( fate, c->target->hfate ); } /* If a NOUPDATE file exists, make dependents eternally old. */ 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", t->name); #endif last = 0; t->time = 0; /* * Don't inherit our fate from our dependents. Decide fate * based only upon other flags and our binding (done later). */ fate = T_FATE_STABLE; } /* Step 3b: determine fate: rebuild target or what? */ /* In English: If can't find or make child, can't make target. If children changed, make target. If target missing, make it. If children newer, make target. If temp's children newer, make temp. If deliberately touched, make it. If up-to-date temp file present, use it. If target exists but parent not, mark target newer. If target newer than parent, mark target newer. Don't propagate child's "newer" status. */ #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 && last > t->time ) { #ifdef OPT_GRAPH_DEBUG_EXT oldTimeStamp = 1; #endif fate = T_FATE_OUTDATED; } else if( t->binding == T_BIND_PARENTS && last > t->time ) { #ifdef OPT_GRAPH_DEBUG_EXT oldTimeStamp = 1; #endif fate = T_FATE_OUTDATED; } 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 && pbinding == T_BIND_MISSING ) { #ifdef OPT_GRAPH_DEBUG_EXT oldTimeStamp = 1; #endif fate = T_FATE_NEWER; } else if( t->binding == T_BIND_EXISTS && ptime && t->time > ptime ) { fate = T_FATE_NEWER; } else if( fate == T_FATE_NEWER ) { 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", t->name, target_fate[fate], oldTimeStamp ? " (by timestamp)" : "" ); else printf( "fate change %s adjusted from %s to %s%s\n", t->name, target_fate[savedFate], target_fate[fate], oldTimeStamp ? " (by timestamp)" : "" ); #endif /* Step 3c: handle missing files */ /* If it's missing and there are no actions to create it, boom. */ /* If we can't make a target we don't care about, 'sokay */ /* We could insist that there are updating actions for all missing */ /* files, but if they have dependents we just pretend it's NOTFILE. */ if( fate == T_FATE_MISSING && !t->actions && !t->deps[ T_DEPS_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 dependents and don't care\n", t->name, target_fate[fate]); #endif fate = T_FATE_STABLE; } else { printf( "don't know how to make %s\n", t->name ); fate = T_FATE_CANTFIND; } } /* Step 3d: propagate dependents' time & fate. */ /* Set leaf time to be our time only if this is a leaf. */ t->time = max( t->time, last ); t->leaf = leaf ? leaf : t->time ; t->fate = fate; /* * Step 4: Recursively make0() headers. */ /* Step 4a: recursively make0() headers */ hlast = 0; hleaf = 0; hfate = T_FATE_STABLE; for( c = t->deps[ T_DEPS_INCLUDES ]; c; c = c->next ) { make0( c->target, pbinding, ptime, depth + 1, counts, anyhow ); hlast = max( hlast, c->target->time ); hlast = max( hlast, c->target->htime ); hleaf = max( hleaf, c->target->leaf ); hleaf = max( hleaf, c->target->hleaf ); #ifdef OPT_GRAPH_DEBUG_EXT if( DEBUG_FATE ) if( hfate < c->target->fate ) printf( "hfate change %s from %s to %s by " "dependency %s\n", t->name, target_fate[hfate], target_fate[c->target->fate], c->target->name); #endif hfate = max( hfate, c->target->fate ); #ifdef OPT_GRAPH_DEBUG_EXT if( DEBUG_FATE ) if( hfate < c->target->hfate ) printf( "hfate change %s from %s to %s by " "headers in %s\n", t->name, target_fate[hfate], target_fate[c->target->hfate], c->target->name); #endif hfate = max( hfate, c->target->hfate ); } /* Step 4b: propagate dependents' time & fate. */ t->htime = hlast; t->hleaf = hleaf ? hleaf : t->htime; t->hfate = hfate; #ifdef OPT_BUILTIN_IFUSED_EXT /* Step 4c: if we're being rebuilt, rebuild any of our ifused dependents. */ makeifused( t, depth ); #endif /* * Step 5: a little harmless tabulating for tracing purposes */ #ifdef OPT_IMPROVED_PATIENCE_EXT ++counts->targets; #else if( !( ++counts->targets % 1000 ) && DEBUG_MAKE ) printf( "...patience...\n" ); #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 && ptime && t->time > ptime ) flag = "*"; if( DEBUG_MAKEPROG ) printf( "made%s\t%s\t%s%s\n", flag, target_fate[ t->fate ], spaces( depth ), t->name ); } #ifdef OPT_GRAPH_DEBUG_EXT /* * dependGraphOutput() - output the DG after make0 has run */ static void dependGraphOutput( TARGET *t, int depth ) { TARGETS *c; if ( (t->flags & T_FLAG_VISITED) != 0 || !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, t->name ); break; default: printf( " %s%2d Name: %s\n", spaces(depth), depth, t->name ); break; } if( strcmp (t->name, t->boundname) ) { printf( " %s Loc: %s\n", spaces(depth), 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_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_UPDATE: printf( " %s : Updating it\n", spaces(depth) ); break; case T_FATE_CANTFIND: printf( " %s : Can't find it\n", spaces(depth) ); break; case T_FATE_CANTMAKE: printf( " %s : Can't 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->deps[ T_DEPS_DEPENDS ]; c; c = c->next ) { printf( " %s : Depends on %s (%s)\n", spaces(depth), c->target->name, target_fate[ c->target->fate ] ); } for( c = t->deps[ T_DEPS_INCLUDES ]; c; c = c->next ) { printf( " %s : Includes %s (%s)\n", spaces(depth), c->target->name, target_fate[ c->target->fate ] ); } for( c = t->deps[ T_DEPS_DEPENDS ]; c; c = c->next ) { dependGraphOutput( c->target, depth + 1 ); } for( c = t->deps[ T_DEPS_INCLUDES ]; c; c = c->next ) { dependGraphOutput( c->target, depth + 1 ); } } #endif
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#20 | 4632 | Matt Armstrong | An OPT_SEMAPHORE feature stolen from Craig McPheeters. | ||
#19 | 4336 | Matt Armstrong |
Fix bug for strange make.c and RULE_UPDATED interaction. If you have a rule with flag RULE_UPDATED, then any dependents must have fate greater than T_FATE_STABLE to be included. However, make.c can get confused for dependency trees like this: a --> b --> d \-> c --> d In this case, make.c can set the fate of "d" before it ever gets to "c". So you will end up with a T_FATE_MISSING target "c" with dependents with T_FATE_STABLE. If "c" happens to have a RULE_UPDATED action, RULE_UPDATED, make1list() will refrain from including it in the list of targets. We hack around this here by explicitly checking for this case and manually tweaking the dependents fate to at least T_FATE_NEWER. An alternate fix is to modify make1cmds() to take a TARGET* instead of an ACTIONS* and, when the target is T_FATE_MISSING, have it mask off the RULE_UPDATED flag when calling make1list(). |
||
#18 | 4045 | Matt Armstrong |
patchlevel a.t - take the public perfoce depot's change 4044. Change 4044 by matt_armstrong@matt_armstrong-jrukman-jam on 2003/12/23 17:03:13 Fix //guest/matt_armstrong/jam/bug/3/... (as well as 2/... and 1/...). Introduce a pass *before* make0() that propagates INCLUDES relationships fully thruout the dependency graph. bug/3 was caused by make0 trying to do too much at once. You can't properly deal with cycles in the INCLUDES graph and correctly determine dependencies in one pass. We now have three passes through the dependency graph in make.c 1) make0bscan() - bind and scan all targets in the tree 2) make0includes() - gather all INCLUDES from sub-INCLUDES in a way that is safe from cycles in the INCLUDES graph. 3) make0() - fate determination TODO: verify correct bindtarget() use in make0bscan() and make0includes() Affected files ... ... //guest/matt_armstrong/jam/fix/2/make.c#7 edit ... //guest/matt_armstrong/jam/fix/2/rules.h#6 edit |
||
#17 | 4018 | Matt Armstrong |
Take //guest/matt_armstrong/jam/fix/2/... changes (again). |
||
#16 | 4004 | Matt Armstrong |
Back out changes 3969, 3971, 3972 -- they didn't really fix anything. |
||
#15 | 3972 | Matt Armstrong |
bootstrap integrations from //guest/matt_armstrong/jam/fix/2/... (no code change) |
||
#14 | 3971 | Matt Armstrong |
Take //guest/matt_armstrong/jam/fix/2/... changes. |
||
#13 | 3969 | Matt Armstrong |
Integrate from //guest/matt_armstrong/jam/fix/2/...@3963 -- no real changes. |
||
#12 | 3950 | Matt Armstrong |
Integrate from //guest/matt_armstrong/jam/fix/1/... thru change 3948 and make no changes. |
||
#11 | 3661 | Matt Armstrong | improve progress indication | ||
#10 | 3516 | Matt Armstrong |
Steal OPT_INTERRUPT_FIX and re-steal OPT_GRAPH_DEBUG_EXT from Craig. |
||
#9 | 3323 | Matt Armstrong |
Attempt to fix the -g bug's interaction with the "first" pseudotarget by not sorting the children of NOTFILE targets. |
||
#8 | 3311 | Matt Armstrong | Update from mainline. | ||
#7 | 2860 | Matt Armstrong | Integrate from mainline. | ||
#6 | 2817 | Matt Armstrong | Update with current known working version. | ||
#5 | 2816 | Matt Armstrong |
Integrate from mainline. This does not compile. |
||
#4 | 2507 | Matt Armstrong | update from the mainline | ||
#3 | 2089 | Matt Armstrong | More integrations from upstream. | ||
#2 | 1271 | Matt Armstrong |
This is "my" custom version of Jam. See the LOCAL_DIFFERENCES.txt file for a description of differences from the upstream jam. |
||
#1 | 1270 | Matt Armstrong | In prep for publishing all my patches to jam. | ||
//guest/perforce_software/jam/src/make.c | |||||
#4 | 556 | Perforce staff |
Patch release jam 2.3.2: reverse NOCARE change. NOCARE once again applies to targets with source and/or actions, so that buildable header files get built. |
||
#3 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#2 | 214 | Perforce staff |
Peter Glasscock's NOUPDATE fix, so that a missing dependency doesn't force the update of a NOUPDATE target. NOUPDATE targets should only be updated if they don't exist. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |