mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
Ninja: Avoid creating the same object directories repeatedly
The Ninja generator created the object and PDB directories again for every source file. Remember the directories created or found to exist during generation.
This commit is contained in:
3 files changed
+22
-3
No files matched your search
@@ -637,6 +637,7 @@ void cmGlobalNinjaGenerator::Generate()
|
||||
for (auto& it : this->Configs) {
|
||||
it.second.TargetDependsClosures.clear();
|
||||
}
|
||||
this->ExistingDirectories.clear();
|
||||
|
||||
this->TargetAll = this->NinjaOutputPath("all");
|
||||
this->CMakeCacheFile = this->NinjaOutputPath("CMakeCache.txt");
|
||||
@@ -2451,6 +2452,17 @@ std::string cmGlobalNinjaGenerator::NinjaOutputPath(
|
||||
return cmStrCat(this->OutputPathPrefix, path);
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::EnsureDirectoryExists(std::string const& path)
|
||||
{
|
||||
// The same object and PDB directories are requested for every source.
|
||||
if (this->ExistingDirectories.count(path)) {
|
||||
return;
|
||||
}
|
||||
if (cmSystemTools::MakeDirectory(path)) {
|
||||
this->ExistingDirectories.insert(path);
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::StripNinjaOutputPathPrefixAsSuffix(
|
||||
std::string& path)
|
||||
{
|
||||
|
||||
@@ -432,6 +432,10 @@ public:
|
||||
bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); }
|
||||
void StripNinjaOutputPathPrefixAsSuffix(std::string& path);
|
||||
|
||||
/// Create a directory unless it was already created or found to exist
|
||||
/// during this generation.
|
||||
void EnsureDirectoryExists(std::string const& path);
|
||||
|
||||
bool WriteDyndepFile(
|
||||
std::string const& dir_top_src, std::string const& dir_top_bld,
|
||||
std::string const& dir_cur_src, std::string const& dir_cur_bld,
|
||||
@@ -576,6 +580,9 @@ private:
|
||||
/// The set of custom command outputs we have seen.
|
||||
std::set<std::string> CustomCommandOutputs;
|
||||
|
||||
/// Directories known to exist, see EnsureDirectoryExists.
|
||||
std::unordered_set<std::string> ExistingDirectories;
|
||||
|
||||
/// The mapping from source file to assumed dependencies.
|
||||
std::map<std::string, std::set<std::string>> AssumedSourceDependencies;
|
||||
|
||||
|
||||
@@ -2801,15 +2801,15 @@ std::string cmNinjaTargetGenerator::GetSwiftModuleOutput(
|
||||
void cmNinjaTargetGenerator::EnsureDirectoryExists(
|
||||
std::string const& path) const
|
||||
{
|
||||
cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
|
||||
if (cmSystemTools::FileIsFullPath(path)) {
|
||||
cmSystemTools::MakeDirectory(path);
|
||||
gg->EnsureDirectoryExists(path);
|
||||
} else {
|
||||
cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
|
||||
std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory();
|
||||
// Also ensures there is a trailing slash.
|
||||
gg->StripNinjaOutputPathPrefixAsSuffix(fullPath);
|
||||
fullPath += path;
|
||||
cmSystemTools::MakeDirectory(fullPath);
|
||||
gg->EnsureDirectoryExists(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user