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"; | 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 + "/Executable"); | 20 bundle_data->executable_dir() = SourceDir(bundle_root_dir + "/MacOS"); |
21 bundle_data->plugins_dir() = SourceDir(bundle_root_dir + "/PlugIns"); | 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 TestWithScope setup; | |
29 Err err; | 28 Err err; |
30 | 29 |
| 30 TestWithScope setup; |
31 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 31 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
32 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar")); | |
33 target.set_output_type(Target::CREATE_BUNDLE); | |
34 | 32 |
35 SetupBundleDataDir(&target.bundle_data(), "//out/Debug"); | 33 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); |
| 34 bundle_data.set_output_type(Target::BUNDLE_DATA); |
| 35 bundle_data.sources().push_back(SourceFile("//foo/input1.txt")); |
| 36 bundle_data.sources().push_back(SourceFile("//foo/input2.txt")); |
| 37 bundle_data.action_values().outputs() = SubstitutionList::MakeForTest( |
| 38 "{{bundle_resources_dir}}/{{source_file_part}}"); |
| 39 bundle_data.SetToolchain(setup.toolchain()); |
| 40 bundle_data.visibility().SetPublic(); |
| 41 ASSERT_TRUE(bundle_data.OnResolved(&err)); |
36 | 42 |
37 std::vector<SourceFile> sources; | 43 Target create_bundle( |
38 sources.push_back(SourceFile("//foo/input1.txt")); | 44 setup.settings(), |
39 sources.push_back(SourceFile("//foo/input2.txt")); | 45 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), |
40 target.bundle_data().file_rules().push_back(BundleFileRule( | 46 setup.toolchain()->label().name())); |
41 sources, SubstitutionPattern::MakeForTest( | 47 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); |
42 "{{bundle_resources_dir}}/{{source_file_part}}"))); | 48 create_bundle.set_output_type(Target::CREATE_BUNDLE); |
43 | 49 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data)); |
44 target.SetToolchain(setup.toolchain()); | 50 create_bundle.SetToolchain(setup.toolchain()); |
45 ASSERT_TRUE(target.OnResolved(&err)); | 51 ASSERT_TRUE(create_bundle.OnResolved(&err)); |
46 | 52 |
47 std::ostringstream out; | 53 std::ostringstream out; |
48 NinjaCreateBundleTargetWriter writer(&target, out); | 54 NinjaCreateBundleTargetWriter writer(&create_bundle, out); |
49 writer.Run(); | 55 writer.Run(); |
50 | 56 |
51 const char expected[] = | 57 const char expected[] = |
52 "build bar.bundle/Resources/input1.txt: copy_bundle_data " | 58 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data " |
53 "../../foo/input1.txt\n" | 59 "../../foo/input1.txt\n" |
54 "build bar.bundle/Resources/input2.txt: copy_bundle_data " | 60 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data " |
55 "../../foo/input2.txt\n" | 61 "../../foo/input2.txt\n" |
56 "build obj/baz/bar.stamp: stamp " | 62 "build obj/baz/bar.stamp: stamp " |
57 "bar.bundle/Resources/input1.txt " | 63 "bar.bundle/Contents/Resources/input1.txt " |
58 "bar.bundle/Resources/input2.txt\n" | 64 "bar.bundle/Contents/Resources/input2.txt\n" |
59 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 65 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
60 std::string out_str = out.str(); | 66 std::string out_str = out.str(); |
61 EXPECT_EQ(expected, out_str); | 67 EXPECT_EQ(expected, out_str); |
62 } | 68 } |
63 | 69 |
64 // Tests multiple files from asset catalog. | 70 // Tests multiple files from asset catalog. |
65 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) { | 71 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) { |
66 TestWithScope setup; | |
67 Err err; | 72 Err err; |
68 | 73 |
| 74 TestWithScope setup; |
69 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 75 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
70 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar")); | |
71 target.set_output_type(Target::CREATE_BUNDLE); | |
72 | 76 |
73 SetupBundleDataDir(&target.bundle_data(), "//out/Debug"); | 77 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); |
| 78 bundle_data.set_output_type(Target::BUNDLE_DATA); |
| 79 bundle_data.sources().push_back( |
| 80 SourceFile("//foo/Foo.xcassets/Contents.json")); |
| 81 bundle_data.sources().push_back( |
| 82 SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json")); |
| 83 bundle_data.sources().push_back( |
| 84 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png")); |
| 85 bundle_data.sources().push_back( |
| 86 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png")); |
| 87 bundle_data.sources().push_back( |
| 88 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png")); |
| 89 bundle_data.action_values().outputs() = SubstitutionList::MakeForTest( |
| 90 "{{bundle_resources_dir}}/{{source_file_part}}"); |
| 91 bundle_data.SetToolchain(setup.toolchain()); |
| 92 bundle_data.visibility().SetPublic(); |
| 93 ASSERT_TRUE(bundle_data.OnResolved(&err)); |
74 | 94 |
75 std::vector<SourceFile>& asset_catalog_sources = | 95 Target create_bundle( |
76 target.bundle_data().asset_catalog_sources(); | 96 setup.settings(), |
77 asset_catalog_sources.push_back( | 97 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), |
78 SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json")); | 98 setup.toolchain()->label().name())); |
79 asset_catalog_sources.push_back( | 99 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); |
80 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png")); | 100 create_bundle.set_output_type(Target::CREATE_BUNDLE); |
81 asset_catalog_sources.push_back( | 101 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data)); |
82 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png")); | 102 create_bundle.SetToolchain(setup.toolchain()); |
83 asset_catalog_sources.push_back( | 103 ASSERT_TRUE(create_bundle.OnResolved(&err)); |
84 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png")); | |
85 | |
86 target.SetToolchain(setup.toolchain()); | |
87 ASSERT_TRUE(target.OnResolved(&err)); | |
88 | 104 |
89 std::ostringstream out; | 105 std::ostringstream out; |
90 NinjaCreateBundleTargetWriter writer(&target, out); | 106 NinjaCreateBundleTargetWriter writer(&create_bundle, out); |
91 writer.Run(); | 107 writer.Run(); |
92 | 108 |
93 const char expected[] = | 109 const char expected[] = |
94 "build bar.bundle/Resources/Assets.car: compile_xcassets " | 110 "build bar.bundle/Contents/Resources/Assets.car: compile_xcassets " |
95 "../../foo/Foo.xcassets | " | 111 "../../foo/Foo.xcassets | obj/foo/data.stamp\n" |
96 "../../foo/Foo.xcassets/foo.imageset/Contents.json " | 112 "build obj/baz/bar.stamp: stamp " |
97 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png " | 113 "bar.bundle/Contents/Resources/Assets.car\n" |
98 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png " | |
99 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n" | |
100 "build obj/baz/bar.stamp: stamp bar.bundle/Resources/Assets.car\n" | |
101 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 114 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
102 std::string out_str = out.str(); | 115 std::string out_str = out.str(); |
103 EXPECT_EQ(expected, out_str); | 116 EXPECT_EQ(expected, out_str); |
104 } | 117 } |
105 | 118 |
106 // Tests that the phony target for the top-level bundle directory is generated | 119 // Tests that the phony target for the top-level bundle directory is generated |
107 // correctly. | 120 // correctly. |
108 TEST(NinjaCreateBundleTargetWriter, BundleRootDirOutput) { | 121 TEST(NinjaCreateBundleTargetWriter, PhonyTarget) { |
109 TestWithScope setup; | |
110 Err err; | 122 Err err; |
111 | 123 |
| 124 TestWithScope setup; |
112 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 125 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
113 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar")); | |
114 target.set_output_type(Target::CREATE_BUNDLE); | |
115 | 126 |
116 const std::string bundle_root_dir("//out/Debug/bar.bundle/Contents"); | 127 Target create_bundle( |
117 target.bundle_data().root_dir() = SourceDir(bundle_root_dir); | 128 setup.settings(), |
118 target.bundle_data().resources_dir() = | 129 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), |
119 SourceDir(bundle_root_dir + "/Resources"); | 130 setup.toolchain()->label().name())); |
120 target.bundle_data().executable_dir() = SourceDir(bundle_root_dir + "/MacOS"); | 131 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); |
121 target.bundle_data().plugins_dir() = SourceDir(bundle_root_dir + "/Plug Ins"); | 132 create_bundle.set_output_type(Target::CREATE_BUNDLE); |
122 | 133 create_bundle.SetToolchain(setup.toolchain()); |
123 std::vector<SourceFile> sources; | 134 ASSERT_TRUE(create_bundle.OnResolved(&err)); |
124 sources.push_back(SourceFile("//foo/input1.txt")); | |
125 sources.push_back(SourceFile("//foo/input2.txt")); | |
126 target.bundle_data().file_rules().push_back(BundleFileRule( | |
127 sources, SubstitutionPattern::MakeForTest( | |
128 "{{bundle_resources_dir}}/{{source_file_part}}"))); | |
129 | |
130 target.SetToolchain(setup.toolchain()); | |
131 ASSERT_TRUE(target.OnResolved(&err)); | |
132 | 135 |
133 std::ostringstream out; | 136 std::ostringstream out; |
134 NinjaCreateBundleTargetWriter writer(&target, out); | 137 NinjaCreateBundleTargetWriter writer(&create_bundle, out); |
135 writer.Run(); | 138 writer.Run(); |
136 | 139 |
137 const char expected[] = | 140 const char expected[] = |
138 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data " | 141 "build obj/baz/bar.stamp: stamp\n" |
139 "../../foo/input1.txt\n" | |
140 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data " | |
141 "../../foo/input2.txt\n" | |
142 "build obj/baz/bar.stamp: stamp " | |
143 "bar.bundle/Contents/Resources/input1.txt " | |
144 "bar.bundle/Contents/Resources/input2.txt\n" | |
145 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 142 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
146 std::string out_str = out.str(); | 143 std::string out_str = out.str(); |
147 EXPECT_EQ(expected, out_str); | 144 EXPECT_EQ(expected, out_str); |
148 } | 145 } |
149 | 146 |
150 // Tests complex target with multiple bundle_data sources, including | 147 // Tests complex target with multiple bundle_data sources, including |
151 // some asset catalog. | 148 // some asset catalog. |
152 TEST(NinjaCreateBundleTargetWriter, ImplicitDeps) { | 149 TEST(NinjaCreateBundleTargetWriter, Complex) { |
153 TestWithScope setup; | |
154 Err err; | 150 Err err; |
155 | 151 |
| 152 TestWithScope setup; |
156 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 153 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
157 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar")); | |
158 target.set_output_type(Target::CREATE_BUNDLE); | |
159 | 154 |
160 SetupBundleDataDir(&target.bundle_data(), "//out/Debug"); | 155 Target bundle_data0(setup.settings(), |
| 156 Label(SourceDir("//qux/"), "info_plist")); |
| 157 bundle_data0.set_output_type(Target::BUNDLE_DATA); |
| 158 bundle_data0.sources().push_back(SourceFile("//qux/qux-Info.plist")); |
| 159 bundle_data0.action_values().outputs() = |
| 160 SubstitutionList::MakeForTest("{{bundle_root_dir}}/Info.plist"); |
| 161 bundle_data0.SetToolchain(setup.toolchain()); |
| 162 bundle_data0.visibility().SetPublic(); |
| 163 ASSERT_TRUE(bundle_data0.OnResolved(&err)); |
161 | 164 |
162 std::vector<SourceFile> sources1; | 165 Target bundle_data1(setup.settings(), Label(SourceDir("//foo/"), "data")); |
163 sources1.push_back(SourceFile("//foo/input1.txt")); | 166 bundle_data1.set_output_type(Target::BUNDLE_DATA); |
164 sources1.push_back(SourceFile("//foo/input2.txt")); | 167 bundle_data1.sources().push_back(SourceFile("//foo/input1.txt")); |
165 target.bundle_data().file_rules().push_back(BundleFileRule( | 168 bundle_data1.sources().push_back(SourceFile("//foo/input2.txt")); |
166 sources1, SubstitutionPattern::MakeForTest( | 169 bundle_data1.action_values().outputs() = SubstitutionList::MakeForTest( |
167 "{{bundle_resources_dir}}/{{source_file_part}}"))); | 170 "{{bundle_resources_dir}}/{{source_file_part}}"); |
| 171 bundle_data1.SetToolchain(setup.toolchain()); |
| 172 bundle_data1.visibility().SetPublic(); |
| 173 ASSERT_TRUE(bundle_data1.OnResolved(&err)); |
168 | 174 |
169 std::vector<SourceFile> sources2; | 175 Target bundle_data2(setup.settings(), Label(SourceDir("//foo/"), "assets")); |
170 sources2.push_back(SourceFile("//qux/Info.plist")); | 176 bundle_data2.set_output_type(Target::BUNDLE_DATA); |
171 target.bundle_data().file_rules().push_back(BundleFileRule( | 177 bundle_data2.sources().push_back( |
172 sources2, | 178 SourceFile("//foo/Foo.xcassets/Contents.json")); |
173 SubstitutionPattern::MakeForTest("{{bundle_root_dir}}/Info.plist"))); | 179 bundle_data2.sources().push_back( |
| 180 SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json")); |
| 181 bundle_data2.sources().push_back( |
| 182 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png")); |
| 183 bundle_data2.sources().push_back( |
| 184 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png")); |
| 185 bundle_data2.sources().push_back( |
| 186 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png")); |
| 187 bundle_data2.action_values().outputs() = SubstitutionList::MakeForTest( |
| 188 "{{bundle_resources_dir}}/{{source_file_part}}"); |
| 189 bundle_data2.SetToolchain(setup.toolchain()); |
| 190 bundle_data2.visibility().SetPublic(); |
| 191 ASSERT_TRUE(bundle_data2.OnResolved(&err)); |
174 | 192 |
175 std::vector<SourceFile> empty_source; | 193 Target bundle_data3(setup.settings(), Label(SourceDir("//quz/"), "assets")); |
176 target.bundle_data().file_rules().push_back(BundleFileRule( | 194 bundle_data3.set_output_type(Target::BUNDLE_DATA); |
177 empty_source, SubstitutionPattern::MakeForTest( | 195 bundle_data3.sources().push_back( |
178 "{{bundle_plugins_dir}}/{{source_file_part}}"))); | 196 SourceFile("//quz/Quz.xcassets/Contents.json")); |
| 197 bundle_data3.sources().push_back( |
| 198 SourceFile("//quz/Quz.xcassets/quz.imageset/Contents.json")); |
| 199 bundle_data3.sources().push_back( |
| 200 SourceFile("//quz/Quz.xcassets/quz.imageset/QuzIcon-29.png")); |
| 201 bundle_data3.sources().push_back( |
| 202 SourceFile("//quz/Quz.xcassets/quz.imageset/QuzIcon-29@2x.png")); |
| 203 bundle_data3.sources().push_back( |
| 204 SourceFile("//quz/Quz.xcassets/quz.imageset/QuzIcon-29@3x.png")); |
| 205 bundle_data3.action_values().outputs() = SubstitutionList::MakeForTest( |
| 206 "{{bundle_resources_dir}}/{{source_file_part}}"); |
| 207 bundle_data3.SetToolchain(setup.toolchain()); |
| 208 bundle_data3.visibility().SetPublic(); |
| 209 ASSERT_TRUE(bundle_data3.OnResolved(&err)); |
179 | 210 |
180 std::vector<SourceFile>& asset_catalog_sources = | 211 Target create_bundle( |
181 target.bundle_data().asset_catalog_sources(); | 212 setup.settings(), |
182 asset_catalog_sources.push_back( | 213 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), |
183 SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json")); | 214 setup.toolchain()->label().name())); |
184 asset_catalog_sources.push_back( | 215 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); |
185 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png")); | 216 create_bundle.set_output_type(Target::CREATE_BUNDLE); |
186 asset_catalog_sources.push_back( | 217 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data0)); |
187 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png")); | 218 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data1)); |
188 asset_catalog_sources.push_back( | 219 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data2)); |
189 SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png")); | 220 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data3)); |
190 | 221 create_bundle.SetToolchain(setup.toolchain()); |
191 target.SetToolchain(setup.toolchain()); | 222 ASSERT_TRUE(create_bundle.OnResolved(&err)); |
192 ASSERT_TRUE(target.OnResolved(&err)); | |
193 | 223 |
194 std::ostringstream out; | 224 std::ostringstream out; |
195 NinjaCreateBundleTargetWriter writer(&target, out); | 225 NinjaCreateBundleTargetWriter writer(&create_bundle, out); |
196 writer.Run(); | 226 writer.Run(); |
197 | 227 |
198 const char expected[] = | 228 const char expected[] = |
199 "build bar.bundle/Resources/input1.txt: copy_bundle_data " | 229 "build bar.bundle/Contents/Info.plist: copy_bundle_data " |
| 230 "../../qux/qux-Info.plist\n" |
| 231 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data " |
200 "../../foo/input1.txt\n" | 232 "../../foo/input1.txt\n" |
201 "build bar.bundle/Resources/input2.txt: copy_bundle_data " | 233 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data " |
202 "../../foo/input2.txt\n" | 234 "../../foo/input2.txt\n" |
203 "build bar.bundle/Info.plist: copy_bundle_data " | 235 "build obj/baz/bar.xcassets.inputdeps.stamp: stamp " |
204 "../../qux/Info.plist\n" | 236 "obj/foo/assets.stamp " |
205 "build bar.bundle/Resources/Assets.car: compile_xcassets " | 237 "obj/quz/assets.stamp\n" |
206 "../../foo/Foo.xcassets | " | 238 "build bar.bundle/Contents/Resources/Assets.car: compile_xcassets " |
207 "../../foo/Foo.xcassets/foo.imageset/Contents.json " | 239 "../../foo/Foo.xcassets " |
208 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png " | 240 "../../quz/Quz.xcassets | obj/baz/bar.xcassets.inputdeps.stamp\n" |
209 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png " | |
210 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n" | |
211 "build obj/baz/bar.stamp: stamp " | 241 "build obj/baz/bar.stamp: stamp " |
212 "bar.bundle/Resources/input1.txt " | 242 "bar.bundle/Contents/Info.plist " |
213 "bar.bundle/Resources/input2.txt " | 243 "bar.bundle/Contents/Resources/input1.txt " |
214 "bar.bundle/Info.plist " | 244 "bar.bundle/Contents/Resources/input2.txt " |
215 "bar.bundle/Resources/Assets.car\n" | 245 "bar.bundle/Contents/Resources/Assets.car\n" |
216 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 246 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
217 std::string out_str = out.str(); | 247 std::string out_str = out.str(); |
218 EXPECT_EQ(expected, out_str); | 248 EXPECT_EQ(expected, out_str); |
219 } | 249 } |
220 | 250 |
221 // Tests multiple files with an output pattern. | 251 // Tests code signing steps. |
222 TEST(NinjaCreateBundleTargetWriter, CodeSigning) { | 252 TEST(NinjaCreateBundleTargetWriter, CodeSigning) { |
223 TestWithScope setup; | |
224 Err err; | 253 Err err; |
225 | 254 |
| 255 TestWithScope setup; |
226 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 256 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
227 | 257 |
228 // Simulate a binary build by another target. Since no toolchain is defined | 258 Target executable(setup.settings(), Label(SourceDir("//baz/"), "quz")); |
229 // use an action instead of an executable target for simplicity. | 259 executable.set_output_type(Target::EXECUTABLE); |
230 Target binary(setup.settings(), Label(SourceDir("//baz/"), "quz")); | 260 executable.sources().push_back(SourceFile("//baz/quz.c")); |
231 binary.set_output_type(Target::EXECUTABLE); | 261 executable.SetToolchain(setup.toolchain()); |
232 binary.visibility().SetPublic(); | 262 executable.visibility().SetPublic(); |
233 binary.sources().push_back(SourceFile("//baz/quz.c")); | 263 ASSERT_TRUE(executable.OnResolved(&err)); |
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 | 264 |
239 Target target(setup.settings(), | 265 Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); |
240 Label(SourceDir("//baz/"), "bar", | 266 bundle_data.set_output_type(Target::BUNDLE_DATA); |
241 setup.toolchain()->label().dir(), | 267 bundle_data.sources().push_back(SourceFile("//foo/input1.txt")); |
242 setup.toolchain()->label().name())); | 268 bundle_data.sources().push_back(SourceFile("//foo/input2.txt")); |
243 target.set_output_type(Target::CREATE_BUNDLE); | 269 bundle_data.action_values().outputs() = SubstitutionList::MakeForTest( |
| 270 "{{bundle_resources_dir}}/{{source_file_part}}"); |
| 271 bundle_data.SetToolchain(setup.toolchain()); |
| 272 bundle_data.visibility().SetPublic(); |
| 273 ASSERT_TRUE(bundle_data.OnResolved(&err)); |
244 | 274 |
245 SetupBundleDataDir(&target.bundle_data(), "//out/Debug"); | 275 Target create_bundle( |
246 | 276 setup.settings(), |
247 std::vector<SourceFile> sources; | 277 Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), |
248 sources.push_back(SourceFile("//foo/input1.txt")); | 278 setup.toolchain()->label().name())); |
249 sources.push_back(SourceFile("//foo/input2.txt")); | 279 SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); |
250 target.bundle_data().file_rules().push_back(BundleFileRule( | 280 create_bundle.set_output_type(Target::CREATE_BUNDLE); |
251 sources, SubstitutionPattern::MakeForTest( | 281 create_bundle.bundle_data().set_code_signing_script( |
252 "{{bundle_resources_dir}}/{{source_file_part}}"))); | |
253 | |
254 target.bundle_data().set_code_signing_script( | |
255 SourceFile("//build/codesign.py")); | 282 SourceFile("//build/codesign.py")); |
256 target.bundle_data().code_signing_sources().push_back( | 283 create_bundle.bundle_data().code_signing_sources().push_back( |
257 SourceFile("//out/Debug/obj/baz/quz/bin")); | 284 SourceFile("//out/Debug/quz")); |
258 target.bundle_data().code_signing_outputs() = SubstitutionList::MakeForTest( | 285 create_bundle.bundle_data().code_signing_outputs() = |
259 "//out/Debug/bar.bundle/quz", | 286 SubstitutionList::MakeForTest( |
260 "//out/Debug/bar.bundle/_CodeSignature/CodeResources"); | 287 "//out/Debug/bar.bundle/Contents/quz", |
261 target.bundle_data().code_signing_args() = SubstitutionList::MakeForTest( | 288 "//out/Debug/bar.bundle/_CodeSignature/CodeResources"); |
262 "-b=obj/baz/quz/bin", | 289 create_bundle.bundle_data().code_signing_args() = |
263 "bar.bundle"); | 290 SubstitutionList::MakeForTest("-b=quz", "bar.bundle"); |
264 | 291 create_bundle.public_deps().push_back(LabelTargetPair(&executable)); |
265 target.public_deps().push_back(LabelTargetPair(&binary)); | 292 create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data)); |
266 | 293 create_bundle.SetToolchain(setup.toolchain()); |
267 target.SetToolchain(setup.toolchain()); | 294 ASSERT_TRUE(create_bundle.OnResolved(&err)); |
268 ASSERT_TRUE(target.OnResolved(&err)); | |
269 | 295 |
270 std::ostringstream out; | 296 std::ostringstream out; |
271 NinjaCreateBundleTargetWriter writer(&target, out); | 297 NinjaCreateBundleTargetWriter writer(&create_bundle, out); |
272 writer.Run(); | 298 writer.Run(); |
273 | 299 |
274 const char expected[] = | 300 const char expected[] = |
275 "rule __baz_bar___toolchain_default__code_signing_rule\n" | 301 "rule __baz_bar___toolchain_default__code_signing_rule\n" |
276 " command = ../../build/codesign.py -b=obj/baz/quz/bin bar.bundle\n" | 302 " command = ../../build/codesign.py -b=quz bar.bundle\n" |
277 " description = CODE SIGNING //baz:bar(//toolchain:default)\n" | 303 " description = CODE SIGNING //baz:bar(//toolchain:default)\n" |
278 " restat = 1\n" | 304 " restat = 1\n" |
279 "\n" | 305 "\n" |
280 "build bar.bundle/Resources/input1.txt: copy_bundle_data " | 306 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data " |
281 "../../foo/input1.txt\n" | 307 "../../foo/input1.txt\n" |
282 "build bar.bundle/Resources/input2.txt: copy_bundle_data " | 308 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data " |
283 "../../foo/input2.txt\n" | 309 "../../foo/input2.txt\n" |
284 "build obj/baz/bar.codesigning.inputdeps.stamp: stamp " | 310 "build obj/baz/bar.codesigning.inputdeps.stamp: stamp " |
285 "../../build/codesign.py " | 311 "../../build/codesign.py " |
286 "obj/baz/quz/bin " | 312 "quz " |
287 "bar.bundle/Resources/input1.txt " | 313 "bar.bundle/Contents/Resources/input1.txt " |
288 "bar.bundle/Resources/input2.txt\n" | 314 "bar.bundle/Contents/Resources/input2.txt " |
289 "build bar.bundle/quz bar.bundle/_CodeSignature/CodeResources: " | 315 "./quz\n" |
| 316 "build bar.bundle/Contents/quz bar.bundle/_CodeSignature/CodeResources: " |
290 "__baz_bar___toolchain_default__code_signing_rule " | 317 "__baz_bar___toolchain_default__code_signing_rule " |
291 "| obj/baz/bar.codesigning.inputdeps.stamp\n" | 318 "| obj/baz/bar.codesigning.inputdeps.stamp\n" |
292 "build obj/baz/bar.stamp: stamp " | 319 "build obj/baz/bar.stamp: stamp " |
293 "bar.bundle/quz " | 320 "bar.bundle/Contents/quz " |
294 "bar.bundle/_CodeSignature/CodeResources\n" | 321 "bar.bundle/_CodeSignature/CodeResources\n" |
295 "build bar.bundle: phony obj/baz/bar.stamp\n"; | 322 "build bar.bundle: phony obj/baz/bar.stamp\n"; |
296 std::string out_str = out.str(); | 323 std::string out_str = out.str(); |
297 EXPECT_EQ(expected, out_str); | 324 EXPECT_EQ(expected, out_str); |
298 } | 325 } |
OLD | NEW |