]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/search.c
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * Copyright 2001-2004 David Abrahams.
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or copy at
11 * http://www.boost.org/LICENSE_1_0.txt)
24 #include "timestamp.h"
31 typedef struct _binding
37 static struct hash
* explicit_bindings
= 0;
40 void call_bind_rule( OBJECT
* target_
, OBJECT
* boundname_
)
42 LIST
* const bind_rule
= var_get( root_module(), constant_BINDRULE
);
43 if ( !list_empty( bind_rule
) )
45 OBJECT
* target
= object_copy( target_
);
46 OBJECT
* boundname
= object_copy( boundname_
);
47 if ( boundname
&& target
)
49 /* Prepare the argument list. */
53 /* First argument is the target name. */
54 lol_add( frame
->args
, list_new( target
) );
56 lol_add( frame
->args
, list_new( boundname
) );
57 if ( lol_get( frame
->args
, 1 ) )
59 OBJECT
* rulename
= list_front( bind_rule
);
60 list_free( evaluate_rule( bindrule( rulename
, root_module() ), rulename
, frame
) );
69 object_free( boundname
);
71 object_free( target
);
76 /* Records the binding of a target with an explicit LOCATE. */
77 void set_explicit_binding( OBJECT
* target
, OBJECT
* locate
)
86 if ( !explicit_bindings
)
87 explicit_bindings
= hashinit( sizeof( BINDING
), "explicitly specified "
92 /* Parse the filename. */
93 path_parse( object_str( target
), f
);
95 /* Ignore the grist. */
99 /* Root the target path at the given location. */
100 f
->f_root
.ptr
= object_str( locate
);
101 f
->f_root
.len
= strlen( object_str( locate
) );
103 path_build( f
, buf
);
104 boundname
= object_new( buf
->value
);
106 out_printf( "explicit locate %s: %s\n", object_str( target
), buf
->value
);
108 key
= path_as_key( boundname
);
109 object_free( boundname
);
111 ba
= (BINDING
*)hash_insert( explicit_bindings
, key
, &found
);
122 * search.c - find a target along $(SEARCH) or $(LOCATE).
124 * First, check if LOCATE is set. If so, use it to determine the location of
125 * target and return, regardless of whether anything exists at that location.
127 * Second, examine all directories in SEARCH. If the file exists there or there
128 * is another target with the same name already placed at this location via the
129 * LOCATE setting, stop and return the location. In case of a previous target,
130 * return its name via the 'another_target' argument.
132 * This behaviour allows handling dependencies on generated files.
134 * If caller does not expect that the target is generated, 0 can be passed as
138 OBJECT
* search( OBJECT
* target
, timestamp
* const time
,
139 OBJECT
* * another_target
, int const file
)
145 OBJECT
* boundname
= 0;
147 if ( another_target
)
150 if ( !explicit_bindings
)
151 explicit_bindings
= hashinit( sizeof( BINDING
), "explicitly specified "
156 /* Parse the filename. */
157 path_parse( object_str( target
), f
);
162 varlist
= var_get( root_module(), constant_LOCATE
);
163 if ( !list_empty( varlist
) )
166 f
->f_root
.ptr
= object_str( list_front( varlist
) );
167 f
->f_root
.len
= strlen( object_str( list_front( varlist
) ) );
169 path_build( f
, buf
);
172 out_printf( "locate %s: %s\n", object_str( target
), buf
->value
);
174 key
= object_new( buf
->value
);
175 timestamp_from_path( time
, key
);
179 else if ( varlist
= var_get( root_module(), constant_SEARCH
),
180 !list_empty( varlist
) )
182 LISTITER iter
= list_begin( varlist
);
183 LISTITER
const end
= list_end( varlist
);
184 for ( ; iter
!= end
; iter
= list_next( iter
) )
191 f
->f_root
.ptr
= object_str( list_item( iter
) );
192 f
->f_root
.len
= strlen( object_str( list_item( iter
) ) );
194 string_truncate( buf
, 0 );
195 path_build( f
, buf
);
198 out_printf( "search %s: %s\n", object_str( target
), buf
->value
);
200 test_path
= object_new( buf
->value
);
201 key
= path_as_key( test_path
);
202 object_free( test_path
);
203 ff
= file_query( key
);
204 timestamp_from_path( time
, key
);
206 if ( ( ba
= (BINDING
*)hash_find( explicit_bindings
, key
) ) )
209 out_printf(" search %s: found explicitly located target %s\n",
210 object_str( target
), object_str( ba
->target
) );
211 if ( another_target
)
212 *another_target
= ba
->target
;
219 if ( !file
|| ff
->is_file
)
232 /* Look for the obvious. */
233 /* This is a questionable move. Should we look in the obvious place if
241 string_truncate( buf
, 0 );
242 path_build( f
, buf
);
245 out_printf( "search %s: %s\n", object_str( target
), buf
->value
);
247 key
= object_new( buf
->value
);
248 timestamp_from_path( time
, key
);
252 boundname
= object_new( buf
->value
);
255 /* Prepare a call to BINDRULE if the variable is set. */
256 call_bind_rule( target
, boundname
);
262 static void free_binding( void * xbinding
, void * data
)
264 object_free( ( (BINDING
*)xbinding
)->binding
);
268 void search_done( void )
270 if ( explicit_bindings
)
272 hashenumerate( explicit_bindings
, free_binding
, 0 );
273 hashdone( explicit_bindings
);