Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80373 - trunk/tools/build/v2/engine
From: jurko.gospodnetic_at_[hidden]
Date: 2012-09-03 10:31:48


Author: jurko
Date: 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
New Revision: 80373
URL: http://svn.boost.org/trac/boost/changeset/80373

Log:
Internal Boost Jam pwd.c module cleanup - module renamed to cwd.c, refactored to initialize the current working folder at program startup and exit if this operation fails instead of attempting to plow on with an empty current working folder, the internal cwd() operation now returns an OBJECT instead of a LIST pointer so it would be more generic and not specialized just for the PWD builtin rule implementation.
Added:
   trunk/tools/build/v2/engine/cwd.c
      - copied, changed from r80326, /trunk/tools/build/v2/engine/pwd.c
   trunk/tools/build/v2/engine/cwd.h
      - copied, changed from r80326, /trunk/tools/build/v2/engine/pwd.h
Removed:
   trunk/tools/build/v2/engine/pwd.c
   trunk/tools/build/v2/engine/pwd.h
Text files modified:
   trunk/tools/build/v2/engine/build.bat | 4
   trunk/tools/build/v2/engine/build.jam | 2
   trunk/tools/build/v2/engine/build.sh | 2
   trunk/tools/build/v2/engine/builtins.c | 4
   trunk/tools/build/v2/engine/cwd.c | 81 ++++++++++++++++++++-------------------
   trunk/tools/build/v2/engine/cwd.h | 29 +++++++++++--
   trunk/tools/build/v2/engine/jam.c | 5 +
   7 files changed, 75 insertions(+), 52 deletions(-)

Modified: trunk/tools/build/v2/engine/build.bat
==============================================================================
--- trunk/tools/build/v2/engine/build.bat (original)
+++ trunk/tools/build/v2/engine/build.bat 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -470,8 +470,8 @@
 set BJAM_SOURCES=%BJAM_SOURCES% object.c option.c output.c parse.c pathnt.c
 set BJAM_SOURCES=%BJAM_SOURCES% pathsys.c regexp.c rules.c scan.c search.c
 set BJAM_SOURCES=%BJAM_SOURCES% subst.c timestamp.c variable.c modules.c
-set BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c md5.c pwd.c
-set BJAM_SOURCES=%BJAM_SOURCES% class.c w32_getreg.c native.c modules/set.c
+set BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c md5.c class.c
+set BJAM_SOURCES=%BJAM_SOURCES% cwd.c w32_getreg.c native.c modules/set.c
 set BJAM_SOURCES=%BJAM_SOURCES% modules/path.c modules/regex.c
 set BJAM_SOURCES=%BJAM_SOURCES% modules/property-set.c modules/sequence.c
 set BJAM_SOURCES=%BJAM_SOURCES% modules/order.c

Modified: trunk/tools/build/v2/engine/build.jam
==============================================================================
--- trunk/tools/build/v2/engine/build.jam (original)
+++ trunk/tools/build/v2/engine/build.jam 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -482,7 +482,7 @@
     hash.c hcache.c headers.c hdrmacro.c jam.c jambase.c jamgram.c lists.c
     make.c make1.c mem.c object.c option.c output.c parse.c pathsys.c regexp.c
     rules.c scan.c search.c subst.c w32_getreg.c timestamp.c variable.c
- modules.c strings.c filesys.c builtins.c pwd.c class.c native.c md5.c
+ modules.c strings.c filesys.c builtins.c class.c cwd.c native.c md5.c
     modules/set.c modules/path.c modules/regex.c modules/property-set.c
     modules/sequence.c modules/order.c ;
 if $(OS) = NT

Modified: trunk/tools/build/v2/engine/build.sh
==============================================================================
--- trunk/tools/build/v2/engine/build.sh (original)
+++ trunk/tools/build/v2/engine/build.sh 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -249,7 +249,7 @@
  hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c\
  object.c option.c output.c parse.c pathsys.c pathunix.c regexp.c rules.c\
  scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c\
- builtins.c pwd.c class.c native.c md5.c w32_getreg.c modules/set.c\
+ builtins.c class.c cwd.c native.c md5.c w32_getreg.c modules/set.c\
  modules/path.c modules/regex.c modules/property-set.c modules/sequence.c\
  modules/order.c"
 case $BOOST_JAM_TOOLSET in

