2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-15 00:52:16 +00:00

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.

[SVN r80373]
This commit is contained in:
Jurko Gospodnetić
2012-09-03 14:31:46 +00:00
parent dbdab64743
commit 7fa25470b6
9 changed files with 127 additions and 104 deletions

View File

@@ -470,8 +470,8 @@ set BJAM_SOURCES=%BJAM_SOURCES% jambase.c jamgram.c lists.c make.c make1.c
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

View File

@@ -482,7 +482,7 @@ jam.source =
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

View File

@@ -249,7 +249,7 @@ BJAM_SOURCES="\
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

View File

@@ -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_caller_module( FRAME * frame, int flags )
LIST * builtin_pwd( FRAME * frame, int flags )
{
return pwd();
return list_new( object_copy( cwd() ) );
}

83
v2/engine/cwd.c Normal file
View File

@@ -0,0 +1,83 @@
/*
* 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 "cwd.h"
#include "jam.h"
#include "mem.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__ )
# 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
static OBJECT * cwd_;
void cwd_init( void )
{
int buffer_size = PATH_MAX;
char * cwd_buffer = 0;
int error;
assert( !cwd_ );
do
{
char * const buffer = BJAM_MALLOC_RAW( buffer_size );
cwd_buffer = getcwd( buffer, buffer_size );
error = errno;
if ( cwd_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 );
}
buffer_size *= 2;
BJAM_FREE_RAW( buffer );
}
while ( !cwd_ && error == ERANGE );
if ( !cwd_ )
{
perror( "can not get current working directory" );
exit( EXITBAD );
}
}
OBJECT * cwd( void )
{
assert( cwd_ );
return cwd_;
}
void cwd_done( void )
{
assert( cwd_ );
object_free( cwd_ );
cwd_ = NULL;
}

35
v2/engine/cwd.h Normal file
View File

@@ -0,0 +1,35 @@
/*
* 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)
*/
/*
* cwd.h - manages the current working folder information
*/
#ifndef CWD_H
#define CWD_H
#include "object.h"
/* 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

View File

@@ -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 @@ int main( int argc, char * * argv, char * * arg_environ )
}
constants_init();
cwd_init();
{
PROFILE_ENTER( MAIN );
@@ -579,7 +580,7 @@ int main( int argc, char * * argv, char * * arg_environ )
class_done();
modules_done();
regex_done();
pwd_done();
cwd_done();
path_done();
function_done();
list_done();

View 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 );
}
}

View 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