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

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

Issue 311733002: Redo escaping in GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 6 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
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 11 matching lines...) Expand all
22 22
23 std::ostringstream out; 23 std::ostringstream out;
24 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 24 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
25 25
26 FileTemplate output_template = writer.GetOutputTemplate(); 26 FileTemplate output_template = writer.GetOutputTemplate();
27 27
28 SourceFile source("//foo/bar.in"); 28 SourceFile source("//foo/bar.in");
29 std::vector<OutputFile> output_files; 29 std::vector<OutputFile> output_files;
30 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files); 30 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files);
31 31
32 std::string out_str = out.str(); 32 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str());
33 #if defined(OS_WIN)
34 std::replace(out_str.begin(), out_str.end(), '\\', '/');
35 #endif
36 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out_str);
37 } 33 }
38 34
39 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLineWithDepfile) { 35 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLineWithDepfile) {
40 TestWithScope setup; 36 TestWithScope setup;
41 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 37 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
42 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 38 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
43 39
44 target.action_values().set_depfile( 40 target.action_values().set_depfile(
45 SourceFile("//out/Debug/gen/{{source_name_part}}.d")); 41 SourceFile("//out/Debug/gen/{{source_name_part}}.d"));
46 target.action_values().outputs().push_back( 42 target.action_values().outputs().push_back(
47 SourceFile("//out/Debug/gen/{{source_name_part}}.h")); 43 SourceFile("//out/Debug/gen/{{source_name_part}}.h"));
48 target.action_values().outputs().push_back( 44 target.action_values().outputs().push_back(
49 SourceFile("//out/Debug/gen/{{source_name_part}}.cc")); 45 SourceFile("//out/Debug/gen/{{source_name_part}}.cc"));
50 46
51 std::ostringstream out; 47 std::ostringstream out;
52 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 48 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
53 49
54 FileTemplate output_template = writer.GetOutputTemplate(); 50 FileTemplate output_template = writer.GetOutputTemplate();
55 51
56 SourceFile source("//foo/bar.in"); 52 SourceFile source("//foo/bar.in");
57 std::vector<OutputFile> output_files; 53 std::vector<OutputFile> output_files;
58 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files); 54 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files);
59 55
60 std::string out_str = out.str(); 56 EXPECT_EQ(" gen/bar.d gen/bar.h gen/bar.cc", out.str());
61 #if defined(OS_WIN)
62 std::replace(out_str.begin(), out_str.end(), '\\', '/');
63 #endif
64 EXPECT_EQ(" gen/bar.d gen/bar.h gen/bar.cc", out_str);
65 } 57 }
66 58
67 TEST(NinjaActionTargetWriter, WriteArgsSubstitutions) { 59 TEST(NinjaActionTargetWriter, WriteArgsSubstitutions) {
68 TestWithScope setup; 60 TestWithScope setup;
69 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 61 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
70 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 62 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
71 63
72 std::ostringstream out; 64 std::ostringstream out;
73 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 65 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
74 66
75 std::vector<std::string> args; 67 std::vector<std::string> args;
76 args.push_back("-i"); 68 args.push_back("-i");
77 args.push_back("{{source}}"); 69 args.push_back("{{source}}");
78 args.push_back("--out=foo bar{{source_name_part}}.o"); 70 args.push_back("--out=foo bar{{source_name_part}}.o");
79 FileTemplate args_template(args); 71 FileTemplate args_template(args);
80 72
81 writer.WriteArgsSubstitutions(SourceFile("//foo/b ar.in"), args_template); 73 writer.WriteArgsSubstitutions(SourceFile("//foo/b ar.in"), args_template);
82
83 std::string out_str = out.str();
84 #if defined(OS_WIN) 74 #if defined(OS_WIN)
85 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 75 EXPECT_EQ(" source = \"../../foo/b$ ar.in\"\n"
76 " source_name_part = \"b$ ar\"\n",
77 out.str());
78 #else
79 EXPECT_EQ(" source = ../../foo/b\\$ ar.in\n"
80 " source_name_part = b\\$ ar\n",
81 out.str());
86 #endif 82 #endif
87 EXPECT_EQ(" source = ../../foo/b$ ar.in\n source_name_part = b$ ar\n",
88 out_str);
89 } 83 }
90 84
91 // Makes sure that we write sources as input dependencies for actions with 85 // Makes sure that we write sources as input dependencies for actions with
92 // both sources and source_prereqs (ACTION_FOREACH treats the sources 86 // both sources and source_prereqs (ACTION_FOREACH treats the sources
93 // differently). 87 // differently).
94 TEST(NinjaActionTargetWriter, ActionWithSources) { 88 TEST(NinjaActionTargetWriter, ActionWithSources) {
95 TestWithScope setup; 89 TestWithScope setup;
96 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 90 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
97 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 91 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
98 target.set_output_type(Target::ACTION); 92 target.set_output_type(Target::ACTION);
(...skipping 20 matching lines...) Expand all
119 "rule __foo_bar___rule\n" 113 "rule __foo_bar___rule\n"
120 " command = /usr/bin/python ../../foo/script.py\n" 114 " command = /usr/bin/python ../../foo/script.py\n"
121 " description = ACTION //foo:bar()\n" 115 " description = ACTION //foo:bar()\n"
122 " restat = 1\n" 116 " restat = 1\n"
123 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 117 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
124 "../../foo/included.txt ../../foo/source.txt\n" 118 "../../foo/included.txt ../../foo/source.txt\n"
125 "\n" 119 "\n"
126 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" 120 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n"
127 "\n" 121 "\n"
128 "build obj/foo/bar.stamp: stamp foo.out\n"; 122 "build obj/foo/bar.stamp: stamp foo.out\n";
129 std::string out_str = out.str(); 123 EXPECT_EQ(expected_linux, out.str());
130 #if defined(OS_WIN)
131 std::replace(out_str.begin(), out_str.end(), '\\', '/');
132 #endif
133 EXPECT_EQ(expected_linux, out_str);
134 } 124 }
135 125
136 // Windows. 126 // Windows.
137 { 127 {
138 // Note: we use forward slashes here so that the output will be the same on 128 // Note: we use forward slashes here so that the output will be the same on
139 // Linux and Windows. 129 // Linux and Windows.
140 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 130 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
141 "C:/python/python.exe"))); 131 "C:/python/python.exe")));
142 setup.settings()->set_target_os(Settings::WIN); 132 setup.settings()->set_target_os(Settings::WIN);
143 133
144 std::ostringstream out; 134 std::ostringstream out;
145 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 135 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
146 writer.Run(); 136 writer.Run();
147 137
148 // TODO(brettw) I think we'll need to worry about backslashes here
149 // depending if we're on actual Windows or Linux pretending to be Windows.
150 const char expected_win[] = 138 const char expected_win[] =
151 "rule __foo_bar___rule\n" 139 "rule __foo_bar___rule\n"
152 " command = C$:/python/python.exe gyp-win-tool action-wrapper environme nt.x86 __foo_bar___rule.$unique_name.rsp\n" 140 " command = C$:/python/python.exe gyp-win-tool action-wrapper environme nt.x86 __foo_bar___rule.$unique_name.rsp\n"
153 " description = ACTION //foo:bar()\n" 141 " description = ACTION //foo:bar()\n"
154 " restat = 1\n" 142 " restat = 1\n"
155 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 143 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
156 " rspfile_content = C$:/python/python.exe ../../foo/script.py\n" 144 " rspfile_content = C$:/python/python.exe ../../foo/script.py\n"
157 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 145 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
158 "../../foo/included.txt ../../foo/source.txt\n" 146 "../../foo/included.txt ../../foo/source.txt\n"
159 "\n" 147 "\n"
160 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" 148 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n"
161 "\n" 149 "\n"
162 "build obj/foo/bar.stamp: stamp foo.out\n"; 150 "build obj/foo/bar.stamp: stamp foo.out\n";
163 std::string out_str = out.str(); 151 EXPECT_EQ(expected_win, out.str());
164 #if defined(OS_WIN)
165 std::replace(out_str.begin(), out_str.end(), '\\', '/');
166 #endif
167 EXPECT_EQ(expected_win, out_str);
168 } 152 }
169 } 153 }
170 154
171 TEST(NinjaActionTargetWriter, ForEach) { 155 TEST(NinjaActionTargetWriter, ForEach) {
172 TestWithScope setup; 156 TestWithScope setup;
173 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 157 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
174 158
175 // Some dependencies that the action can depend on. Use actions for these 159 // Some dependencies that the action can depend on. Use actions for these
176 // so they have a nice platform-independent stamp file that can appear in the 160 // so they have a nice platform-independent stamp file that can appear in the
177 // output (rather than having to worry about how the current platform names 161 // output (rather than having to worry about how the current platform names
(...skipping 29 matching lines...) Expand all
207 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 191 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
208 "/usr/bin/python"))); 192 "/usr/bin/python")));
209 193
210 std::ostringstream out; 194 std::ostringstream out;
211 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 195 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
212 writer.Run(); 196 writer.Run();
213 197
214 const char expected_linux[] = 198 const char expected_linux[] =
215 "rule __foo_bar___rule\n" 199 "rule __foo_bar___rule\n"
216 " command = /usr/bin/python ../../foo/script.py -i ${source} " 200 " command = /usr/bin/python ../../foo/script.py -i ${source} "
201 // Escaping is different between Windows and Posix.
202 #if defined(OS_WIN)
217 "\"--out=foo$ bar${source_name_part}.o\"\n" 203 "\"--out=foo$ bar${source_name_part}.o\"\n"
204 #else
205 "--out=foo\\$ bar${source_name_part}.o\n"
206 #endif
218 " description = ACTION //foo:bar()\n" 207 " description = ACTION //foo:bar()\n"
219 " restat = 1\n" 208 " restat = 1\n"
220 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 209 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
221 "../../foo/included.txt obj/foo/dep.stamp\n" 210 "../../foo/included.txt obj/foo/dep.stamp\n"
222 "\n" 211 "\n"
223 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " 212 "build input1.out: __foo_bar___rule ../../foo/input1.txt | "
224 "obj/foo/bar.inputdeps.stamp\n" 213 "obj/foo/bar.inputdeps.stamp\n"
225 " source = ../../foo/input1.txt\n" 214 " source = ../../foo/input1.txt\n"
226 " source_name_part = input1\n" 215 " source_name_part = input1\n"
227 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " 216 "build input2.out: __foo_bar___rule ../../foo/input2.txt | "
228 "obj/foo/bar.inputdeps.stamp\n" 217 "obj/foo/bar.inputdeps.stamp\n"
229 " source = ../../foo/input2.txt\n" 218 " source = ../../foo/input2.txt\n"
230 " source_name_part = input2\n" 219 " source_name_part = input2\n"
231 "\n" 220 "\n"
232 "build obj/foo/bar.stamp: " 221 "build obj/foo/bar.stamp: "
233 "stamp input1.out input2.out obj/foo/datadep.stamp\n"; 222 "stamp input1.out input2.out obj/foo/datadep.stamp\n";
234 223
235 std::string out_str = out.str(); 224 std::string out_str = out.str();
236 #if defined(OS_WIN) 225 #if defined(OS_WIN)
237 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 226 std::replace(out_str.begin(), out_str.end(), '\\', '/');
238 #endif 227 #endif
239 EXPECT_EQ(expected_linux, out_str); 228 EXPECT_EQ(expected_linux, out_str);
240 } 229 }
241 230
242 // Windows. 231 // Windows.
243 { 232 {
244 // Note: we use forward slashes here so that the output will be the same on
245 // Linux and Windows.
246 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 233 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
247 "C:/python/python.exe"))); 234 "C:/python/python.exe")));
248 setup.settings()->set_target_os(Settings::WIN); 235 setup.settings()->set_target_os(Settings::WIN);
249 236
250 std::ostringstream out; 237 std::ostringstream out;
251 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 238 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
252 writer.Run(); 239 writer.Run();
253 240
254 // TODO(brettw) I think we'll need to worry about backslashes here
255 // depending if we're on actual Windows or Linux pretending to be Windows.
256 const char expected_win[] = 241 const char expected_win[] =
257 "rule __foo_bar___rule\n" 242 "rule __foo_bar___rule\n"
258 " command = C$:/python/python.exe gyp-win-tool action-wrapper " 243 " command = C$:/python/python.exe gyp-win-tool action-wrapper "
259 "environment.x86 __foo_bar___rule.$unique_name.rsp\n" 244 "environment.x86 __foo_bar___rule.$unique_name.rsp\n"
260 " description = ACTION //foo:bar()\n" 245 " description = ACTION //foo:bar()\n"
261 " restat = 1\n" 246 " restat = 1\n"
262 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 247 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
263 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " 248 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
249 #if defined(OS_WIN)
264 "${source} \"--out=foo$ bar${source_name_part}.o\"\n" 250 "${source} \"--out=foo$ bar${source_name_part}.o\"\n"
251 #else
252 "${source} --out=foo\\$ bar${source_name_part}.o\n"
253 #endif
265 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 254 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
266 "../../foo/included.txt obj/foo/dep.stamp\n" 255 "../../foo/included.txt obj/foo/dep.stamp\n"
267 "\n" 256 "\n"
268 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " 257 "build input1.out: __foo_bar___rule ../../foo/input1.txt | "
269 "obj/foo/bar.inputdeps.stamp\n" 258 "obj/foo/bar.inputdeps.stamp\n"
270 " unique_name = 0\n" 259 " unique_name = 0\n"
271 " source = ../../foo/input1.txt\n" 260 " source = ../../foo/input1.txt\n"
272 " source_name_part = input1\n" 261 " source_name_part = input1\n"
273 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " 262 "build input2.out: __foo_bar___rule ../../foo/input2.txt | "
274 "obj/foo/bar.inputdeps.stamp\n" 263 "obj/foo/bar.inputdeps.stamp\n"
275 " unique_name = 1\n" 264 " unique_name = 1\n"
276 " source = ../../foo/input2.txt\n" 265 " source = ../../foo/input2.txt\n"
277 " source_name_part = input2\n" 266 " source_name_part = input2\n"
278 "\n" 267 "\n"
279 "build obj/foo/bar.stamp: " 268 "build obj/foo/bar.stamp: "
280 "stamp input1.out input2.out obj/foo/datadep.stamp\n"; 269 "stamp input1.out input2.out obj/foo/datadep.stamp\n";
281 std::string out_str = out.str(); 270 EXPECT_EQ(expected_win, out.str());
282 #if defined(OS_WIN)
283 std::replace(out_str.begin(), out_str.end(), '\\', '/');
284 #endif
285 EXPECT_EQ(expected_win, out_str);
286 } 271 }
287 } 272 }
288 273
289 TEST(NinjaActionTargetWriter, ForEachWithDepfile) { 274 TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
290 TestWithScope setup; 275 TestWithScope setup;
291 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 276 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
292 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 277 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
293 target.set_output_type(Target::ACTION_FOREACH); 278 target.set_output_type(Target::ACTION_FOREACH);
294 279
295 target.sources().push_back(SourceFile("//foo/input1.txt")); 280 target.sources().push_back(SourceFile("//foo/input1.txt"));
(...skipping 19 matching lines...) Expand all
315 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 300 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
316 "/usr/bin/python"))); 301 "/usr/bin/python")));
317 302
318 std::ostringstream out; 303 std::ostringstream out;
319 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 304 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
320 writer.Run(); 305 writer.Run();
321 306
322 const char expected_linux[] = 307 const char expected_linux[] =
323 "rule __foo_bar___rule\n" 308 "rule __foo_bar___rule\n"
324 " command = /usr/bin/python ../../foo/script.py -i ${source} " 309 " command = /usr/bin/python ../../foo/script.py -i ${source} "
310 #if defined(OS_WIN)
325 "\"--out=foo$ bar${source_name_part}.o\"\n" 311 "\"--out=foo$ bar${source_name_part}.o\"\n"
312 #else
313 "--out=foo\\$ bar${source_name_part}.o\n"
314 #endif
326 " description = ACTION //foo:bar()\n" 315 " description = ACTION //foo:bar()\n"
327 " restat = 1\n" 316 " restat = 1\n"
328 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 317 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
329 "../../foo/included.txt\n" 318 "../../foo/included.txt\n"
330 "\n" 319 "\n"
331 "build gen/input1.d input1.out: __foo_bar___rule ../../foo/input1.txt" 320 "build gen/input1.d input1.out: __foo_bar___rule ../../foo/input1.txt"
332 " | obj/foo/bar.inputdeps.stamp\n" 321 " | obj/foo/bar.inputdeps.stamp\n"
333 " source = ../../foo/input1.txt\n" 322 " source = ../../foo/input1.txt\n"
334 " source_name_part = input1\n" 323 " source_name_part = input1\n"
335 " depfile = gen/input1.d\n" 324 " depfile = gen/input1.d\n"
336 "build gen/input2.d input2.out: __foo_bar___rule ../../foo/input2.txt" 325 "build gen/input2.d input2.out: __foo_bar___rule ../../foo/input2.txt"
337 " | obj/foo/bar.inputdeps.stamp\n" 326 " | obj/foo/bar.inputdeps.stamp\n"
338 " source = ../../foo/input2.txt\n" 327 " source = ../../foo/input2.txt\n"
339 " source_name_part = input2\n" 328 " source_name_part = input2\n"
340 " depfile = gen/input2.d\n" 329 " depfile = gen/input2.d\n"
341 "\n" 330 "\n"
342 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 331 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
343 332 EXPECT_EQ(expected_linux, out.str());
344 std::string out_str = out.str();
345 #if defined(OS_WIN)
346 std::replace(out_str.begin(), out_str.end(), '\\', '/');
347 #endif
348 EXPECT_EQ(expected_linux, out_str);
349 } 333 }
350 334
351 // Windows. 335 // Windows.
352 { 336 {
353 // Note: we use forward slashes here so that the output will be the same on
354 // Linux and Windows.
355 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 337 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
356 "C:/python/python.exe"))); 338 "C:/python/python.exe")));
357 setup.settings()->set_target_os(Settings::WIN); 339 setup.settings()->set_target_os(Settings::WIN);
358 340
359 std::ostringstream out; 341 std::ostringstream out;
360 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 342 NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
361 writer.Run(); 343 writer.Run();
362 344
363 // TODO(brettw) I think we'll need to worry about backslashes here
364 // depending if we're on actual Windows or Linux pretending to be Windows.
365 const char expected_win[] = 345 const char expected_win[] =
366 "rule __foo_bar___rule\n" 346 "rule __foo_bar___rule\n"
367 " command = C$:/python/python.exe gyp-win-tool action-wrapper " 347 " command = C$:/python/python.exe gyp-win-tool action-wrapper "
368 "environment.x86 __foo_bar___rule.$unique_name.rsp\n" 348 "environment.x86 __foo_bar___rule.$unique_name.rsp\n"
369 " description = ACTION //foo:bar()\n" 349 " description = ACTION //foo:bar()\n"
370 " restat = 1\n" 350 " restat = 1\n"
371 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 351 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
372 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " 352 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
353 #if defined(OS_WIN)
373 "${source} \"--out=foo$ bar${source_name_part}.o\"\n" 354 "${source} \"--out=foo$ bar${source_name_part}.o\"\n"
355 #else
356 "${source} --out=foo\\$ bar${source_name_part}.o\n"
357 #endif
374 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 358 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
375 "../../foo/included.txt\n" 359 "../../foo/included.txt\n"
376 "\n" 360 "\n"
377 "build gen/input1.d input1.out: __foo_bar___rule ../../foo/input1.txt" 361 "build gen/input1.d input1.out: __foo_bar___rule ../../foo/input1.txt"
378 " | obj/foo/bar.inputdeps.stamp\n" 362 " | obj/foo/bar.inputdeps.stamp\n"
379 " unique_name = 0\n" 363 " unique_name = 0\n"
380 " source = ../../foo/input1.txt\n" 364 " source = ../../foo/input1.txt\n"
381 " source_name_part = input1\n" 365 " source_name_part = input1\n"
382 " depfile = gen/input1.d\n" 366 " depfile = gen/input1.d\n"
383 "build gen/input2.d input2.out: __foo_bar___rule ../../foo/input2.txt" 367 "build gen/input2.d input2.out: __foo_bar___rule ../../foo/input2.txt"
384 " | obj/foo/bar.inputdeps.stamp\n" 368 " | obj/foo/bar.inputdeps.stamp\n"
385 " unique_name = 1\n" 369 " unique_name = 1\n"
386 " source = ../../foo/input2.txt\n" 370 " source = ../../foo/input2.txt\n"
387 " source_name_part = input2\n" 371 " source_name_part = input2\n"
388 " depfile = gen/input2.d\n" 372 " depfile = gen/input2.d\n"
389 "\n" 373 "\n"
390 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 374 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
391 std::string out_str = out.str(); 375 EXPECT_EQ(expected_win, out.str());
392 #if defined(OS_WIN)
393 std::replace(out_str.begin(), out_str.end(), '\\', '/');
394 #endif
395 EXPECT_EQ(expected_win, out_str);
396 } 376 }
397 } 377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698