diff options
author | Brad King <brad.king@kitware.com> | 2014-12-08 20:12:51 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-12-08 20:35:50 (GMT) |
commit | ce331bab929c5a38e048ba15d7393dcf96fad9e1 (patch) | |
tree | 21357d2d12d5b425b596bca81cbd70e91b912ba0 /Source/cmGlobalGenerator.cxx | |
parent | 09498b2ead29a64816e5c301b7465164cec25c1c (diff) | |
download | CMake-ce331bab929c5a38e048ba15d7393dcf96fad9e1.zip CMake-ce331bab929c5a38e048ba15d7393dcf96fad9e1.tar.gz CMake-ce331bab929c5a38e048ba15d7393dcf96fad9e1.tar.bz2 |
find_library: Fix repeat call after changing directory content (#15293)
We use cmGlobalGenerator::GetDirectoryContent to avoid repeating
directory listings. However, GetDirectoryContent loads content from
disk at most once. This breaks find_library calls that occur when disk
content has changed since preceding find_library calls.
Teach cmGlobalGenerator::GetDirectoryContent to save the directory
modification time when content is loaded and re-load content if it
changes.
Create a RunCMake.find_library test with a case covering this.
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 29ab7d0..dd7fbc8 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2725,7 +2725,9 @@ void cmGlobalGenerator::AddToManifest(const std::string& config, // Add to the content listing for the file's directory. std::string dir = cmSystemTools::GetFilenamePath(f); std::string file = cmSystemTools::GetFilenameName(f); - this->DirectoryContentMap[dir].insert(file); + DirectoryContent& dc = this->DirectoryContentMap[dir]; + dc.Generated.insert(file); + dc.All.insert(file); } //---------------------------------------------------------------------------- @@ -2733,25 +2735,32 @@ std::set<std::string> const& cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk) { DirectoryContent& dc = this->DirectoryContentMap[dir]; - if(needDisk && !dc.LoadedFromDisk) + if(needDisk) { - // Load the directory content from disk. - cmsys::Directory d; - if(d.Load(dir)) + long mt = cmSystemTools::ModifiedTime(dir); + if (mt != dc.LastDiskTime) { - unsigned long n = d.GetNumberOfFiles(); - for(unsigned long i = 0; i < n; ++i) + // Reset to non-loaded directory content. + dc.All = dc.Generated; + + // Load the directory content from disk. + cmsys::Directory d; + if(d.Load(dir)) { - const char* f = d.GetFile(i); - if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0) + unsigned long n = d.GetNumberOfFiles(); + for(unsigned long i = 0; i < n; ++i) { - dc.insert(f); + const char* f = d.GetFile(i); + if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0) + { + dc.All.insert(f); + } } } + dc.LastDiskTime = mt; } - dc.LoadedFromDisk = true; } - return dc; + return dc.All; } //---------------------------------------------------------------------------- |