Repository: godotengine/godot
File: platform/macos/platform_macos_builders.py (Python)

Code before:
            "#bin/" + (prefix + env.extra_suffix + env.module_version_string).replace(".", "_") + ".app"
        ).abspath
        templ = env.Dir("#misc/dist/macos_tools.app").abspath
        if os.path.exists(app_dir):
            shutil.rmtree(app_dir)

        # Create the .app bundle directory itself from scratch so that the creation
        # date is accurate, but copy the rest of the template over.
        os.mkdir(app_dir)
        shutil.copytree(
            os.path.join(templ, "Contents"),
            os.path.join(app_dir, "Contents"),
            ignore=shutil.ignore_patterns("Info.plist"),
        )

        if not os.path.isdir(app_dir + "/Contents/MacOS"):
            os.mkdir(app_dir + "/Contents/MacOS")
        if target_bin != "":
            shutil.copy(target_bin, app_dir + "/Contents/MacOS/Godot")
        if "mono" in env.module_version_string:
            shutil.copytree(env.Dir("#bin/GodotSharp").abspath, app_dir + "/Contents/Resources/GodotSharp")
        version = get_build_version(False)
        short_version = get_build_version(True)
        name = "custom_build"
        if os.getenv("BUILD_NAME") is not None:
            name = os.getenv("BUILD_NAME")
        with open(env.Dir("#misc/dist/macos").abspath + "/editor_info_plist.template", "rt", encoding="utf-8") as fin:
            with open(app_dir + "/Contents/Info.plist", "wt", encoding="utf-8", newline="\n") as fout:
                for line in fin:
                    line = line.replace("$version", version)
                    line = line.replace("$short_version", short_version)
                    if name != "official" and name != "steam":
                        line = line.replace("org.godotengine.godot", "org.godotengine.godot." + name)
                    fout.write(line)

        # Sign .app bundle.
        if env["bundle_sign_identity"] != "":
            sign_command = [
                "codesign",
                "-s",
                env["bundle_sign_identity"],
                "--deep",
                "--force",
                "--options=runtime",
                "--entitlements",
            ]
            if env.dev_build:
                sign_command += [env.Dir("#misc/dist/macos").abspath + "/editor_debug.entitlements"]
            else:
                sign_command += [env.Dir("#misc/dist/macos").abspath + "/editor.entitlements"]
            sign_command += [app_dir]

Review comment (refactor):
This is already done in `platform_methods.py::get_build_version()` so it could be extracted from `name`.

Though I'm not sure why we even have `platform_methods.py::get_build_version()` that duplicates what `method.py::get_version_info()` provides, maybe they should be unified back so the logic to deal with `version.py` and env variables is in a single place.

Code after:
        app_dir = env.Dir(
            "#bin/" + (prefix + env.extra_suffix + env.module_version_string).replace(".", "_") + ".app"
        ).abspath
        templ = env.Dir("#misc/dist/macos_tools.app").abspath
        if os.path.exists(app_dir):
            shutil.rmtree(app_dir)

        # Create the .app bundle directory itself from scratch so that the creation
        # date is accurate, but copy the rest of the template over.
        os.mkdir(app_dir)
        shutil.copytree(
            os.path.join(templ, "Contents"),
            os.path.join(app_dir, "Contents"),
            ignore=shutil.ignore_patterns("Info.plist"),
        )

        if not os.path.isdir(app_dir + "/Contents/MacOS"):
            os.mkdir(app_dir + "/Contents/MacOS")
        if target_bin != "":
            shutil.copy(target_bin, app_dir + "/Contents/MacOS/Godot")
        if "mono" in env.module_version_string:
            shutil.copytree(env.Dir("#bin/GodotSharp").abspath, app_dir + "/Contents/Resources/GodotSharp")
        version = get_version_info("", True)
        with open(env.Dir("#misc/dist/macos").abspath + "/editor_info_plist.template", "rt", encoding="utf-8") as fin:
            with open(app_dir + "/Contents/Info.plist", "wt", encoding="utf-8", newline="\n") as fout:
                for line in fin:
                    line = line.replace("$version", "{major}.{minor}.{patch}.{status}.{build}".format(**version))
                    line = line.replace("$short_version", "{major}.{minor}.{patch}".format(**version))
                    if version["build"] != "official" and version["build"] != "steam":
                        line = line.replace("org.godotengine.godot", "org.godotengine.godot." + version["build"])
                    fout.write(line)

        # Sign .app bundle.
        if env["bundle_sign_identity"] != "":
            sign_command = [
                "codesign",
                "-s",
                env["bundle_sign_identity"],
                "--deep",
                "--force",
                "--options=runtime",
                "--entitlements",
            ]
            if env.dev_build:
                sign_command += [env.Dir("#misc/dist/macos").abspath + "/editor_debug.entitlements"]
            else:
                sign_command += [env.Dir("#misc/dist/macos").abspath + "/editor.entitlements"]
            sign_command += [app_dir]
            subprocess.run(sign_command)

    else: