Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/src/history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
-- _zyk2507_
* Fix testing of JAM_SEMAPHORE.
-- _Paolo Pastori_
* Fix HDRRULE builtin rule to work in modules loaded by build system.
Added searching-only interfaces to modules and targets.
-- _Paolo Pastori_

== Version 5.4.2

Expand Down
8 changes: 1 addition & 7 deletions src/build/scanner.jam
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ rule propagate ( scanner : targets * : including-target )
{
HDRSCAN on $(targets) = [ on $(including-target) return $(HDRSCAN) ] ;
SCANNER on $(targets) = $(scanner) ;
HDRRULE on $(targets) = scanner.hdrrule ;
HDRRULE on $(targets) = hdrrule ;
HDRGRIST on $(targets) = [ on $(including-target) return $(HDRGRIST) ] ;
}

Expand All @@ -155,9 +155,3 @@ rule hdrrule ( target : matches * : binding )
local scanner = [ on $(target) return $(SCANNER) ] ;
$(scanner).process $(target) : $(matches) : $(binding) ;
}


# hdrrule must be available at global scope so it can be invoked by header
# scanning.
#
IMPORT scanner : hdrrule : : scanner.hdrrule ;
8 changes: 5 additions & 3 deletions src/engine/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,10 +1375,12 @@ void print_source_line( FRAME * frame )
char const * file;
int line;
get_source_line( frame, &file, &line );
if ( line < 0 )
out_printf( "(builtin):" );
else
if ( line > 0 )
out_printf( "%s:%d:", file, line );
else if ( line == 0 )
out_printf( "%s:", file );
else
out_printf( "(builtin):" );
}


Expand Down
7 changes: 7 additions & 0 deletions src/engine/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void constants_init( void )
constant_FILE_ARCHIVESCAN = object_new( "FILE_ARCHIVESCAN" );

constant_RESPONSE_FILE_SUB = object_new( "RESPONSE_FILE_SUB" );
constant_FILENAME = object_new( "__FILENAME__" );
constant_MODULE = object_new( "__MODULE__" );

}

void constants_done( void )
Expand Down Expand Up @@ -122,6 +125,8 @@ void constants_done( void )
object_free( constant_BUILTIN_GLOB_ARCHIVE_BACK );

object_free( constant_RESPONSE_FILE_SUB );
object_free( constant_FILENAME );
object_free( constant_MODULE );
}

OBJECT * constant_empty;
Expand Down Expand Up @@ -172,3 +177,5 @@ OBJECT * constant_FILE_ARCHIVESCAN;
OBJECT * constant_BUILTIN_GLOB_ARCHIVE_BACK;

OBJECT * constant_RESPONSE_FILE_SUB;
OBJECT * constant_FILENAME;
OBJECT * constant_MODULE;
2 changes: 2 additions & 0 deletions src/engine/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ extern OBJECT * constant_FILE_ARCHIVESCAN; /* "FILE_ARCHIVESCAN" */
extern OBJECT * constant_BUILTIN_GLOB_ARCHIVE_BACK; /* "BUILTIN_GLOB_ARCHIVE_BACK" */

extern OBJECT * constant_RESPONSE_FILE_SUB; // "RESPONSE_FILE_SUB"
extern OBJECT * constant_FILENAME; // "__FILENAME__"
extern OBJECT * constant_MODULE; // "__MODULE__"

#endif
19 changes: 16 additions & 3 deletions src/engine/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4830,15 +4830,28 @@ LIST * function_run( FUNCTION * function_, FRAME * frame )
LIST * vars = s->pop<LIST *>();
LISTITER iter = list_begin( targets );
LISTITER const end = list_end( targets );
bool not_in_root_m = frame->module != root_module();
for ( ; iter != end; iter = list_next( iter ) )
{
TARGET * t = bindtarget( list_item( iter ) );
b2::target_ref tr( bindtarget( list_item( iter ) ) );
LISTITER vars_iter = list_begin( vars );
LISTITER const vars_end = list_end( vars );
for ( ; vars_iter != vars_end; vars_iter = list_next( vars_iter
) )
t->settings = addsettings( t->settings, VAR_SET, list_item(
vars_iter ), list_copy( value ) );
{
// when setting an HDRULE on some target which is not
// on root module decorate the target with module
// information to allow next retrieval of the rule,
// as a workaround for issue #502
if (not_in_root_m &&
object_equal(list_item(vars_iter), constant_HDRRULE))
{
if (frame->file)
tr.on_set( constant_FILENAME, frame->file );
tr.on_set( constant_MODULE, frame->module->name );
}
tr.on_set( list_item( vars_iter ), value );
}
}
list_free( vars );
list_free( targets );
Expand Down
113 changes: 72 additions & 41 deletions src/engine/headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "jam.h"
#include "headers.h"

