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