Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75768 - trunk/tools/build/v2/engine
From: steven_at_[hidden]
Date: 2011-12-02 00:11:11


Author: steven_watanabe
Date: 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
New Revision: 75768
URL: http://svn.boost.org/trac/boost/changeset/75768

Log:
Clean up down casing paths and usage of short_path_to_long_path.
Text files modified:
   trunk/tools/build/v2/engine/filent.c | 34 ++++++++++-----
   trunk/tools/build/v2/engine/filesys.c | 4 +
   trunk/tools/build/v2/engine/jam.c | 1
   trunk/tools/build/v2/engine/pathsys.h | 9 ++++
   trunk/tools/build/v2/engine/pathunix.c | 82 ++++++++++++++++++++++++++++++++++-----
   trunk/tools/build/v2/engine/rules.c | 6 --
   trunk/tools/build/v2/engine/timestamp.c | 38 +-----------------
   7 files changed, 110 insertions(+), 64 deletions(-)

Modified: trunk/tools/build/v2/engine/filent.c
==============================================================================
--- trunk/tools/build/v2/engine/filent.c (original)
+++ trunk/tools/build/v2/engine/filent.c 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -63,8 +63,6 @@
 
     file_info_t * d = 0;
 
- dir = short_path_to_long_path( dir );
-
     /* First enter directory itself */
 
     d = file_query( dir );
@@ -85,11 +83,15 @@
         int ret;
         struct _finddata_t finfo[ 1 ];
         LIST * files = L0;
- int d_length = strlen( object_str( d->name ) );
+ int d_length;
+
+ dir = short_path_to_long_path( dir );
+
+ d_length = strlen( object_str( dir ) );
 
         memset( (char *)&f, '\0', sizeof( f ) );
 
- f.f_dir.ptr = object_str( d->name );
+ f.f_dir.ptr = object_str( dir );
         f.f_dir.len = d_length;
 
         /* Now enter contents of directory */
@@ -104,8 +106,8 @@
              * its trailing path separator or otherwise we would not support the
              * Windows root folder specified without its drive letter, i.e. '\'.
              */
- char trailingChar = object_str( d->name )[ d_length - 1 ] ;
- string_copy( filespec, object_str( d->name ) );
+ char trailingChar = object_str( dir )[ d_length - 1 ] ;
+ string_copy( filespec, object_str( dir ) );
             if ( ( trailingChar != '\\' ) && ( trailingChar != '/' ) )
                 string_append( filespec, "\\" );
             string_append( filespec, "*" );
@@ -181,6 +183,7 @@
         # endif
         string_free( filename );
         string_free( filespec );
+ object_free( dir );
 
         d->files = files;
     }
@@ -189,11 +192,17 @@
     {
         unsigned long len = strlen( object_str( d->name ) );
         if ( len == 1 && object_str( d->name )[0] == '\\' )
- (*func)( closure, d->name, 1 /* stat()'ed */, d->time );
- else if ( len == 3 && object_str( d->name )[1] == ':' ) {
+ {
+ OBJECT * dir = short_path_to_long_path( d->name );
+ (*func)( closure, dir, 1 /* stat()'ed */, d->time );
+ object_free( dir );
+ }
+ else if ( len == 3 && object_str( d->name )[1] == ':' )
+ {
             char buf[4];
+ OBJECT * dir1 = short_path_to_long_path( d->name );
             OBJECT * dir2;
- (*func)( closure, d->name, 1 /* stat()'ed */, d->time );
+ (*func)( closure, dir1, 1 /* stat()'ed */, d->time );
             /* We've just entered 3-letter drive name spelling (with trailing
                slash), into the hash table. Now enter two-letter variant,
                without trailing slash, so that if we try to check whether
@@ -206,11 +215,13 @@
                There will be no trailing slash in $(p), but there will be one
                in $(p2). But, that seems rather fragile.
             */
- strcpy( buf, object_str( d->name ) );
+ strcpy( buf, object_str( dir1 ) );
             buf[2] = 0;
             dir2 = object_new( buf );
             (*func)( closure, dir2, 1 /* stat()'ed */, d->time );
+ printf( "root: %s, %s\n", object_str(dir1), object_str(dir2) );
             object_free( dir2 );
+ object_free( dir1 );
         }
     }
 
@@ -221,12 +232,11 @@
         while ( files )
         {
             file_info_t * ff = file_info( files->value );
- (*func)( closure, ff->name, 1 /* stat()'ed */, ff->time );
+ (*func)( closure, files->value, 1 /* stat()'ed */, ff->time );
             files = list_next( files );
         }
     }
 