Modified: trunk/tools/build/v2/engine/builtins.c
==============================================================================
--- trunk/tools/build/v2/engine/builtins.c (original)
+++ trunk/tools/build/v2/engine/builtins.c 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -9,6 +9,7 @@
 
 #include "compile.h"
 #include "constants.h"
+#include "cwd.h"
 #include "filesys.h"
 #include "frames.h"
 #include "hash.h"
@@ -20,7 +21,6 @@
 #include "object.h"
 #include "parse.h"
 #include "pathsys.h"
-#include "pwd.h"
 #include "rules.h"
 #include "strings.h"
 #include "subst.h"
@@ -1371,7 +1371,7 @@
 
 LIST * builtin_pwd( FRAME * frame, int flags )
 {
- return pwd();
+ return list_new( object_copy( cwd() ) );
 }
 
 

Copied: trunk/tools/build/v2/engine/cwd.c (from r80326, /trunk/tools/build/v2/engine/pwd.c)
==============================================================================
--- /trunk/tools/build/v2/engine/pwd.c (original)
+++ trunk/tools/build/v2/engine/cwd.c 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -6,23 +6,23 @@
  * http://www.boost.org/LICENSE_1_0.txt)
  */
 
-#include "jam.h"
-#include "pwd.h"
+#include "cwd.h"
 
+#include "jam.h"
 #include "mem.h"
-#include "object.h"
 #include "pathsys.h"
 
+#include <assert.h>
 #include <errno.h>
 #include <limits.h>
 
 /* MinGW on Windows declares PATH_MAX in limits.h */
-#if defined(NT) && !defined(__GNUC__)
+#if defined( NT ) && !defined( __GNUC__ )
 # include <direct.h>
 # define PATH_MAX _MAX_PATH
 #else
 # include <unistd.h>
-# if defined(__COMO__)
+# if defined( __COMO__ )
 # include <linux/limits.h>
 # endif
 #endif
@@ -31,50 +31,53 @@
 # define PATH_MAX 1024
 #endif
 
-/* The current directory can not change in Boost Jam, so optimize pwd() by
- * caching the result.
-*/
-static OBJECT * pwd_result;
 
+static OBJECT * cwd_;
 
-LIST * pwd( void )
+
+void cwd_init( void )
 {
- if ( !pwd_result )
+ int buffer_size = PATH_MAX;
+ char * cwd_buffer = 0;
+ int error;
+
+ assert( !cwd_ );
+
+ do
     {
- int buffer_size = PATH_MAX;
- char * result_buffer = 0;
- int error;
- do
+ char * const buffer = BJAM_MALLOC_RAW( buffer_size );
+ cwd_buffer = getcwd( buffer, buffer_size );
+ error = errno;
+ if ( cwd_buffer )
         {
- char * const buffer = BJAM_MALLOC_RAW( buffer_size );
- result_buffer = getcwd( buffer, buffer_size );
- error = errno;
- if ( result_buffer )
- {
- /* We return the path using its canonical/long/key format. */
- OBJECT * const result = object_new( result_buffer );
- pwd_result = path_as_key( result );
- object_free( result );
- }
- buffer_size *= 2;
- BJAM_FREE_RAW( buffer );
+ /* We store the path using its canonical/long/key format. */
+ OBJECT * const cwd = object_new( cwd_buffer );
+ cwd_ = path_as_key( cwd );
+ object_free( cwd );
         }
- while ( !pwd_result && error == ERANGE );
+ buffer_size *= 2;
+ BJAM_FREE_RAW( buffer );
+ }
+ while ( !cwd_ && error == ERANGE );
 
- if ( !pwd_result )
- {
- perror( "can not get current directory" );
- return L0;
- }
+ if ( !cwd_ )
+ {
+ perror( "can not get current working directory" );
+ exit( EXITBAD );
     }
- return list_new( object_copy( pwd_result ) );
 }
 
 
-void pwd_done( void )
+OBJECT * cwd( void )
 {
- if ( pwd_result )
- {
- object_free( pwd_result );
- }
+ assert( cwd_ );
+ return cwd_;
+}
+
+
+void cwd_done( void )
+{
+ assert( cwd_ );
+ object_free( cwd_ );
+ cwd_ = NULL;
 }

