From b6dc977ff17b451b43d8a67584400c3b53c7eb8f Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 30 May 2019 12:06:25 +0200 Subject: Ninja: Embrace temporary objects in scopes --- Source/cmNinjaTargetGenerator.cxx | 145 +++++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 65 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 5b8ed90..140730b 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -796,78 +796,93 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() const std::string& config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - std::vector customCommands; - this->GeneratorTarget->GetCustomCommands(customCommands, config); - for (cmSourceFile const* sf : customCommands) { - cmCustomCommand const* cc = sf->GetCustomCommand(); - this->GetLocalGenerator()->AddCustomCommandTarget( - cc, this->GetGeneratorTarget()); - // Record the custom commands for this target. The container is used - // in WriteObjectBuildStatement when called in a loop below. - this->CustomCommands.push_back(cc); + { + std::vector customCommands; + this->GeneratorTarget->GetCustomCommands(customCommands, config); + for (cmSourceFile const* sf : customCommands) { + cmCustomCommand const* cc = sf->GetCustomCommand(); + this->GetLocalGenerator()->AddCustomCommandTarget( + cc, this->GetGeneratorTarget()); + // Record the custom commands for this target. The container is used + // in WriteObjectBuildStatement when called in a loop below. + this->CustomCommands.push_back(cc); + } } - std::vector headerSources; - this->GeneratorTarget->GetHeaderSources(headerSources, config); - this->OSXBundleGenerator->GenerateMacOSXContentStatements( - headerSources, this->MacOSXContentGenerator.get()); - std::vector extraSources; - this->GeneratorTarget->GetExtraSources(extraSources, config); - this->OSXBundleGenerator->GenerateMacOSXContentStatements( - extraSources, this->MacOSXContentGenerator.get()); - std::vector externalObjects; - this->GeneratorTarget->GetExternalObjects(externalObjects, config); - for (cmSourceFile const* sf : externalObjects) { - this->Objects.push_back(this->GetSourceFilePath(sf)); + { + std::vector headerSources; + this->GeneratorTarget->GetHeaderSources(headerSources, config); + this->OSXBundleGenerator->GenerateMacOSXContentStatements( + headerSources, this->MacOSXContentGenerator.get()); } - - cmNinjaDeps orderOnlyDeps; - this->GetLocalGenerator()->AppendTargetDepends( - this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering); - - // Add order-only dependencies on other files associated with the target. - cmAppend(orderOnlyDeps, this->ExtraFiles); - - // Add order-only dependencies on custom command outputs. - for (cmCustomCommand const* cc : this->CustomCommands) { - cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), - this->GetLocalGenerator()); - const std::vector& ccoutputs = ccg.GetOutputs(); - const std::vector& ccbyproducts = ccg.GetByproducts(); - std::transform(ccoutputs.begin(), ccoutputs.end(), - std::back_inserter(orderOnlyDeps), MapToNinjaPath()); - std::transform(ccbyproducts.begin(), ccbyproducts.end(), - std::back_inserter(orderOnlyDeps), MapToNinjaPath()); + { + std::vector extraSources; + this->GeneratorTarget->GetExtraSources(extraSources, config); + this->OSXBundleGenerator->GenerateMacOSXContentStatements( + extraSources, this->MacOSXContentGenerator.get()); } - - std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end()); - orderOnlyDeps.erase(std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()), - orderOnlyDeps.end()); - - // The phony target must depend on at least one input or ninja will explain - // that "output ... of phony edge with no inputs doesn't exist" and consider - // the phony output "dirty". - if (orderOnlyDeps.empty()) { - // Any path that always exists will work here. It would be nice to - // use just "." but that is not supported by Ninja < 1.7. - std::string tgtDir; - tgtDir += this->LocalGenerator->GetCurrentBinaryDirectory(); - tgtDir += "/"; - tgtDir += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir)); + { + std::vector externalObjects; + this->GeneratorTarget->GetExternalObjects(externalObjects, config); + for (cmSourceFile const* sf : externalObjects) { + this->Objects.push_back(this->GetSourceFilePath(sf)); + } } { - cmNinjaDeps orderOnlyTarget; - orderOnlyTarget.push_back(this->OrderDependsTargetForTarget()); - this->GetGlobalGenerator()->WritePhonyBuild( - this->GetBuildFileStream(), - "Order-only phony target for " + this->GetTargetName(), orderOnlyTarget, - cmNinjaDeps(), cmNinjaDeps(), orderOnlyDeps); + cmNinjaDeps orderOnlyDeps; + this->GetLocalGenerator()->AppendTargetDepends( + this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering); + + // Add order-only dependencies on other files associated with the target. + cmAppend(orderOnlyDeps, this->ExtraFiles); + + // Add order-only dependencies on custom command outputs. + for (cmCustomCommand const* cc : this->CustomCommands) { + cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), + this->GetLocalGenerator()); + const std::vector& ccoutputs = ccg.GetOutputs(); + const std::vector& ccbyproducts = ccg.GetByproducts(); + std::transform(ccoutputs.begin(), ccoutputs.end(), + std::back_inserter(orderOnlyDeps), MapToNinjaPath()); + std::transform(ccbyproducts.begin(), ccbyproducts.end(), + std::back_inserter(orderOnlyDeps), MapToNinjaPath()); + } + + std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end()); + orderOnlyDeps.erase( + std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()), + orderOnlyDeps.end()); + + // The phony target must depend on at least one input or ninja will explain + // that "output ... of phony edge with no inputs doesn't exist" and + // consider the phony output "dirty". + if (orderOnlyDeps.empty()) { + // Any path that always exists will work here. It would be nice to + // use just "." but that is not supported by Ninja < 1.7. + std::string tgtDir; + tgtDir += this->LocalGenerator->GetCurrentBinaryDirectory(); + tgtDir += "/"; + tgtDir += + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); + orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir)); + } + + { + cmNinjaDeps orderOnlyTarget; + orderOnlyTarget.push_back(this->OrderDependsTargetForTarget()); + this->GetGlobalGenerator()->WritePhonyBuild( + this->GetBuildFileStream(), + "Order-only phony target for " + this->GetTargetName(), + orderOnlyTarget, cmNinjaDeps(), cmNinjaDeps(), orderOnlyDeps); + } } - std::vector objectSources; - this->GeneratorTarget->GetObjectSources(objectSources, config); - for (cmSourceFile const* sf : objectSources) { - this->WriteObjectBuildStatement(sf); + + { + std::vector objectSources; + this->GeneratorTarget->GetObjectSources(objectSources, config); + for (cmSourceFile const* sf : objectSources) { + this->WriteObjectBuildStatement(sf); + } } for (auto const& langDDIFiles : this->DDIFiles) { -- cgit v0.12