From c96efa76b9887793ab95a1a70cbd6650d0b7c083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 18 Sep 2020 15:43:32 +0200 Subject: [PATCH] [ion] Windows Makefile: build .rc from the list of assets --- build/rules.mk | 2 +- ion/src/simulator/linux/Makefile | 4 +- ion/src/simulator/windows/Makefile | 18 ++++++-- ion/src/simulator/windows/assets.py | 59 ++++++++++++++++++++++++++ ion/src/simulator/windows/images.cpp | 2 +- ion/src/simulator/windows/resources.py | 41 ------------------ ion/src/simulator/windows/resources.rc | 7 +-- 7 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 ion/src/simulator/windows/assets.py delete mode 100644 ion/src/simulator/windows/resources.py diff --git a/build/rules.mk b/build/rules.mk index d8a6ccb13..a56ad5b6c 100644 --- a/build/rules.mk +++ b/build/rules.mk @@ -56,7 +56,7 @@ $(eval $(call rule_for, \ $(eval $(call rule_for, \ WINDRES, %.o, %.rc, \ - $$(WINDRES) $$< -O coff -o $$@, \ + $$(WINDRES) $$< -Ioutput/release/simulator/windows -O coff -o $$@, \ global \ )) diff --git a/ion/src/simulator/linux/Makefile b/ion/src/simulator/linux/Makefile index 763561232..f711cb920 100644 --- a/ion/src/simulator/linux/Makefile +++ b/ion/src/simulator/linux/Makefile @@ -29,9 +29,9 @@ LDFLAGS += -ljpeg $(eval $(call rule_for, \ LINUX_ASSETS, \ - ion/src/simulator/linux/assets.s, \ + ion/src/simulator/linux/assets.s ion/src/simulator/linux/images.h, \ $(assets_paths), \ - $$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --implementation $$@, \ + $$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --header $$@ --implementation $$@, \ global \ )) diff --git a/ion/src/simulator/windows/Makefile b/ion/src/simulator/windows/Makefile index 00cc6c9f9..97a2001b3 100644 --- a/ion/src/simulator/windows/Makefile +++ b/ion/src/simulator/windows/Makefile @@ -22,12 +22,22 @@ LDFLAGS += -lgdiplus SFLAGS += -I$(BUILD_DIR) $(eval $(call rule_for, \ - WINDOWS_RESOURCES, \ + WINDOWS_ASSETS, \ ion/src/simulator/windows/resources.h, \ - ion/src/simulator/windows/resources.rc, \ - $$(PYTHON) ion/src/simulator/windows/resources.py --resource $$^ --header $$@, \ + $(assets_paths), \ + $$(PYTHON) ion/src/simulator/windows/assets.py --files $$^ --header-resource-rc $$@, \ global \ )) -$(BUILD_DIR)/ion/src/simulator/windows/images.o: $(BUILD_DIR)/ion/src/simulator/windows/resources.h +$(eval $(call rule_for, \ + WINDOWS_ASSETS, \ + ion/src/simulator/windows/resource_mapping.h, \ + $(assets_paths), \ + $$(PYTHON) ion/src/simulator/windows/assets.py --files $$^ --header-resource-mapping $$@, \ + global \ +)) + + +$(BUILD_DIR)/ion/src/simulator/windows/images.o: $(BUILD_DIR)/ion/src/simulator/windows/resource_mapping.h +$(BUILD_DIR)/ion/src/simulator/windows/resources.o: $(BUILD_DIR)/ion/src/simulator/windows/resources.h diff --git a/ion/src/simulator/windows/assets.py b/ion/src/simulator/windows/assets.py new file mode 100644 index 000000000..9a7895360 --- /dev/null +++ b/ion/src/simulator/windows/assets.py @@ -0,0 +1,59 @@ +# This script generates two headers: +# - the list of the resources to be included in resources.rc +# - the mapping of the resource names and identifiers + +import sys +import re +import argparse +import io + +parser = argparse.ArgumentParser(description="Process some windows resources.") +parser.add_argument('--files', nargs='+', help='a list of file names') +parser.add_argument('--header-resource-rc', help='the .h file to generate to be included in .rc') +parser.add_argument('--header-resource-mapping', help='the .h file to generate mapping resource names and identifiers') +args = parser.parse_args() + +def process_line(f, line): + rc_re = re.compile('^(\d{1,4}) RCDATA "\.\./assets/(.*)"') + rc_match = rc_re.match(line) + if rc_match: + f.write('{"' + rc_match.groups()[1] + '", ' + rc_match.groups()[0] + '},\n') + return True + return False + +identifier = 300 + +def print_declaration(f, asset, identifier): + f.write(str(identifier) + " RCDATA " + "../assets/" + asset + "\n") + +def print_mapping(f, asset, identifier): + f.write('{"' + asset + '", ' + str(identifier) + '},\n') + +def print_mapping_header(f): + f.write("#ifndef ION_SIMULATOR_WINDOWS_RESOURCES_H\n") + f.write("#define ION_SIMULATOR_WINDOWS_RESOURCES_H\n\n") + f.write("// This file is auto-generated by assets.py\n\n") + f.write("constexpr struct {const char * identifier; int id; } resourcesIdentifiers[] = {\n") + +def print_mapping_footer(f): + f.write("};\n\n") + f.write("#endif\n") + +def print(files, path, print_header, print_footer, process_asset): + f = open(path, "w") + print_header(f) + identifier = 300 + for asset in files: + process_asset(f, asset, identifier) + identifier += 1 + print_footer(f) + f.close() + + +if (args.header_resource_rc): + print(args.files, args.header_resource_rc, lambda f: None, lambda f: None, print_declaration) + +if (args.header_resource_mapping): + print(args.files, args.header_resource_mapping, print_mapping_header, print_mapping_footer, print_mapping) + + diff --git a/ion/src/simulator/windows/images.cpp b/ion/src/simulator/windows/images.cpp index 540ee7ead..7ef6e5ee6 100644 --- a/ion/src/simulator/windows/images.cpp +++ b/ion/src/simulator/windows/images.cpp @@ -1,5 +1,5 @@ #include "../shared/platform.h" -#include +#include #include #include diff --git a/ion/src/simulator/windows/resources.py b/ion/src/simulator/windows/resources.py deleted file mode 100644 index 47298ed20..000000000 --- a/ion/src/simulator/windows/resources.py +++ /dev/null @@ -1,41 +0,0 @@ -# This script generates a .h file representing available resources to access -# them from C code - -import sys -import re -import argparse -import io - -parser = argparse.ArgumentParser(description="Process some jpg files.") -parser.add_argument('--resource', help='the resources.rc file') -parser.add_argument('--header', help='the .h file to generate') -args = parser.parse_args() - -def process_line(f, line): - rc_re = re.compile('^(\d{1,4}) RCDATA "\.\./assets/(.*)"') - rc_match = rc_re.match(line) - if rc_match: - f.write('{"' + rc_match.groups()[1] + '", ' + rc_match.groups()[0] + '},\n') - return True - return False - -def process_resource(resource, path): - rc = open(resource, "r") - f = open(path, "w") - - f.write("#ifndef ION_SIMULATOR_WINDOWS_RESOURCES_H\n") - f.write("#define ION_SIMULATOR_WINDOWS_RESOURCES_H\n\n") - f.write("// This file is auto-generated by resources.py\n\n") - f.write("constexpr struct {const char * identifier; int id; } resourcesIdentifiers[] = {\n") - - while (process_line(f, rc.readline())): - pass - - f.write("};\n\n") - f.write("#endif\n") - rc.close() - f.close() - -process_resource(args.resource, args.header) - - diff --git a/ion/src/simulator/windows/resources.rc b/ion/src/simulator/windows/resources.rc index 3fa2840ce..0cfd4175d 100644 --- a/ion/src/simulator/windows/resources.rc +++ b/ion/src/simulator/windows/resources.rc @@ -1,9 +1,4 @@ -300 RCDATA "../assets/background.jpg" -301 RCDATA "../assets/horizontal_arrow.png" -302 RCDATA "../assets/large_squircle.png" -303 RCDATA "../assets/round.png" -304 RCDATA "../assets/small_squircle.png" -305 RCDATA "../assets/vertical_arrow.png" +#include 1 VERSIONINFO FILEVERSION 1,0,0,0