OLD | NEW |
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" |
11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
12 #include "tools/gn/test_with_scope.h" | 12 #include "tools/gn/test_with_scope.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 void SetupBundleDataDir(BundleData* bundle_data, const std::string& root_dir) { | 16 void SetupBundleDataDir(BundleData* bundle_data, const std::string& root_dir) { |
17 std::string bundle_root_dir = root_dir + "/bar.bundle/Contents"; | 17 std::string bundle_root_dir = root_dir + "/bar.bundle/Contents"; |
18 bundle_data->root_dir() = SourceDir(bundle_root_dir); | 18 bundle_data->root_dir() = SourceDir(bundle_root_dir); |
19 bundle_data->resources_dir() = SourceDir(bundle_root_dir + "/Resources"); | 19 bundle_data->resources_dir() = SourceDir(bundle_root_dir + "/Resources"); |
20 bundle_data->executable_dir() = SourceDir(bundle_root_dir + "/MacOS"); | 20 bundle_data->executable_dir() = SourceDir(bundle_root_dir + "/MacOS"); |
21 bundle_data->plugins_dir() = SourceDir(bundle_root_dir + "/Plug Ins"); | 21 bundle_data->plugins_dir() = SourceDir(bundle_root_dir + "/Plug Ins"); |
22 } | 22 } |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 // Tests multiple files with an output pattern. | 26 // Tests multiple files with an output pattern. |
27 TEST(NinjaCreateBundleTargetWriter, Run) { | 27 TEST(NinjaCreateBundleTargetWriter, Run) { |
28 Err err; | 28 Err err; |
29 | |
30 TestWithScope setup; | 29 TestWithScope setup; |
31 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
32 | 30 |
33 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); | 31 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); |
34 bundle_data.set_output_type(Target::BUNDLE_DATA); | 32 bundle_data.set_output_type(Target::BUNDLE_DATA); |
35 bundle_data.sources().push_back(SourceFile("//foo/input1.txt")); | 33 bundle_data.sources().push_back(SourceFile("//foo/input1.txt")); |
36 bundle_data.sources().push_back(SourceFile("//foo/input2.txt")); | 34 bundle_data.sources().push_back(SourceFile("//foo/input2.txt")); |
37 bundle_data.action_values().outputs() = SubstitutionList::MakeForTest( | 35 bundle_data.action_values().outputs() = SubstitutionList::MakeForTest( |
38 "{{bundle_resources_dir}}/{{source_file_part}}"); | 36 "{{bundle_resources_dir}}/{{source_file_part}}"); |
39 bundle_data.SetToolchain(setup.toolchain()); | 37 bundle_data.SetToolchain(setup.toolchain()); |
40 bundle_data.visibility().SetPublic(); | 38 bundle_data.visibility().SetPublic(); |
41 ASSERT_TRUE(bundle_data.OnResolved(&err)); | 39 ASSERT_TRUE(bundle_data.OnResolved(&err)); |
(...skipping 21 matching lines...) Expand all Loading... |
63 "bar.bundle/Contents/Resources/input1.txt " | 61 "bar.bundle/Contents/Resources/input1.txt " |
64 "bar.bundle/Contents/Resources/input2.txt\n" | 62 "bar.bundle/Contents/Resources/input2.txt\n" |
65 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 63 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
66 std::string out_str = out.str(); | 64 std::string out_str = out.str(); |
67 EXPECT_EQ(expected, out_str); | 65 EXPECT_EQ(expected, out_str); |
68 } | 66 } |
69 | 67 |
70 // Tests multiple files from asset catalog. | 68 // Tests multiple files from asset catalog. |
71 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) { | 69 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) { |
72 Err err; | 70 Err err; |
73 | |
74 TestWithScope setup; | 71 TestWithScope setup; |
75 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
76 | 72 |
77 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); | 73 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); |
78 bundle_data.set_output_type(Target::BUNDLE_DATA); | 74 bundle_data.set_output_type(Target::BUNDLE_DATA); |
79 bundle_data.sources().push_back( | 75 bundle_data.sources().push_back( |
80 SourceFile("//foo/Foo.xcassets/Contents.json")); | 76 SourceFile("//foo/Foo.xcassets/Contents.json")); |
81 bundle_data.sources().push_back( | 77 bundle_data.sources().push_back( |
82 SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json")); | 78 SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json")); |
83 bundle_data.sources().push_back( | 79 bundle_data.sources().push_back( |
84 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png")); | 80 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png")); |
85 bundle_data.sources().push_back( | 81 bundle_data.sources().push_back( |
(...skipping 27 matching lines...) Expand all Loading... |
113 "bar.bundle/Contents/Resources/Assets.car\n" | 109 "bar.bundle/Contents/Resources/Assets.car\n" |
114 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 110 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
115 std::string out_str = out.str(); | 111 std::string out_str = out.str(); |
116 EXPECT_EQ(expected, out_str); | 112 EXPECT_EQ(expected, out_str); |
117 } | 113 } |
118 | 114 |
119 // Tests that the phony target for the top-level bundle directory is generated | 115 // Tests that the phony target for the top-level bundle directory is generated |
120 // correctly. | 116 // correctly. |
121 TEST(NinjaCreateBundleTargetWriter, PhonyTarget) { | 117 TEST(NinjaCreateBundleTargetWriter, PhonyTarget) { |
122 Err err; | 118 Err err; |
123 | |
124 TestWithScope setup; | 119 TestWithScope setup; |
125 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
126 | 120 |
127 Target create_bundle( | 121 Target create_bundle( |
128 setup.settings(), | 122 setup.settings(), |
129 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), | 123 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), |
130 setup.toolchain()->label().name())); | 124 setup.toolchain()->label().name())); |
131 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); | 125 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); |
132 create_bundle.set_output_type(Target::CREATE_BUNDLE); | 126 create_bundle.set_output_type(Target::CREATE_BUNDLE); |
133 create_bundle.SetToolchain(setup.toolchain()); | 127 create_bundle.SetToolchain(setup.toolchain()); |
134 ASSERT_TRUE(create_bundle.OnResolved(&err)); | 128 ASSERT_TRUE(create_bundle.OnResolved(&err)); |
135 | 129 |
136 std::ostringstream out; | 130 std::ostringstream out; |
137 NinjaCreateBundleTargetWriter writer(&create_bundle, out); | 131 NinjaCreateBundleTargetWriter writer(&create_bundle, out); |
138 writer.Run(); | 132 writer.Run(); |
139 | 133 |
140 const char expected[] = | 134 const char expected[] = |
141 "build obj/baz/bar.stamp: stamp\n" | 135 "build obj/baz/bar.stamp: stamp\n" |
142 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 136 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
143 std::string out_str = out.str(); | 137 std::string out_str = out.str(); |
144 EXPECT_EQ(expected, out_str); | 138 EXPECT_EQ(expected, out_str); |
145 } | 139 } |
146 | 140 |
147 // Tests complex target with multiple bundle_data sources, including | 141 // Tests complex target with multiple bundle_data sources, including |
148 // some asset catalog. | 142 // some asset catalog. |
149 TEST(NinjaCreateBundleTargetWriter, Complex) { | 143 TEST(NinjaCreateBundleTargetWriter, Complex) { |
150 Err err; | 144 Err err; |
151 | |
152 TestWithScope setup; | 145 TestWithScope setup; |
153 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
154 | 146 |
155 Target bundle_data0(setup.settings(), | 147 Target bundle_data0(setup.settings(), |
156 Label(SourceDir("//qux/"), "info_plist")); | 148 Label(SourceDir("//qux/"), "info_plist")); |
157 bundle_data0.set_output_type(Target::BUNDLE_DATA); | 149 bundle_data0.set_output_type(Target::BUNDLE_DATA); |
158 bundle_data0.sources().push_back(SourceFile("//qux/qux-Info.plist")); | 150 bundle_data0.sources().push_back(SourceFile("//qux/qux-Info.plist")); |
159 bundle_data0.action_values().outputs() = | 151 bundle_data0.action_values().outputs() = |
160 SubstitutionList::MakeForTest("{{bundle_root_dir}}/Info.plist"); | 152 SubstitutionList::MakeForTest("{{bundle_root_dir}}/Info.plist"); |
161 bundle_data0.SetToolchain(setup.toolchain()); | 153 bundle_data0.SetToolchain(setup.toolchain()); |
162 bundle_data0.visibility().SetPublic(); | 154 bundle_data0.visibility().SetPublic(); |
163 ASSERT_TRUE(bundle_data0.OnResolved(&err)); | 155 ASSERT_TRUE(bundle_data0.OnResolved(&err)); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 "bar.bundle/Contents/Resources/input2.txt " | 236 "bar.bundle/Contents/Resources/input2.txt " |
245 "bar.bundle/Contents/Resources/Assets.car\n" | 237 "bar.bundle/Contents/Resources/Assets.car\n" |
246 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 238 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
247 std::string out_str = out.str(); | 239 std::string out_str = out.str(); |
248 EXPECT_EQ(expected, out_str); | 240 EXPECT_EQ(expected, out_str); |
249 } | 241 } |
250 | 242 |
251 // Tests code signing steps. | 243 // Tests code signing steps. |
252 TEST(NinjaCreateBundleTargetWriter, CodeSigning) { | 244 TEST(NinjaCreateBundleTargetWriter, CodeSigning) { |
253 Err err; | 245 Err err; |
254 | |
255 TestWithScope setup; | 246 TestWithScope setup; |
256 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
257 | 247 |
258 Target executable(setup.settings(), Label(SourceDir("//baz/"), "quz")); | 248 Target executable(setup.settings(), Label(SourceDir("//baz/"), "quz")); |
259 executable.set_output_type(Target::EXECUTABLE); | 249 executable.set_output_type(Target::EXECUTABLE); |
260 executable.sources().push_back(SourceFile("//baz/quz.c")); | 250 executable.sources().push_back(SourceFile("//baz/quz.c")); |
261 executable.SetToolchain(setup.toolchain()); | 251 executable.SetToolchain(setup.toolchain()); |
262 executable.visibility().SetPublic(); | 252 executable.visibility().SetPublic(); |
263 ASSERT_TRUE(executable.OnResolved(&err)); | 253 ASSERT_TRUE(executable.OnResolved(&err)); |
264 | 254 |
265 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); | 255 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); |
266 bundle_data.set_output_type(Target::BUNDLE_DATA); | 256 bundle_data.set_output_type(Target::BUNDLE_DATA); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 "build bar.bundle/Contents/quz bar.bundle/_CodeSignature/CodeResources: " | 306 "build bar.bundle/Contents/quz bar.bundle/_CodeSignature/CodeResources: " |
317 "__baz_bar___toolchain_default__code_signing_rule " | 307 "__baz_bar___toolchain_default__code_signing_rule " |
318 "| obj/baz/bar.codesigning.inputdeps.stamp\n" | 308 "| obj/baz/bar.codesigning.inputdeps.stamp\n" |
319 "build obj/baz/bar.stamp: stamp " | 309 "build obj/baz/bar.stamp: stamp " |
320 "bar.bundle/Contents/quz " | 310 "bar.bundle/Contents/quz " |
321 "bar.bundle/_CodeSignature/CodeResources\n" | 311 "bar.bundle/_CodeSignature/CodeResources\n" |
322 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 312 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
323 std::string out_str = out.str(); | 313 std::string out_str = out.str(); |
324 EXPECT_EQ(expected, out_str); | 314 EXPECT_EQ(expected, out_str); |
325 } | 315 } |
OLD | NEW |