SCsub 4.9 KB

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