Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tools/gn/test_with_scope.cc

Issue 1892393002: 🐜 GN: Make write_runtime_deps take effect only a target is resolved (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/test_with_scope.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/test_with_scope.h" 5 #include "tools/gn/test_with_scope.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "tools/gn/parser.h" 10 #include "tools/gn/parser.h"
11 #include "tools/gn/tokenizer.h" 11 #include "tools/gn/tokenizer.h"
12 12
13 TestWithScope::TestWithScope() 13 TestWithScope::TestWithScope()
14 : build_settings_(), 14 : build_settings_(),
15 settings_(&build_settings_, std::string()), 15 settings_(&build_settings_, std::string()),
16 toolchain_(&settings_, Label(SourceDir("//toolchain/"), "default")), 16 toolchain_(&settings_, Label(SourceDir("//toolchain/"), "default")),
17 scope_(&settings_), 17 scope_(&settings_),
18 scope_progammatic_provider_(&scope_, true) { 18 scope_progammatic_provider_(&scope_, true) {
19 build_settings_.SetBuildDir(SourceDir("//out/Debug/")); 19 build_settings_.SetBuildDir(SourceDir("//out/Debug/"));
20 build_settings_.set_print_callback( 20 build_settings_.set_print_callback(
21 base::Bind(&TestWithScope::AppendPrintOutput, base::Unretained(this))); 21 base::Bind(&TestWithScope::AppendPrintOutput, base::Unretained(this)));
22 22
23 settings_.set_toolchain_label(toolchain_.label()); 23 settings_.set_toolchain_label(toolchain_.label());
24 settings_.set_default_toolchain_label(toolchain_.label()); 24 settings_.set_default_toolchain_label(toolchain_.label());
25 25
26 SetupToolchain(&toolchain_); 26 SetupToolchain(&toolchain_);
27 scope_.set_item_collector(&items_);
27 } 28 }
28 29
29 TestWithScope::~TestWithScope() { 30 TestWithScope::~TestWithScope() {
30 } 31 }
31 32
32 Label TestWithScope::ParseLabel(const std::string& str) const { 33 Label TestWithScope::ParseLabel(const std::string& str) const {
33 Err err; 34 Err err;
34 Label result = Label::Resolve(SourceDir("//"), toolchain_.label(), 35 Label result = Label::Resolve(SourceDir("//"), toolchain_.label(),
35 Value(nullptr, str), &err); 36 Value(nullptr, str), &err);
36 CHECK(!err.has_error()); 37 CHECK(!err.has_error());
37 return result; 38 return result;
38 } 39 }
39 40
41 bool TestWithScope::ExecuteSnippet(const std::string& str, Err* err) {
42 TestParseInput input(str);
43 if (input.has_error()) {
44 *err = input.parse_err();
45 return false;
46 }
47
48 size_t first_item = items_.size();
49 input.parsed()->Execute(&scope_, err);
50 if (err->has_error())
51 return false;
52
53 for (size_t i = first_item; i < items_.size(); ++i) {
54 CHECK(items_[i]->AsTarget() != nullptr)
55 << "Only targets are supported in ExecuteSnippet()";
56 items_[i]->AsTarget()->SetToolchain(&toolchain_);
57 if (!items_[i]->OnResolved(err))
58 return false;
59 }
60 return true;
61 }
62
40 // static 63 // static
41 void TestWithScope::SetupToolchain(Toolchain* toolchain) { 64 void TestWithScope::SetupToolchain(Toolchain* toolchain) {
42 Err err; 65 Err err;
43 66
44 // CC 67 // CC
45 std::unique_ptr<Tool> cc_tool(new Tool); 68 std::unique_ptr<Tool> cc_tool(new Tool);
46 SetCommandForTool( 69 SetCommandForTool(
47 "cc {{source}} {{cflags}} {{cflags_c}} {{defines}} {{include_dirs}} " 70 "cc {{source}} {{cflags}} {{cflags_c}} {{defines}} {{include_dirs}} "
48 "-o {{output}}", 71 "-o {{output}}",
49 cc_tool.get()); 72 cc_tool.get());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 const std::string& label_string, 206 const std::string& label_string,
184 Target::OutputType type) 207 Target::OutputType type)
185 : Target(setup.settings(), setup.ParseLabel(label_string)) { 208 : Target(setup.settings(), setup.ParseLabel(label_string)) {
186 visibility().SetPublic(); 209 visibility().SetPublic();
187 set_output_type(type); 210 set_output_type(type);
188 SetToolchain(setup.toolchain()); 211 SetToolchain(setup.toolchain());
189 } 212 }
190 213
191 TestTarget::~TestTarget() { 214 TestTarget::~TestTarget() {
192 } 215 }
OLDNEW
« no previous file with comments | « tools/gn/test_with_scope.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698