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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 "defines =\n" | 104 "defines =\n" |
105 "include_dirs =\n" | 105 "include_dirs =\n" |
106 "root_out_dir = .\n" | 106 "root_out_dir = .\n" |
107 "target_out_dir = obj/foo\n" | 107 "target_out_dir = obj/foo\n" |
108 "target_output_name = libstlib\n" | 108 "target_output_name = libstlib\n" |
109 "\n" | 109 "\n" |
110 "\n" | 110 "\n" |
111 // There are no sources so there are no params to alink. (In practice | 111 // There are no sources so there are no params to alink. (In practice |
112 // this will probably fail in the archive tool.) | 112 // this will probably fail in the archive tool.) |
113 "build obj/foo/libstlib.a: alink || obj/foo/bar.stamp\n" | 113 "build obj/foo/libstlib.a: alink || obj/foo/bar.stamp\n" |
| 114 " arflags =\n" |
114 " output_extension = \n" | 115 " output_extension = \n" |
115 " output_dir = \n"; | 116 " output_dir = \n"; |
116 std::string out_str = out.str(); | 117 std::string out_str = out.str(); |
117 EXPECT_EQ(expected, out_str); | 118 EXPECT_EQ(expected, out_str); |
118 } | 119 } |
119 | 120 |
120 // Make the static library 'complete', which means it should be linked. | 121 // Make the static library 'complete', which means it should be linked. |
121 stlib_target.set_complete_static_lib(true); | 122 stlib_target.set_complete_static_lib(true); |
122 { | 123 { |
123 std::ostringstream out; | 124 std::ostringstream out; |
124 NinjaBinaryTargetWriter writer(&stlib_target, out); | 125 NinjaBinaryTargetWriter writer(&stlib_target, out); |
125 writer.Run(); | 126 writer.Run(); |
126 | 127 |
127 const char expected[] = | 128 const char expected[] = |
128 "defines =\n" | 129 "defines =\n" |
129 "include_dirs =\n" | 130 "include_dirs =\n" |
130 "root_out_dir = .\n" | 131 "root_out_dir = .\n" |
131 "target_out_dir = obj/foo\n" | 132 "target_out_dir = obj/foo\n" |
132 "target_output_name = libstlib\n" | 133 "target_output_name = libstlib\n" |
133 "\n" | 134 "\n" |
134 "\n" | 135 "\n" |
135 // Ordering of the obj files here should come out in the order | 136 // Ordering of the obj files here should come out in the order |
136 // specified, with the target's first, followed by the source set's, in | 137 // specified, with the target's first, followed by the source set's, in |
137 // order. | 138 // order. |
138 "build obj/foo/libstlib.a: alink obj/foo/bar.input1.o " | 139 "build obj/foo/libstlib.a: alink obj/foo/bar.input1.o " |
139 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj " | 140 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj " |
140 "|| obj/foo/bar.stamp\n" | 141 "|| obj/foo/bar.stamp\n" |
| 142 " arflags =\n" |
141 " output_extension = \n" | 143 " output_extension = \n" |
142 " output_dir = \n"; | 144 " output_dir = \n"; |
143 std::string out_str = out.str(); | 145 std::string out_str = out.str(); |
144 EXPECT_EQ(expected, out_str); | 146 EXPECT_EQ(expected, out_str); |
145 } | 147 } |
146 } | 148 } |
147 | 149 |
| 150 TEST(NinjaBinaryTargetWriter, StaticLibrary) { |
| 151 TestWithScope setup; |
| 152 Err err; |
| 153 |
| 154 TestTarget target(setup, "//foo:bar", Target::STATIC_LIBRARY); |
| 155 target.sources().push_back(SourceFile("//foo/input1.cc")); |
| 156 target.config_values().arflags().push_back("--asdf"); |
| 157 ASSERT_TRUE(target.OnResolved(&err)); |
| 158 |
| 159 std::ostringstream out; |
| 160 NinjaBinaryTargetWriter writer(&target, out); |
| 161 writer.Run(); |
| 162 |
| 163 const char expected[] = |
| 164 "defines =\n" |
| 165 "include_dirs =\n" |
| 166 "cflags =\n" |
| 167 "cflags_cc =\n" |
| 168 "root_out_dir = .\n" |
| 169 "target_out_dir = obj/foo\n" |
| 170 "target_output_name = libbar\n" |
| 171 "\n" |
| 172 "build obj/foo/libbar.input1.o: cxx ../../foo/input1.cc\n" |
| 173 "\n" |
| 174 "build obj/foo/libbar.a: alink obj/foo/libbar.input1.o\n" |
| 175 " arflags = --asdf\n" |
| 176 " output_extension = \n" |
| 177 " output_dir = \n"; |
| 178 std::string out_str = out.str(); |
| 179 EXPECT_EQ(expected, out_str); |
| 180 } |
| 181 |
148 // This tests that output extension and output dir overrides apply, and input | 182 // This tests that output extension and output dir overrides apply, and input |
149 // dependencies are applied. | 183 // dependencies are applied. |
150 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) { | 184 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) { |
151 TestWithScope setup; | 185 TestWithScope setup; |
152 Err err; | 186 Err err; |
153 | 187 |
154 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 188 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
155 | 189 |
156 // An action for our library to depend on. | 190 // An action for our library to depend on. |
157 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 191 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 772 |
739 EXPECT_FALSE(scheduler.is_failed()); | 773 EXPECT_FALSE(scheduler.is_failed()); |
740 | 774 |
741 std::ostringstream out; | 775 std::ostringstream out; |
742 NinjaBinaryTargetWriter writer(&target, out); | 776 NinjaBinaryTargetWriter writer(&target, out); |
743 writer.Run(); | 777 writer.Run(); |
744 | 778 |
745 // Should have issued an error. | 779 // Should have issued an error. |
746 EXPECT_TRUE(scheduler.is_failed()); | 780 EXPECT_TRUE(scheduler.is_failed()); |
747 } | 781 } |
OLD | NEW |