- object_free( dir );
     PROFILE_EXIT( FILE_DIRSCAN );
 }
 

Modified: trunk/tools/build/v2/engine/filesys.c
==============================================================================
--- trunk/tools/build/v2/engine/filesys.c (original)
+++ trunk/tools/build/v2/engine/filesys.c 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -43,6 +43,8 @@
     if ( !filecache_hash )
         filecache_hash = hashinit( sizeof( file_info_t ), "file_info" );
 
+ filename = path_as_key( filename );
+
     finfo->name = filename;
     finfo->is_file = 0;
     finfo->is_dir = 0;
@@ -55,6 +57,8 @@
         finfo->name = object_copy( finfo->name );
     }
 
+ object_free( filename );
+
     return finfo;
 }
 

Modified: trunk/tools/build/v2/engine/jam.c
==============================================================================
--- trunk/tools/build/v2/engine/jam.c (original)
+++ trunk/tools/build/v2/engine/jam.c 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -620,6 +620,7 @@
     regex_done();
     exec_done();
     pwd_done();
+ path_done();
     function_done();
     list_done();
     constants_done();

Modified: trunk/tools/build/v2/engine/pathsys.h
==============================================================================
--- trunk/tools/build/v2/engine/pathsys.h (original)
+++ trunk/tools/build/v2/engine/pathsys.h 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -59,6 +59,13 @@
 
 #endif
 
+/** Given a path, returns an object that can be
+ used as a unique key for that path. Equivalent
+ paths such as a/b, A\B, and a\B on NT all yield the
+ same key.
+ */
+OBJECT * path_as_key( OBJECT * path );
+
 #ifdef USE_PATHUNIX
 /** Returns a static pointer to the system dependent path to the temporary
     directory. NOTE: *without* a trailing path separator.
@@ -83,4 +90,6 @@
 */
 char * executable_path (const char *argv0);
 
+void path_done( void );
+
 #endif

Modified: trunk/tools/build/v2/engine/pathunix.c
==============================================================================
--- trunk/tools/build/v2/engine/pathunix.c (original)
+++ trunk/tools/build/v2/engine/pathunix.c 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -326,6 +326,7 @@
             return len;
         }
         _tcsncpy(ret,path,2);
+ ret[0] = toupper(ret[0]);
     }
 
     /* Expand the path for each subpath, and strip trailing backslashes */
@@ -384,23 +385,82 @@
 
 OBJECT * short_path_to_long_path( OBJECT * short_path )
 {
- /* Short circuit names with grists. */
- if ( object_str( short_path )[ 0 ] == '<' )
- {
- return object_copy( short_path );
- }
+ char buffer2[_MAX_PATH];
+ int ret = ShortPathToLongPath( object_str( short_path ), buffer2, _MAX_PATH );
+
+ if (ret)
+ return object_new( buffer2 );
     else
+ return object_copy( short_path );
+}
+
+#endif
+
+#ifdef NT
+
+struct path_key_entry
+{
+ OBJECT * path;
+ OBJECT * key;
+};
+
+static struct hash * path_key_cache;
+
+OBJECT * path_as_key( OBJECT * path )
+{
+ struct path_key_entry e, *result = &e;
+
+ if ( ! path_key_cache )
+ path_key_cache = hashinit( sizeof( struct path_key_entry ), "path to key" );
+
+ result->path = path;
+ if ( hashenter( path_key_cache, (HASHDATA * *)&result ) )
     {
- char buffer2[_MAX_PATH];
- int ret = ShortPathToLongPath( object_str( short_path ), buffer2, _MAX_PATH );
+ string buf[1];
+ char * s;
+ string_copy( buf, object_str( path ) );
+ for ( s = buf->value; s < buf->value + buf->size; ++s )
+ {
+ if ( *s == '/' )
+ *s = '\\';
+ else
+ *s = tolower( *s );
+ }
+ result->path = object_copy( path );
+ result->key = object_new( buf->value );
+ string_free( buf );
+ }
+
+ return result->key;
+}
 
