forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppDirectoryTree.cxx
More file actions
316 lines (274 loc) · 10.9 KB
/
ppDirectoryTree.cxx
File metadata and controls
316 lines (274 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Filename: ppDirectoryTree.cxx
// Created by: drose (28Sep00)
//
////////////////////////////////////////////////////////////////////
#include "ppDirectoryTree.h"
#include "ppDirectory.h"
#include "ppDependableFile.h"
#include "tokenize.h"
#include <algorithm>
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
PPDirectoryTree::
PPDirectoryTree(PPDirectoryTree *main_tree) {
if (main_tree == NULL) {
_main_tree = this;
} else {
_main_tree = main_tree;
}
_root = new PPDirectory(this);
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
PPDirectoryTree::
~PPDirectoryTree() {
delete _root;
RelatedTrees::iterator ri;
for (ri = _related_trees.begin(); ri != _related_trees.end(); ++ri) {
delete (*ri);
}
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::get_main_tree
// Access: Public
// Description: Returns the PPDirectoryTree that represents the
// actual source hierarchy. If the return value is
// something other than this, it indicates that this
// tree is an external dependable tree.
////////////////////////////////////////////////////////////////////
PPDirectoryTree *PPDirectoryTree::
get_main_tree() {
return _main_tree;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::set_fullpath
// Access: Public
// Description: Indicates the full path to the root of this
// particular tree.
////////////////////////////////////////////////////////////////////
void PPDirectoryTree::
set_fullpath(const string &fullpath) {
_fullpath = fullpath;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::scan_source
// Access: Public
// Description: Reads in the complete hierarchy of source files,
// beginning at the current directory.
////////////////////////////////////////////////////////////////////
bool PPDirectoryTree::
scan_source(PPNamedScopes *named_scopes) {
if (!_root->r_scan("")) {
return false;
}
if (!_root->read_source_file("", named_scopes)) {
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::scan_depends
// Access: Public
// Description: Reads in the depends file for each source file, and
// then sorts the files into dependency order.
////////////////////////////////////////////////////////////////////
bool PPDirectoryTree::
scan_depends(PPNamedScopes *named_scopes) {
if (!_root->read_depends_file(named_scopes)) {
return false;
}
if (!_root->resolve_dependencies()) {
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::scan_extra_depends
// Access: Public
// Description: Accepts the value of DEPENDABLE_HEADER_DIRS, which
// was presumably set by the various Config.pp and/or
// Depends.pp scripts that were read in, and treats each
// named filename there as the name of a directory that
// contains header files in a separate but related tree,
// for which we also need to generate dependency rules
// in this tree.
////////////////////////////////////////////////////////////////////
bool PPDirectoryTree::
scan_extra_depends(const string &dependable_header_dirs,
const string &cache_filename) {
bool okflag = true;
vector<string> dirnames;
tokenize_whitespace(dependable_header_dirs, dirnames);
// Sort dirnames and remove duplicates.
sort(dirnames.begin(), dirnames.end());
dirnames.erase(unique(dirnames.begin(), dirnames.end()), dirnames.end());
vector<string>::const_iterator ni;
for (ni = dirnames.begin(); ni != dirnames.end(); ++ni) {
string dirname = (*ni);
if (dirname[0] != '/') {
// Insist that the external dirname be a full pathname.
dirname = _fullpath + "/" + dirname;
}
// Now we need to make up a different tree for each external
// dirname.
PPDirectoryTree *tree = new PPDirectoryTree(this);
tree->set_fullpath(dirname);
_related_trees.push_back(tree);
if (!tree->get_root()->scan_extra_depends(cache_filename)) {
okflag = false;
}
}
return okflag;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::count_source_files
// Access: Public
// Description: Returns the number of directories within the tree
// that actually have a Sources.pp file that was read.
////////////////////////////////////////////////////////////////////
int PPDirectoryTree::
count_source_files() const {
return _root->count_source_files();
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::get_root
// Access: Public
// Description: Returns the root directory of the tree.
////////////////////////////////////////////////////////////////////
PPDirectory *PPDirectoryTree::
get_root() const {
return _root;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::get_fullpath
// Access: Public
// Description: Returns the full path to the root of the tree.
////////////////////////////////////////////////////////////////////
const string &PPDirectoryTree::
get_fullpath() const {
return _fullpath;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::get_complete_tree
// Access: Public
// Description: Returns a single string listing the relative path
// from the source root to each source directory in the
// tree, delimited by spaces.
////////////////////////////////////////////////////////////////////
string PPDirectoryTree::
get_complete_tree() const {
return _root->get_complete_subtree();
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::find_dirname
// Access: Public
// Description: Searches for the a source directory with the
// matching dirname. This is just the name of the
// directory itself, not the relative path to the
// directory.
////////////////////////////////////////////////////////////////////
PPDirectory *PPDirectoryTree::
find_dirname(const string &dirname) const {
Dirnames::const_iterator di;
di = _dirnames.find(dirname);
if (di != _dirnames.end()) {
return (*di).second;
}
// No such dirname; too bad.
return (PPDirectory *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::find_dependable_file
// Access: Public
// Description: Returns a PPDependableFile object corresponding to
// the named filename, searching all of the known source
// subdirectories. This can only find files marked by a
// previous call to get_dependable_file() with is_header
// set to true. Unlike
// get_dependable_file_by_pathname() or
// PPDirectory::get_dependable_file(), this does not
// create an entry if it does not exist; instead, it
// returns NULL if no matching file can be found.
////////////////////////////////////////////////////////////////////
PPDependableFile *PPDirectoryTree::
find_dependable_file(const string &filename) const {
Dependables::const_iterator di;
di = _dependables.find(filename);
if (di != _dependables.end()) {
return (*di).second;
}
return (PPDependableFile *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::get_dependable_file_by_pathname
// Access: Public
// Description: Given a dirname/filename for a particular dependable
// filename, return (or create and return) the
// corresponding PPDirectoryTree. This is different
// from find_dependable_file() in that an explicit
// dirname is given, and the entry will be created if
// it does not already exist. However, if the directory
// name does not exist, nothing is created, and NULL is
// returned.
////////////////////////////////////////////////////////////////////
PPDependableFile *PPDirectoryTree::
get_dependable_file_by_dirpath(const string &dirpath, bool is_header) {
size_t slash = dirpath.rfind('/');
if (slash == string::npos) {
// No valid directory name.
return (PPDependableFile *)NULL;
}
string dirname = dirpath.substr(0, slash);
string filename = dirpath.substr(slash + 1);
if (!dirname.empty() && dirname[0] == '+') {
// "+dirname/filename" means to look first for the file as an
// external file, meaning it has no dirname.
dirname = dirname.substr(1);
PPDependableFile *result = get_main_tree()->find_dependable_file(filename);
if (result != (PPDependableFile *)NULL) {
return result;
}
}
PPDirectory *dir = find_dirname(dirname);
if (dir == (PPDirectory *)NULL) {
// No valid directory name.
return (PPDependableFile *)NULL;
}
return dir->get_dependable_file(filename, is_header);
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::read_file_dependencies
// Access: Public
// Description: Before processing the source files, makes a pass and
// reads in all of the dependency cache files so we'll
// have a heads-up on which files depend on the others.
////////////////////////////////////////////////////////////////////
void PPDirectoryTree::
read_file_dependencies(const string &cache_filename) {
_root->read_file_dependencies(cache_filename);
RelatedTrees::iterator ri;
for (ri = _related_trees.begin(); ri != _related_trees.end(); ++ri) {
(*ri)->read_file_dependencies(cache_filename);
}
}
////////////////////////////////////////////////////////////////////
// Function: PPDirectoryTree::update_file_dependencies
// Access: Public
// Description: After all source processing has completed, makes one
// more pass through the directory hierarchy and writes
// out the inter-file dependency cache.
////////////////////////////////////////////////////////////////////
void PPDirectoryTree::
update_file_dependencies(const string &cache_filename) {
_root->update_file_dependencies(cache_filename);
RelatedTrees::iterator ri;
for (ri = _related_trees.begin(); ri != _related_trees.end(); ++ri) {
(*ri)->update_file_dependencies(cache_filename);
}
}