From 90446fe9f381eaaa86caed2facc09ee1cf5fb52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 19 Jun 2023 11:28:22 +0200 Subject: [PATCH] SCons: Move platform logo/run icon to `export` folder Follow-up to #75932. Since these icons are only used by the export plugin, it makes sense to move them and generate the headers there. The whole `detect.is_active()` logic seems to be a leftover from before times, as far back as 1.0-stable it already wasn't used for anything. So I'm removing it and moving the export icon generation to `platform_methods`, where it makes more sense. --- SConstruct | 17 +++++------- methods.py | 27 ------------------- platform/android/detect.py | 4 --- platform/android/export/export_plugin.cpp | 4 +-- platform/android/{ => export}/logo.svg | 0 platform/android/{ => export}/run_icon.svg | 0 platform/ios/detect.py | 4 --- platform/ios/export/export_plugin.cpp | 2 +- platform/ios/{ => export}/logo.svg | 0 platform/linuxbsd/detect.py | 4 --- platform/linuxbsd/export/export_plugin.cpp | 4 +-- platform/linuxbsd/{ => export}/logo.svg | 0 platform/linuxbsd/{ => export}/run_icon.svg | 0 platform/macos/detect.py | 4 --- platform/macos/export/export_plugin.cpp | 4 +-- platform/macos/{ => export}/logo.svg | 0 platform/macos/{ => export}/run_icon.svg | 0 platform/uwp/detect.py | 4 --- platform/uwp/export/export_plugin.cpp | 2 +- platform/uwp/{ => export}/logo.svg | 0 platform/web/detect.py | 4 --- platform/web/export/export_plugin.cpp | 4 +-- platform/web/{ => export}/logo.svg | 0 platform/web/{ => export}/run_icon.svg | 0 platform/windows/detect.py | 4 --- platform/windows/export/export_plugin.cpp | 4 +-- platform/windows/{ => export}/logo.svg | 0 platform/windows/{ => export}/run_icon.svg | 0 platform_methods.py | 30 +++++++++++++++++++++ 29 files changed, 48 insertions(+), 78 deletions(-) rename platform/android/{ => export}/logo.svg (100%) rename platform/android/{ => export}/run_icon.svg (100%) rename platform/ios/{ => export}/logo.svg (100%) rename platform/linuxbsd/{ => export}/logo.svg (100%) rename platform/linuxbsd/{ => export}/run_icon.svg (100%) rename platform/macos/{ => export}/logo.svg (100%) rename platform/macos/{ => export}/run_icon.svg (100%) rename platform/uwp/{ => export}/logo.svg (100%) rename platform/web/{ => export}/logo.svg (100%) rename platform/web/{ => export}/run_icon.svg (100%) rename platform/windows/{ => export}/logo.svg (100%) rename platform/windows/{ => export}/run_icon.svg (100%) diff --git a/SConstruct b/SConstruct index c67ce9fb9f9..f65e6bab04b 100644 --- a/SConstruct +++ b/SConstruct @@ -56,7 +56,7 @@ import methods import glsl_builders import gles3_builders import scu_builders -from platform_methods import architectures, architecture_aliases +from platform_methods import architectures, architecture_aliases, generate_export_icons if ARGUMENTS.get("target", "editor") == "editor": _helper_module("editor.editor_builders", "editor/editor_builders.py") @@ -68,9 +68,6 @@ platform_list = [] # list of platforms platform_opts = {} # options for each platform platform_flags = {} # flags for each platform platform_doc_class_path = {} - -active_platforms = [] -active_platform_ids = [] platform_exporters = [] platform_apis = [] @@ -93,13 +90,13 @@ for x in sorted(glob.glob("platform/*")): except Exception: pass + platform_name = x[9:] + if os.path.exists(x + "/export/export.cpp"): - platform_exporters.append(x[9:]) + platform_exporters.append(platform_name) + generate_export_icons(x, platform_name) if os.path.exists(x + "/api/api.cpp"): - platform_apis.append(x[9:]) - if detect.is_active(): - active_platforms.append(detect.get_name()) - active_platform_ids.append(x) + platform_apis.append(platform_name) if detect.can_build(): x = x.replace("platform/", "") # rest of world x = x.replace("platform\\", "") # win32 @@ -109,8 +106,6 @@ for x in sorted(glob.glob("platform/*")): sys.path.remove(tmppath) sys.modules.pop("detect") -methods.save_active_platforms(active_platforms, active_platform_ids) - custom_tools = ["default"] platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False)) diff --git a/methods.py b/methods.py index 4c1357c688a..571a3f739eb 100644 --- a/methods.py +++ b/methods.py @@ -559,33 +559,6 @@ def use_windows_spawn_fix(self, platform=None): self["SPAWN"] = mySpawn -def save_active_platforms(apnames, ap): - for x in ap: - svg_names = [] - if os.path.isfile(x + "/logo.svg"): - svg_names.append("logo") - if os.path.isfile(x + "/run_icon.svg"): - svg_names.append("run_icon") - - for name in svg_names: - svgf = open(x + "/" + name + ".svg", "rb") - b = svgf.read(1) - svg_str = " /* AUTOGENERATED FILE, DO NOT EDIT */ \n" - svg_str += " static const char *_" + x[9:] + "_" + name + '_svg = "' - while len(b) == 1: - svg_str += "\\" + hex(ord(b))[1:] - b = svgf.read(1) - - svg_str += '";\n' - - svgf.close() - - # NOTE: It is safe to generate this file here, since this is still executed serially - wf = x + "/" + name + "_svg.gen.h" - with open(wf, "w") as svgw: - svgw.write(svg_str) - - def no_verbose(sys, env): colors = {} diff --git a/platform/android/detect.py b/platform/android/detect.py index 20aced3524d..2860898e5c5 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -9,10 +9,6 @@ if TYPE_CHECKING: from SCons import Environment -def is_active(): - return True - - def get_name(): return "Android" diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index cb82091073e..5d31c4911c5 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -30,9 +30,9 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" -#include "../run_icon_svg.gen.h" #include "gradle_export_util.h" +#include "logo_svg.gen.h" +#include "run_icon_svg.gen.h" #include "core/config/project_settings.h" #include "core/io/dir_access.h" diff --git a/platform/android/logo.svg b/platform/android/export/logo.svg similarity index 100% rename from platform/android/logo.svg rename to platform/android/export/logo.svg diff --git a/platform/android/run_icon.svg b/platform/android/export/run_icon.svg similarity index 100% rename from platform/android/run_icon.svg rename to platform/android/export/run_icon.svg diff --git a/platform/ios/detect.py b/platform/ios/detect.py index bab055dbd59..f5501e3d85f 100644 --- a/platform/ios/detect.py +++ b/platform/ios/detect.py @@ -8,10 +8,6 @@ if TYPE_CHECKING: from SCons import Environment -def is_active(): - return True - - def get_name(): return "iOS" diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index 9962a482504..1b9b02d0e07 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -30,7 +30,7 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" +#include "logo_svg.gen.h" #include "core/string/translation.h" #include "editor/editor_node.h" diff --git a/platform/ios/logo.svg b/platform/ios/export/logo.svg similarity index 100% rename from platform/ios/logo.svg rename to platform/ios/export/logo.svg diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index dadc03685bf..9faa73d6d24 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -10,10 +10,6 @@ if TYPE_CHECKING: from SCons import Environment -def is_active(): - return True - - def get_name(): return "LinuxBSD" diff --git a/platform/linuxbsd/export/export_plugin.cpp b/platform/linuxbsd/export/export_plugin.cpp index 082040c8d69..f74bdf35166 100644 --- a/platform/linuxbsd/export/export_plugin.cpp +++ b/platform/linuxbsd/export/export_plugin.cpp @@ -30,8 +30,8 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" -#include "../run_icon_svg.gen.h" +#include "logo_svg.gen.h" +#include "run_icon_svg.gen.h" #include "core/config/project_settings.h" #include "editor/editor_node.h" diff --git a/platform/linuxbsd/logo.svg b/platform/linuxbsd/export/logo.svg similarity index 100% rename from platform/linuxbsd/logo.svg rename to platform/linuxbsd/export/logo.svg diff --git a/platform/linuxbsd/run_icon.svg b/platform/linuxbsd/export/run_icon.svg similarity index 100% rename from platform/linuxbsd/run_icon.svg rename to platform/linuxbsd/export/run_icon.svg diff --git a/platform/macos/detect.py b/platform/macos/detect.py index 7b8d3fd8533..21e824b2d37 100644 --- a/platform/macos/detect.py +++ b/platform/macos/detect.py @@ -9,10 +9,6 @@ if TYPE_CHECKING: from SCons import Environment -def is_active(): - return True - - def get_name(): return "macOS" diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 6aef43dd8b3..2d185db812a 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -30,11 +30,11 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" -#include "../run_icon_svg.gen.h" #include "codesign.h" #include "lipo.h" +#include "logo_svg.gen.h" #include "macho.h" +#include "run_icon_svg.gen.h" #include "core/io/image_loader.h" #include "core/string/translation.h" diff --git a/platform/macos/logo.svg b/platform/macos/export/logo.svg similarity index 100% rename from platform/macos/logo.svg rename to platform/macos/export/logo.svg diff --git a/platform/macos/run_icon.svg b/platform/macos/export/run_icon.svg similarity index 100% rename from platform/macos/run_icon.svg rename to platform/macos/export/run_icon.svg diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py index 03c4fd547ee..604f5e48e3e 100644 --- a/platform/uwp/detect.py +++ b/platform/uwp/detect.py @@ -9,10 +9,6 @@ if TYPE_CHECKING: from SCons import Environment -def is_active(): - return True - - def get_name(): return "UWP" diff --git a/platform/uwp/export/export_plugin.cpp b/platform/uwp/export/export_plugin.cpp index a0a91a1cf1b..0332fbf7187 100644 --- a/platform/uwp/export/export_plugin.cpp +++ b/platform/uwp/export/export_plugin.cpp @@ -30,7 +30,7 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" +#include "logo_svg.gen.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" diff --git a/platform/uwp/logo.svg b/platform/uwp/export/logo.svg similarity index 100% rename from platform/uwp/logo.svg rename to platform/uwp/export/logo.svg diff --git a/platform/web/detect.py b/platform/web/detect.py index 419d8918f28..2685cbcd63e 100644 --- a/platform/web/detect.py +++ b/platform/web/detect.py @@ -17,10 +17,6 @@ if TYPE_CHECKING: from SCons import Environment -def is_active(): - return True - - def get_name(): return "Web" diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp index e3cdd6a60d7..0bc3b92f090 100644 --- a/platform/web/export/export_plugin.cpp +++ b/platform/web/export/export_plugin.cpp @@ -30,8 +30,8 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" -#include "../run_icon_svg.gen.h" +#include "logo_svg.gen.h" +#include "run_icon_svg.gen.h" #include "core/config/project_settings.h" #include "editor/editor_scale.h" diff --git a/platform/web/logo.svg b/platform/web/export/logo.svg similarity index 100% rename from platform/web/logo.svg rename to platform/web/export/logo.svg diff --git a/platform/web/run_icon.svg b/platform/web/export/run_icon.svg similarity index 100% rename from platform/web/run_icon.svg rename to platform/web/export/run_icon.svg diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 3a6ca664499..bec1fd2cb63 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -13,10 +13,6 @@ if TYPE_CHECKING: STACK_SIZE = 8388608 -def is_active(): - return True - - def get_name(): return "Windows" diff --git a/platform/windows/export/export_plugin.cpp b/platform/windows/export/export_plugin.cpp index 367b4711966..b521a649be1 100644 --- a/platform/windows/export/export_plugin.cpp +++ b/platform/windows/export/export_plugin.cpp @@ -30,8 +30,8 @@ #include "export_plugin.h" -#include "../logo_svg.gen.h" -#include "../run_icon_svg.gen.h" +#include "logo_svg.gen.h" +#include "run_icon_svg.gen.h" #include "core/config/project_settings.h" #include "core/io/image_loader.h" diff --git a/platform/windows/logo.svg b/platform/windows/export/logo.svg similarity index 100% rename from platform/windows/logo.svg rename to platform/windows/export/logo.svg diff --git a/platform/windows/run_icon.svg b/platform/windows/export/run_icon.svg similarity index 100% rename from platform/windows/run_icon.svg rename to platform/windows/export/run_icon.svg diff --git a/platform_methods.py b/platform_methods.py index ed0ab980d07..8b2c62ad4a3 100644 --- a/platform_methods.py +++ b/platform_methods.py @@ -110,3 +110,33 @@ def detect_arch(): print("Unsupported CPU architecture: " + host_machine) print("Falling back to x86_64.") return "x86_64" + + +def generate_export_icons(platform_path, platform_name): + """ + Generate headers for logo and run icon for the export plugin. + """ + export_path = platform_path + "/export" + svg_names = [] + if os.path.isfile(export_path + "/logo.svg"): + svg_names.append("logo") + if os.path.isfile(export_path + "/run_icon.svg"): + svg_names.append("run_icon") + + for name in svg_names: + svgf = open(export_path + "/" + name + ".svg", "rb") + b = svgf.read(1) + svg_str = " /* AUTOGENERATED FILE, DO NOT EDIT */ \n" + svg_str += " static const char *_" + platform_name + "_" + name + '_svg = "' + while len(b) == 1: + svg_str += "\\" + hex(ord(b))[1:] + b = svgf.read(1) + + svg_str += '";\n' + + svgf.close() + + # NOTE: It is safe to generate this file here, since this is still executed serially. + wf = export_path + "/" + name + "_svg.gen.h" + with open(wf, "w") as svgw: + svgw.write(svg_str)