From 62d59323899330197e795872c13c1d300a97d088 Mon Sep 17 00:00:00 2001 From: Daniel Eiband Date: Wed, 11 Sep 2019 11:32:23 +0200 Subject: Refatoring: Extract AnyOutputMatches utility --- Source/cmMakefile.cxx | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 16cc453..3a80b02 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2012,27 +2012,34 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type, return &it->second; } +namespace { +bool AnyOutputMatches(const std::string& name, + const std::vector& outputs) +{ + for (std::string const& output : outputs) { + std::string::size_type pos = output.rfind(name); + // If the output matches exactly + if (pos != std::string::npos && pos == output.size() - name.size() && + (pos == 0 || output[pos - 1] == '/')) { + return true; + } + } + return false; +} +} + cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput( const std::string& name) const { - std::string out; - - // look through all the source files that have custom commands - // and see if the custom command has the passed source file as an output + // Look through all the source files that have custom commands and see if the + // custom command has the passed source file as an output. for (cmSourceFile* src : this->SourceFiles) { - // does this source file have a custom command? + // Does this source file have a custom command? if (src->GetCustomCommand()) { // Does the output of the custom command match the source file name? - const std::vector& outputs = - src->GetCustomCommand()->GetOutputs(); - for (std::string const& output : outputs) { - out = output; - std::string::size_type pos = out.rfind(name); - // If the output matches exactly - if (pos != std::string::npos && pos == out.size() - name.size() && - (pos == 0 || out[pos - 1] == '/')) { - return src; - } + if (AnyOutputMatches(name, src->GetCustomCommand()->GetOutputs())) { + // Return the first matching output. + return src; } } } -- cgit v0.12