#include "constants.h"
#include "compile.h"
#include "frames.h"
#include "lists.h"
Expand All @@ -42,71 +43,101 @@
#endif

#include <errno.h>
#include <string.h>
#include <stdio.h>

#include <string>


// max numebr of regular expression sourced from HDRSCAN
#define MAX_SCAN_REGEXPS 10


/*
* headers() - scan a target for include files and call HDRRULE
*/

#define MAXINC 10

void headers( TARGET * t )
{
LIST * hdrscan;
LIST * hdrrule;
#ifndef OPT_HEADER_CACHE_EXT
LIST * headlist = L0;
#endif
b2::regex::program re_prog[MAXINC];
int rec = 0;
LISTITER iter;
LISTITER end;
module_t * rootm = root_module();

hdrscan = var_get( root_module(), constant_HDRSCAN );
if ( list_empty( hdrscan ) )
return;
b2::list_cref hdrscan( var_get( rootm, constant_HDRSCAN ) );
if ( hdrscan.empty() ) return;

hdrrule = var_get( root_module(), constant_HDRRULE );
if ( list_empty( hdrrule ) )
return;
b2::list_cref hdrrule( var_get( rootm, constant_HDRRULE ) );
if ( hdrrule.empty() ) return;

if ( is_debug_header() )
out_printf( "header scan %s\n", object_str( t->name ) );

/* Compile all regular expressions in HDRSCAN */
iter = list_begin( hdrscan );
end = list_end( hdrscan );
for ( ; ( rec < MAXINC ) && iter != end; iter = list_next( iter ) )
b2::list_cref fln_arg( var_get( rootm, constant_FILENAME ) );
b2::value_ptr file_ptr = fln_arg.empty() ? nullptr : list_front( *fln_arg );
b2::list_cref mod_arg( var_get( rootm, constant_MODULE ) );
b2::value_ptr user_mod = mod_arg.empty() ? nullptr : list_front( *mod_arg );

// this is used for error reporting purposes only
FRAME frame_re[ 1 ];
frame_init( frame_re );
std::string varname = std::string("HDRSCAN on ") + object_str( t->name );
frame_re->rulename = varname.c_str();
lol_add( frame_re->args, list_copy( *hdrscan ) );
// try to retrieve at least the user jamfile filename
if (file_ptr)
{
re_prog[ rec ].reset( list_item( iter )->str() );
rec += 1;
frame_re->file = file_ptr;
frame_re->line = 0; // only filename is known
}

/* Doctor up call to HDRRULE rule */
/* Get LIST of included files. */
// compile all regular expressions in HDRSCAN
b2::regex::program re_prog[MAX_SCAN_REGEXPS];
int rec = 0;
{
FRAME frame[ 1 ];
frame_init( frame );
lol_add( frame->args, list_new( object_copy( t->name ) ) );
#ifdef OPT_HEADER_CACHE_EXT
lol_add( frame->args, hcache( t, rec, re_prog, hdrscan ) );
#else
lol_add( frame->args, headers1( headlist, t->boundname, rec, re_prog ) );
#endif
// compilation errors print a nice error message and exit
b2::regex::frame_ctx ctx(frame_re);

if ( lol_get( frame->args, 1 ) )
b2::list_cref::iterator iter = hdrscan.begin();
b2::list_cref::iterator end = hdrscan.end();
for ( ; ( rec < MAX_SCAN_REGEXPS ) && iter != end; iter++ )
{
OBJECT * rulename = list_front( hdrrule );
/* The third argument to HDRRULE is the bound name of $(<). */
lol_add( frame->args, list_new( object_copy( t->boundname ) ) );
list_free( evaluate_rule( bindrule( rulename, frame->module ), rulename, frame ) );
re_prog[ rec ].reset( (*iter)->str() );
rec += 1;
}
}

/* Clean up. */
frame_free( frame );
FRAME frame[ 1 ];
frame_init( frame );
frame->prev = frame_re;
varname = std::string("HDRRULE on ") + object_str( t->name );
frame_re->rulename = varname.c_str();
if (user_mod)
{
// do not thrust user_mod, search for module with find_module
frame->module = find_module(user_mod);
if (! frame->module) frame->module = rootm;
}

// Get LIST of included files
lol_add( frame->args, list_new( object_copy( t->name ) ) );
#ifdef OPT_HEADER_CACHE_EXT
lol_add( frame->args, hcache( t, rec, re_prog, *hdrscan ) );
#else
LIST * headlist = L0;
lol_add( frame->args, headers1( headlist, t->boundname, rec, re_prog ) );
#endif

// Call HDRRULE rule
if ( lol_get( frame->args, 1 ) )
{
b2::value_ptr rulename = list_front( *hdrrule );
// The third argument to HDRRULE is the bound name of $(<).
lol_add( frame->args, list_new( object_copy( t->boundname ) ) );
list_free( evaluate_rule( bindrule( rulename, frame->module ), rulename, frame ) );
}

// Clean up.
frame_free( frame );
frame_free( frame_re );
}
#undef MAX_SCAN_REGEXPS


