Chromium Code Reviews| 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 if (err != nullptr) { | |
|
brettw
2016/04/19 18:29:39
I've not used optional errors in any places to avo
agrieve
2016/04/20 00:45:02
Done.
| |
| 45 *err = input.parse_err(); | |
| 46 } | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 size_t first_item = items_.size(); | |
| 51 Err my_err; | |
| 52 input.parsed()->Execute(&scope_, &my_err); | |
| 53 if (my_err.has_error()) { | |
| 54 if (err != nullptr) { | |
| 55 *err = my_err; | |
| 56 } | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 for (size_t i = first_item; i < items_.size(); ++i) { | |
| 61 CHECK(items_[i]->AsTarget() != nullptr) | |
| 62 << "Only targets are supported in ExecuteSnippet()"; | |
| 63 items_[i]->AsTarget()->SetToolchain(&toolchain_); | |
| 64 if (!items_[i]->OnResolved(err)) | |
| 65 return false; | |
| 66 } | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 40 // static | 70 // static |
| 41 void TestWithScope::SetupToolchain(Toolchain* toolchain) { | 71 void TestWithScope::SetupToolchain(Toolchain* toolchain) { |
| 42 Err err; | 72 Err err; |
| 43 | 73 |
| 44 // CC | 74 // CC |
| 45 std::unique_ptr<Tool> cc_tool(new Tool); | 75 std::unique_ptr<Tool> cc_tool(new Tool); |
| 46 SetCommandForTool( | 76 SetCommandForTool( |
| 47 "cc {{source}} {{cflags}} {{cflags_c}} {{defines}} {{include_dirs}} " | 77 "cc {{source}} {{cflags}} {{cflags_c}} {{defines}} {{include_dirs}} " |
| 48 "-o {{output}}", | 78 "-o {{output}}", |
| 49 cc_tool.get()); | 79 cc_tool.get()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 const std::string& label_string, | 213 const std::string& label_string, |
| 184 Target::OutputType type) | 214 Target::OutputType type) |
| 185 : Target(setup.settings(), setup.ParseLabel(label_string)) { | 215 : Target(setup.settings(), setup.ParseLabel(label_string)) { |
| 186 visibility().SetPublic(); | 216 visibility().SetPublic(); |
| 187 set_output_type(type); | 217 set_output_type(type); |
| 188 SetToolchain(setup.toolchain()); | 218 SetToolchain(setup.toolchain()); |
| 189 } | 219 } |
| 190 | 220 |
| 191 TestTarget::~TestTarget() { | 221 TestTarget::~TestTarget() { |
| 192 } | 222 } |
| OLD | NEW |