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

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

Issue 2010173004: [Mac/GN] Collect a bundle's data_deps when using `gn desc runtime_deps`. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/runtime_deps.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "tools/gn/runtime_deps.h" 10 #include "tools/gn/runtime_deps.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // Tests that the search for dependencies terminates at a bundle target, 261 // Tests that the search for dependencies terminates at a bundle target,
262 // ignoring any shared libraries or loadable modules that get copied into the 262 // ignoring any shared libraries or loadable modules that get copied into the
263 // bundle. 263 // bundle.
264 TEST(RuntimeDeps, CreateBundle) { 264 TEST(RuntimeDeps, CreateBundle) {
265 TestWithScope setup; 265 TestWithScope setup;
266 Err err; 266 Err err;
267 267
268 // Dependency hierarchy: 268 // Dependency hierarchy:
269 // main(exe) -> dep(bundle) -> dep(shared_library) -> dep(source set) 269 // main(exe) -> dep(bundle) -> dep(shared_library) -> dep(source set)
270 // -> dep(bundle_data) -> dep(loadable_module) 270 // -> dep(bundle_data) -> dep(loadable_module)
271 // -> data(lm.data)
272 // -> datadep(datadep) -> data(dd.data)
271 273
272 const SourceDir source_dir("//"); 274 const SourceDir source_dir("//");
273 const std::string& build_dir = setup.build_settings()->build_dir().value(); 275 const std::string& build_dir = setup.build_settings()->build_dir().value();
274 276
275 Target loadable_module(setup.settings(), 277 Target loadable_module(setup.settings(),
276 Label(source_dir, "loadable_module")); 278 Label(source_dir, "loadable_module"));
277 InitTargetWithType(setup, &loadable_module, Target::LOADABLE_MODULE); 279 InitTargetWithType(setup, &loadable_module, Target::LOADABLE_MODULE);
280 loadable_module.data().push_back("//lm.data");
278 ASSERT_TRUE(loadable_module.OnResolved(&err)); 281 ASSERT_TRUE(loadable_module.OnResolved(&err));
279 282
280 Target module_data(setup.settings(), Label(source_dir, "module_data")); 283 Target module_data(setup.settings(), Label(source_dir, "module_data"));
281 InitTargetWithType(setup, &module_data, Target::BUNDLE_DATA); 284 InitTargetWithType(setup, &module_data, Target::BUNDLE_DATA);
282 module_data.private_deps().push_back(LabelTargetPair(&loadable_module)); 285 module_data.private_deps().push_back(LabelTargetPair(&loadable_module));
283 module_data.bundle_data().file_rules().push_back(BundleFileRule( 286 module_data.bundle_data().file_rules().push_back(BundleFileRule(
284 std::vector<SourceFile>{SourceFile(build_dir + "loadable_module.so")}, 287 std::vector<SourceFile>{SourceFile(build_dir + "loadable_module.so")},
285 SubstitutionPattern::MakeForTest("{{bundle_resources_dir}}"))); 288 SubstitutionPattern::MakeForTest("{{bundle_resources_dir}}")));
286 ASSERT_TRUE(module_data.OnResolved(&err)); 289 ASSERT_TRUE(module_data.OnResolved(&err));
287 290
(...skipping 11 matching lines...) Expand all
299 ASSERT_TRUE(dylib.OnResolved(&err)); 302 ASSERT_TRUE(dylib.OnResolved(&err));
300 303
301 Target dylib_data(setup.settings(), Label(source_dir, "dylib_data")); 304 Target dylib_data(setup.settings(), Label(source_dir, "dylib_data"));
302 InitTargetWithType(setup, &dylib_data, Target::BUNDLE_DATA); 305 InitTargetWithType(setup, &dylib_data, Target::BUNDLE_DATA);
303 dylib_data.private_deps().push_back(LabelTargetPair(&dylib)); 306 dylib_data.private_deps().push_back(LabelTargetPair(&dylib));
304 dylib_data.bundle_data().file_rules().push_back(BundleFileRule( 307 dylib_data.bundle_data().file_rules().push_back(BundleFileRule(
305 std::vector<SourceFile>{SourceFile(build_dir + "dylib")}, 308 std::vector<SourceFile>{SourceFile(build_dir + "dylib")},
306 SubstitutionPattern::MakeForTest("{{bundle_executable_dir}}"))); 309 SubstitutionPattern::MakeForTest("{{bundle_executable_dir}}")));
307 ASSERT_TRUE(dylib_data.OnResolved(&err)); 310 ASSERT_TRUE(dylib_data.OnResolved(&err));
308 311
312 Target data_dep(setup.settings(), Label(source_dir, "datadep"));
313 InitTargetWithType(setup, &data_dep, Target::EXECUTABLE);
314 data_dep.data().push_back("//dd.data");
315 ASSERT_TRUE(data_dep.OnResolved(&err));
316
309 Target bundle(setup.settings(), Label(source_dir, "bundle")); 317 Target bundle(setup.settings(), Label(source_dir, "bundle"));
310 InitTargetWithType(setup, &bundle, Target::CREATE_BUNDLE); 318 InitTargetWithType(setup, &bundle, Target::CREATE_BUNDLE);
311 const std::string root_dir(build_dir + "Bundle.framework/Versions/A/"); 319 const std::string root_dir(build_dir + "Bundle.framework/Versions/A/");
312 bundle.bundle_data().root_dir() = SourceDir(root_dir); 320 bundle.bundle_data().root_dir() = SourceDir(root_dir);
313 bundle.bundle_data().resources_dir() = SourceDir(root_dir + "Resources"); 321 bundle.bundle_data().resources_dir() = SourceDir(root_dir + "Resources");
314 bundle.bundle_data().executable_dir() = SourceDir(root_dir + "MacOS"); 322 bundle.bundle_data().executable_dir() = SourceDir(root_dir + "MacOS");
315 bundle.private_deps().push_back(LabelTargetPair(&dylib_data)); 323 bundle.private_deps().push_back(LabelTargetPair(&dylib_data));
316 bundle.private_deps().push_back(LabelTargetPair(&module_data)); 324 bundle.private_deps().push_back(LabelTargetPair(&module_data));
325 bundle.data_deps().push_back(LabelTargetPair(&data_dep));
326 bundle.data().push_back("//b.data");
317 ASSERT_TRUE(bundle.OnResolved(&err)); 327 ASSERT_TRUE(bundle.OnResolved(&err));
318 328
319 Target main(setup.settings(), Label(source_dir, "main")); 329 Target main(setup.settings(), Label(source_dir, "main"));
320 InitTargetWithType(setup, &main, Target::EXECUTABLE); 330 InitTargetWithType(setup, &main, Target::EXECUTABLE);
321 main.data_deps().push_back(LabelTargetPair(&bundle)); 331 main.data_deps().push_back(LabelTargetPair(&bundle));
322 ASSERT_TRUE(main.OnResolved(&err)); 332 ASSERT_TRUE(main.OnResolved(&err));
323 333
324 std::vector<std::pair<OutputFile, const Target*>> result = 334 std::vector<std::pair<OutputFile, const Target*>> result =
325 ComputeRuntimeDeps(&main); 335 ComputeRuntimeDeps(&main);
326 336
327 // The result should have deps of main, datadep, final_in.dat 337 // The result should have deps of main, datadep, final_in.dat
328 ASSERT_EQ(2u, result.size()) << GetVectorDescription(result); 338 ASSERT_EQ(5u, result.size()) << GetVectorDescription(result);
329 339
330 // The first one should always be the main exe. 340 // The first one should always be the main exe.
331 EXPECT_EQ(MakePair("./main", &main), result[0]); 341 EXPECT_EQ(MakePair("./main", &main), result[0]);
332 342
333 // The second one should be the framework bundle, not its included 343 // The rest of the ordering is undefined.
334 // loadable_module or its intermediate shared_library. 344
335 EXPECT_EQ(MakePair("Bundle.framework/", &bundle), result[1]); 345 // The framework bundle's internal dependencies should not be incldued.
346 EXPECT_TRUE(std::find(result.begin(), result.end(),
347 MakePair("Bundle.framework/", &bundle)) !=
348 result.end()) << GetVectorDescription(result);
349 // But direct data and data dependencies should be.
350 EXPECT_TRUE(std::find(result.begin(), result.end(),
351 MakePair("./datadep", &data_dep)) !=
352 result.end()) << GetVectorDescription(result);
353 EXPECT_TRUE(std::find(result.begin(), result.end(),
354 MakePair("../../dd.data", &data_dep)) !=
355 result.end()) << GetVectorDescription(result);
356 EXPECT_TRUE(std::find(result.begin(), result.end(),
357 MakePair("../../b.data", &bundle)) !=
358 result.end()) << GetVectorDescription(result);
336 } 359 }
337 360
338 // Tests that a dependency duplicated in regular and data deps is processed 361 // Tests that a dependency duplicated in regular and data deps is processed
339 // as a data dep. 362 // as a data dep.
340 TEST(RuntimeDeps, Dupe) { 363 TEST(RuntimeDeps, Dupe) {
341 TestWithScope setup; 364 TestWithScope setup;
342 Err err; 365 Err err;
343 366
344 Target action(setup.settings(), Label(SourceDir("//"), "action")); 367 Target action(setup.settings(), Label(SourceDir("//"), "action"));
345 InitTargetWithType(setup, &action, Target::ACTION); 368 InitTargetWithType(setup, &action, Target::ACTION);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 err = Err(); 404 err = Err();
382 EXPECT_TRUE(setup.ExecuteSnippet( 405 EXPECT_TRUE(setup.ExecuteSnippet(
383 "if (true) {\n" 406 "if (true) {\n"
384 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n" 407 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n"
385 "} else {\n" 408 "} else {\n"
386 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n" 409 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n"
387 "}", &err)); 410 "}", &err));
388 EXPECT_EQ(1U, setup.items().size()); 411 EXPECT_EQ(1U, setup.items().size());
389 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size()); 412 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size());
390 } 413 }
OLDNEW
« no previous file with comments | « tools/gn/runtime_deps.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698