mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
fix caching
This commit is contained in:
parent
82a8cc00cf
commit
c72ae36a9f
@ -73,7 +73,7 @@ update_from_cache(const vector<string> &words) {
|
||||
time_t mtime = strtol(words[1].c_str(), (char **)NULL, 10);
|
||||
if (mtime == get_mtime()) {
|
||||
// The modification matches; preserve the cache information.
|
||||
PPDirectoryTree *tree = _directory->get_tree()->get_main_tree();
|
||||
PPDirectoryTree *tree = _directory->get_tree();
|
||||
|
||||
_dependencies.clear();
|
||||
vector<string>::const_iterator wi;
|
||||
@ -125,6 +125,9 @@ write_cache(ostream &out) {
|
||||
if ((*di)._okcircular) {
|
||||
out << "/";
|
||||
}
|
||||
if ((*di)._file->get_directory()->get_tree() != get_directory()->get_tree()) {
|
||||
out << "+";
|
||||
}
|
||||
out << (*di)._file->get_dirpath();
|
||||
}
|
||||
|
||||
@ -361,18 +364,23 @@ compute_dependencies(string &circularity) {
|
||||
|
||||
if ((_flags & F_from_cache) == 0) {
|
||||
// Now open the file and scan it for #include statements.
|
||||
ifstream in(get_fullpath().c_str());
|
||||
if (!in) {
|
||||
Filename filename(get_fullpath());
|
||||
filename.set_text();
|
||||
ifstream in;
|
||||
if (!filename.open_read(in)) {
|
||||
// Can't read the file, or the file doesn't exist. Interesting.
|
||||
if (exists()) {
|
||||
cerr << "Warning: dependent file " << get_fullpath()
|
||||
cerr << "Warning: dependent file " << filename
|
||||
<< " exists but cannot be read.\n";
|
||||
} else {
|
||||
cerr << "Warning: dependent file " << get_fullpath()
|
||||
cerr << "Warning: dependent file " << filename
|
||||
<< " does not exist.\n";
|
||||
}
|
||||
|
||||
} else {
|
||||
if (verbose) {
|
||||
cerr << "Reading (dep) \"" << filename << "\"\n";
|
||||
}
|
||||
PPDirectoryTree *tree = _directory->get_tree()->get_main_tree();
|
||||
|
||||
bool okcircular = false;
|
||||
|
@ -491,6 +491,10 @@ scan_extra_depends(const string &cache_filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
cerr << "Scanning external directory " << get_fullpath() << "\n";
|
||||
}
|
||||
|
||||
vector<string>::const_iterator fi;
|
||||
for (fi = filenames.begin(); fi != filenames.end(); ++fi) {
|
||||
string filename = (*fi);
|
||||
@ -512,12 +516,13 @@ scan_extra_depends(const string &cache_filename) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PPDirectory::
|
||||
read_source_file(const string &prefix, PPNamedScopes *named_scopes) {
|
||||
string source_filename = prefix + SOURCE_FILENAME;
|
||||
Filename source_filename = prefix + SOURCE_FILENAME;
|
||||
source_filename.set_text();
|
||||
|
||||
ifstream in(source_filename.c_str());
|
||||
if (in) {
|
||||
ifstream in;
|
||||
if (source_filename.open_read(in)) {
|
||||
if (verbose) {
|
||||
cerr << "Reading (dir) \"" << source_filename << "\"\n";
|
||||
cerr << "Reading (dir) \"" << source_filename << "\"\n";
|
||||
}
|
||||
|
||||
named_scopes->set_current(_dirname);
|
||||
@ -706,28 +711,33 @@ compute_depends_index() {
|
||||
void PPDirectory::
|
||||
read_file_dependencies(const string &cache_filename) {
|
||||
// Open up the dependency cache file in the directory.
|
||||
string cache_pathname = get_path() + "/" + cache_filename;
|
||||
ifstream in(cache_pathname.c_str());
|
||||
if (!in) {
|
||||
Filename cache_pathname(get_fullpath(), cache_filename);
|
||||
cache_pathname.set_text();
|
||||
ifstream in;
|
||||
|
||||
if (!cache_pathname.open_read(in)) {
|
||||
// Can't read it. Maybe it's not there. No problem.
|
||||
return;
|
||||
}
|
||||
if (verbose) {
|
||||
cerr << "Reading (dep) \"" << cache_pathname.c_str() << "\"\n";
|
||||
}
|
||||
|
||||
string line;
|
||||
getline(in, line);
|
||||
while (!in.fail() && !in.eof()) {
|
||||
vector<string> words;
|
||||
tokenize_whitespace(line, words);
|
||||
if (words.size() >= 2) {
|
||||
PPDependableFile *file = get_dependable_file(words[0], false);
|
||||
file->update_from_cache(words);
|
||||
if (verbose) {
|
||||
cerr << "Couldn't read \"" << cache_pathname << "\"\n";
|
||||
}
|
||||
} else {
|
||||
if (verbose) {
|
||||
cerr << "Loading cache \"" << cache_pathname << "\"\n";
|
||||
}
|
||||
getline(in, line);
|
||||
}
|
||||
|
||||
string line;
|
||||
getline(in, line);
|
||||
while (!in.fail() && !in.eof()) {
|
||||
vector<string> words;
|
||||
tokenize_whitespace(line, words);
|
||||
if (words.size() >= 2) {
|
||||
PPDependableFile *file = get_dependable_file(words[0], false);
|
||||
file->update_from_cache(words);
|
||||
}
|
||||
getline(in, line);
|
||||
}
|
||||
}
|
||||
|
||||
Children::iterator ci;
|
||||
for (ci = _children.begin(); ci != _children.end(); ++ci) {
|
||||
(*ci)->read_file_dependencies(cache_filename);
|
||||
@ -771,13 +781,18 @@ update_file_dependencies(const string &cache_filename) {
|
||||
cerr << "Cannot update cache dependency file " << cache_pathname << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
cerr << "Rewriting cache " << cache_pathname << "\n";
|
||||
}
|
||||
|
||||
// Walk through our list of dependable files, writing them out the
|
||||
// the cache file.
|
||||
bool external_tree = (_tree->get_main_tree() != _tree);
|
||||
Dependables::const_iterator di;
|
||||
for (di = _dependables.begin(); di != _dependables.end(); ++di) {
|
||||
PPDependableFile *file = (*di).second;
|
||||
if (file->was_examined()) {
|
||||
if (file->was_examined() || external_tree) {
|
||||
if (file->is_circularity()) {
|
||||
cerr << "Warning: circular #include directives:\n"
|
||||
<< " " << file->get_circularity() << "\n";
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "ppDirectoryTree.h"
|
||||
#include "ppDirectory.h"
|
||||
#include "ppDependableFile.h"
|
||||
#include "tokenize.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -257,6 +258,16 @@ get_dependable_file_by_dirpath(const string &dirpath, bool is_header) {
|
||||
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.
|
||||
@ -276,6 +287,11 @@ get_dependable_file_by_dirpath(const string &dirpath, bool is_header) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user