summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorRosen Matev <r.matev@gmail.com>2019-05-10 12:37:39 (GMT)
committerRosen Matev <r.matev@gmail.com>2019-05-14 13:58:00 (GMT)
commit9f76961de87d8911d13867d469c38087e47a0b60 (patch)
tree13cf78b16bcbf13e6a4aef6b6963c38137083b21 /Source
parent5a2023f904c5da80a4614c133b7d7d8f4f719e96 (diff)
downloadCMake-9f76961de87d8911d13867d469c38087e47a0b60.zip
CMake-9f76961de87d8911d13867d469c38087e47a0b60.tar.gz
CMake-9f76961de87d8911d13867d469c38087e47a0b60.tar.bz2
Support job pools in custom commands and targets
Provide a way for custom commands and targets to set the pool variable of the ninja build statement. Setting `JOB_POOL` is not compatible with `USES_TERMINAL`, which implies the `console` pool. The option is silently ignored with other generators. Closes: #18483
Diffstat (limited to 'Source')
-rw-r--r--Source/cmAddCustomCommandCommand.cxx19
-rw-r--r--Source/cmAddCustomTargetCommand.cxx14
-rw-r--r--Source/cmCustomCommand.cxx10
-rw-r--r--Source/cmCustomCommand.h5
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx10
-rw-r--r--Source/cmGlobalNinjaGenerator.h3
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx2
-rw-r--r--Source/cmLocalNinjaGenerator.cxx2
-rw-r--r--Source/cmMakefile.cxx29
-rw-r--r--Source/cmMakefile.h10
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.cxx2
11 files changed, 78 insertions, 28 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
index a840f17..0be3c85 100644
--- a/Source/cmAddCustomCommandCommand.cxx
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -31,7 +31,7 @@ bool cmAddCustomCommandCommand::InitialPass(
return false;
}
- std::string source, target, main_dependency, working, depfile;
+ std::string source, target, main_dependency, working, depfile, job_pool;
std::string comment_buffer;
const char* comment = nullptr;
std::vector<std::string> depends, outputs, output, byproducts;
@@ -65,6 +65,7 @@ bool cmAddCustomCommandCommand::InitialPass(
doing_comment,
doing_working_directory,
doing_depfile,
+ doing_job_pool,
doing_nothing
};
@@ -81,6 +82,7 @@ bool cmAddCustomCommandCommand::InitialPass(
MAKE_STATIC_KEYWORD(DEPENDS);
MAKE_STATIC_KEYWORD(DEPFILE);
MAKE_STATIC_KEYWORD(IMPLICIT_DEPENDS);
+ MAKE_STATIC_KEYWORD(JOB_POOL);
MAKE_STATIC_KEYWORD(MAIN_DEPENDENCY);
MAKE_STATIC_KEYWORD(OUTPUT);
MAKE_STATIC_KEYWORD(OUTPUTS);
@@ -104,6 +106,7 @@ bool cmAddCustomCommandCommand::InitialPass(
keywords.insert(keyDEPENDS);
keywords.insert(keyDEPFILE);
keywords.insert(keyIMPLICIT_DEPENDS);
+ keywords.insert(keyJOB_POOL);
keywords.insert(keyMAIN_DEPENDENCY);
keywords.insert(keyOUTPUT);
keywords.insert(keyOUTPUTS);
@@ -170,6 +173,8 @@ bool cmAddCustomCommandCommand::InitialPass(
this->Makefile->GetGlobalGenerator()->GetName());
return false;
}
+ } else if (copy == keyJOB_POOL) {
+ doing = doing_job_pool;
}
} else {
std::string filename;
@@ -211,6 +216,9 @@ bool cmAddCustomCommandCommand::InitialPass(
case doing_depfile:
depfile = copy;
break;
+ case doing_job_pool:
+ job_pool = copy;
+ break;
case doing_working_directory:
working = copy;
break;
@@ -318,6 +326,11 @@ bool cmAddCustomCommandCommand::InitialPass(
return false;
}
+ if (uses_terminal && !job_pool.empty()) {
+ this->SetError("JOB_POOL is shadowed by USES_TERMINAL.");
+ return false;
+ }
+
// Choose which mode of the command to use.
bool escapeOldStyle = !verbatim;
if (source.empty() && output.empty()) {
@@ -325,14 +338,14 @@ bool cmAddCustomCommandCommand::InitialPass(
std::vector<std::string> no_depends;
this->Makefile->AddCustomCommandToTarget(
target, byproducts, no_depends, commandLines, cctype, comment,
- working.c_str(), escapeOldStyle, uses_terminal, depfile,
+ working.c_str(), escapeOldStyle, uses_terminal, depfile, job_pool,
command_expand_lists);
} else if (target.empty()) {
// Target is empty, use the output.
this->Makefile->AddCustomCommandToOutput(
output, byproducts, depends, main_dependency, commandLines, comment,
working.c_str(), false, escapeOldStyle, uses_terminal,
- command_expand_lists, depfile);
+ command_expand_lists, depfile, job_pool);
// Add implicit dependency scanning requests if any were given.
if (!implicit_depends.empty()) {
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx
index 8240d3e..0ecd5f5 100644
--- a/Source/cmAddCustomTargetCommand.cxx
+++ b/Source/cmAddCustomTargetCommand.cxx
@@ -52,6 +52,7 @@ bool cmAddCustomTargetCommand::InitialPass(
std::string comment_buffer;
const char* comment = nullptr;
std::vector<std::string> sources;
+ std::string job_pool;
// Keep track of parser state.
enum tdoing
@@ -62,6 +63,7 @@ bool cmAddCustomTargetCommand::InitialPass(
doing_working_directory,
doing_comment,
doing_source,
+ doing_job_pool,
doing_nothing
};
tdoing doing = doing_command;
@@ -97,6 +99,8 @@ bool cmAddCustomTargetCommand::InitialPass(
command_expand_lists = true;
} else if (copy == "COMMENT") {
doing = doing_comment;
+ } else if (copy == "JOB_POOL") {
+ doing = doing_job_pool;
} else if (copy == "COMMAND") {
doing = doing_command;
@@ -137,6 +141,9 @@ bool cmAddCustomTargetCommand::InitialPass(
case doing_source:
sources.push_back(copy);
break;
+ case doing_job_pool:
+ job_pool = copy;
+ break;
default:
this->SetError("Wrong syntax. Unknown type of argument.");
return false;
@@ -200,12 +207,17 @@ bool cmAddCustomTargetCommand::InitialPass(
return true;
}
+ if (uses_terminal && !job_pool.empty()) {
+ this->SetError("JOB_POOL is shadowed by USES_TERMINAL.");
+ return false;
+ }
+
// Add the utility target to the makefile.
bool escapeOldStyle = !verbatim;
cmTarget* target = this->Makefile->AddUtilityCommand(
targetName, cmMakefile::TargetOrigin::Project, excludeFromAll,
working_directory.c_str(), byproducts, depends, commandLines,
- escapeOldStyle, comment, uses_terminal, command_expand_lists);
+ escapeOldStyle, comment, uses_terminal, command_expand_lists, job_pool);
// Add additional user-specified source files to the target.
target->AddSources(sources);
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx
index 242ceaa..ad8c9b9 100644
--- a/Source/cmCustomCommand.cxx
+++ b/Source/cmCustomCommand.cxx
@@ -134,3 +134,13 @@ void cmCustomCommand::SetDepfile(const std::string& depfile)
{
this->Depfile = depfile;
}
+
+const std::string& cmCustomCommand::GetJobPool() const
+{
+ return this->JobPool;
+}
+
+void cmCustomCommand::SetJobPool(const std::string& job_pool)
+{
+ this->JobPool = job_pool;
+}
diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h
index 50f15a4..9a6f239 100644
--- a/Source/cmCustomCommand.h
+++ b/Source/cmCustomCommand.h
@@ -89,6 +89,10 @@ public:
const std::string& GetDepfile() const;
void SetDepfile(const std::string& depfile);
+ /** Set/Get the job_pool (used by the Ninja generator) */
+ const std::string& GetJobPool() const;
+ void SetJobPool(const std::string& job_pool);
+
private:
std::vector<std::string> Outputs;
std::vector<std::string> Byproducts;
@@ -99,6 +103,7 @@ private:
std::string Comment;
std::string WorkingDirectory;
std::string Depfile;
+ std::string JobPool;
bool HaveComment = false;
bool EscapeAllowMakeVars = false;
bool EscapeOldStyle = true;
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 4fa6ee6..522ffe6 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -252,8 +252,9 @@ void cmGlobalNinjaGenerator::AddCustomCommandRule()
void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
const std::string& command, const std::string& description,
- const std::string& comment, const std::string& depfile, bool uses_terminal,
- bool restat, const cmNinjaDeps& outputs, const cmNinjaDeps& deps,
+ const std::string& comment, const std::string& depfile,
+ const std::string& job_pool, bool uses_terminal, bool restat,
+ const cmNinjaDeps& outputs, const cmNinjaDeps& deps,
const cmNinjaDeps& orderOnly)
{
std::string cmd = command; // NOLINT(*)
@@ -273,6 +274,8 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
}
if (uses_terminal && SupportsConsolePool()) {
vars["pool"] = "console";
+ } else if (!job_pool.empty()) {
+ vars["pool"] = job_pool;
}
if (!depfile.empty()) {
vars["depfile"] = depfile;
@@ -951,7 +954,8 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
std::back_inserter(orderOnlyDeps));
WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
"Assume dependencies for generated source file.",
- /*depfile*/ "", /*uses_terminal*/ false,
+ /*depfile*/ "", /*job_pool*/ "",
+ /*uses_terminal*/ false,
/*restat*/ true, cmNinjaDeps(1, asd.first),
cmNinjaDeps(), orderOnlyDeps);
}
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index efd1d8f..3ab4171 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -129,7 +129,8 @@ public:
void WriteCustomCommandBuild(const std::string& command,
const std::string& description,
const std::string& comment,
- const std::string& depfile, bool uses_terminal,
+ const std::string& depfile,
+ const std::string& pool, bool uses_terminal,
bool restat, const cmNinjaDeps& outputs,
const cmNinjaDeps& deps = cmNinjaDeps(),
const cmNinjaDeps& orderOnly = cmNinjaDeps());
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index db673bb..69cf2b7 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -568,7 +568,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
gen->GetMakefile()->AddCustomCommandToTarget(
target->GetName(), no_byproducts, no_depends, commandLines,
cmTarget::POST_BUILD, "Depend check for xcode", dir.c_str(), true,
- false, "", false, cmMakefile::AcceptObjectLibraryCommands);
+ false, "", "", false, cmMakefile::AcceptObjectLibraryCommands);
}
if (!this->IsExcluded(target)) {
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index f4e3ed8..3704864 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -509,7 +509,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild(
this->BuildCommandLine(cmdLines, customStep),
this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0],
- cc->GetDepfile(), cc->GetUsesTerminal(),
+ cc->GetDepfile(), cc->GetJobPool(), cc->GetUsesTerminal(),
/*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps,
orderOnlyDeps);
}
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6c390f7..ca5f009 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -814,8 +814,8 @@ void cmMakefile::AddCustomCommandToTarget(
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle,
- bool uses_terminal, const std::string& depfile, bool command_expand_lists,
- ObjectLibraryCommands objLibraryCommands)
+ bool uses_terminal, const std::string& depfile, const std::string& job_pool,
+ bool command_expand_lists, ObjectLibraryCommands objLibraryCommands)
{
// Find the target to which to add the custom command.
cmTargets::iterator ti = this->Targets.find(target);
@@ -890,6 +890,7 @@ void cmMakefile::AddCustomCommandToTarget(
cc.SetUsesTerminal(uses_terminal);
cc.SetCommandExpandLists(command_expand_lists);
cc.SetDepfile(depfile);
+ cc.SetJobPool(job_pool);
switch (type) {
case cmTarget::PRE_BUILD:
t.AddPreBuildCommand(cc);
@@ -909,7 +910,8 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
const std::vector<std::string>& depends, const std::string& main_dependency,
const cmCustomCommandLines& commandLines, const char* comment,
const char* workingDir, bool replace, bool escapeOldStyle,
- bool uses_terminal, bool command_expand_lists, const std::string& depfile)
+ bool uses_terminal, bool command_expand_lists, const std::string& depfile,
+ const std::string& job_pool)
{
// Make sure there is at least one output.
if (outputs.empty()) {
@@ -1003,6 +1005,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
cc->SetUsesTerminal(uses_terminal);
cc->SetCommandExpandLists(command_expand_lists);
cc->SetDepfile(depfile);
+ cc->SetJobPool(job_pool);
file->SetCustomCommand(cc);
this->UpdateOutputToSourceMap(outputs, file);
}
@@ -1040,7 +1043,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
const std::string& main_dependency, const cmCustomCommandLines& commandLines,
const char* comment, const char* workingDir, bool replace,
bool escapeOldStyle, bool uses_terminal, bool command_expand_lists,
- const std::string& depfile)
+ const std::string& depfile, const std::string& job_pool)
{
std::vector<std::string> outputs;
outputs.push_back(output);
@@ -1048,7 +1051,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
return this->AddCustomCommandToOutput(
outputs, no_byproducts, depends, main_dependency, commandLines, comment,
workingDir, replace, escapeOldStyle, uses_terminal, command_expand_lists,
- depfile);
+ depfile, job_pool);
}
void cmMakefile::AddCustomCommandOldStyle(
@@ -1142,13 +1145,14 @@ cmTarget* cmMakefile::AddUtilityCommand(
const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle,
- const char* comment, bool uses_terminal, bool command_expand_lists)
+ const char* comment, bool uses_terminal, bool command_expand_lists,
+ const std::string& job_pool)
{
std::vector<std::string> no_byproducts;
- return this->AddUtilityCommand(utilityName, origin, excludeFromAll,
- workingDirectory, no_byproducts, depends,
- commandLines, escapeOldStyle, comment,
- uses_terminal, command_expand_lists);
+ return this->AddUtilityCommand(
+ utilityName, origin, excludeFromAll, workingDirectory, no_byproducts,
+ depends, commandLines, escapeOldStyle, comment, uses_terminal,
+ command_expand_lists, job_pool);
}
cmTarget* cmMakefile::AddUtilityCommand(
@@ -1156,7 +1160,8 @@ cmTarget* cmMakefile::AddUtilityCommand(
const char* workingDirectory, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle,
- const char* comment, bool uses_terminal, bool command_expand_lists)
+ const char* comment, bool uses_terminal, bool command_expand_lists,
+ const std::string& job_pool)
{
// Create a target instance for this utility.
cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName);
@@ -1182,7 +1187,7 @@ cmTarget* cmMakefile::AddUtilityCommand(
this->AddCustomCommandToOutput(
forced, byproducts, depends, no_main_dependency, commandLines, comment,
workingDirectory, no_replace, escapeOldStyle, uses_terminal,
- command_expand_lists);
+ command_expand_lists, /*depfile=*/"", job_pool);
cmSourceFile* sf = target->AddSourceCMP0049(force);
// The output is not actually created so mark it symbolic.
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 8cc14f3..be1ac5a 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -150,7 +150,7 @@ public:
const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle = true,
bool uses_terminal = false, const std::string& depfile = "",
- bool command_expand_lists = false,
+ const std::string& job_pool = "", bool command_expand_lists = false,
ObjectLibraryCommands objLibraryCommands = RejectObjectLibraryCommands);
cmSourceFile* AddCustomCommandToOutput(
const std::vector<std::string>& outputs,
@@ -160,14 +160,14 @@ public:
const cmCustomCommandLines& commandLines, const char* comment,
const char* workingDir, bool replace = false, bool escapeOldStyle = true,
bool uses_terminal = false, bool command_expand_lists = false,
- const std::string& depfile = "");
+ const std::string& depfile = "", const std::string& job_pool = "");
cmSourceFile* AddCustomCommandToOutput(
const std::string& output, const std::vector<std::string>& depends,
const std::string& main_dependency,
const cmCustomCommandLines& commandLines, const char* comment,
const char* workingDir, bool replace = false, bool escapeOldStyle = true,
bool uses_terminal = false, bool command_expand_lists = false,
- const std::string& depfile = "");
+ const std::string& depfile = "", const std::string& job_pool = "");
void AddCustomCommandOldStyle(const std::string& target,
const std::vector<std::string>& outputs,
const std::vector<std::string>& depends,
@@ -223,14 +223,14 @@ public:
const char* workingDirectory, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
const char* comment = nullptr, bool uses_terminal = false,
- bool command_expand_lists = false);
+ bool command_expand_lists = false, const std::string& job_pool = "");
cmTarget* AddUtilityCommand(
const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
const char* comment = nullptr, bool uses_terminal = false,
- bool command_expand_lists = false);
+ bool command_expand_lists = false, const std::string& job_pool = "");
/**
* Add a subdirectory to the build.
diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx
index 95fcf66..ab777c8 100644
--- a/Source/cmNinjaUtilityTargetGenerator.cxx
+++ b/Source/cmNinjaUtilityTargetGenerator.cxx
@@ -132,7 +132,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
this->GetGlobalGenerator()->WriteCustomCommandBuild(
command, desc, "Utility command for " + this->GetTargetName(),
- /*depfile*/ "", uses_terminal,
+ /*depfile*/ "", /*job_pool*/ "", uses_terminal,
/*restat*/ true, util_outputs, deps);
this->GetGlobalGenerator()->WritePhonyBuild(