Copied: trunk/tools/build/v2/engine/cwd.h (from r80326, /trunk/tools/build/v2/engine/pwd.h)
==============================================================================
--- /trunk/tools/build/v2/engine/pwd.h (original)
+++ trunk/tools/build/v2/engine/cwd.h 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -5,12 +5,31 @@
  * http://www.boost.org/LICENSE_1_0.txt)
  */
 
-#ifndef PWD_H
-#define PWD_H
+/*
+ * cwd.h - manages the current working folder information
+ */
+
+#ifndef CWD_H
+#define CWD_H
+
+#include "object.h"
 
-#include "lists.h"
 
-LIST * pwd( void );
-void pwd_done( void );
+/* cwd() - returns the current working folder */
+OBJECT * cwd( void );
+
+/* cwd_init() - initialize the cwd module functionality
+ *
+ * The current working folder can not change in Boost Jam so this function
+ * gets the current working folder information from the OS and stores it
+ * internally.
+ *
+ * Expected to be called at program startup before the program's current
+ * working folder has been changed
+ */
+void cwd_init( void );
+
+/* cwd_done() - cleans up the cwd module functionality */
+void cwd_done( void );
 
 #endif

Modified: trunk/tools/build/v2/engine/jam.c
==============================================================================
--- trunk/tools/build/v2/engine/jam.c (original)
+++ trunk/tools/build/v2/engine/jam.c 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
@@ -113,7 +113,7 @@
 #include "option.h"
 #include "output.h"
 #include "parse.h"
-#include "pwd.h"
+#include "cwd.h"
 #include "rules.h"
 #include "scan.h"
 #include "search.h"
@@ -345,6 +345,7 @@
     }
 
     constants_init();
+ cwd_init();
 
     {
         PROFILE_ENTER( MAIN );
@@ -579,7 +580,7 @@
     class_done();
     modules_done();
     regex_done();
- pwd_done();
+ cwd_done();
     path_done();
     function_done();
     list_done();

Deleted: trunk/tools/build/v2/engine/pwd.c
==============================================================================
--- trunk/tools/build/v2/engine/pwd.c 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
+++ (empty file)
@@ -1,80 +0,0 @@
-/*
- * Copyright 2002. Vladimir Prus
- * Copyright 2005. Rene Rivera
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#include "jam.h"
-#include "pwd.h"
-
-#include "mem.h"
-#include "object.h"
-#include "pathsys.h"
-
-#include <errno.h>
-#include <limits.h>
-
-/* MinGW on Windows declares PATH_MAX in limits.h */
-#if defined(NT) && !defined(__GNUC__)
-# include <direct.h>
-# define PATH_MAX _MAX_PATH
-#else
-# include <unistd.h>
-# if defined(__COMO__)
-# include <linux/limits.h>
-# endif
-#endif
-
-#ifndef PATH_MAX
-# define PATH_MAX 1024
-#endif
-
-/* The current directory can not change in Boost Jam, so optimize pwd() by
- * caching the result.
-*/
-static OBJECT * pwd_result;
-
-
-LIST * pwd( void )
-{
- if ( !pwd_result )
- {
- int buffer_size = PATH_MAX;
- char * result_buffer = 0;
- int error;
- do
- {
- char * const buffer = BJAM_MALLOC_RAW( buffer_size );
- result_buffer = getcwd( buffer, buffer_size );
- error = errno;
- if ( result_buffer )
- {
- /* We return the path using its canonical/long/key format. */
- OBJECT * const result = object_new( result_buffer );
- pwd_result = path_as_key( result );
- object_free( result );
- }
- buffer_size *= 2;
- BJAM_FREE_RAW( buffer );
- }
- while ( !pwd_result && error == ERANGE );
-
- if ( !pwd_result )
- {
- perror( "can not get current directory" );
- return L0;
- }
- }
- return list_new( object_copy( pwd_result ) );
-}
-
-
-void pwd_done( void )
-{
- if ( pwd_result )
- {
- object_free( pwd_result );
- }
-}

Deleted: trunk/tools/build/v2/engine/pwd.h
==============================================================================
--- trunk/tools/build/v2/engine/pwd.h 2012-09-03 10:31:46 EDT (Mon, 03 Sep 2012)
+++ (empty file)
@@ -1,16 +0,0 @@
-/*
- * Copyright 2002. Vladimir Prus
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#ifndef PWD_H
-#define PWD_H
-
-#include "lists.h"
-
-LIST * pwd( void );
-void pwd_done( void );
-
-#endif


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