Boost logo

Boost-Build :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2005-10-29 14:10:28


David Abrahams wrote:
> Reece Dunn <msclrhd_at_[hidden]> writes:
>>Zbynek Winkler wrote:
>>
>>>:) I think we should start reading each others emails. IMO what has
>>>happened here is that each one of us saw the light at various points of
>>>time. So I guess that we all are proposing
>>>
>>> actions compile.c++
>>> {
>>> mv @(INCLUDES) $(<).rsp
>>> cl $(<).rsp ....
>>> }
>>>
>>>where the @() syntax takes the variable, outputs its contents to a
>>>temporary file and returns its filename instead.
>>
>>Yes! Now... how to port the functionality to bjam from Matt's code.
>
> Probably you should just implement it from scratch. Anything
> involving string manipulation (which is most things) would need to be
> rewritten anyway, since Perforce Jam uses only unsafe fixed-sized
> buffers. It can't be that hard. If you look at execnt.c you'll see
> that there's already some code for generating temporary (.bat in this
> case) files.

I have attached the patch for an initial port of native bjam response
file support based on Matt's code. This allows for:

mv @("-I$(INCLUDES)) $(<).rsp
cl @"$(<).rsp" ....

or

cl @@("-I$(INCLUDES)) ....

Note the @@(...) syntax on the cl command.

The patch currently only supports NT (because of getTempPath()), so I
would like help porting to other OSes. Linux would probably be:

const char * getTempPath( void )
{
return "/tmp/";
}

I have a modified msvc.jam to use this code and it works well. Comments?

- Reece
 --------------030808000005070609070409 Content-Type: text/plain;
name="bjam-response.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="bjam-response.diff"

Index: execcmd.h
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/jam_src/execcmd.h,v
retrieving revision 1.3
diff -u -r1.3 execcmd.h
--- execcmd.h 12 Feb 2005 02:30:17 -0000 1.3
+++ execcmd.h 29 Oct 2005 18:44:30 -0000
@@ -17,6 +17,8 @@
double user;
} timing_info;

+const char *getTempDir(void);
+
void execcmd(
char *string,
void (*func)( void *closure, int status, timing_info* ),
Index: execnt.c
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/jam_src/execnt.c,v
retrieving revision 1.22
diff -u -r1.22 execnt.c
--- execnt.c 10 Oct 2005 20:33:20 -0000 1.22
+++ execnt.c 29 Oct 2005 18:43:40 -0000
@@ -441,7 +441,7 @@
}

/* SVA - handle temp dirs with spaces in the path */
-static const char *getTempDir(void)
+const char *getTempDir(void)
{
static char tempPath[_MAX_PATH];
static char *pTempPath=NULL;
Index: variable.c
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/jam_src/variable.c,v
retrieving revision 1.12
diff -u -r1.12 variable.c
--- variable.c 26 Sep 2005 05:26:14 -0000 1.12
+++ variable.c 29 Oct 2005 18:50:18 -0000
@@ -6,6 +6,7 @@

/* This file is ALSO:
* Copyright 2001-2004 David Abrahams.
+ * Copyright 2005 Reece H. Dunn.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
*/
@@ -19,6 +20,8 @@
# include "filesys.h"
# include "newstr.h"
# include "strings.h"
+# include "execcmd.h"
+# include <limits.h>
# include <stdlib.h>

/*
@@ -28,6 +31,7 @@
*
* var_defines() - load a bunch of variable=value settings
* var_string() - expand a string with variables in it
+ * var_string_file() - expand a string with variables in it to a file
* var_get() - get value of a user defined symbol
* var_set() - set a variable in jam's user defined symbol table
* var_swap() - swap a variable's value with the given one
@@ -207,6 +211,62 @@

if( in[0] == '$' && in[1] == '(' )
dollar++;
+ else if( in[0] == '@' && in[1] == '(' )
+ {
+ int depth = 1;
+ char *ine = in + 2;
+
+ while( *ine && depth > 0 )
+ {
+ switch( *ine )
+ {
+ case '(':
+ ++depth;
+ break;
+ case ')':
+ --depth;
+ break;
+ }
+ ++ine;
+ }
+
+ if( depth == 0 )
+ {
+ static int rsp_count = 0;
+ char save = ine[ -1 ];
+ char rsp_name[ _MAX_PATH ];
+ int rsp_len;
+ FILE * rsp;
+
+ const char *tempdir = getTempDir();
+
+ sprintf( rsp_name, "%s\\rsp%06d.rsp", tempdir, rsp_count );
+ rsp_count++;
+ rsp_len = strlen( rsp_name );
+ rsp = fopen( rsp_name, "w" );
+
+ if (!rsp)
+ {
+ printf( "failed to write response file!\n" );
+ exit( EXITBAD );
+ }
+
+ ine[ -1 ] = '\0';
+
+ var_string_file( in + 2, rsp, lol );
+
+ ine[ -1 ] = save;
+
+ fclose( rsp );
+
+ if(( out + rsp_len ) >= oute )
+ return -1;
+
+ strcpy( out, rsp_name );
+ out += rsp_len;
+ }
+ in = ine;
+ }

*out++ = *in++;
}
@@ -253,6 +313,76 @@
}

/*
+ * var_string_file() - expand a string with variables in it to a file
+ *
+ * Copies in to f; doesn't modify targets & sources.
+ */
+
+void
+var_string_file(
+ char *in,
+ FILE *f,
+ LOL *lol )
+{
+ char buffer[ 1024 ];
+ char *oute = buffer + sizeof(buffer) - 1;
+
+ while( *in )
+ {
+ char *out = buffer;
+ int dollar = 0;
+
+ /* Skip white space */
+
+ while( isspace( *in ) )
+ {
+ in++;
+ }
+
+ /* Copy non-white space, watching for variables */
+
+ while( *in && !isspace( *in ) )
+ {
+ if( out >= oute )
+ {
+ printf( "variable name limit of %d exceeded!\n", sizeof(buffer));
+ exit( EXITBAD );
+ }
+
+ if( in[0] == '$' && in[1] == '(' )
+ {
+ dollar++;
+ }
+
+ *out++ = *in++;
+ }
+
+ /* If a variable encountered, expand it and and embed the */
+ /* space-separated members of the list in the output. */
+
+ if( dollar )
+ {
+ LIST *l;
+
+ l = var_expand( L0, buffer, out, lol, 0 );
+
+ for( ; l; l = list_next( l ) )
+ {
+ fputs( l->string, f );
+ fputc( '\n', f );
+ }
+
+ list_free( l );
+ }
+ else
+ {
+ fputs( out, f );
+ fputc( '\n', f );
+ }
+ }
+}
+
+/*
* var_get() - get value of a user defined symbol
*
* Returns NULL if symbol unset.
Index: variable.h
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/jam_src/variable.h,v
retrieving revision 1.5
diff -u -r1.5 variable.h
--- variable.h 30 May 2005 03:42:38 -0000 1.5
+++ variable.h 29 Oct 2005 17:46:37 -0000
@@ -8,10 +8,13 @@
* variable.h - handle jam multi-element variables
*/

+# include <stdio.h>
+
struct hash;

void var_defines( char* const *e, int preprocess );
int var_string( char *in, char *out, int outsize, LOL *lol );
+void var_string_file( char *in, FILE *rsp, LOL *lol );
LIST * var_get( char *symbol );
void var_set( char *symbol, LIST *value, int flag );
LIST * var_swap( char *symbol, LIST *value );
 --------------030808000005070609070409--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk