SCsub 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. Import("env")
  4. import os
  5. import shutil
  6. import subprocess
  7. import platform_macos_builders
  8. from platform_methods import get_build_version, lipo
  9. def generate_bundle(target, source, env):
  10. bin_dir = Dir("#bin").abspath
  11. if env.editor_build:
  12. # Editor bundle.
  13. prefix = "godot." + env["platform"] + "." + env["target"]
  14. if env.dev_build:
  15. prefix += ".dev"
  16. if env["precision"] == "double":
  17. prefix += ".double"
  18. # Lipo editor executable.
  19. target_bin = lipo(bin_dir + "/" + prefix, env.extra_suffix + env.module_version_string)
  20. # Assemble .app bundle and update version info.
  21. app_dir = Dir(
  22. "#bin/" + (prefix + env.extra_suffix + env.module_version_string).replace(".", "_") + ".app"
  23. ).abspath
  24. templ = Dir("#misc/dist/macos_tools.app").abspath
  25. if os.path.exists(app_dir):
  26. shutil.rmtree(app_dir)
  27. # Create the .app bundle directory itself from scratch so that the creation
  28. # date is accurate, but copy the rest of the template over.
  29. os.mkdir(app_dir)
  30. shutil.copytree(
  31. os.path.join(templ, "Contents"),
  32. os.path.join(app_dir, "Contents"),
  33. ignore=shutil.ignore_patterns("Info.plist"),
  34. )
  35. if not os.path.isdir(app_dir + "/Contents/MacOS"):
  36. os.mkdir(app_dir + "/Contents/MacOS")
  37. if target_bin != "":
  38. shutil.copy(target_bin, app_dir + "/Contents/MacOS/Godot")
  39. if "mono" in env.module_version_string:
  40. shutil.copytree(Dir("#bin/GodotSharp").abspath, app_dir + "/Contents/Resources/GodotSharp")
  41. version = get_build_version(False)
  42. short_version = get_build_version(True)
  43. with open(Dir("#misc/dist/macos").abspath + "/editor_info_plist.template", "rt", encoding="utf-8") as fin:
  44. with open(app_dir + "/Contents/Info.plist", "wt", encoding="utf-8", newline="\n") as fout:
  45. for line in fin:
  46. line = line.replace("$version", version)
  47. line = line.replace("$short_version", short_version)
  48. fout.write(line)
  49. # Sign .app bundle.
  50. if env["bundle_sign_identity"] != "":
  51. sign_command = [
  52. "codesign",
  53. "-s",
  54. env["bundle_sign_identity"],
  55. "--deep",
  56. "--force",
  57. "--options=runtime",
  58. "--entitlements",
  59. ]
  60. if env.dev_build:
  61. sign_command += [Dir("#misc/dist/macos").abspath + "/editor_debug.entitlements"]
  62. else:
  63. sign_command += [Dir("#misc/dist/macos").abspath + "/editor.entitlements"]
  64. sign_command += [app_dir]
  65. subprocess.run(sign_command)
  66. else:
  67. # Template bundle.
  68. app_prefix = "godot." + env["platform"]
  69. rel_prefix = "godot." + env["platform"] + "." + "template_release"
  70. dbg_prefix = "godot." + env["platform"] + "." + "template_debug"
  71. if env.dev_build:
  72. app_prefix += ".dev"
  73. rel_prefix += ".dev"
  74. dbg_prefix += ".dev"
  75. if env["precision"] == "double":
  76. app_prefix += ".double"
  77. rel_prefix += ".double"
  78. dbg_prefix += ".double"
  79. # Lipo template executables.
  80. rel_target_bin = lipo(bin_dir + "/" + rel_prefix, env.extra_suffix + env.module_version_string)
  81. dbg_target_bin = lipo(bin_dir + "/" + dbg_prefix, env.extra_suffix + env.module_version_string)
  82. # Assemble .app bundle.
  83. app_dir = Dir("#bin/macos_template.app").abspath
  84. templ = Dir("#misc/dist/macos_template.app").abspath
  85. if os.path.exists(app_dir):
  86. shutil.rmtree(app_dir)
  87. shutil.copytree(templ, app_dir)
  88. if not os.path.isdir(app_dir + "/Contents/MacOS"):
  89. os.mkdir(app_dir + "/Contents/MacOS")
  90. if rel_target_bin != "":
  91. shutil.copy(rel_target_bin, app_dir + "/Contents/MacOS/godot_macos_release.universal")
  92. if dbg_target_bin != "":
  93. shutil.copy(dbg_target_bin, app_dir + "/Contents/MacOS/godot_macos_debug.universal")
  94. # ZIP .app bundle.
  95. zip_dir = Dir("#bin/" + (app_prefix + env.extra_suffix + env.module_version_string).replace(".", "_")).abspath
  96. shutil.make_archive(zip_dir, "zip", root_dir=bin_dir, base_dir="macos_template.app")
  97. shutil.rmtree(app_dir)
  98. files = [
  99. "os_macos.mm",
  100. "godot_application.mm",
  101. "godot_application_delegate.mm",
  102. "crash_handler_macos.mm",
  103. "macos_terminal_logger.mm",
  104. "display_server_macos.mm",
  105. "godot_button_view.mm",
  106. "godot_content_view.mm",
  107. "godot_status_item.mm",
  108. "godot_window_delegate.mm",
  109. "godot_window.mm",
  110. "key_mapping_macos.mm",
  111. "godot_main_macos.mm",
  112. "godot_menu_delegate.mm",
  113. "godot_menu_item.mm",
  114. "godot_open_save_delegate.mm",
  115. "native_menu_macos.mm",
  116. "dir_access_macos.mm",
  117. "tts_macos.mm",
  118. "rendering_context_driver_vulkan_macos.mm",
  119. "gl_manager_macos_angle.mm",
  120. "gl_manager_macos_legacy.mm",
  121. ]
  122. prog = env.add_program("#bin/godot", files)
  123. if env["debug_symbols"] and env["separate_debug_symbols"]:
  124. env.AddPostAction(prog, env.Run(platform_macos_builders.make_debug_macos))
  125. if env["generate_bundle"]:
  126. generate_bundle_command = env.Command("generate_bundle", [], generate_bundle)
  127. command = env.AlwaysBuild(generate_bundle_command)
  128. env.Depends(command, [prog])