From 24c9106b7b2c3729985b89b06a2732ee3f555022 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 6 Apr 2016 12:55:15 +0200 Subject: [PATCH 1/3] cmNinjaTargetGenerator: Factor out helper for forced response file check --- Source/cmNinjaNormalTargetGenerator.cxx | 4 +--- Source/cmNinjaTargetGenerator.cxx | 7 +++++++ Source/cmNinjaTargetGenerator.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index c34df3cb1..54cacef0b 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -698,9 +698,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator(); int commandLineLengthLimit = 1; - const char* forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE"; - if (!mf->IsDefinitionSet(forceRspFile) && - cmSystemTools::GetEnv(forceRspFile) == 0) + if (!this->ForceResponseFile()) { commandLineLengthLimit = calculateCommandLineLengthLimit( globalGen.GetRuleCmdLength(this->LanguageLinkerRule())); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 5ff4fdb38..87f0e3af6 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -795,3 +795,10 @@ void cmNinjaTargetGenerator::addPoolNinjaVariable( vars["pool"] = pool; } } + +bool cmNinjaTargetGenerator::ForceResponseFile() +{ + static std::string const forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE"; + return (this->GetMakefile()->IsDefinitionSet(forceRspFile) || + cmSystemTools::GetEnv(forceRspFile) != 0); +} diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index e3ec4232f..371bc3cc6 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -152,6 +152,8 @@ protected: cmGeneratorTarget* target, cmNinjaVars& vars); + bool ForceResponseFile(); + private: cmLocalNinjaGenerator* LocalGenerator; /// List of object files for this target. From f9644a2d1b52fb566bdad9a7211a86a167d73859 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 6 Apr 2016 12:55:15 +0200 Subject: [PATCH 2/3] cmGlobalNinjaGenerator: Clarify logic for forcing use of response files Update the WriteBuild method to use a negative command line length limit to specify that we should force use of response files. --- Source/cmGlobalNinjaGenerator.cxx | 7 ++++--- Source/cmGlobalNinjaGenerator.h | 2 +- Source/cmNinjaNormalTargetGenerator.cxx | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index f12396f50..fadb0cf82 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -230,9 +230,10 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, std::string assignments = variable_assignments.str(); const std::string& args = arguments; bool useResponseFile = false; - if (cmdLineLimit > 0 - && args.size() + buildstr.size() + assignments.size() - > (size_t) cmdLineLimit) { + if (cmdLineLimit < 0 || + (cmdLineLimit > 0 && + (args.size() + buildstr.size() + assignments.size()) + > static_cast(cmdLineLimit))) { variable_assignments.str(std::string()); cmGlobalNinjaGenerator::WriteVariable(variable_assignments, "RSP_FILE", rspfile, "", 1); diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 3023a95c6..3093a1113 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -94,7 +94,7 @@ public: const cmNinjaDeps& orderOnlyDeps, const cmNinjaVars& variables, const std::string& rspfile = std::string(), - int cmdLineLimit = -1, + int cmdLineLimit = 0, bool* usedResponseFile = 0); /** diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 54cacef0b..322f37d2f 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -697,7 +697,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator(); - int commandLineLengthLimit = 1; + int commandLineLengthLimit = -1; if (!this->ForceResponseFile()) { commandLineLengthLimit = calculateCommandLineLengthLimit( From 7731e44f87ca9f70335f211a4ef64a1ea68c7f10 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 6 Apr 2016 12:55:15 +0200 Subject: [PATCH 3/3] Ninja: Honor CMAKE_NINJA_FORCE_RESPONSE_FILE for compile rules --- Source/cmNinjaTargetGenerator.cxx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 87f0e3af6..753a5ae49 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -341,11 +341,25 @@ cmNinjaTargetGenerator cmMakefile* mf = this->GetMakefile(); + std::string flags = "$FLAGS"; + std::string rspfile; + std::string rspcontent; + std::string responseFlag; + + if (this->ForceResponseFile()) + { + rspfile = "$RSP_FILE"; + responseFlag = "@" + rspfile; + rspcontent = " $DEFINES $INCLUDES $FLAGS"; + flags = responseFlag; + vars.Defines = ""; + vars.Includes = ""; + } + // Tell ninja dependency format so all deps can be loaded into a database std::string deptype; std::string depfile; std::string cldeps; - std::string flags = "$FLAGS"; if (this->NeedDepTypeMSVC(lang)) { deptype = "msvc"; @@ -460,8 +474,8 @@ cmNinjaTargetGenerator comment.str(), depfile, deptype, - /*rspfile*/ "", - /*rspcontent*/ "", + rspfile, + rspcontent, /*restat*/ "", /*generator*/ false); } @@ -641,6 +655,9 @@ cmNinjaTargetGenerator this->SetMsvcTargetPdbVariable(vars); + int const commandLineLengthLimit = this->ForceResponseFile() ? -1 : 0; + std::string const rspfile = objectFileName + ".rsp"; + this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), comment, rule, @@ -648,7 +665,10 @@ cmNinjaTargetGenerator explicitDeps, implicitDeps, orderOnlyDeps, - vars); + vars, + rspfile, + commandLineLengthLimit); + if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) { std::vector outputList;