/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ /* * rules.c - access to RULEs, TARGETs, and ACTIONs * * External routines: * * bindrule() - return pointer to RULE, creating it if necessary * bindtarget() - return pointer to TARGET, creating it if necessary * copytarget() - make a new target with the old target's name * touchtarget() - mark a target to simulate being new * targetlist() - turn list of target names into a TARGET chain * targetentry() - add a TARGET to a chain of TARGETS * targetchain() - append two TARGET chains * actionlist() - append to an ACTION chain * addsettings() - add a deferred "set" command to a target * copysettings() - copy a settings list for temp use * pushsettings() - set all target specific variables * popsettings() - reset target specific variables to their pre-push values * freesettings() - delete a settings list * donerules() - free RULE and TARGET tables * * 04/12/94 (seiwald) - actionlist() now just appends a single action. * 08/23/94 (seiwald) - Support for '+=' (append to variable) * 06/21/02 (seiwald) - support for named parameters * 11/04/02 (seiwald) - const-ing for string literals * 12/03/02 (seiwald) - fix odd includes support by grafting them onto depends * 12/17/02 (seiwald) - new copysettings() to protect target-specific vars * 01/14/03 (seiwald) - fix includes fix with new internal includes TARGET */ # include "jam.h" # include "lists.h" # include "parse.h" # include "variable.h" # include "rules.h" # include "newstr.h" # include "hash.h" static struct hash *rulehash = 0; static struct hash *targethash = 0; /* * bindrule() - return pointer to RULE, creating it if necessary */ RULE * bindrule( const char *rulename ) { RULE rule, *r = &rule; if( !rulehash ) rulehash = hashinit( sizeof( RULE ), "rules" ); r->name = rulename; if( hashenter( rulehash, (HASHDATA **)&r ) ) { r->name = newstr( rulename ); /* never freed */ r->procedure = (PARSE *)0; r->actions = (char *)0; r->bindlist = L0; r->params = L0; r->flags = 0; } return r; } /* * bindtarget() - return pointer to TARGET, creating it if necessary */ TARGET * bindtarget( const char *targetname ) { TARGET target, *t = ⌖ if( !targethash ) targethash = hashinit( sizeof( TARGET ), "targets" ); t->name = targetname; if( hashenter( targethash, (HASHDATA **)&t ) ) { memset( (char *)t, '\0', sizeof( *t ) ); t->name = newstr( targetname ); /* never freed */ t->boundname = t->name; /* default for T_FLAG_NOTFILE */ } return t; } /* * copytarget() - make a new target with the old target's name * * Not entered into hash table -- for internal nodes. */ TARGET * copytarget( const TARGET *ot ) { TARGET *t; t = (TARGET *)malloc( sizeof( *t ) ); memset( (char *)t, '\0', sizeof( *t ) ); t->name = copystr( ot->name ); t->boundname = t->name; t->flags |= T_FLAG_NOTFILE | T_FLAG_INTERNAL; return t; } /* * touchtarget() - mark a target to simulate being new */ void touchtarget( const char *t ) { bindtarget( t )->flags |= T_FLAG_TOUCHED; } /* * targetlist() - turn list of target names into a TARGET chain * * Inputs: * chain existing TARGETS to append to * targets list of target names */ TARGETS * targetlist( TARGETS *chain, LIST *targets ) { for( ; targets; targets = list_next( targets ) ) chain = targetentry( chain, bindtarget( targets->string ) ); return chain; } /* * targetentry() - add a TARGET to a chain of TARGETS * * Inputs: * chain exisitng TARGETS to append to * target new target to append */ TARGETS * targetentry( TARGETS *chain, TARGET *target ) { TARGETS *c; c = (TARGETS *)malloc( sizeof( TARGETS ) ); c->target = target; if( !chain ) chain = c; else chain->tail->next = c; chain->tail = c; c->next = 0; return chain; } /* * targetchain() - append two TARGET chains * * Inputs: * chain exisitng TARGETS to append to * target new target to append */ TARGETS * targetchain( TARGETS *chain, TARGETS *targets ) { TARGETS *c; if( !targets ) return chain; else if( !chain ) return targets; chain->tail->next = targets; chain->tail = targets->tail; return chain; } /* * actionlist() - append to an ACTION chain */ ACTIONS * actionlist( ACTIONS *chain, ACTION *action ) { ACTIONS *actions = (ACTIONS *)malloc( sizeof( ACTIONS ) ); actions->action = action; if( !chain ) chain = actions; else chain->tail->next = actions; chain->tail = actions; actions->next = 0; return chain; } /* * addsettings() - add a deferred "set" command to a target * * Adds a variable setting (varname=list) onto a chain of settings * for a particular target. Replaces the previous previous value, * if any, unless 'append' says to append the new list onto the old. * Returns the head of the chain of settings. */ SETTINGS * addsettings( SETTINGS *head, int setflag, const char *symbol, LIST *value ) { SETTINGS *v; /* Look for previous setting */ for( v = head; v; v = v->next ) if( !strcmp( v->symbol, symbol ) ) break; /* If not previously set, alloc a new. */ /* If appending, do so. */ /* Else free old and set new. */ if( !v ) { v = (SETTINGS *)malloc( sizeof( *v ) ); v->symbol = newstr( symbol ); v->value = value; v->next = head; head = v; } else switch( setflag ) { case VAR_SET: /* Toss old, set new */ list_free( v->value ); v->value = value; break; case VAR_APPEND: /* Append new to old */ v->value = list_append( v->value, value ); break; case VAR_DEFAULT: /* Toss new, old already set */ list_free( value ); break; } /* Return (new) head of list. */ return head; } /* * copysettings() - copy a settings list for temp use * * When target-specific variables are pushed into place with pushsettings(), * any global variables with the same name are swapped onto the target's * SETTINGS chain. If that chain gets modified (by using the "on target" * syntax), popsettings() would wrongly swap those modified values back * as the new global values. * * copysettings() protects the target's SETTINGS chain by providing a * copy of the chain to pass to pushsettings() and popsettings(), so that * the target's original SETTINGS chain can be modified using the usual * "on target" syntax. */ SETTINGS * copysettings( SETTINGS *from ) { SETTINGS *head = 0, *v; for( ; from; from = from->next ) { SETTINGS *v = (SETTINGS *)malloc( sizeof( *v ) ); v->symbol = copystr( from->symbol ); v->value = list_copy( 0, from->value ); v->next = head; head = v; } return head; } /* * pushsettings() - set all target specific variables */ void pushsettings( SETTINGS *v ) { for( ; v; v = v->next ) v->value = var_swap( v->symbol, v->value ); } /* * popsettings() - reset target specific variables to their pre-push values */ void popsettings( SETTINGS *v ) { pushsettings( v ); /* just swap again */ } /* * freesettings() - delete a settings list */ void freesettings( SETTINGS *v ) { while( v ) { SETTINGS *n = v->next; freestr( v->symbol ); list_free( v->value ); free( (char *)v ); v = n; } } /* * donerules() - free RULE and TARGET tables */ void donerules() { hashdone( rulehash ); hashdone( targethash ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 9713 | Ben_Key |
Branching //public/jam/... to //guest/Ben_Key/jam/trunk/... |
||
//guest/perforce_software/jam/src/rules.c | |||||
#9 | 2614 | rmg |
Fix to includes of includes not being considered, broken by 2499. Details taken from email to jamming: The challenge is to make included includes appear as direct includes, so that they get considered. This used to work by recursion, because each TARGET node computed the summary of its includes -- the hfate and htime -- along with the summary of its dependents -- the fate and time. Alas, that previous arrangement confused make1() into treating headers as direct dependencies during the build phase. A.o | A.c -- A.h (Read depends down, includes across) (Failed build of A.h aborts build of A.c) The fix to the confused make1() problem was to consolidate the special handling of includes by having make0() tack onto a target's list of dependendies any of the target's dependents' includes. Unfortunately, this fix did not recurse: if the target's dependents' includes included other files, those files were not added to the target's dependencies. A.o | A.c -- A.h -- B.h -- C.h is rewritten to: A.o | \ A.c A.h -- B.h -- C.h (A.o depends on A.h, but not B.h or C.h. This is the current, broken state of jam 2.5rc1.) Matt's bugfix added some recursion at this point, by transitively appending includes' includes onto the includes chain. But, as he found out (and I did before), this can slow make0() down considerably, as typically header files all include each other and you wind up with lots of really long chains. A.o | A.c -- A.h -- B.h -- C.h is rewritten to: A.o | A.c -- A.h -- B.h -- C.h - B.h - C.h - C.h (Matt's fix: if the .h files include each other, the includes chains get very long.) The final(?) fix I have is relatively simple, but is an extra step: to have make0() replace a target's includes chain with a single pseudo-target whose dependencies are the original target's includes. That pseudo-target gets passed to make0(), which then recursively consolidates its fate and time. This then makes a target's includes fate and time available in a single target hanging off the original target. A.o | A.c -- A.h -- B.h -- C.h is rewritten to: A.o | \ A.c A.c-includes | \ A.h A.h-includes | \ B.h B.h-includes | C.h (New pseudo-target xxx-includes recursively consolidates fate and time of all included targets.) While this new scheme does add a node for every include file, it is linear, rather than exponential, and the time is pretty much neglible. User-visible bugfix not documented, because there is no place in RELNOTES for release-candidate fixes. Bumped patchlevel to 2.5rc2. |
||
#8 | 2559 | rmg |
Fix 'var on target ?= value' so that var is only set if it did not have a target-specific value. Previously, it would just overwrite the var's value. Bug fix documented in RELNOTES. === computer:1666: Change 39566 by seiwald@play-seiwald on 2002/12/27 14:44:01 |
||
#7 | 2529 | rmg |
Fix "on target" variables during header scan, from Matt Armstrong. Setting target-specific variables while under the influence of the target's target-specific variables caused the _global_ values to be modified. This happened both during header file scanning and with the "on target statement" syntax. The manifestation of this was if a file #included itself, HdrRule would accidentally set HDRRULE/HDRSCAN globally, and then all files (executables, etc) would get scanned for includes. While this borrows from Matt's fix, it is a slightly different implementation. User visible fix documented in RELNOTES. === computer:1666: Change 39095 by seiwald@play-seiwald on 2002/12/17 14:00:58 |
||
#6 | 2499 | rmg |
Fix 'includes' support so that included files aren't treated as direct dependencies during the command execution phase. If an included file failed to build, make1() would bypass the including file. Now make0() appends each child's 'includes' onto its own 'depends' list, eliminating 'includes'-specific code in make0() and make1(). This not only fixes the bug, but removes some complexity as well. Bug fix documented in RELNOTES. === computer:1666: Change 38399 by seiwald@play-seiwald on 2002/12/03 16:00:40 |
||
#5 | 2493 | rmg |
Rewrite the past: update all jam's source with comments to reflect changes since about 2.3, very early 2001. Whitespace only change. === computer:1666: Change 37660 by seiwald@play-seiwald on 2002/11/06 22:41:35 Note: I regenerated jamgram.c on my linux 7.3 system prior to the submit, since patch was so unhappy trying to lay down the changes from Christopher's change. Presumably this is just due to different yacc/bison/whatever particulars on the system where Christopher made the changes originally. - rmg |
||
#4 | 2491 | rmg |
Some consting in jam to make it more compilable by C++ compilers. No functional change. === computer:1666: Change 37433 by perforce@perforce on 2002/10/30 16:08:51 Recreational const-ing of jam, for compilers that don't allow "string" to be passed as a non-const char *. This included a few places where we were modifying what could possibly have been read-only storage, oddly enough. No functional change. === computer:1666: Change 37602 by seiwald@play-seiwald on 2002/11/04 17:25:40 |
||
#3 | 2482 | rmg |
Jam.html partial rewrite and the support for named parameters to rules. === computer:1666: Change 34516 by seiwald@play-seiwald on 2002/06/21 23:59:12 |
||
#2 | 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. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |