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/target.h" | 9 #include "tools/gn/target.h" |
10 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 "cflags_objcc =\n" | 77 "cflags_objcc =\n" |
78 "root_out_dir = .\n" | 78 "root_out_dir = .\n" |
79 "target_out_dir = obj/foo\n" | 79 "target_out_dir = obj/foo\n" |
80 "target_output_name = libshlib\n" | 80 "target_output_name = libshlib\n" |
81 "\n" | 81 "\n" |
82 "\n" | 82 "\n" |
83 // Ordering of the obj files here should come out in the order | 83 // Ordering of the obj files here should come out in the order |
84 // specified, with the target's first, followed by the source set's, in | 84 // specified, with the target's first, followed by the source set's, in |
85 // order. | 85 // order. |
86 "build ./libshlib.so: solink obj/foo/bar.input1.o " | 86 "build ./libshlib.so: solink obj/foo/bar.input1.o " |
87 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj\n" | 87 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj " |
| 88 "|| obj/foo/bar.stamp\n" |
88 " ldflags =\n" | 89 " ldflags =\n" |
89 " libs =\n" | 90 " libs =\n" |
90 " output_extension = .so\n"; | 91 " output_extension = .so\n"; |
91 std::string out_str = out.str(); | 92 std::string out_str = out.str(); |
92 EXPECT_EQ(expected, out_str); | 93 EXPECT_EQ(expected, out_str); |
93 } | 94 } |
94 | 95 |
95 // A static library that depends on the source set (should not link it). | 96 // A static library that depends on the source set (should not link it). |
96 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); | 97 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); |
97 stlib_target.set_output_type(Target::STATIC_LIBRARY); | 98 stlib_target.set_output_type(Target::STATIC_LIBRARY); |
(...skipping 14 matching lines...) Expand all Loading... |
112 "cflags_cc =\n" | 113 "cflags_cc =\n" |
113 "cflags_objc =\n" | 114 "cflags_objc =\n" |
114 "cflags_objcc =\n" | 115 "cflags_objcc =\n" |
115 "root_out_dir = .\n" | 116 "root_out_dir = .\n" |
116 "target_out_dir = obj/foo\n" | 117 "target_out_dir = obj/foo\n" |
117 "target_output_name = libstlib\n" | 118 "target_output_name = libstlib\n" |
118 "\n" | 119 "\n" |
119 "\n" | 120 "\n" |
120 // There are no sources so there are no params to alink. (In practice | 121 // There are no sources so there are no params to alink. (In practice |
121 // this will probably fail in the archive tool.) | 122 // this will probably fail in the archive tool.) |
122 "build obj/foo/libstlib.a: alink\n" | 123 "build obj/foo/libstlib.a: alink || obj/foo/bar.stamp\n" |
123 " ldflags =\n" | 124 " ldflags =\n" |
124 " libs =\n" | 125 " libs =\n" |
125 " output_extension = \n"; | 126 " output_extension = \n"; |
126 std::string out_str = out.str(); | 127 std::string out_str = out.str(); |
127 EXPECT_EQ(expected, out_str); | 128 EXPECT_EQ(expected, out_str); |
128 } | 129 } |
129 | 130 |
130 // Make the static library 'complete', which means it should be linked. | 131 // Make the static library 'complete', which means it should be linked. |
131 stlib_target.set_complete_static_lib(true); | 132 stlib_target.set_complete_static_lib(true); |
132 { | 133 { |
(...skipping 11 matching lines...) Expand all Loading... |
144 "cflags_objcc =\n" | 145 "cflags_objcc =\n" |
145 "root_out_dir = .\n" | 146 "root_out_dir = .\n" |
146 "target_out_dir = obj/foo\n" | 147 "target_out_dir = obj/foo\n" |
147 "target_output_name = libstlib\n" | 148 "target_output_name = libstlib\n" |
148 "\n" | 149 "\n" |
149 "\n" | 150 "\n" |
150 // Ordering of the obj files here should come out in the order | 151 // Ordering of the obj files here should come out in the order |
151 // specified, with the target's first, followed by the source set's, in | 152 // specified, with the target's first, followed by the source set's, in |
152 // order. | 153 // order. |
153 "build obj/foo/libstlib.a: alink obj/foo/bar.input1.o " | 154 "build obj/foo/libstlib.a: alink obj/foo/bar.input1.o " |
154 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj\n" | 155 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj " |
| 156 "|| obj/foo/bar.stamp\n" |
155 " ldflags =\n" | 157 " ldflags =\n" |
156 " libs =\n" | 158 " libs =\n" |
157 " output_extension = \n"; | 159 " output_extension = \n"; |
158 std::string out_str = out.str(); | 160 std::string out_str = out.str(); |
159 EXPECT_EQ(expected, out_str); | 161 EXPECT_EQ(expected, out_str); |
160 } | 162 } |
161 } | 163 } |
162 | 164 |
163 // This tests that output extension overrides apply, and input dependencies | 165 // This tests that output extension overrides apply, and input dependencies |
164 // are applied. | 166 // are applied. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 "\n" | 262 "\n" |
261 "build ./libshlib.so: solink obj/foo/libshlib.input1.o " | 263 "build ./libshlib.so: solink obj/foo/libshlib.input1.o " |
262 "obj/foo/libshlib.input2.o\n" | 264 "obj/foo/libshlib.input2.o\n" |
263 " ldflags =\n" | 265 " ldflags =\n" |
264 " libs =\n" | 266 " libs =\n" |
265 " output_extension = .so\n"; | 267 " output_extension = .so\n"; |
266 | 268 |
267 std::string out_str = out.str(); | 269 std::string out_str = out.str(); |
268 EXPECT_EQ(expected, out_str); | 270 EXPECT_EQ(expected, out_str); |
269 } | 271 } |
| 272 |
| 273 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { |
| 274 TestWithScope setup; |
| 275 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 276 setup.settings()->set_target_os(Settings::LINUX); |
| 277 |
| 278 Err err; |
| 279 |
| 280 // This target is a data (runtime) dependency of the intermediate target. |
| 281 Target data(setup.settings(), Label(SourceDir("//foo/"), "data_target")); |
| 282 data.set_output_type(Target::EXECUTABLE); |
| 283 data.visibility().SetPublic(); |
| 284 data.SetToolchain(setup.toolchain()); |
| 285 ASSERT_TRUE(data.OnResolved(&err)); |
| 286 |
| 287 // Intermediate source set target. |
| 288 Target inter(setup.settings(), Label(SourceDir("//foo/"), "inter")); |
| 289 inter.set_output_type(Target::SOURCE_SET); |
| 290 inter.visibility().SetPublic(); |
| 291 inter.data_deps().push_back(LabelTargetPair(&data)); |
| 292 inter.SetToolchain(setup.toolchain()); |
| 293 inter.sources().push_back(SourceFile("//foo/inter.cc")); |
| 294 ASSERT_TRUE(inter.OnResolved(&err)) << err.message(); |
| 295 |
| 296 // Write out the intermediate target. |
| 297 std::ostringstream inter_out; |
| 298 NinjaBinaryTargetWriter inter_writer(&inter, inter_out); |
| 299 inter_writer.Run(); |
| 300 |
| 301 // The intermediate source set will be a stamp file that depends on the |
| 302 // object files, and will have an order-only dependency on its data dep and |
| 303 // data file. |
| 304 const char inter_expected[] = |
| 305 "defines =\n" |
| 306 "include_dirs =\n" |
| 307 "cflags =\n" |
| 308 "cflags_c =\n" |
| 309 "cflags_cc =\n" |
| 310 "cflags_objc =\n" |
| 311 "cflags_objcc =\n" |
| 312 "root_out_dir = .\n" |
| 313 "target_out_dir = obj/foo\n" |
| 314 "target_output_name = inter\n" |
| 315 "\n" |
| 316 "build obj/foo/inter.inter.o: cxx ../../foo/inter.cc\n" |
| 317 "\n" |
| 318 "build obj/foo/inter.stamp: stamp obj/foo/inter.inter.o || " |
| 319 "./data_target\n"; |
| 320 EXPECT_EQ(inter_expected, inter_out.str()); |
| 321 |
| 322 // Final target. |
| 323 Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); |
| 324 exe.set_output_type(Target::EXECUTABLE); |
| 325 exe.public_deps().push_back(LabelTargetPair(&inter)); |
| 326 exe.SetToolchain(setup.toolchain()); |
| 327 exe.sources().push_back(SourceFile("//foo/final.cc")); |
| 328 ASSERT_TRUE(exe.OnResolved(&err)); |
| 329 |
| 330 std::ostringstream final_out; |
| 331 NinjaBinaryTargetWriter final_writer(&exe, final_out); |
| 332 final_writer.Run(); |
| 333 |
| 334 // The final output depends on both object files (one from the final target, |
| 335 // one from the source set) and has an order-only dependency on the source |
| 336 // set's stamp file and the final target's data file. The source set stamp |
| 337 // dependency will create an implicit order-only dependency on the data |
| 338 // target. |
| 339 const char final_expected[] = |
| 340 "defines =\n" |
| 341 "include_dirs =\n" |
| 342 "cflags =\n" |
| 343 "cflags_c =\n" |
| 344 "cflags_cc =\n" |
| 345 "cflags_objc =\n" |
| 346 "cflags_objcc =\n" |
| 347 "root_out_dir = .\n" |
| 348 "target_out_dir = obj/foo\n" |
| 349 "target_output_name = exe\n" |
| 350 "\n" |
| 351 "build obj/foo/exe.final.o: cxx ../../foo/final.cc\n" |
| 352 "\n" |
| 353 "build ./exe: link obj/foo/exe.final.o obj/foo/inter.inter.o || " |
| 354 "obj/foo/inter.stamp\n" |
| 355 " ldflags =\n" |
| 356 " libs =\n" |
| 357 " output_extension = \n"; |
| 358 EXPECT_EQ(final_expected, final_out.str()); |
| 359 } |
OLD | NEW |