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

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

Issue 26537002: Add a UniqueVector class to GN (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: REview comments, remove npos 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
« no previous file with comments | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/output_file.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 <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/test_with_scope.h" 9 #include "tools/gn/test_with_scope.h"
10 10
(...skipping 11 matching lines...) Expand all
22 target.sources().push_back(SourceFile("//foo/input3.o")); 22 target.sources().push_back(SourceFile("//foo/input3.o"));
23 target.sources().push_back(SourceFile("//foo/input4.obj")); 23 target.sources().push_back(SourceFile("//foo/input4.obj"));
24 target.OnResolved(); 24 target.OnResolved();
25 25
26 // Source set itself. 26 // Source set itself.
27 { 27 {
28 std::ostringstream out; 28 std::ostringstream out;
29 NinjaBinaryTargetWriter writer(&target, setup.toolchain(), out); 29 NinjaBinaryTargetWriter writer(&target, setup.toolchain(), out);
30 writer.Run(); 30 writer.Run();
31 31
32 // TODO(brettw) I think we'll need to worry about backslashes here
33 // depending if we're on actual Windows or Linux pretending to be Windows.
34 const char expected_win[] = 32 const char expected_win[] =
35 "defines =\n" 33 "defines =\n"
36 "includes =\n" 34 "includes =\n"
37 "cflags =\n" 35 "cflags =\n"
38 "cflags_c =\n" 36 "cflags_c =\n"
39 "cflags_cc =\n" 37 "cflags_cc =\n"
40 "cflags_objc =\n" 38 "cflags_objc =\n"
41 "cflags_objcc =\n" 39 "cflags_objcc =\n"
42 "target_name = bar\n" 40 "target_name = bar\n"
43 "target_out_dir = obj/foo\n" 41 "target_out_dir = obj/foo\n"
(...skipping 15 matching lines...) Expand all
59 Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); 57 Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib"));
60 shlib_target.set_output_type(Target::SHARED_LIBRARY); 58 shlib_target.set_output_type(Target::SHARED_LIBRARY);
61 shlib_target.deps().push_back(LabelTargetPair(&target)); 59 shlib_target.deps().push_back(LabelTargetPair(&target));
62 shlib_target.OnResolved(); 60 shlib_target.OnResolved();
63 61
64 { 62 {
65 std::ostringstream out; 63 std::ostringstream out;
66 NinjaBinaryTargetWriter writer(&shlib_target, setup.toolchain(), out); 64 NinjaBinaryTargetWriter writer(&shlib_target, setup.toolchain(), out);
67 writer.Run(); 65 writer.Run();
68 66
69 // TODO(brettw) I think we'll need to worry about backslashes here
70 // depending if we're on actual Windows or Linux pretending to be Windows.
71 const char expected_win[] = 67 const char expected_win[] =
72 "defines =\n" 68 "defines =\n"
73 "includes =\n" 69 "includes =\n"
74 "cflags =\n" 70 "cflags =\n"
75 "cflags_c =\n" 71 "cflags_c =\n"
76 "cflags_cc =\n" 72 "cflags_cc =\n"
77 "cflags_objc =\n" 73 "cflags_objc =\n"
78 "cflags_objcc =\n" 74 "cflags_objcc =\n"
79 "target_name = shlib\n" 75 "target_name = shlib\n"
80 "target_out_dir = obj/foo\n" 76 "target_out_dir = obj/foo\n"
81 "root_out_dir = \n" 77 "root_out_dir = \n"
82 "\n" 78 "\n"
83 "\n" 79 "\n"
84 "manifests = obj/foo/shlib.intermediate.manifest\n" 80 "manifests = obj/foo/shlib.intermediate.manifest\n"
85 "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate." 81 "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate."
86 "manifest\n" 82 "manifest\n"
87 "libs =\n" 83 "libs =\n"
88 // Ordering of the obj files here is arbitrary. Currently they're put 84 // Ordering of the obj files here should come out in the order
89 // in a set and come out sorted. 85 // specified, with the target's first, followed by the source set's, in
90 "build shlib.dll shlib.dll.lib: solink ../../foo/input3.o " 86 // order.
91 "../../foo/input4.obj obj/foo/bar.input1.obj " 87 "build shlib.dll shlib.dll.lib: solink obj/foo/bar.input1.obj "
92 "obj/foo/bar.input2.obj\n" 88 "obj/foo/bar.input2.obj ../../foo/input3.o "
89 "../../foo/input4.obj\n"
93 " soname = shlib.dll\n" 90 " soname = shlib.dll\n"
94 " lib = shlib.dll\n" 91 " lib = shlib.dll\n"
95 " dll = shlib.dll\n" 92 " dll = shlib.dll\n"
96 " implibflag = /IMPLIB:shlib.dll.lib\n\n"; 93 " implibflag = /IMPLIB:shlib.dll.lib\n\n";
97 std::string out_str = out.str(); 94 std::string out_str = out.str();
98 #if defined(OS_WIN) 95 #if defined(OS_WIN)
99 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 96 std::replace(out_str.begin(), out_str.end(), '\\', '/');
100 #endif 97 #endif
101 EXPECT_EQ(expected_win, out_str); 98 EXPECT_EQ(expected_win, out_str);
102 } 99 }
103 100
104 // A static library that depends on the source set (should not link it). 101 // A static library that depends on the source set (should not link it).
105 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); 102 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib"));
106 stlib_target.set_output_type(Target::STATIC_LIBRARY); 103 stlib_target.set_output_type(Target::STATIC_LIBRARY);
107 stlib_target.deps().push_back(LabelTargetPair(&target)); 104 stlib_target.deps().push_back(LabelTargetPair(&target));
108 stlib_target.OnResolved(); 105 stlib_target.OnResolved();
109 106
110 { 107 {
111 std::ostringstream out; 108 std::ostringstream out;
112 NinjaBinaryTargetWriter writer(&stlib_target, setup.toolchain(), out); 109 NinjaBinaryTargetWriter writer(&stlib_target, setup.toolchain(), out);
113 writer.Run(); 110 writer.Run();
114 111
115 // TODO(brettw) I think we'll need to worry about backslashes here
116 // depending if we're on actual Windows or Linux pretending to be Windows.
117 const char expected_win[] = 112 const char expected_win[] =
118 "defines =\n" 113 "defines =\n"
119 "includes =\n" 114 "includes =\n"
120 "cflags =\n" 115 "cflags =\n"
121 "cflags_c =\n" 116 "cflags_c =\n"
122 "cflags_cc =\n" 117 "cflags_cc =\n"
123 "cflags_objc =\n" 118 "cflags_objc =\n"
124 "cflags_objcc =\n" 119 "cflags_objcc =\n"
125 "target_name = stlib\n" 120 "target_name = stlib\n"
126 "target_out_dir = obj/foo\n" 121 "target_out_dir = obj/foo\n"
(...skipping 24 matching lines...) Expand all
151 target.set_output_type(Target::SHARED_LIBRARY); 146 target.set_output_type(Target::SHARED_LIBRARY);
152 target.set_output_extension(std::string("so.6")); 147 target.set_output_extension(std::string("so.6"));
153 target.sources().push_back(SourceFile("//foo/input1.cc")); 148 target.sources().push_back(SourceFile("//foo/input1.cc"));
154 target.sources().push_back(SourceFile("//foo/input2.cc")); 149 target.sources().push_back(SourceFile("//foo/input2.cc"));
155 target.OnResolved(); 150 target.OnResolved();
156 151
157 std::ostringstream out; 152 std::ostringstream out;
158 NinjaBinaryTargetWriter writer(&target, setup.toolchain(), out); 153 NinjaBinaryTargetWriter writer(&target, setup.toolchain(), out);
159 writer.Run(); 154 writer.Run();
160 155
161 // TODO(brettw) I think we'll need to worry about backslashes here
162 // depending if we're on actual Windows or Linux pretending to be Windows.
163 const char expected[] = 156 const char expected[] =
164 "defines =\n" 157 "defines =\n"
165 "includes =\n" 158 "includes =\n"
166 "cflags =\n" 159 "cflags =\n"
167 "cflags_c =\n" 160 "cflags_c =\n"
168 "cflags_cc =\n" 161 "cflags_cc =\n"
169 "cflags_objc =\n" 162 "cflags_objc =\n"
170 "cflags_objcc =\n" 163 "cflags_objcc =\n"
171 "target_name = shlib\n" 164 "target_name = shlib\n"
172 "target_out_dir = obj/foo\n" 165 "target_out_dir = obj/foo\n"
(...skipping 27 matching lines...) Expand all
200 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); 193 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib"));
201 target.set_output_type(Target::SHARED_LIBRARY); 194 target.set_output_type(Target::SHARED_LIBRARY);
202 target.set_output_extension(std::string()); 195 target.set_output_extension(std::string());
203 target.sources().push_back(SourceFile("//foo/input1.cc")); 196 target.sources().push_back(SourceFile("//foo/input1.cc"));
204 target.sources().push_back(SourceFile("//foo/input2.cc")); 197 target.sources().push_back(SourceFile("//foo/input2.cc"));
205 198
206 std::ostringstream out; 199 std::ostringstream out;
207 NinjaBinaryTargetWriter writer(&target, setup.toolchain(), out); 200 NinjaBinaryTargetWriter writer(&target, setup.toolchain(), out);
208 writer.Run(); 201 writer.Run();
209 202
210 // TODO(brettw) I think we'll need to worry about backslashes here
211 // depending if we're on actual Windows or Linux pretending to be Windows.
212 const char expected[] = 203 const char expected[] =
213 "defines =\n" 204 "defines =\n"
214 "includes =\n" 205 "includes =\n"
215 "cflags =\n" 206 "cflags =\n"
216 "cflags_c =\n" 207 "cflags_c =\n"
217 "cflags_cc =\n" 208 "cflags_cc =\n"
218 "cflags_objc =\n" 209 "cflags_objc =\n"
219 "cflags_objcc =\n" 210 "cflags_objcc =\n"
220 "target_name = shlib\n" 211 "target_name = shlib\n"
221 "target_out_dir = obj/foo\n" 212 "target_out_dir = obj/foo\n"
222 "root_out_dir = \n" 213 "root_out_dir = \n"
223 "\n" 214 "\n"
224 "build obj/foo/shlib.input1.o: cxx ../../foo/input1.cc\n" 215 "build obj/foo/shlib.input1.o: cxx ../../foo/input1.cc\n"
225 "build obj/foo/shlib.input2.o: cxx ../../foo/input2.cc\n" 216 "build obj/foo/shlib.input2.o: cxx ../../foo/input2.cc\n"
226 "\n" 217 "\n"
227 "ldflags =\n" 218 "ldflags =\n"
228 "libs =\n" 219 "libs =\n"
229 "build libshlib.so: solink obj/foo/shlib.input1.o " 220 "build libshlib.so: solink obj/foo/shlib.input1.o "
230 "obj/foo/shlib.input2.o\n" 221 "obj/foo/shlib.input2.o\n"
231 " soname = libshlib.so\n" 222 " soname = libshlib.so\n"
232 " lib = libshlib.so\n" 223 " lib = libshlib.so\n"
233 "\n"; 224 "\n";
234 225
235 std::string out_str = out.str(); 226 std::string out_str = out.str();
236 #if defined(OS_WIN) 227 #if defined(OS_WIN)
237 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 228 std::replace(out_str.begin(), out_str.end(), '\\', '/');
238 #endif 229 #endif
239 EXPECT_EQ(expected, out_str); 230 EXPECT_EQ(expected, out_str);
240 } 231 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/output_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698