Commit 3e0d5228 authored by tripta.g's avatar tripta.g Committed by Commit Bot

Use ContainsValue() instead of std::find() in tools/

BUG=561800

Review-Url: https://codereview.chromium.org/2938163003
Cr-Commit-Position: refs/heads/master@{#480018}
parent 9ea317b9
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "tools/gn/action_target_generator.h" #include "tools/gn/action_target_generator.h"
#include "base/stl_util.h"
#include "tools/gn/build_settings.h" #include "tools/gn/build_settings.h"
#include "tools/gn/err.h" #include "tools/gn/err.h"
#include "tools/gn/filesystem_utils.h" #include "tools/gn/filesystem_utils.h"
...@@ -73,10 +74,8 @@ void ActionTargetGenerator::DoRun() { ...@@ -73,10 +74,8 @@ void ActionTargetGenerator::DoRun() {
// together. // together.
const auto& required_args_substitutions = const auto& required_args_substitutions =
target_->action_values().args().required_types(); target_->action_values().args().required_types();
bool has_rsp_file_name = std::find(required_args_substitutions.begin(), bool has_rsp_file_name = base::ContainsValue(required_args_substitutions,
required_args_substitutions.end(), SUBSTITUTION_RSP_FILE_NAME);
SUBSTITUTION_RSP_FILE_NAME) !=
required_args_substitutions.end();
if (target_->action_values().uses_rsp_file() && !has_rsp_file_name) { if (target_->action_values().uses_rsp_file() && !has_rsp_file_name) {
*err_ = Err(function_call_, "Missing {{response_file_name}} in args.", *err_ = Err(function_call_, "Missing {{response_file_name}} in args.",
"This target defines response_file_contents but doesn't use\n" "This target defines response_file_contents but doesn't use\n"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/stl_util.h"
#include "tools/gn/functions.h" #include "tools/gn/functions.h"
#include "tools/gn/parse_tree.h" #include "tools/gn/parse_tree.h"
#include "tools/gn/scope.h" #include "tools/gn/scope.h"
...@@ -94,8 +95,7 @@ Value RunProcessFileTemplate(Scope* scope, ...@@ -94,8 +95,7 @@ Value RunProcessFileTemplate(Scope* scope,
} }
auto& types = subst.required_types(); auto& types = subst.required_types();
if (std::find(types.begin(), types.end(), if (base::ContainsValue(types, SUBSTITUTION_SOURCE_TARGET_RELATIVE)) {
SUBSTITUTION_SOURCE_TARGET_RELATIVE) != types.end()) {
*err = Err(template_arg, "Not a valid substitution type for the function."); *err = Err(template_arg, "Not a valid substitution type for the function.");
return Value(); return Value();
} }
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm> #include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/runtime_deps.h" #include "tools/gn/runtime_deps.h"
#include "tools/gn/scheduler.h" #include "tools/gn/scheduler.h"
...@@ -91,29 +90,25 @@ TEST(RuntimeDeps, Libs) { ...@@ -91,29 +90,25 @@ TEST(RuntimeDeps, Libs) {
EXPECT_TRUE(MakePair("./main", &main) == result[0]); EXPECT_TRUE(MakePair("./main", &main) == result[0]);
// The rest of the ordering is undefined. First the data files. // The rest of the ordering is undefined. First the data files.
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(result, MakePair("../../stat.dat", &stat)))
MakePair("../../stat.dat", &stat)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(
EXPECT_TRUE(std::find(result.begin(), result.end(), base::ContainsValue(result, MakePair("../../shared.dat", &shared)))
MakePair("../../shared.dat", &shared)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(
EXPECT_TRUE(std::find(result.begin(), result.end(), base::ContainsValue(result, MakePair("../../loadable.dat", &loadable)))
MakePair("../../loadable.dat", &loadable)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(base::ContainsValue(result, MakePair("../../set.dat", &set)))
EXPECT_TRUE(std::find(result.begin(), result.end(), << GetVectorDescription(result);
MakePair("../../set.dat", &set)) != EXPECT_TRUE(base::ContainsValue(result, MakePair("../../main.dat", &main)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
EXPECT_TRUE(std::find(result.begin(), result.end(),
MakePair("../../main.dat", &main)) !=
result.end()) << GetVectorDescription(result);
// Check the static library and loadable module. // Check the static library and loadable module.
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(result, MakePair("./libshared.so", &shared)))
MakePair("./libshared.so", &shared)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(
EXPECT_TRUE(std::find(result.begin(), result.end(), base::ContainsValue(result, MakePair("./libloadable.so", &loadable)))
MakePair("./libloadable.so", &loadable)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result);
} }
// Tests that executables that aren't listed as data deps aren't included in // Tests that executables that aren't listed as data deps aren't included in
...@@ -163,12 +158,11 @@ TEST(RuntimeDeps, ExeDataDep) { ...@@ -163,12 +158,11 @@ TEST(RuntimeDeps, ExeDataDep) {
EXPECT_TRUE(MakePair("./main", &main) == result[0]); EXPECT_TRUE(MakePair("./main", &main) == result[0]);
// The rest of the ordering is undefined. // The rest of the ordering is undefined.
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(result, MakePair("./datadep", &datadep)))
MakePair("./datadep", &datadep)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(
EXPECT_TRUE(std::find(result.begin(), result.end(), base::ContainsValue(result, MakePair("../../final_in.dat", &final_in)))
MakePair("../../final_in.dat", &final_in)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result);
} }
// Tests that action and copy outputs are considered if they're data deps, but // Tests that action and copy outputs are considered if they're data deps, but
...@@ -232,24 +226,23 @@ TEST(RuntimeDeps, ActionOutputs) { ...@@ -232,24 +226,23 @@ TEST(RuntimeDeps, ActionOutputs) {
EXPECT_TRUE(MakePair("./main", &main) == result[0]); EXPECT_TRUE(MakePair("./main", &main) == result[0]);
// The rest of the ordering is undefined. // The rest of the ordering is undefined.
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(
MakePair("../../datadep.data", &datadep)) != base::ContainsValue(result, MakePair("../../datadep.data", &datadep)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(
MakePair("../../datadep_copy.data", &datadep_copy)) != result, MakePair("../../datadep_copy.data", &datadep_copy)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(
MakePair("../../datadep.output", &datadep)) != base::ContainsValue(result, MakePair("../../datadep.output", &datadep)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(
MakePair("../../datadep_copy.output", &datadep_copy)) != result, MakePair("../../datadep_copy.output", &datadep_copy)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(result, MakePair("../../dep.data", &dep)))
MakePair("../../dep.data", &dep)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(
EXPECT_TRUE(std::find(result.begin(), result.end(), base::ContainsValue(result, MakePair("../../dep_copy/data/", &dep_copy)))
MakePair("../../dep_copy/data/", &dep_copy)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result);
// Explicitly asking for the runtime deps of an action target only includes // Explicitly asking for the runtime deps of an action target only includes
// the data and not all outputs. // the data and not all outputs.
...@@ -344,19 +337,16 @@ TEST(RuntimeDeps, CreateBundle) { ...@@ -344,19 +337,16 @@ TEST(RuntimeDeps, CreateBundle) {
// The rest of the ordering is undefined. // The rest of the ordering is undefined.
// The framework bundle's internal dependencies should not be incldued. // The framework bundle's internal dependencies should not be incldued.
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(
MakePair("Bundle.framework/", &bundle)) != base::ContainsValue(result, MakePair("Bundle.framework/", &bundle)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
// But direct data and data dependencies should be. // But direct data and data dependencies should be.
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(base::ContainsValue(result, MakePair("./datadep", &data_dep)))
MakePair("./datadep", &data_dep)) != << GetVectorDescription(result);
result.end()) << GetVectorDescription(result); EXPECT_TRUE(base::ContainsValue(result, MakePair("../../dd.data", &data_dep)))
EXPECT_TRUE(std::find(result.begin(), result.end(), << GetVectorDescription(result);
MakePair("../../dd.data", &data_dep)) != EXPECT_TRUE(base::ContainsValue(result, MakePair("../../b.data", &bundle)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
EXPECT_TRUE(std::find(result.begin(), result.end(),
MakePair("../../b.data", &bundle)) !=
result.end()) << GetVectorDescription(result);
} }
// Tests that a dependency duplicated in regular and data deps is processed // Tests that a dependency duplicated in regular and data deps is processed
...@@ -380,9 +370,9 @@ TEST(RuntimeDeps, Dupe) { ...@@ -380,9 +370,9 @@ TEST(RuntimeDeps, Dupe) {
// The results should be the executable and the copy output. // The results should be the executable and the copy output.
std::vector<std::pair<OutputFile, const Target*>> result = std::vector<std::pair<OutputFile, const Target*>> result =
ComputeRuntimeDeps(&target); ComputeRuntimeDeps(&target);
EXPECT_TRUE(std::find(result.begin(), result.end(), EXPECT_TRUE(
MakePair("../../action.output", &action)) != base::ContainsValue(result, MakePair("../../action.output", &action)))
result.end()) << GetVectorDescription(result); << GetVectorDescription(result);
} }
// Tests that actions can't have output substitutions. // Tests that actions can't have output substitutions.
......
...@@ -6,9 +6,8 @@ ...@@ -6,9 +6,8 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm>
#include "base/bind.h" #include "base/bind.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "tools/gn/config_values_extractors.h" #include "tools/gn/config_values_extractors.h"
...@@ -95,8 +94,7 @@ bool EnsureFileIsGeneratedByDependency(const Target* target, ...@@ -95,8 +94,7 @@ bool EnsureFileIsGeneratedByDependency(const Target* target,
Toolchain::ToolType tool_type; Toolchain::ToolType tool_type;
if (!target->GetOutputFilesForSource(source, &tool_type, &source_outputs)) if (!target->GetOutputFilesForSource(source, &tool_type, &source_outputs))
continue; continue;
if (std::find(source_outputs.begin(), source_outputs.end(), file) != if (base::ContainsValue(source_outputs, file))
source_outputs.end())
return true; return true;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment