platform_macos_builders.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. """Functions used to generate source files during build time"""
  2. import os
  3. import shutil
  4. import subprocess
  5. from platform_methods import get_build_version, lipo
  6. def generate_bundle(target, source, env):
  7. bin_dir = env.Dir("#bin").abspath
  8. if env.editor_build:
  9. # Editor bundle.
  10. prefix = "godot." + env["platform"] + "." + env["target"]
  11. if env.dev_build:
  12. prefix += ".dev"
  13. if env["precision"] == "double":
  14. prefix += ".double"
  15. # Lipo editor executable.
  16. target_bin = lipo(bin_dir + "/" + prefix, env.extra_suffix + env.module_version_string)
  17. # Assemble .app bundle and update version info.
  18. app_dir = env.Dir(
  19. "#bin/" + (prefix + env.extra_suffix + env.module_version_string).replace(".", "_") + ".app"
  20. ).abspath
  21. templ = env.Dir("#misc/dist/macos_tools.app").abspath
  22. if os.path.exists(app_dir):
  23. shutil.rmtree(app_dir)
  24. # Create the .app bundle directory itself from scratch so that the creation
  25. # date is accurate, but copy the rest of the template over.
  26. os.mkdir(app_dir)
  27. shutil.copytree(
  28. os.path.join(templ, "Contents"),
  29. os.path.join(app_dir, "Contents"),
  30. ignore=shutil.ignore_patterns("Info.plist"),
  31. )
  32. if not os.path.isdir(app_dir + "/Contents/MacOS"):
  33. os.mkdir(app_dir + "/Contents/MacOS")
  34. if target_bin != "":
  35. shutil.copy(target_bin, app_dir + "/Contents/MacOS/Godot")
  36. if "mono" in env.module_version_string:
  37. shutil.copytree(env.Dir("#bin/GodotSharp").abspath, app_dir + "/Contents/Resources/GodotSharp")
  38. version = get_build_version(False)
  39. short_version = get_build_version(True)
  40. with open(env.Dir("#misc/dist/macos").abspath + "/editor_info_plist.template", "rt", encoding="utf-8") as fin:
  41. with open(app_dir + "/Contents/Info.plist", "wt", encoding="utf-8", newline="\n") as fout:
  42. for line in fin:
  43. line = line.replace("$version", version)
  44. line = line.replace("$short_version", short_version)
  45. fout.write(line)
  46. # Sign .app bundle.
  47. if env["bundle_sign_identity"] != "":
  48. sign_command = [
  49. "codesign",
  50. "-s",
  51. env["bundle_sign_identity"],
  52. "--deep",
  53. "--force",
  54. "--options=runtime",
  55. "--entitlements",
  56. ]
  57. if env.dev_build:
  58. sign_command += [env.Dir("#misc/dist/macos").abspath + "/editor_debug.entitlements"]
  59. else:
  60. sign_command += [env.Dir("#misc/dist/macos").abspath + "/editor.entitlements"]
  61. sign_command += [app_dir]
  62. subprocess.run(sign_command)
  63. else:
  64. # Template bundle.
  65. app_prefix = "godot." + env["platform"]
  66. rel_prefix = "godot." + env["platform"] + "." + "template_release"
  67. dbg_prefix = "godot." + env["platform"] + "." + "template_debug"
  68. if env.dev_build:
  69. app_prefix += ".dev"
  70. rel_prefix += ".dev"
  71. dbg_prefix += ".dev"
  72. if env["precision"] == "double":
  73. app_prefix += ".double"
  74. rel_prefix += ".double"
  75. dbg_prefix += ".double"
  76. # Lipo template executables.
  77. rel_target_bin = lipo(bin_dir + "/" + rel_prefix, env.extra_suffix + env.module_version_string)
  78. dbg_target_bin = lipo(bin_dir + "/" + dbg_prefix, env.extra_suffix + env.module_version_string)
  79. # Assemble .app bundle.
  80. app_dir = env.Dir("#bin/macos_template.app").abspath
  81. templ = env.Dir("#misc/dist/macos_template.app").abspath
  82. if os.path.exists(app_dir):
  83. shutil.rmtree(app_dir)
  84. shutil.copytree(templ, app_dir)
  85. if not os.path.isdir(app_dir + "/Contents/MacOS"):
  86. os.mkdir(app_dir + "/Contents/MacOS")
  87. if rel_target_bin != "":
  88. shutil.copy(rel_target_bin, app_dir + "/Contents/MacOS/godot_macos_release.universal")
  89. if dbg_target_bin != "":
  90. shutil.copy(dbg_target_bin, app_dir + "/Contents/MacOS/godot_macos_debug.universal")
  91. # ZIP .app bundle.
  92. zip_dir = env.Dir(
  93. "#bin/" + (app_prefix + env.extra_suffix + env.module_version_string).replace(".", "_")
  94. ).abspath
  95. shutil.make_archive(zip_dir, "zip", root_dir=bin_dir, base_dir="macos_template.app")
  96. shutil.rmtree(app_dir)
  97. def make_debug_macos(target, source, env):
  98. dst = str(target[0])
  99. if env["macports_clang"] != "no":
  100. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  101. mpclangver = env["macports_clang"]
  102. os.system(mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-dsymutil {0} -o {0}.dSYM".format(dst))
  103. else:
  104. os.system("dsymutil {0} -o {0}.dSYM".format(dst))
  105. os.system("strip -u -r {0}".format(dst))