OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |