SCsub 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. shutil.copytree(templ, app_dir, ignore=shutil.ignore_patterns("Contents/Info.plist"))
  28. if not os.path.isdir(app_dir + "/Contents/MacOS"):
  29. os.mkdir(app_dir + "/Contents/MacOS")
  30. if target_bin != "":
  31. shutil.copy(target_bin, app_dir + "/Contents/MacOS/Godot")
  32. if "mono" in env.module_version_string:
  33. shutil.copytree(Dir("#bin/GodotSharp").abspath, app_dir + "/Contents/Resources/GodotSharp")
  34. version = get_build_version(False)
  35. short_version = get_build_version(True)
  36. with open(Dir("#misc/dist/macos").abspath + "/editor_info_plist.template", "rt", encoding="utf-8") as fin:
  37. with open(app_dir + "/Contents/Info.plist", "wt", encoding="utf-8", newline="\n") as fout:
  38. for line in fin:
  39. line = line.replace("$version", version)
  40. line = line.replace("$short_version", short_version)
  41. fout.write(line)
  42. # Sign .app bundle.
  43. if env["bundle_sign_identity"] != "":
  44. sign_command = [
  45. "codesign",
  46. "-s",
  47. env["bundle_sign_identity"],
  48. "--deep",
  49. "--force",
  50. "--options=runtime",
  51. "--entitlements",
  52. ]
  53. if env.dev_build:
  54. sign_command += [Dir("#misc/dist/macos").abspath + "/editor_debug.entitlements"]
  55. else:
  56. sign_command += [Dir("#misc/dist/macos").abspath + "/editor.entitlements"]
  57. sign_command += [app_dir]
  58. subprocess.run(sign_command)
  59. else:
  60. # Template bundle.
  61. app_prefix = "godot." + env["platform"]
  62. rel_prefix = "godot." + env["platform"] + "." + "template_release"
  63. dbg_prefix = "godot." + env["platform"] + "." + "template_debug"
  64. if env.dev_build:
  65. app_prefix += ".dev"
  66. rel_prefix += ".dev"
  67. dbg_prefix += ".dev"
  68. if env["precision"] == "double":
  69. app_prefix += ".double"
  70. rel_prefix += ".double"
  71. dbg_prefix += ".double"
  72. # Lipo template executables.
  73. rel_target_bin = lipo(bin_dir + "/" + rel_prefix, env.extra_suffix + env.module_version_string)
  74. dbg_target_bin = lipo(bin_dir + "/" + dbg_prefix, env.extra_suffix + env.module_version_string)
  75. # Assemble .app bundle.
  76. app_dir = Dir("#bin/macos_template.app").abspath
  77. templ = Dir("#misc/dist/macos_template.app").abspath
  78. if os.path.exists(app_dir):
  79. shutil.rmtree(app_dir)
  80. shutil.copytree(templ, app_dir)
  81. if not os.path.isdir(app_dir + "/Contents/MacOS"):
  82. os.mkdir(app_dir + "/Contents/MacOS")
  83. if rel_target_bin != "":
  84. shutil.copy(rel_target_bin, app_dir + "/Contents/MacOS/godot_macos_release.universal")
  85. if dbg_target_bin != "":
  86. shutil.copy(dbg_target_bin, app_dir + "/Contents/MacOS/godot_macos_debug.universal")
  87. # ZIP .app bundle.
  88. zip_dir = Dir("#bin/" + (app_prefix + env.extra_suffix + env.module_version_string).replace(".", "_")).abspath
  89. shutil.make_archive(zip_dir, "zip", root_dir=bin_dir, base_dir="macos_template.app")
  90. shutil.rmtree(app_dir)
  91. files = [
  92. "os_macos.mm",
  93. "godot_application.mm",
  94. "godot_application_delegate.mm",
  95. "crash_handler_macos.mm",
  96. "macos_terminal_logger.mm",
  97. "display_server_macos.mm",
  98. "godot_button_view.mm",
  99. "godot_content_view.mm",
  100. "godot_status_item.mm",
  101. "godot_window_delegate.mm",
  102. "godot_window.mm",
  103. "key_mapping_macos.mm",
  104. "godot_main_macos.mm",
  105. "godot_menu_delegate.mm",
  106. "godot_menu_item.mm",
  107. "godot_open_save_delegate.mm",
  108. "native_menu_macos.mm",
  109. "dir_access_macos.mm",
  110. "tts_macos.mm",
  111. "rendering_context_driver_vulkan_macos.mm",
  112. "gl_manager_macos_angle.mm",
  113. "gl_manager_macos_legacy.mm",
  114. ]
  115. prog = env.add_program("#bin/godot", files)
  116. if env["debug_symbols"] and env["separate_debug_symbols"]:
  117. env.AddPostAction(prog, env.Run(platform_macos_builders.make_debug_macos))
  118. if env["generate_bundle"]:
  119. generate_bundle_command = env.Command("generate_bundle", [], generate_bundle)
  120. command = env.AlwaysBuild(generate_bundle_command)
  121. env.Depends(command, [prog])