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

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

Issue 2060273002: [GN] Add support for code signing to "create_bundle" targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ios-strings-binary
Patch Set: Remove superfluous \n Created 4 years, 6 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_create_bundle_target_writer.cc ('k') | tools/gn/variables.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_create_bundle_target_writer.h" 5 #include "tools/gn/ninja_create_bundle_target_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 std::ostringstream out; 47 std::ostringstream out;
48 NinjaCreateBundleTargetWriter writer(&target, out); 48 NinjaCreateBundleTargetWriter writer(&target, out);
49 writer.Run(); 49 writer.Run();
50 50
51 const char expected[] = 51 const char expected[] =
52 "build bar.bundle/Resources/input1.txt: copy_bundle_data " 52 "build bar.bundle/Resources/input1.txt: copy_bundle_data "
53 "../../foo/input1.txt\n" 53 "../../foo/input1.txt\n"
54 "build bar.bundle/Resources/input2.txt: copy_bundle_data " 54 "build bar.bundle/Resources/input2.txt: copy_bundle_data "
55 "../../foo/input2.txt\n" 55 "../../foo/input2.txt\n"
56 "\n"
57 "build obj/baz/bar.stamp: stamp " 56 "build obj/baz/bar.stamp: stamp "
58 "bar.bundle/Resources/input1.txt " 57 "bar.bundle/Resources/input1.txt "
59 "bar.bundle/Resources/input2.txt\n" 58 "bar.bundle/Resources/input2.txt\n"
60 "build bar.bundle: phony obj/baz/bar.stamp\n"; 59 "build bar.bundle: phony obj/baz/bar.stamp\n";
61 std::string out_str = out.str(); 60 std::string out_str = out.str();
62 EXPECT_EQ(expected, out_str); 61 EXPECT_EQ(expected, out_str);
63 } 62 }
64 63
65 // Tests multiple files from asset catalog. 64 // Tests multiple files from asset catalog.
66 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) { 65 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) {
(...skipping 24 matching lines...) Expand all
91 NinjaCreateBundleTargetWriter writer(&target, out); 90 NinjaCreateBundleTargetWriter writer(&target, out);
92 writer.Run(); 91 writer.Run();
93 92
94 const char expected[] = 93 const char expected[] =
95 "build bar.bundle/Resources/Assets.car: compile_xcassets " 94 "build bar.bundle/Resources/Assets.car: compile_xcassets "
96 "../../foo/Foo.xcassets | " 95 "../../foo/Foo.xcassets | "
97 "../../foo/Foo.xcassets/foo.imageset/Contents.json " 96 "../../foo/Foo.xcassets/foo.imageset/Contents.json "
98 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png " 97 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png "
99 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png " 98 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png "
100 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n" 99 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n"
101 "\n"
102 "build obj/baz/bar.stamp: stamp bar.bundle/Resources/Assets.car\n" 100 "build obj/baz/bar.stamp: stamp bar.bundle/Resources/Assets.car\n"
103 "build bar.bundle: phony obj/baz/bar.stamp\n"; 101 "build bar.bundle: phony obj/baz/bar.stamp\n";
104 std::string out_str = out.str(); 102 std::string out_str = out.str();
105 EXPECT_EQ(expected, out_str); 103 EXPECT_EQ(expected, out_str);
106 } 104 }
107 105
108 // Tests that the phony target for the top-level bundle directory is generated 106 // Tests that the phony target for the top-level bundle directory is generated
109 // correctly. 107 // correctly.
110 TEST(NinjaCreateBundleTargetWriter, BundleRootDirOutput) { 108 TEST(NinjaCreateBundleTargetWriter, BundleRootDirOutput) {
111 TestWithScope setup; 109 TestWithScope setup;
(...skipping 22 matching lines...) Expand all
134 132
135 std::ostringstream out; 133 std::ostringstream out;
136 NinjaCreateBundleTargetWriter writer(&target, out); 134 NinjaCreateBundleTargetWriter writer(&target, out);
137 writer.Run(); 135 writer.Run();
138 136
139 const char expected[] = 137 const char expected[] =
140 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data " 138 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data "
141 "../../foo/input1.txt\n" 139 "../../foo/input1.txt\n"
142 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data " 140 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data "
143 "../../foo/input2.txt\n" 141 "../../foo/input2.txt\n"
144 "\n"
145 "build obj/baz/bar.stamp: stamp " 142 "build obj/baz/bar.stamp: stamp "
146 "bar.bundle/Contents/Resources/input1.txt " 143 "bar.bundle/Contents/Resources/input1.txt "
147 "bar.bundle/Contents/Resources/input2.txt\n" 144 "bar.bundle/Contents/Resources/input2.txt\n"
148 "build bar.bundle: phony obj/baz/bar.stamp\n"; 145 "build bar.bundle: phony obj/baz/bar.stamp\n";
149 std::string out_str = out.str(); 146 std::string out_str = out.str();
150 EXPECT_EQ(expected, out_str); 147 EXPECT_EQ(expected, out_str);
151 } 148 }
152 149
153 // Tests complex target with multiple bundle_data sources, including 150 // Tests complex target with multiple bundle_data sources, including
154 // some asset catalog. 151 // some asset catalog.
155 TEST(NinjaCreateBundleTargetWriter, OrderOnlyDeps) { 152 TEST(NinjaCreateBundleTargetWriter, ImplicitDeps) {
156 TestWithScope setup; 153 TestWithScope setup;
157 Err err; 154 Err err;
158 155
159 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 156 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
160 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar")); 157 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar"));
161 target.set_output_type(Target::CREATE_BUNDLE); 158 target.set_output_type(Target::CREATE_BUNDLE);
162 159
163 SetupBundleDataDir(&target.bundle_data(), "//out/Debug"); 160 SetupBundleDataDir(&target.bundle_data(), "//out/Debug");
164 161
165 std::vector<SourceFile> sources1; 162 std::vector<SourceFile> sources1;
(...skipping 30 matching lines...) Expand all
196 193
197 std::ostringstream out; 194 std::ostringstream out;
198 NinjaCreateBundleTargetWriter writer(&target, out); 195 NinjaCreateBundleTargetWriter writer(&target, out);
199 writer.Run(); 196 writer.Run();
200 197
201 const char expected[] = 198 const char expected[] =
202 "build bar.bundle/Resources/input1.txt: copy_bundle_data " 199 "build bar.bundle/Resources/input1.txt: copy_bundle_data "
203 "../../foo/input1.txt\n" 200 "../../foo/input1.txt\n"
204 "build bar.bundle/Resources/input2.txt: copy_bundle_data " 201 "build bar.bundle/Resources/input2.txt: copy_bundle_data "
205 "../../foo/input2.txt\n" 202 "../../foo/input2.txt\n"
206 "build bar.bundle/Info.plist: copy_bundle_data ../../qux/Info.plist\n" 203 "build bar.bundle/Info.plist: copy_bundle_data "
204 "../../qux/Info.plist\n"
207 "build bar.bundle/Resources/Assets.car: compile_xcassets " 205 "build bar.bundle/Resources/Assets.car: compile_xcassets "
208 "../../foo/Foo.xcassets | " 206 "../../foo/Foo.xcassets | "
209 "../../foo/Foo.xcassets/foo.imageset/Contents.json " 207 "../../foo/Foo.xcassets/foo.imageset/Contents.json "
210 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png " 208 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png "
211 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png " 209 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png "
212 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n" 210 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n"
213 "\n"
214 "build obj/baz/bar.stamp: stamp " 211 "build obj/baz/bar.stamp: stamp "
215 "bar.bundle/Resources/input1.txt " 212 "bar.bundle/Resources/input1.txt "
216 "bar.bundle/Resources/input2.txt " 213 "bar.bundle/Resources/input2.txt "
217 "bar.bundle/Info.plist " 214 "bar.bundle/Info.plist "
218 "bar.bundle/Resources/Assets.car\n" 215 "bar.bundle/Resources/Assets.car\n"
219 "build bar.bundle: phony obj/baz/bar.stamp\n"; 216 "build bar.bundle: phony obj/baz/bar.stamp\n";
220 std::string out_str = out.str(); 217 std::string out_str = out.str();
221 EXPECT_EQ(expected, out_str); 218 EXPECT_EQ(expected, out_str);
222 } 219 }
220
221 // Tests multiple files with an output pattern.
222 TEST(NinjaCreateBundleTargetWriter, CodeSigning) {
223 TestWithScope setup;
224 Err err;
225
226 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
227
228 // Simulate a binary build by another target. Since no toolchain is defined
229 // use an action instead of an executable target for simplicity.
230 Target binary(setup.settings(), Label(SourceDir("//baz/"), "quz"));
231 binary.set_output_type(Target::EXECUTABLE);
232 binary.visibility().SetPublic();
233 binary.sources().push_back(SourceFile("//baz/quz.c"));
234 binary.set_output_name("obj/baz/quz/bin");
235 binary.set_output_prefix_override(true);
236 binary.SetToolchain(setup.toolchain());
237 ASSERT_TRUE(binary.OnResolved(&err));
238
239 Target target(setup.settings(),
240 Label(SourceDir("//baz/"), "bar",
241 setup.toolchain()->label().dir(),
242 setup.toolchain()->label().name()));
243 target.set_output_type(Target::CREATE_BUNDLE);
244
245 SetupBundleDataDir(&target.bundle_data(), "//out/Debug");
246
247 std::vector<SourceFile> sources;
248 sources.push_back(SourceFile("//foo/input1.txt"));
249 sources.push_back(SourceFile("//foo/input2.txt"));
250 target.bundle_data().file_rules().push_back(BundleFileRule(
251 sources, SubstitutionPattern::MakeForTest(
252 "{{bundle_resources_dir}}/{{source_file_part}}")));
253
254 target.bundle_data().set_code_signing_script(
255 SourceFile("//build/codesign.py"));
256 target.bundle_data().code_signing_sources().push_back(
257 SourceFile("//out/Debug/obj/baz/quz/bin"));
258 target.bundle_data().code_signing_outputs() = SubstitutionList::MakeForTest(
259 "//out/Debug/bar.bundle/quz",
260 "//out/Debug/bar.bundle/_CodeSignature/CodeResources");
261 target.bundle_data().code_signing_args() = SubstitutionList::MakeForTest(
262 "-b=obj/baz/quz/bin",
263 "bar.bundle");
264
265 target.public_deps().push_back(LabelTargetPair(&binary));
266
267 target.SetToolchain(setup.toolchain());
268 ASSERT_TRUE(target.OnResolved(&err));
269
270 std::ostringstream out;
271 NinjaCreateBundleTargetWriter writer(&target, out);
272 writer.Run();
273
274 const char expected[] =
275 "rule __baz_bar___toolchain_default__code_signing_rule\n"
276 " command = ../../build/codesign.py -b=obj/baz/quz/bin bar.bundle\n"
277 " description = CODE SIGNING //baz:bar(//toolchain:default)\n"
278 " restat = 1\n"
279 "\n"
280 "build bar.bundle/Resources/input1.txt: copy_bundle_data "
281 "../../foo/input1.txt\n"
282 "build bar.bundle/Resources/input2.txt: copy_bundle_data "
283 "../../foo/input2.txt\n"
284 "build obj/baz/bar.codesigning.inputdeps.stamp: stamp "
285 "../../build/codesign.py "
286 "obj/baz/quz/bin "
287 "bar.bundle/Resources/input1.txt "
288 "bar.bundle/Resources/input2.txt\n"
289 "build bar.bundle/quz bar.bundle/_CodeSignature/CodeResources: "
290 "__baz_bar___toolchain_default__code_signing_rule "
291 "| obj/baz/bar.codesigning.inputdeps.stamp\n"
292 "build obj/baz/bar.stamp: stamp "
293 "bar.bundle/quz "
294 "bar.bundle/_CodeSignature/CodeResources\n"
295 "build bar.bundle: phony obj/baz/bar.stamp\n";
296 std::string out_str = out.str();
297 EXPECT_EQ(expected, out_str);
298 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_create_bundle_target_writer.cc ('k') | tools/gn/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698