OLD | NEW |
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 MakePair("../../dep_copy/data/", &dep_copy)) != | 251 MakePair("../../dep_copy/data/", &dep_copy)) != |
252 result.end()) << GetVectorDescription(result); | 252 result.end()) << GetVectorDescription(result); |
253 | 253 |
254 // Explicitly asking for the runtime deps of an action target only includes | 254 // Explicitly asking for the runtime deps of an action target only includes |
255 // the data and not all outputs. | 255 // the data and not all outputs. |
256 result = ComputeRuntimeDeps(&dep); | 256 result = ComputeRuntimeDeps(&dep); |
257 ASSERT_EQ(1u, result.size()); | 257 ASSERT_EQ(1u, result.size()); |
258 EXPECT_TRUE(MakePair("../../dep.data", &dep) == result[0]); | 258 EXPECT_TRUE(MakePair("../../dep.data", &dep) == result[0]); |
259 } | 259 } |
260 | 260 |
| 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 |
| 263 // bundle. |
| 264 TEST(RuntimeDeps, CreateBundle) { |
| 265 TestWithScope setup; |
| 266 Err err; |
| 267 |
| 268 // Dependency hierarchy: |
| 269 // main(exe) -> dep(bundle) -> dep(shared_library) -> dep(source set) |
| 270 // -> dep(bundle_data) -> dep(loadable_module) |
| 271 |
| 272 const SourceDir source_dir("//"); |
| 273 const std::string& build_dir = setup.build_settings()->build_dir().value(); |
| 274 |
| 275 Target loadable_module(setup.settings(), |
| 276 Label(source_dir, "loadable_module")); |
| 277 InitTargetWithType(setup, &loadable_module, Target::LOADABLE_MODULE); |
| 278 ASSERT_TRUE(loadable_module.OnResolved(&err)); |
| 279 |
| 280 Target module_data(setup.settings(), Label(source_dir, "module_data")); |
| 281 InitTargetWithType(setup, &module_data, Target::BUNDLE_DATA); |
| 282 module_data.private_deps().push_back(LabelTargetPair(&loadable_module)); |
| 283 module_data.bundle_data().file_rules().push_back(BundleFileRule( |
| 284 std::vector<SourceFile>{SourceFile(build_dir + "loadable_module.so")}, |
| 285 SubstitutionPattern::MakeForTest("{{bundle_resources_dir}}"))); |
| 286 ASSERT_TRUE(module_data.OnResolved(&err)); |
| 287 |
| 288 Target source_set(setup.settings(), Label(source_dir, "sources")); |
| 289 InitTargetWithType(setup, &source_set, Target::SOURCE_SET); |
| 290 source_set.sources().push_back(SourceFile(source_dir.value() + "foo.cc")); |
| 291 ASSERT_TRUE(source_set.OnResolved(&err)); |
| 292 |
| 293 Target dylib(setup.settings(), Label(source_dir, "dylib")); |
| 294 dylib.set_output_prefix_override(true); |
| 295 dylib.set_output_extension(""); |
| 296 dylib.set_output_name("Bundle"); |
| 297 InitTargetWithType(setup, &dylib, Target::SHARED_LIBRARY); |
| 298 dylib.private_deps().push_back(LabelTargetPair(&source_set)); |
| 299 ASSERT_TRUE(dylib.OnResolved(&err)); |
| 300 |
| 301 Target dylib_data(setup.settings(), Label(source_dir, "dylib_data")); |
| 302 InitTargetWithType(setup, &dylib_data, Target::BUNDLE_DATA); |
| 303 dylib_data.private_deps().push_back(LabelTargetPair(&dylib)); |
| 304 dylib_data.bundle_data().file_rules().push_back(BundleFileRule( |
| 305 std::vector<SourceFile>{SourceFile(build_dir + "dylib")}, |
| 306 SubstitutionPattern::MakeForTest("{{bundle_executable_dir}}"))); |
| 307 ASSERT_TRUE(dylib_data.OnResolved(&err)); |
| 308 |
| 309 Target bundle(setup.settings(), Label(source_dir, "bundle")); |
| 310 InitTargetWithType(setup, &bundle, Target::CREATE_BUNDLE); |
| 311 const std::string root_dir(build_dir + "Bundle.framework/Versions/A/"); |
| 312 bundle.bundle_data().root_dir() = SourceDir(root_dir); |
| 313 bundle.bundle_data().resources_dir() = SourceDir(root_dir + "Resources"); |
| 314 bundle.bundle_data().executable_dir() = SourceDir(root_dir + "MacOS"); |
| 315 bundle.private_deps().push_back(LabelTargetPair(&dylib_data)); |
| 316 bundle.private_deps().push_back(LabelTargetPair(&module_data)); |
| 317 ASSERT_TRUE(bundle.OnResolved(&err)); |
| 318 |
| 319 Target main(setup.settings(), Label(source_dir, "main")); |
| 320 InitTargetWithType(setup, &main, Target::EXECUTABLE); |
| 321 main.data_deps().push_back(LabelTargetPair(&bundle)); |
| 322 ASSERT_TRUE(main.OnResolved(&err)); |
| 323 |
| 324 std::vector<std::pair<OutputFile, const Target*>> result = |
| 325 ComputeRuntimeDeps(&main); |
| 326 |
| 327 // The result should have deps of main, datadep, final_in.dat |
| 328 ASSERT_EQ(2u, result.size()) << GetVectorDescription(result); |
| 329 |
| 330 // The first one should always be the main exe. |
| 331 EXPECT_EQ(MakePair("./main", &main), result[0]); |
| 332 |
| 333 // The second one should be the framework bundle, not its included |
| 334 // loadable_module or its intermediate shared_library. |
| 335 EXPECT_EQ(MakePair("Bundle.framework/", &bundle), result[1]); |
| 336 } |
| 337 |
261 // Tests that a dependency duplicated in regular and data deps is processed | 338 // Tests that a dependency duplicated in regular and data deps is processed |
262 // as a data dep. | 339 // as a data dep. |
263 TEST(RuntimeDeps, Dupe) { | 340 TEST(RuntimeDeps, Dupe) { |
264 TestWithScope setup; | 341 TestWithScope setup; |
265 Err err; | 342 Err err; |
266 | 343 |
267 Target action(setup.settings(), Label(SourceDir("//"), "action")); | 344 Target action(setup.settings(), Label(SourceDir("//"), "action")); |
268 InitTargetWithType(setup, &action, Target::ACTION); | 345 InitTargetWithType(setup, &action, Target::ACTION); |
269 action.action_values().outputs() = | 346 action.action_values().outputs() = |
270 SubstitutionList::MakeForTest("//action.output"); | 347 SubstitutionList::MakeForTest("//action.output"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 err = Err(); | 381 err = Err(); |
305 EXPECT_TRUE(setup.ExecuteSnippet( | 382 EXPECT_TRUE(setup.ExecuteSnippet( |
306 "if (true) {\n" | 383 "if (true) {\n" |
307 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n" | 384 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n" |
308 "} else {\n" | 385 "} else {\n" |
309 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n" | 386 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n" |
310 "}", &err)); | 387 "}", &err)); |
311 EXPECT_EQ(1U, setup.items().size()); | 388 EXPECT_EQ(1U, setup.items().size()); |
312 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size()); | 389 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size()); |
313 } | 390 } |
OLD | NEW |