/*
Expand Down
8 changes: 8 additions & 0 deletions src/engine/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ static struct hash * module_hash = 0;
static module_t root;


module_t * find_module( OBJECT * name )
{
if ( module_hash )
return (module_t *)hash_find( module_hash, name );
return 0;
}


module_t * bindmodule( OBJECT * name )
{
if ( !name )
Expand Down
1 change: 1 addition & 0 deletions src/engine/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct module_t
int user_module = 0;
};

module_t * find_module( OBJECT * name );
module_t * bindmodule( OBJECT * name );
module_t * root_module();
void delete_module( module_t * );
Expand Down
35 changes: 16 additions & 19 deletions src/engine/regexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@
#include "outerr.h"
#include "strview.h"

#include <ctype.h>
#include <stdio.h>
#ifndef ultrix
#include <stdlib.h>
#endif
#include <string.h>

#include <cctype>
#include <cstring>
#include <string>
#include <unordered_map>

Expand All @@ -86,8 +81,10 @@ void regerror(char const * message)
if (frame)
{
msgs.push_back(
std::string("rule ") + frame->rulename + " called with: ("
+ args_to_string( frame->args ) + " )" );
std::string(frame->rulename)
// TODO: use constant_HDRSCAN
+ (std::strncmp(frame->rulename, "HDRSCAN", 7) ? "" : " =")
+ args_to_string( frame->args ) );
}

msgs.push_back( "bad regex" );
Expand Down Expand Up @@ -352,10 +349,10 @@ struct compiler
len = 0;
for (; scan != nullptr; scan = regnext(scan))
if (OP(scan) == EXACTLY
&& static_cast<int32_t>(strlen(OPERAND(scan))) >= len)
&& static_cast<int32_t>(std::strlen(OPERAND(scan))) >= len)
{
longest = OPERAND(scan);
len = static_cast<int32_t>(strlen(OPERAND(scan)));
len = static_cast<int32_t>(std::strlen(OPERAND(scan)));
}
r->regmust = longest;
r->regmlen = len;
Expand Down Expand Up @@ -942,18 +939,18 @@ struct executor
break;
case WORDA:
/* Must be looking at a letter, digit, or _ */
if (!reg_in.empty() && (!isalnum(reg_in[0]))
if (!reg_in.empty() && (!std::isalnum(reg_in[0]))
&& reg_in[0] != '_')
return false;
/* Prev must be BOL or nonword */
if (reg_in.begin() > reg_bol
&& (isalnum(reg_in.begin()[-1])
&& (std::isalnum(reg_in.begin()[-1])
|| reg_in.begin()[-1] == '_'))
return false;
break;
case WORDZ:
/* Must be looking at non letter, digit, or _ */
if (reg_in.empty() || isalnum(reg_in[0])
if (reg_in.empty() || std::isalnum(reg_in[0])
|| reg_in[0] == '_')
return false;
/* We don't care what the previous char was */
Expand All @@ -970,21 +967,21 @@ struct executor
opnd = OPERAND(scan);
/* Inline the first character, for speed. */
if (reg_in.empty() || *opnd != reg_in[0]) return false;
len = strlen(opnd);
len = std::strlen(opnd);
if (len > 1 && reg_in.compare(0, len, opnd) != 0)
return false;
reg_in = reg_in.substr(len);
}
break;
case ANYOF:
if (reg_in.empty()
|| strchr(OPERAND(scan), reg_in[0]) == NULL)
|| std::strchr(OPERAND(scan), reg_in[0]) == NULL)
return false;
reg_in = reg_in.substr(1);
break;
case ANYBUT:
if (reg_in.empty()
|| strchr(OPERAND(scan), reg_in[0]) != NULL)
|| std::strchr(OPERAND(scan), reg_in[0]) != NULL)
return false;
reg_in = reg_in.substr(1);
break;
Expand Down Expand Up @@ -1143,14 +1140,14 @@ struct executor
}
break;
case ANYOF:
while (!scan.empty() && strchr(opnd, scan[0]) != nullptr)
while (!scan.empty() && std::strchr(opnd, scan[0]) != nullptr)
{
count++;
scan = scan.substr(1);
}
break;
case ANYBUT:
while (!scan.empty() && strchr(opnd, scan[0]) == nullptr)
while (!scan.empty() && std::strchr(opnd, scan[0]) == nullptr)
{
count++;
scan = scan.substr(1);
Expand Down
Loading
Loading