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

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

Issue 440333002: Support more configurability in GN toolchains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unsigned check Created 6 years, 4 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.h » ('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/ninja_action_target_writer.h" 9 #include "tools/gn/ninja_action_target_writer.h"
10 #include "tools/gn/substitution_list.h" 10 #include "tools/gn/substitution_list.h"
11 #include "tools/gn/target.h"
11 #include "tools/gn/test_with_scope.h" 12 #include "tools/gn/test_with_scope.h"
12 13
13 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLine) { 14 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLine) {
14 TestWithScope setup; 15 TestWithScope setup;
15 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 16 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
17
16 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
19 target.set_output_type(Target::ACTION_FOREACH);
17 target.action_values().outputs() = SubstitutionList::MakeForTest( 20 target.action_values().outputs() = SubstitutionList::MakeForTest(
18 "//out/Debug/gen/a b{{source_name_part}}.h", 21 "//out/Debug/gen/a b{{source_name_part}}.h",
19 "//out/Debug/gen/{{source_name_part}}.cc"); 22 "//out/Debug/gen/{{source_name_part}}.cc");
20 23
24 target.SetToolchain(setup.toolchain());
25 target.OnResolved();
26
21 std::ostringstream out; 27 std::ostringstream out;
22 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 28 NinjaActionTargetWriter writer(&target, out);
23 29
24 SourceFile source("//foo/bar.in"); 30 SourceFile source("//foo/bar.in");
25 std::vector<OutputFile> output_files; 31 std::vector<OutputFile> output_files;
26 writer.WriteOutputFilesForBuildLine(source, &output_files); 32 writer.WriteOutputFilesForBuildLine(source, &output_files);
27 33
28 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); 34 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str());
29 } 35 }
30 36
31 // Tests an action with no sources. 37 // Tests an action with no sources.
32 TEST(NinjaActionTargetWriter, ActionNoSources) { 38 TEST(NinjaActionTargetWriter, ActionNoSources) {
33 TestWithScope setup; 39 TestWithScope setup;
34 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 40 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
35 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 41 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
36 target.set_output_type(Target::ACTION); 42 target.set_output_type(Target::ACTION);
37 43
38 target.action_values().set_script(SourceFile("//foo/script.py")); 44 target.action_values().set_script(SourceFile("//foo/script.py"));
39 target.inputs().push_back(SourceFile("//foo/included.txt")); 45 target.inputs().push_back(SourceFile("//foo/included.txt"));
40 46
41 target.action_values().outputs() = 47 target.action_values().outputs() =
42 SubstitutionList::MakeForTest("//out/Debug/foo.out"); 48 SubstitutionList::MakeForTest("//out/Debug/foo.out");
43 49
50 target.SetToolchain(setup.toolchain());
51 target.OnResolved();
52
44 setup.settings()->set_target_os(Settings::LINUX); 53 setup.settings()->set_target_os(Settings::LINUX);
45 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 54 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
46 "/usr/bin/python"))); 55 "/usr/bin/python")));
47 56
48 std::ostringstream out; 57 std::ostringstream out;
49 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 58 NinjaActionTargetWriter writer(&target, out);
50 writer.Run(); 59 writer.Run();
51 60
52 const char expected[] = 61 const char expected[] =
53 "rule __foo_bar___rule\n" 62 "rule __foo_bar___rule\n"
54 " command = /usr/bin/python ../../foo/script.py\n" 63 " command = /usr/bin/python ../../foo/script.py\n"
55 " description = ACTION //foo:bar()\n" 64 " description = ACTION //foo:bar()\n"
56 " restat = 1\n" 65 " restat = 1\n"
57 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 66 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
58 "../../foo/included.txt\n" 67 "../../foo/included.txt\n"
59 "\n" 68 "\n"
(...skipping 12 matching lines...) Expand all
72 target.set_output_type(Target::ACTION); 81 target.set_output_type(Target::ACTION);
73 82
74 target.action_values().set_script(SourceFile("//foo/script.py")); 83 target.action_values().set_script(SourceFile("//foo/script.py"));
75 84
76 target.sources().push_back(SourceFile("//foo/source.txt")); 85 target.sources().push_back(SourceFile("//foo/source.txt"));
77 target.inputs().push_back(SourceFile("//foo/included.txt")); 86 target.inputs().push_back(SourceFile("//foo/included.txt"));
78 87
79 target.action_values().outputs() = 88 target.action_values().outputs() =
80 SubstitutionList::MakeForTest("//out/Debug/foo.out"); 89 SubstitutionList::MakeForTest("//out/Debug/foo.out");
81 90
91 target.SetToolchain(setup.toolchain());
92 target.OnResolved();
93
82 // Posix. 94 // Posix.
83 { 95 {
84 setup.settings()->set_target_os(Settings::LINUX); 96 setup.settings()->set_target_os(Settings::LINUX);
85 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 97 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
86 "/usr/bin/python"))); 98 "/usr/bin/python")));
87 99
88 std::ostringstream out; 100 std::ostringstream out;
89 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 101 NinjaActionTargetWriter writer(&target, out);
90 writer.Run(); 102 writer.Run();
91 103
92 const char expected_linux[] = 104 const char expected_linux[] =
93 "rule __foo_bar___rule\n" 105 "rule __foo_bar___rule\n"
94 " command = /usr/bin/python ../../foo/script.py\n" 106 " command = /usr/bin/python ../../foo/script.py\n"
95 " description = ACTION //foo:bar()\n" 107 " description = ACTION //foo:bar()\n"
96 " restat = 1\n" 108 " restat = 1\n"
97 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 109 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
98 "../../foo/included.txt ../../foo/source.txt\n" 110 "../../foo/included.txt ../../foo/source.txt\n"
99 "\n" 111 "\n"
100 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" 112 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n"
101 "\n" 113 "\n"
102 "build obj/foo/bar.stamp: stamp foo.out\n"; 114 "build obj/foo/bar.stamp: stamp foo.out\n";
103 EXPECT_EQ(expected_linux, out.str()); 115 EXPECT_EQ(expected_linux, out.str());
104 } 116 }
105 117
106 // Windows. 118 // Windows.
107 { 119 {
108 // Note: we use forward slashes here so that the output will be the same on 120 // Note: we use forward slashes here so that the output will be the same on
109 // Linux and Windows. 121 // Linux and Windows.
110 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 122 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
111 "C:/python/python.exe"))); 123 "C:/python/python.exe")));
112 setup.settings()->set_target_os(Settings::WIN); 124 setup.settings()->set_target_os(Settings::WIN);
113 125
114 std::ostringstream out; 126 std::ostringstream out;
115 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 127 NinjaActionTargetWriter writer(&target, out);
116 writer.Run(); 128 writer.Run();
117 129
118 const char expected_win[] = 130 const char expected_win[] =
119 "rule __foo_bar___rule\n" 131 "rule __foo_bar___rule\n"
120 " command = C$:/python/python.exe gyp-win-tool action-wrapper environme nt.x86 __foo_bar___rule.$unique_name.rsp\n" 132 " command = C$:/python/python.exe gyp-win-tool action-wrapper environme nt.x86 __foo_bar___rule.$unique_name.rsp\n"
121 " description = ACTION //foo:bar()\n" 133 " description = ACTION //foo:bar()\n"
122 " restat = 1\n" 134 " restat = 1\n"
123 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 135 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
124 " rspfile_content = C$:/python/python.exe ../../foo/script.py\n" 136 " rspfile_content = C$:/python/python.exe ../../foo/script.py\n"
125 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 137 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
126 "../../foo/included.txt ../../foo/source.txt\n" 138 "../../foo/included.txt ../../foo/source.txt\n"
127 "\n" 139 "\n"
128 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" 140 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n"
129 "\n" 141 "\n"
130 "build obj/foo/bar.stamp: stamp foo.out\n"; 142 "build obj/foo/bar.stamp: stamp foo.out\n";
131 EXPECT_EQ(expected_win, out.str()); 143 EXPECT_EQ(expected_win, out.str());
132 } 144 }
133 } 145 }
134 146
135 TEST(NinjaActionTargetWriter, ForEach) { 147 TEST(NinjaActionTargetWriter, ForEach) {
136 TestWithScope setup; 148 TestWithScope setup;
137 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 149 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
138 150
139 // Some dependencies that the action can depend on. Use actions for these 151 // Some dependencies that the action can depend on. Use actions for these
140 // so they have a nice platform-independent stamp file that can appear in the 152 // so they have a nice platform-independent stamp file that can appear in the
141 // output (rather than having to worry about how the current platform names 153 // output (rather than having to worry about how the current platform names
142 // binaries). 154 // binaries).
143 Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep")); 155 Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"));
144 dep.set_output_type(Target::ACTION); 156 dep.set_output_type(Target::ACTION);
157 dep.SetToolchain(setup.toolchain());
158 dep.OnResolved();
159
145 Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep")); 160 Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"));
146 datadep.set_output_type(Target::ACTION); 161 datadep.set_output_type(Target::ACTION);
162 datadep.SetToolchain(setup.toolchain());
163 datadep.OnResolved();
147 164
148 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 165 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
149 target.set_output_type(Target::ACTION_FOREACH); 166 target.set_output_type(Target::ACTION_FOREACH);
150 target.deps().push_back(LabelTargetPair(&dep)); 167 target.deps().push_back(LabelTargetPair(&dep));
151 target.datadeps().push_back(LabelTargetPair(&datadep)); 168 target.datadeps().push_back(LabelTargetPair(&datadep));
152 169
153 target.sources().push_back(SourceFile("//foo/input1.txt")); 170 target.sources().push_back(SourceFile("//foo/input1.txt"));
154 target.sources().push_back(SourceFile("//foo/input2.txt")); 171 target.sources().push_back(SourceFile("//foo/input2.txt"));
155 172
156 target.action_values().set_script(SourceFile("//foo/script.py")); 173 target.action_values().set_script(SourceFile("//foo/script.py"));
157 174
158 target.action_values().args() = SubstitutionList::MakeForTest( 175 target.action_values().args() = SubstitutionList::MakeForTest(
159 "-i", 176 "-i",
160 "{{source}}", 177 "{{source}}",
161 "--out=foo bar{{source_name_part}}.o"); 178 "--out=foo bar{{source_name_part}}.o");
162 target.action_values().outputs() = SubstitutionList::MakeForTest( 179 target.action_values().outputs() = SubstitutionList::MakeForTest(
163 "//out/Debug/{{source_name_part}}.out"); 180 "//out/Debug/{{source_name_part}}.out");
164 181
165 target.inputs().push_back(SourceFile("//foo/included.txt")); 182 target.inputs().push_back(SourceFile("//foo/included.txt"));
166 183
184 target.SetToolchain(setup.toolchain());
185 target.OnResolved();
186
167 // Posix. 187 // Posix.
168 { 188 {
169 setup.settings()->set_target_os(Settings::LINUX); 189 setup.settings()->set_target_os(Settings::LINUX);
170 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 190 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
171 "/usr/bin/python"))); 191 "/usr/bin/python")));
172 192
173 std::ostringstream out; 193 std::ostringstream out;
174 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 194 NinjaActionTargetWriter writer(&target, out);
175 writer.Run(); 195 writer.Run();
176 196
177 const char expected_linux[] = 197 const char expected_linux[] =
178 "rule __foo_bar___rule\n" 198 "rule __foo_bar___rule\n"
179 " command = /usr/bin/python ../../foo/script.py -i ${in} " 199 " command = /usr/bin/python ../../foo/script.py -i ${in} "
180 // Escaping is different between Windows and Posix. 200 // Escaping is different between Windows and Posix.
181 #if defined(OS_WIN) 201 #if defined(OS_WIN)
182 "\"--out=foo$ bar${source_name_part}.o\"\n" 202 "\"--out=foo$ bar${source_name_part}.o\"\n"
183 #else 203 #else
184 "--out=foo\\$ bar${source_name_part}.o\n" 204 "--out=foo\\$ bar${source_name_part}.o\n"
185 #endif 205 #endif
186 " description = ACTION //foo:bar()\n" 206 " description = ACTION //foo:bar()\n"
187 " restat = 1\n" 207 " restat = 1\n"
188 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 208 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
189 "../../foo/included.txt obj/foo/dep.stamp\n" 209 "../../foo/included.txt obj/foo/dep.stamp\n"
190 "\n" 210 "\n"
191 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " 211 "build input1.out: __foo_bar___rule ../../foo/input1.txt | "
192 "obj/foo/bar.inputdeps.stamp\n" 212 "obj/foo/bar.inputdeps.stamp\n"
193 " source_name_part = input1\n" 213 " source_name_part = input1\n"
194 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " 214 "build input2.out: __foo_bar___rule ../../foo/input2.txt | "
195 "obj/foo/bar.inputdeps.stamp\n" 215 "obj/foo/bar.inputdeps.stamp\n"
196 " source_name_part = input2\n" 216 " source_name_part = input2\n"
197 "\n" 217 "\n"
198 "build obj/foo/bar.stamp: " 218 "build obj/foo/bar.stamp: "
199 "stamp input1.out input2.out obj/foo/datadep.stamp\n"; 219 "stamp input1.out input2.out || obj/foo/datadep.stamp\n";
200 220
201 std::string out_str = out.str(); 221 std::string out_str = out.str();
202 #if defined(OS_WIN) 222 #if defined(OS_WIN)
203 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 223 std::replace(out_str.begin(), out_str.end(), '\\', '/');
204 #endif 224 #endif
205 EXPECT_EQ(expected_linux, out_str); 225 EXPECT_EQ(expected_linux, out_str);
206 } 226 }
207 227
208 // Windows. 228 // Windows.
209 { 229 {
210 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 230 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
211 "C:/python/python.exe"))); 231 "C:/python/python.exe")));
212 setup.settings()->set_target_os(Settings::WIN); 232 setup.settings()->set_target_os(Settings::WIN);
213 233
214 std::ostringstream out; 234 std::ostringstream out;
215 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 235 NinjaActionTargetWriter writer(&target, out);
216 writer.Run(); 236 writer.Run();
217 237
218 const char expected_win[] = 238 const char expected_win[] =
219 "rule __foo_bar___rule\n" 239 "rule __foo_bar___rule\n"
220 " command = C$:/python/python.exe gyp-win-tool action-wrapper " 240 " command = C$:/python/python.exe gyp-win-tool action-wrapper "
221 "environment.x86 __foo_bar___rule.$unique_name.rsp\n" 241 "environment.x86 __foo_bar___rule.$unique_name.rsp\n"
222 " description = ACTION //foo:bar()\n" 242 " description = ACTION //foo:bar()\n"
223 " restat = 1\n" 243 " restat = 1\n"
224 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 244 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
225 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " 245 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
226 #if defined(OS_WIN) 246 #if defined(OS_WIN)
227 "${in} \"--out=foo$ bar${source_name_part}.o\"\n" 247 "${in} \"--out=foo$ bar${source_name_part}.o\"\n"
228 #else 248 #else
229 "${in} --out=foo\\$ bar${source_name_part}.o\n" 249 "${in} --out=foo\\$ bar${source_name_part}.o\n"
230 #endif 250 #endif
231 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " 251 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
232 "../../foo/included.txt obj/foo/dep.stamp\n" 252 "../../foo/included.txt obj/foo/dep.stamp\n"
233 "\n" 253 "\n"
234 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " 254 "build input1.out: __foo_bar___rule ../../foo/input1.txt | "
235 "obj/foo/bar.inputdeps.stamp\n" 255 "obj/foo/bar.inputdeps.stamp\n"
236 " unique_name = 0\n" 256 " unique_name = 0\n"
237 " source_name_part = input1\n" 257 " source_name_part = input1\n"
238 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " 258 "build input2.out: __foo_bar___rule ../../foo/input2.txt | "
239 "obj/foo/bar.inputdeps.stamp\n" 259 "obj/foo/bar.inputdeps.stamp\n"
240 " unique_name = 1\n" 260 " unique_name = 1\n"
241 " source_name_part = input2\n" 261 " source_name_part = input2\n"
242 "\n" 262 "\n"
243 "build obj/foo/bar.stamp: " 263 "build obj/foo/bar.stamp: "
244 "stamp input1.out input2.out obj/foo/datadep.stamp\n"; 264 "stamp input1.out input2.out || obj/foo/datadep.stamp\n";
245 EXPECT_EQ(expected_win, out.str()); 265 EXPECT_EQ(expected_win, out.str());
246 } 266 }
247 } 267 }
248 268
249 TEST(NinjaActionTargetWriter, ForEachWithDepfile) { 269 TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
250 TestWithScope setup; 270 TestWithScope setup;
251 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 271 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
252 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 272 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
253 target.set_output_type(Target::ACTION_FOREACH); 273 target.set_output_type(Target::ACTION_FOREACH);
254 274
255 target.sources().push_back(SourceFile("//foo/input1.txt")); 275 target.sources().push_back(SourceFile("//foo/input1.txt"));
256 target.sources().push_back(SourceFile("//foo/input2.txt")); 276 target.sources().push_back(SourceFile("//foo/input2.txt"));
257 277
258 target.action_values().set_script(SourceFile("//foo/script.py")); 278 target.action_values().set_script(SourceFile("//foo/script.py"));
259 279
280 target.SetToolchain(setup.toolchain());
281 target.OnResolved();
282
260 SubstitutionPattern depfile; 283 SubstitutionPattern depfile;
261 Err err; 284 Err err;
262 ASSERT_TRUE( 285 ASSERT_TRUE(
263 depfile.Parse("//out/Debug/gen/{{source_name_part}}.d", NULL, &err)); 286 depfile.Parse("//out/Debug/gen/{{source_name_part}}.d", NULL, &err));
264 target.action_values().set_depfile(depfile); 287 target.action_values().set_depfile(depfile);
265 288
266 target.action_values().args() = SubstitutionList::MakeForTest( 289 target.action_values().args() = SubstitutionList::MakeForTest(
267 "-i", 290 "-i",
268 "{{source}}", 291 "{{source}}",
269 "--out=foo bar{{source_name_part}}.o"); 292 "--out=foo bar{{source_name_part}}.o");
270 target.action_values().outputs() = SubstitutionList::MakeForTest( 293 target.action_values().outputs() = SubstitutionList::MakeForTest(
271 "//out/Debug/{{source_name_part}}.out"); 294 "//out/Debug/{{source_name_part}}.out");
272 295
273 target.inputs().push_back(SourceFile("//foo/included.txt")); 296 target.inputs().push_back(SourceFile("//foo/included.txt"));
274 297
275 // Posix. 298 // Posix.
276 { 299 {
277 setup.settings()->set_target_os(Settings::LINUX); 300 setup.settings()->set_target_os(Settings::LINUX);
278 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 301 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
279 "/usr/bin/python"))); 302 "/usr/bin/python")));
280 303
281 std::ostringstream out; 304 std::ostringstream out;
282 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 305 NinjaActionTargetWriter writer(&target, out);
283 writer.Run(); 306 writer.Run();
284 307
285 const char expected_linux[] = 308 const char expected_linux[] =
286 "rule __foo_bar___rule\n" 309 "rule __foo_bar___rule\n"
287 " command = /usr/bin/python ../../foo/script.py -i ${in} " 310 " command = /usr/bin/python ../../foo/script.py -i ${in} "
288 #if defined(OS_WIN) 311 #if defined(OS_WIN)
289 "\"--out=foo$ bar${source_name_part}.o\"\n" 312 "\"--out=foo$ bar${source_name_part}.o\"\n"
290 #else 313 #else
291 "--out=foo\\$ bar${source_name_part}.o\n" 314 "--out=foo\\$ bar${source_name_part}.o\n"
292 #endif 315 #endif
(...skipping 15 matching lines...) Expand all
308 EXPECT_EQ(expected_linux, out.str()); 331 EXPECT_EQ(expected_linux, out.str());
309 } 332 }
310 333
311 // Windows. 334 // Windows.
312 { 335 {
313 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( 336 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL(
314 "C:/python/python.exe"))); 337 "C:/python/python.exe")));
315 setup.settings()->set_target_os(Settings::WIN); 338 setup.settings()->set_target_os(Settings::WIN);
316 339
317 std::ostringstream out; 340 std::ostringstream out;
318 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); 341 NinjaActionTargetWriter writer(&target, out);
319 writer.Run(); 342 writer.Run();
320 343
321 const char expected_win[] = 344 const char expected_win[] =
322 "rule __foo_bar___rule\n" 345 "rule __foo_bar___rule\n"
323 " command = C$:/python/python.exe gyp-win-tool action-wrapper " 346 " command = C$:/python/python.exe gyp-win-tool action-wrapper "
324 "environment.x86 __foo_bar___rule.$unique_name.rsp\n" 347 "environment.x86 __foo_bar___rule.$unique_name.rsp\n"
325 " description = ACTION //foo:bar()\n" 348 " description = ACTION //foo:bar()\n"
326 " restat = 1\n" 349 " restat = 1\n"
327 " rspfile = __foo_bar___rule.$unique_name.rsp\n" 350 " rspfile = __foo_bar___rule.$unique_name.rsp\n"
328 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " 351 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
(...skipping 13 matching lines...) Expand all
342 "build input2.out: __foo_bar___rule ../../foo/input2.txt" 365 "build input2.out: __foo_bar___rule ../../foo/input2.txt"
343 " | obj/foo/bar.inputdeps.stamp\n" 366 " | obj/foo/bar.inputdeps.stamp\n"
344 " unique_name = 1\n" 367 " unique_name = 1\n"
345 " source_name_part = input2\n" 368 " source_name_part = input2\n"
346 " depfile = gen/input2.d\n" 369 " depfile = gen/input2.d\n"
347 "\n" 370 "\n"
348 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 371 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
349 EXPECT_EQ(expected_win, out.str()); 372 EXPECT_EQ(expected_win, out.str());
350 } 373 }
351 } 374 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_action_target_writer.cc ('k') | tools/gn/ninja_binary_target_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698