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

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

Issue 265703008: Support deps for actions in GN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/ninja_action_target_writer.cc ('k') | tools/gn/ninja_binary_target_writer.cc » ('j') | 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 <algorithm> 5 #include <algorithm>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/file_template.h" 9 #include "tools/gn/file_template.h"
10 #include "tools/gn/ninja_action_target_writer.h" 10 #include "tools/gn/ninja_action_target_writer.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 #if defined(OS_WIN) 162 #if defined(OS_WIN)
163 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 163 std::replace(out_str.begin(), out_str.end(), '\\', '/');
164 #endif 164 #endif
165 EXPECT_EQ(expected_win, out_str); 165 EXPECT_EQ(expected_win, out_str);
166 } 166 }
167 } 167 }
168 168
169 TEST(NinjaActionTargetWriter, ForEach) { 169 TEST(NinjaActionTargetWriter, ForEach) {
170 TestWithScope setup; 170 TestWithScope setup;
171 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 171 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
172
173 // Some dependencies that the action can depend on. Use actions for these
174 // so they have a nice platform-independent stamp file that can appear in the
175 // output (rather than having to worry about how the current platform names
176 // binaries).
177 Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"));
178 dep.set_output_type(Target::ACTION);
179 Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"));
180 datadep.set_output_type(Target::ACTION);
181
172 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 182 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
173 target.set_output_type(Target::ACTION_FOREACH); 183 target.set_output_type(Target::ACTION_FOREACH);
184 target.deps().push_back(LabelTargetPair(&dep));
185 target.datadeps().push_back(LabelTargetPair(&datadep));
174 186
175 target.sources().push_back(SourceFile("//foo/input1.txt")); 187 target.sources().push_back(SourceFile("//foo/input1.txt"));
176 target.sources().push_back(SourceFile("//foo/input2.txt")); 188 target.sources().push_back(SourceFile("//foo/input2.txt"));
177 189
178 target.action_values().set_script(SourceFile("//foo/script.py")); 190 target.action_values().set_script(SourceFile("//foo/script.py"));
179 191
180 target.action_values().args().push_back("-i"); 192 target.action_values().args().push_back("-i");
181 target.action_values().args().push_back("{{source}}"); 193 target.action_values().args().push_back("{{source}}");
182 target.action_values().args().push_back( 194 target.action_values().args().push_back(
183 "--out=foo bar{{source_name_part}}.o"); 195 "--out=foo bar{{source_name_part}}.o");
(...skipping 12 matching lines...) Expand all
196 std::ostringstream out; 208 std::ostringstream out;
197 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 209 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
198 writer.Run(); 210 writer.Run();
199 211
200 const char expected_linux[] = 212 const char expected_linux[] =
201 "rule __foo_bar___rule\n" 213 "rule __foo_bar___rule\n"
202 " command = /usr/bin/python ../../foo/script.py -i ${source} " 214 " command = /usr/bin/python ../../foo/script.py -i ${source} "
203 "\"--out=foo$ bar${source_name_part}.o\"\n" 215 "\"--out=foo$ bar${source_name_part}.o\"\n"
204 " description = ACTION //foo:bar()\n" 216 " description = ACTION //foo:bar()\n"
205 " restat = 1\n" 217 " restat = 1\n"
206 "obj/foo/bar.inputdeps.stamp: stamp ../../foo/included.txt\n" 218 "obj/foo/bar.inputdeps.stamp: "
219 "stamp ../../foo/included.txt obj/foo/dep.stamp\n"
207 "\n" 220 "\n"
208 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " 221 "build input1.out: __foo_bar___rule ../../foo/input1.txt | "
209 "obj/foo/bar.inputdeps.stamp\n" 222 "obj/foo/bar.inputdeps.stamp\n"
210 " source = ../../foo/input1.txt\n" 223 " source = ../../foo/input1.txt\n"
211 " source_name_part = input1\n" 224 " source_name_part = input1\n"
212 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " 225 "build input2.out: __foo_bar___rule ../../foo/input2.txt | "
213 "obj/foo/bar.inputdeps.stamp\n" 226 "obj/foo/bar.inputdeps.stamp\n"
214 " source = ../../foo/input2.txt\n" 227 " source = ../../foo/input2.txt\n"
215 " source_name_part = input2\n" 228 " source_name_part = input2\n"
216 "\n" 229 "\n"
217 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 230 "build obj/foo/bar.stamp: "
231 "stamp input1.out input2.out obj/foo/datadep.stamp\n";
218 232
219 std::string out_str = out.str(); 233 std::string out_str = out.str();
220 #if defined(OS_WIN) 234 #if defined(OS_WIN)
221 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 235 std::replace(out_str.begin(), out_str.end(), '\\', '/');
222 #endif 236 #endif
223 EXPECT_EQ(expected_linux, out_str); 237 EXPECT_EQ(expected_linux, out_str);
224 } 238 }
225 239
226 // Windows. 240 // Windows.
227 { 241 {
(...skipping 11 matching lines...) Expand all
239 // depending if we're on actual Windows or Linux pretending to be Windows. 253 // depending if we're on actual Windows or Linux pretending to be Windows.
240 const char expected_win[] = 254 const char expected_win[] =
241 "rule __foo_bar___rule\n" 255 "rule __foo_bar___rule\n"
242 " command = C$:/python/python.exe gyp-win-tool action-wrapper " 256 " command = C$:/python/python.exe gyp-win-tool action-wrapper "
243 "environment.x86 __foo_bar___rule.$unique_name.rsp\n" 257 "environment.x86 __foo_bar___rule.$unique_name.rsp\n"
244 " description = ACTION //foo:bar()\n" 258 " description = ACTION //foo:bar()\n"
245 " restat = 1\n" 259 " restat = 1\n"
246 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 260 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
247 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " 261 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
248 "${source} \"--out=foo$ bar${source_name_part}.o\"\n" 262 "${source} \"--out=foo$ bar${source_name_part}.o\"\n"
249 "obj/foo/bar.inputdeps.stamp: stamp ../../foo/included.txt\n" 263 "obj/foo/bar.inputdeps.stamp: "
264 "stamp ../../foo/included.txt obj/foo/dep.stamp\n"
250 "\n" 265 "\n"
251 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " 266 "build input1.out: __foo_bar___rule ../../foo/input1.txt | "
252 "obj/foo/bar.inputdeps.stamp\n" 267 "obj/foo/bar.inputdeps.stamp\n"
253 " unique_name = 0\n" 268 " unique_name = 0\n"
254 " source = ../../foo/input1.txt\n" 269 " source = ../../foo/input1.txt\n"
255 " source_name_part = input1\n" 270 " source_name_part = input1\n"
256 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " 271 "build input2.out: __foo_bar___rule ../../foo/input2.txt | "
257 "obj/foo/bar.inputdeps.stamp\n" 272 "obj/foo/bar.inputdeps.stamp\n"
258 " unique_name = 1\n" 273 " unique_name = 1\n"
259 " source = ../../foo/input2.txt\n" 274 " source = ../../foo/input2.txt\n"
260 " source_name_part = input2\n" 275 " source_name_part = input2\n"
261 "\n" 276 "\n"
262 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 277 "build obj/foo/bar.stamp: "
278 "stamp input1.out input2.out obj/foo/datadep.stamp\n";
263 std::string out_str = out.str(); 279 std::string out_str = out.str();
264 #if defined(OS_WIN) 280 #if defined(OS_WIN)
265 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 281 std::replace(out_str.begin(), out_str.end(), '\\', '/');
266 #endif 282 #endif
267 EXPECT_EQ(expected_win, out_str); 283 EXPECT_EQ(expected_win, out_str);
268 } 284 }
269 } 285 }
270 286
271 TEST(NinjaActionTargetWriter, ForEachWithDepfile) { 287 TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
272 TestWithScope setup; 288 TestWithScope setup;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 " depfile = gen/input2.d\n" 384 " depfile = gen/input2.d\n"
369 "\n" 385 "\n"
370 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 386 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
371 std::string out_str = out.str(); 387 std::string out_str = out.str();
372 #if defined(OS_WIN) 388 #if defined(OS_WIN)
373 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 389 std::replace(out_str.begin(), out_str.end(), '\\', '/');
374 #endif 390 #endif
375 EXPECT_EQ(expected_win, out_str); 391 EXPECT_EQ(expected_win, out_str);
376 } 392 }
377 } 393 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_action_target_writer.cc ('k') | tools/gn/ninja_binary_target_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698