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/ninja_binary_target_writer.h" | 5 #include "tools/gn/ninja_binary_target_writer.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 std::string out_str = out.str(); | 234 std::string out_str = out.str(); |
235 EXPECT_EQ(expected, out_str); | 235 EXPECT_EQ(expected, out_str); |
236 } | 236 } |
237 | 237 |
238 TEST(NinjaBinaryTargetWriter, EmptyProductExtension) { | 238 TEST(NinjaBinaryTargetWriter, EmptyProductExtension) { |
239 TestWithScope setup; | 239 TestWithScope setup; |
240 Err err; | 240 Err err; |
241 | 241 |
242 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 242 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
243 | 243 |
244 // This test is the same as ProductExtension, except that | 244 // This test is the same as ProductExtension, except that we call |
245 // we call set_output_extension("") and ensure that we still get the default. | 245 // set_output_extension("") and ensure that we get an empty one and override |
| 246 // the output prefix so that the name matches the target exactly. |
246 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 247 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); |
247 target.set_output_type(Target::SHARED_LIBRARY); | 248 target.set_output_type(Target::SHARED_LIBRARY); |
| 249 target.set_output_prefix_override(true); |
248 target.set_output_extension(std::string()); | 250 target.set_output_extension(std::string()); |
249 target.sources().push_back(SourceFile("//foo/input1.cc")); | 251 target.sources().push_back(SourceFile("//foo/input1.cc")); |
250 target.sources().push_back(SourceFile("//foo/input2.cc")); | 252 target.sources().push_back(SourceFile("//foo/input2.cc")); |
251 | 253 |
252 target.SetToolchain(setup.toolchain()); | 254 target.SetToolchain(setup.toolchain()); |
253 ASSERT_TRUE(target.OnResolved(&err)); | 255 ASSERT_TRUE(target.OnResolved(&err)); |
254 | 256 |
255 std::ostringstream out; | 257 std::ostringstream out; |
256 NinjaBinaryTargetWriter writer(&target, out); | 258 NinjaBinaryTargetWriter writer(&target, out); |
257 writer.Run(); | 259 writer.Run(); |
258 | 260 |
259 const char expected[] = | 261 const char expected[] = |
260 "defines =\n" | 262 "defines =\n" |
261 "include_dirs =\n" | 263 "include_dirs =\n" |
262 "cflags =\n" | 264 "cflags =\n" |
263 "cflags_cc =\n" | 265 "cflags_cc =\n" |
264 "root_out_dir = .\n" | 266 "root_out_dir = .\n" |
265 "target_out_dir = obj/foo\n" | 267 "target_out_dir = obj/foo\n" |
266 "target_output_name = libshlib\n" | 268 "target_output_name = shlib\n" |
267 "\n" | 269 "\n" |
268 "build obj/foo/libshlib.input1.o: cxx ../../foo/input1.cc\n" | 270 "build obj/foo/shlib.input1.o: cxx ../../foo/input1.cc\n" |
269 "build obj/foo/libshlib.input2.o: cxx ../../foo/input2.cc\n" | 271 "build obj/foo/shlib.input2.o: cxx ../../foo/input2.cc\n" |
270 "\n" | 272 "\n" |
271 "build ./libshlib.so: solink obj/foo/libshlib.input1.o " | 273 "build ./shlib: solink obj/foo/shlib.input1.o " |
272 "obj/foo/libshlib.input2.o\n" | 274 "obj/foo/shlib.input2.o\n" |
273 " ldflags =\n" | 275 " ldflags =\n" |
274 " libs =\n" | 276 " libs =\n" |
275 " output_extension = .so\n"; | 277 " output_extension = \n"; |
276 | 278 |
277 std::string out_str = out.str(); | 279 std::string out_str = out.str(); |
278 EXPECT_EQ(expected, out_str); | 280 EXPECT_EQ(expected, out_str); |
279 } | 281 } |
280 | 282 |
281 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { | 283 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { |
282 TestWithScope setup; | 284 TestWithScope setup; |
283 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 285 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
284 | 286 |
285 Err err; | 287 Err err; |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 727 |
726 EXPECT_FALSE(scheduler.is_failed()); | 728 EXPECT_FALSE(scheduler.is_failed()); |
727 | 729 |
728 std::ostringstream out; | 730 std::ostringstream out; |
729 NinjaBinaryTargetWriter writer(&target, out); | 731 NinjaBinaryTargetWriter writer(&target, out); |
730 writer.Run(); | 732 writer.Run(); |
731 | 733 |
732 // Should have issued an error. | 734 // Should have issued an error. |
733 EXPECT_TRUE(scheduler.is_failed()); | 735 EXPECT_TRUE(scheduler.is_failed()); |
734 } | 736 } |
OLD | NEW |