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

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

Issue 1892243002: Write a phony target for the top-level directory of a create_bundle target. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 8 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') | no next file » | 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 writer.Run(); 48 writer.Run();
49 49
50 const char expected[] = 50 const char expected[] =
51 "build bar.bundle/Resources/input1.txt: copy_bundle_data " 51 "build bar.bundle/Resources/input1.txt: copy_bundle_data "
52 "../../foo/input1.txt\n" 52 "../../foo/input1.txt\n"
53 "build bar.bundle/Resources/input2.txt: copy_bundle_data " 53 "build bar.bundle/Resources/input2.txt: copy_bundle_data "
54 "../../foo/input2.txt\n" 54 "../../foo/input2.txt\n"
55 "\n" 55 "\n"
56 "build obj/baz/bar.stamp: stamp " 56 "build obj/baz/bar.stamp: stamp "
57 "bar.bundle/Resources/input1.txt " 57 "bar.bundle/Resources/input1.txt "
58 "bar.bundle/Resources/input2.txt\n"; 58 "bar.bundle/Resources/input2.txt\n"
59 "build bar.bundle: phony obj/baz/bar.stamp\n";
59 std::string out_str = out.str(); 60 std::string out_str = out.str();
60 EXPECT_EQ(expected, out_str); 61 EXPECT_EQ(expected, out_str);
61 } 62 }
62 63
63 // Tests multiple files from asset catalog. 64 // Tests multiple files from asset catalog.
64 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) { 65 TEST(NinjaCreateBundleTargetWriter, AssetCatalog) {
65 TestWithScope setup; 66 TestWithScope setup;
66 Err err; 67 Err err;
67 68
68 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 69 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
(...skipping 21 matching lines...) Expand all
90 writer.Run(); 91 writer.Run();
91 92
92 const char expected[] = 93 const char expected[] =
93 "build bar.bundle/Resources/Assets.car: compile_xcassets " 94 "build bar.bundle/Resources/Assets.car: compile_xcassets "
94 "../../foo/Foo.xcassets | " 95 "../../foo/Foo.xcassets | "
95 "../../foo/Foo.xcassets/foo.imageset/Contents.json " 96 "../../foo/Foo.xcassets/foo.imageset/Contents.json "
96 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png " 97 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png "
97 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png " 98 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png "
98 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n" 99 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n"
99 "\n" 100 "\n"
100 "build obj/baz/bar.stamp: stamp bar.bundle/Resources/Assets.car\n"; 101 "build obj/baz/bar.stamp: stamp bar.bundle/Resources/Assets.car\n"
102 "build bar.bundle: phony obj/baz/bar.stamp\n";
101 std::string out_str = out.str(); 103 std::string out_str = out.str();
102 EXPECT_EQ(expected, out_str); 104 EXPECT_EQ(expected, out_str);
103 } 105 }
106
107 // Tests that the phony target for the top-level bundle directory is generated
108 // correctly.
109 TEST(NinjaCreateBundleTargetWriter, BundleRootDirOutput) {
110 TestWithScope setup;
111 Err err;
112
113 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
114 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar"));
115 target.set_output_type(Target::CREATE_BUNDLE);
116
117 const std::string bundle_root_dir("//out/Debug/bar.bundle/Contents");
118 target.bundle_data().root_dir().assign(bundle_root_dir);
119 target.bundle_data().resources_dir().assign(bundle_root_dir + "/Resources");
120 target.bundle_data().executable_dir().assign(bundle_root_dir + "/MacOS");
121 target.bundle_data().plugins_dir().assign(bundle_root_dir + "/Plug Ins");
122
123 std::vector<SourceFile> sources;
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
133 std::ostringstream out;
134 NinjaCreateBundleTargetWriter writer(&target, out);
135 writer.Run();
136
137 const char expected[] =
138 "build bar.bundle/Contents/Resources/input1.txt: copy_bundle_data "
139 "../../foo/input1.txt\n"
140 "build bar.bundle/Contents/Resources/input2.txt: copy_bundle_data "
141 "../../foo/input2.txt\n"
142 "\n"
143 "build obj/baz/bar.stamp: stamp "
144 "bar.bundle/Contents/Resources/input1.txt "
145 "bar.bundle/Contents/Resources/input2.txt\n"
146 "build bar.bundle: phony obj/baz/bar.stamp\n";
147 std::string out_str = out.str();
148 EXPECT_EQ(expected, out_str);
149 }
104 150
105 // Tests complex target with multiple bundle_data sources, including 151 // Tests complex target with multiple bundle_data sources, including
106 // some asset catalog. 152 // some asset catalog.
107 TEST(NinjaCreateBundleTargetWriter, OrderOnlyDeps) { 153 TEST(NinjaCreateBundleTargetWriter, OrderOnlyDeps) {
108 TestWithScope setup; 154 TestWithScope setup;
109 Err err; 155 Err err;
110 156
111 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 157 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
112 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar")); 158 Target target(setup.settings(), Label(SourceDir("//baz/"), "bar"));
113 target.set_output_type(Target::CREATE_BUNDLE); 159 target.set_output_type(Target::CREATE_BUNDLE);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 "../../foo/Foo.xcassets | " 206 "../../foo/Foo.xcassets | "
161 "../../foo/Foo.xcassets/foo.imageset/Contents.json " 207 "../../foo/Foo.xcassets/foo.imageset/Contents.json "
162 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png " 208 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png "
163 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png " 209 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png "
164 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n" 210 "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png\n"
165 "\n" 211 "\n"
166 "build obj/baz/bar.stamp: stamp " 212 "build obj/baz/bar.stamp: stamp "
167 "bar.bundle/Resources/input1.txt " 213 "bar.bundle/Resources/input1.txt "
168 "bar.bundle/Resources/input2.txt " 214 "bar.bundle/Resources/input2.txt "
169 "bar.bundle/Info.plist " 215 "bar.bundle/Info.plist "
170 "bar.bundle/Resources/Assets.car\n"; 216 "bar.bundle/Resources/Assets.car\n"
217 "build bar.bundle: phony obj/baz/bar.stamp\n";
171 std::string out_str = out.str(); 218 std::string out_str = out.str();
172 EXPECT_EQ(expected, out_str); 219 EXPECT_EQ(expected, out_str);
173 } 220 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_create_bundle_target_writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698