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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "tools/gn/parser.h" | 8 #include "tools/gn/parser.h" |
9 #include "tools/gn/tokenizer.h" | 9 #include "tools/gn/tokenizer.h" |
10 | 10 |
11 namespace { | |
12 | |
13 void SetCommandForTool(const std::string& cmd, Tool* tool) { | |
14 Err err; | |
15 SubstitutionPattern command; | |
16 command.Parse(cmd, nullptr, &err); | |
17 CHECK(!err.has_error()) | |
18 << "Couldn't parse \"" << cmd << "\", " << "got " << err.message(); | |
19 tool->set_command(command); | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 TestWithScope::TestWithScope() | 11 TestWithScope::TestWithScope() |
25 : build_settings_(), | 12 : build_settings_(), |
26 settings_(&build_settings_, std::string()), | 13 settings_(&build_settings_, std::string()), |
27 toolchain_(&settings_, Label(SourceDir("//toolchain/"), "default")), | 14 toolchain_(&settings_, Label(SourceDir("//toolchain/"), "default")), |
28 scope_(&settings_) { | 15 scope_(&settings_) { |
29 build_settings_.SetBuildDir(SourceDir("//out/Debug/")); | 16 build_settings_.SetBuildDir(SourceDir("//out/Debug/")); |
30 build_settings_.set_print_callback( | 17 build_settings_.set_print_callback( |
31 base::Bind(&TestWithScope::AppendPrintOutput, base::Unretained(this))); | 18 base::Bind(&TestWithScope::AppendPrintOutput, base::Unretained(this))); |
32 | 19 |
33 settings_.set_toolchain_label(toolchain_.label()); | 20 settings_.set_toolchain_label(toolchain_.label()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 toolchain->SetTool(Toolchain::TYPE_STAMP, stamp_tool.Pass()); | 112 toolchain->SetTool(Toolchain::TYPE_STAMP, stamp_tool.Pass()); |
126 | 113 |
127 // COPY | 114 // COPY |
128 scoped_ptr<Tool> copy_tool(new Tool); | 115 scoped_ptr<Tool> copy_tool(new Tool); |
129 SetCommandForTool("cp {{source}} {{output}}", copy_tool.get()); | 116 SetCommandForTool("cp {{source}} {{output}}", copy_tool.get()); |
130 toolchain->SetTool(Toolchain::TYPE_COPY, copy_tool.Pass()); | 117 toolchain->SetTool(Toolchain::TYPE_COPY, copy_tool.Pass()); |
131 | 118 |
132 toolchain->ToolchainSetupComplete(); | 119 toolchain->ToolchainSetupComplete(); |
133 } | 120 } |
134 | 121 |
| 122 // static |
| 123 void TestWithScope::SetCommandForTool(const std::string& cmd, Tool* tool) { |
| 124 Err err; |
| 125 SubstitutionPattern command; |
| 126 command.Parse(cmd, nullptr, &err); |
| 127 CHECK(!err.has_error()) |
| 128 << "Couldn't parse \"" << cmd << "\", " << "got " << err.message(); |
| 129 tool->set_command(command); |
| 130 } |
| 131 |
135 void TestWithScope::AppendPrintOutput(const std::string& str) { | 132 void TestWithScope::AppendPrintOutput(const std::string& str) { |
136 print_output_.append(str); | 133 print_output_.append(str); |
137 } | 134 } |
138 | 135 |
139 TestParseInput::TestParseInput(const std::string& input) | 136 TestParseInput::TestParseInput(const std::string& input) |
140 : input_file_(SourceFile("//test")) { | 137 : input_file_(SourceFile("//test")) { |
141 input_file_.SetContents(input); | 138 input_file_.SetContents(input); |
142 | 139 |
143 tokens_ = Tokenizer::Tokenize(&input_file_, &parse_err_); | 140 tokens_ = Tokenizer::Tokenize(&input_file_, &parse_err_); |
144 if (!parse_err_.has_error()) | 141 if (!parse_err_.has_error()) |
145 parsed_ = Parser::Parse(tokens_, &parse_err_); | 142 parsed_ = Parser::Parse(tokens_, &parse_err_); |
146 } | 143 } |
147 | 144 |
148 TestParseInput::~TestParseInput() { | 145 TestParseInput::~TestParseInput() { |
149 } | 146 } |
150 | 147 |
151 TestTarget::TestTarget(TestWithScope& setup, | 148 TestTarget::TestTarget(TestWithScope& setup, |
152 const std::string& label_string, | 149 const std::string& label_string, |
153 Target::OutputType type) | 150 Target::OutputType type) |
154 : Target(setup.settings(), setup.ParseLabel(label_string)) { | 151 : Target(setup.settings(), setup.ParseLabel(label_string)) { |
155 visibility().SetPublic(); | 152 visibility().SetPublic(); |
156 set_output_type(type); | 153 set_output_type(type); |
157 SetToolchain(setup.toolchain()); | 154 SetToolchain(setup.toolchain()); |
158 } | 155 } |
159 | 156 |
160 TestTarget::~TestTarget() { | 157 TestTarget::~TestTarget() { |
161 } | 158 } |
OLD | NEW |