- if (ret)
- return object_new( buffer2 );
- else
- return object_copy( short_path );
+static void free_path_key_entry( void * xentry, void * data )
+{
+ struct path_key_entry * entry = (struct path_key_entry *)xentry;
+ object_free( entry->path );
+ object_free( entry->key );
+}
+
+void path_done( void )
+{
+ if ( path_key_cache )
+ {
+ hashenumerate( path_key_cache, &free_path_key_entry, (void *)0 );
+ hashdone( path_key_cache );
     }
 }
 
+#else
+
+OBJECT * path_as_key( OBJECT * path )
+{
+ return object_copy( path );
+}
+
+void path_done( void )
+{
+}
+
 #endif
 
 static string path_tmpdir_buffer[1];

Modified: trunk/tools/build/v2/engine/rules.c
==============================================================================
--- trunk/tools/build/v2/engine/rules.c (original)
+++ trunk/tools/build/v2/engine/rules.c 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -164,9 +164,6 @@
     if ( !targethash )
         targethash = hashinit( sizeof( TARGET ), "targets" );
 
-#ifdef NT
- target_name = short_path_to_long_path( target_name );
-#endif
     t->name = target_name;
 
     if ( hashenter( targethash, (HASHDATA * *)&t ) )
@@ -175,9 +172,6 @@
         t->name = object_copy( target_name );
         t->boundname = object_copy( t->name ); /* default for T_FLAG_NOTFILE */
     }
-#ifdef NT
- object_free( target_name );
-#endif
 
     return t;
 }

Modified: trunk/tools/build/v2/engine/timestamp.c
==============================================================================
--- trunk/tools/build/v2/engine/timestamp.c (original)
+++ trunk/tools/build/v2/engine/timestamp.c 2011-12-02 00:11:10 EST (Fri, 02 Dec 2011)
@@ -74,28 +74,9 @@
     BINDING binding;
     BINDING * b = &binding;
     string buf[ 1 ];
-#ifdef DOWNSHIFT_PATHS
- string path;
- char * p;
-#endif
-
-#ifdef DOWNSHIFT_PATHS
- string_copy( &path, object_str( target ) );
- p = path.value;
 
- do
- {
- *p = tolower( *p );
-#ifdef NT
- /* On NT, we must use backslashes or the file will not be found. */
- if ( *p == '/' )
- *p = PATH_DELIM;
-#endif
- }
- while ( *p++ );
+ target = path_as_key( target );
 
- target = object_new( path.value );
-#endif /* #ifdef DOWNSHIFT_PATHS */
     string_new( buf );
 
     if ( !bindhash )
@@ -184,10 +165,8 @@
 
     *time = b->progress == BIND_FOUND ? b->time : 0;
         string_free( buf );
-#ifdef DOWNSHIFT_PATHS
- string_free( &path );
+
     object_free( target );
-#endif
 
     PROFILE_EXIT( timestamp );
 }
@@ -199,16 +178,7 @@
     BINDING * b = &binding;
     struct hash * bindhash = (struct hash *)closure;
 
-#ifdef DOWNSHIFT_PATHS
- char path[ MAXJPATH ];
- char * p = path;
- const char * t = object_str( target );
-
- do *p++ = tolower( *t );
- while ( *t++ );
-
- target = object_new( path );
-#endif
+ target = path_as_key( target );
 
     b->name = target;
     b->flags = 0;
@@ -222,9 +192,7 @@
     if ( DEBUG_BINDSCAN )
         printf( "time ( %s ) : %s\n", object_str( target ), time_progress[ b->progress ] );
 
-#ifdef DOWNSHIFT_PATHS
     object_free( target );
-#endif
 }
 
 static void free_timestamps ( void * xbinding, void * data )


Boost-Commit 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