resource_file_conflict.patch 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Apthorp <[email protected]>
  3. Date: Thu, 20 Sep 2018 17:48:59 -0700
  4. Subject: resource_file_conflict.patch
  5. Resolve conflict between //chrome's .pak files and //electron's. The paths
  6. that chrome code hardcodes require that we generate resources at these
  7. paths, but GN throws errors if there are multiple targets that generate the
  8. same files.
  9. This is due to the hardcoded names here:
  10. https://chromium.googlesource.com/chromium/src/+/69.0.3497.106/ui/base/resource/resource_bundle.cc#780
  11. and here:
  12. https://chromium.googlesource.com/chromium/src/+/69.0.3497.106/ui/base/resource/resource_bundle_mac.mm#50
  13. This isn't needed on Mac because resource files are copied into the app bundle,
  14. and are built in `$root_out_dir/electron_repack` (while Chromium's resources
  15. target `$root_out_dir/repack`), but on Windows and Linux, the resource files go
  16. directly in `$root_out_dir`, and so they conflict.
  17. We don't actually ever generate Chromium's resource paks, but without this
  18. patch, GN refuses to generate the ninja files:
  19. ERROR at //tools/grit/repack.gni:35:3: Duplicate output file.
  20. action(_repack_target_name) {
  21. ^----------------------------
  22. Two or more targets generate the same output:
  23. chrome_100_percent.pak
  24. This is can often be fixed by changing one of the target names, or by
  25. setting an output_name on one of them.
  26. Collisions:
  27. //chrome:packed_resources_100_percent
  28. //electron:packed_resources_100_percent
  29. See //tools/grit/repack.gni:35:3: Collision.
  30. action(_repack_target_name) {
  31. ^----------------------------
  32. Some alternatives to this patch:
  33. 1. Refactor upstream in such a way that the "chrome" pak names were
  34. configurable, for instance by adding a method to ResourceBundle::Delegate that
  35. LoadChromeResources would check.
  36. 2. Pass a Delegate that overrides `GetPathForResourcePack`, check for the
  37. `chrome_{100,200}_percent.pak` filenames, and rewrite them to
  38. `electron_{100,200}_percent.pak`.
  39. 3. Initialize the resource bundle with DO_NOT_LOAD_COMMON_RESOURCES and load
  40. the paks ourselves.
  41. None of these options seems like a substantial maintainability win over this patch to me (@nornagon).
  42. diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn
  43. index 6a696e816a185f8492674fcaf1cbbf7e2faabf99..a6e0a53d4ebbd585114bc0cda2e2d1caaab4a015 100644
  44. --- a/chrome/BUILD.gn
  45. +++ b/chrome/BUILD.gn
  46. @@ -1545,7 +1545,7 @@ if (is_chrome_branded && !is_android) {
  47. }
  48. }
  49. -if (!is_android) {
  50. +if (!is_android && !is_electron_build) {
  51. chrome_paks("packed_resources") {
  52. if (is_mac) {
  53. output_dir = "$root_gen_dir/repack"
  54. @@ -1574,6 +1574,12 @@ if (!is_android) {
  55. }
  56. }
  57. +if (is_electron_build) {
  58. + group("packed_resources") {
  59. + public_deps = [ "//electron:packed_resources" ]
  60. + }
  61. +}
  62. +
  63. repack("unit_tests_pak") {
  64. sources = [ "$root_gen_dir/chrome/chrome_test_resources.pak" ]
  65. output = "$root_out_dir/unit_tests.pak"