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