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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/ninja_binary_target_writer.h" | 8 #include "tools/gn/ninja_binary_target_writer.h" |
9 #include "tools/gn/scheduler.h" | 9 #include "tools/gn/scheduler.h" |
10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
11 #include "tools/gn/test_with_scope.h" | 11 #include "tools/gn/test_with_scope.h" |
12 | 12 |
13 TEST(NinjaBinaryTargetWriter, SourceSet) { | 13 TEST(NinjaBinaryTargetWriter, SourceSet) { |
14 TestWithScope setup; | 14 TestWithScope setup; |
15 Err err; | 15 Err err; |
16 | 16 |
17 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 17 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
18 setup.settings()->set_target_os(Settings::WIN); | |
19 | 18 |
20 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 19 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
21 target.set_output_type(Target::SOURCE_SET); | 20 target.set_output_type(Target::SOURCE_SET); |
22 target.visibility().SetPublic(); | 21 target.visibility().SetPublic(); |
23 target.sources().push_back(SourceFile("//foo/input1.cc")); | 22 target.sources().push_back(SourceFile("//foo/input1.cc")); |
24 target.sources().push_back(SourceFile("//foo/input2.cc")); | 23 target.sources().push_back(SourceFile("//foo/input2.cc")); |
25 // Also test object files, which should be just passed through to the | 24 // Also test object files, which should be just passed through to the |
26 // dependents to link. | 25 // dependents to link. |
27 target.sources().push_back(SourceFile("//foo/input3.o")); | 26 target.sources().push_back(SourceFile("//foo/input3.o")); |
28 target.sources().push_back(SourceFile("//foo/input4.obj")); | 27 target.sources().push_back(SourceFile("//foo/input4.obj")); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 144 } |
146 } | 145 } |
147 | 146 |
148 // This tests that output extension overrides apply, and input dependencies | 147 // This tests that output extension overrides apply, and input dependencies |
149 // are applied. | 148 // are applied. |
150 TEST(NinjaBinaryTargetWriter, ProductExtensionAndInputDeps) { | 149 TEST(NinjaBinaryTargetWriter, ProductExtensionAndInputDeps) { |
151 TestWithScope setup; | 150 TestWithScope setup; |
152 Err err; | 151 Err err; |
153 | 152 |
154 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 153 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
155 setup.settings()->set_target_os(Settings::LINUX); | |
156 | 154 |
157 // An action for our library to depend on. | 155 // An action for our library to depend on. |
158 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 156 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); |
159 action.set_output_type(Target::ACTION_FOREACH); | 157 action.set_output_type(Target::ACTION_FOREACH); |
160 action.visibility().SetPublic(); | 158 action.visibility().SetPublic(); |
161 action.SetToolchain(setup.toolchain()); | 159 action.SetToolchain(setup.toolchain()); |
162 ASSERT_TRUE(action.OnResolved(&err)); | 160 ASSERT_TRUE(action.OnResolved(&err)); |
163 | 161 |
164 // A shared library w/ the product_extension set to a custom value. | 162 // A shared library w/ the product_extension set to a custom value. |
165 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 163 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 199 |
202 std::string out_str = out.str(); | 200 std::string out_str = out.str(); |
203 EXPECT_EQ(expected, out_str); | 201 EXPECT_EQ(expected, out_str); |
204 } | 202 } |
205 | 203 |
206 TEST(NinjaBinaryTargetWriter, EmptyProductExtension) { | 204 TEST(NinjaBinaryTargetWriter, EmptyProductExtension) { |
207 TestWithScope setup; | 205 TestWithScope setup; |
208 Err err; | 206 Err err; |
209 | 207 |
210 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 208 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
211 setup.settings()->set_target_os(Settings::LINUX); | |
212 | 209 |
213 // This test is the same as ProductExtension, except that | 210 // This test is the same as ProductExtension, except that |
214 // we call set_output_extension("") and ensure that we still get the default. | 211 // we call set_output_extension("") and ensure that we still get the default. |
215 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 212 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); |
216 target.set_output_type(Target::SHARED_LIBRARY); | 213 target.set_output_type(Target::SHARED_LIBRARY); |
217 target.set_output_extension(std::string()); | 214 target.set_output_extension(std::string()); |
218 target.sources().push_back(SourceFile("//foo/input1.cc")); | 215 target.sources().push_back(SourceFile("//foo/input1.cc")); |
219 target.sources().push_back(SourceFile("//foo/input2.cc")); | 216 target.sources().push_back(SourceFile("//foo/input2.cc")); |
220 | 217 |
221 target.SetToolchain(setup.toolchain()); | 218 target.SetToolchain(setup.toolchain()); |
(...skipping 21 matching lines...) Expand all Loading... |
243 " libs =\n" | 240 " libs =\n" |
244 " output_extension = .so\n"; | 241 " output_extension = .so\n"; |
245 | 242 |
246 std::string out_str = out.str(); | 243 std::string out_str = out.str(); |
247 EXPECT_EQ(expected, out_str); | 244 EXPECT_EQ(expected, out_str); |
248 } | 245 } |
249 | 246 |
250 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { | 247 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { |
251 TestWithScope setup; | 248 TestWithScope setup; |
252 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 249 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
253 setup.settings()->set_target_os(Settings::LINUX); | |
254 | 250 |
255 Err err; | 251 Err err; |
256 | 252 |
257 // This target is a data (runtime) dependency of the intermediate target. | 253 // This target is a data (runtime) dependency of the intermediate target. |
258 Target data(setup.settings(), Label(SourceDir("//foo/"), "data_target")); | 254 Target data(setup.settings(), Label(SourceDir("//foo/"), "data_target")); |
259 data.set_output_type(Target::EXECUTABLE); | 255 data.set_output_type(Target::EXECUTABLE); |
260 data.visibility().SetPublic(); | 256 data.visibility().SetPublic(); |
261 data.SetToolchain(setup.toolchain()); | 257 data.SetToolchain(setup.toolchain()); |
262 ASSERT_TRUE(data.OnResolved(&err)); | 258 ASSERT_TRUE(data.OnResolved(&err)); |
263 | 259 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 "obj/foo/inter.stamp\n" | 321 "obj/foo/inter.stamp\n" |
326 " ldflags =\n" | 322 " ldflags =\n" |
327 " libs =\n" | 323 " libs =\n" |
328 " output_extension = \n"; | 324 " output_extension = \n"; |
329 EXPECT_EQ(final_expected, final_out.str()); | 325 EXPECT_EQ(final_expected, final_out.str()); |
330 } | 326 } |
331 | 327 |
332 TEST(NinjaBinaryTargetWriter, SharedLibraryModuleDefinitionFile) { | 328 TEST(NinjaBinaryTargetWriter, SharedLibraryModuleDefinitionFile) { |
333 TestWithScope setup; | 329 TestWithScope setup; |
334 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 330 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
335 setup.settings()->set_target_os(Settings::WIN); | |
336 | 331 |
337 Target shared_lib(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 332 Target shared_lib(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
338 shared_lib.set_output_type(Target::SHARED_LIBRARY); | 333 shared_lib.set_output_type(Target::SHARED_LIBRARY); |
339 shared_lib.SetToolchain(setup.toolchain()); | 334 shared_lib.SetToolchain(setup.toolchain()); |
340 shared_lib.sources().push_back(SourceFile("//foo/sources.cc")); | 335 shared_lib.sources().push_back(SourceFile("//foo/sources.cc")); |
341 shared_lib.sources().push_back(SourceFile("//foo/bar.def")); | 336 shared_lib.sources().push_back(SourceFile("//foo/bar.def")); |
342 | 337 |
343 Err err; | 338 Err err; |
344 ASSERT_TRUE(shared_lib.OnResolved(&err)); | 339 ASSERT_TRUE(shared_lib.OnResolved(&err)); |
345 | 340 |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 | 691 |
697 EXPECT_FALSE(scheduler.is_failed()); | 692 EXPECT_FALSE(scheduler.is_failed()); |
698 | 693 |
699 std::ostringstream out; | 694 std::ostringstream out; |
700 NinjaBinaryTargetWriter writer(&target, out); | 695 NinjaBinaryTargetWriter writer(&target, out); |
701 writer.Run(); | 696 writer.Run(); |
702 | 697 |
703 // Should have issued an error. | 698 // Should have issued an error. |
704 EXPECT_TRUE(scheduler.is_failed()); | 699 EXPECT_TRUE(scheduler.is_failed()); |
705 } | 700 } |
OLD | NEW |