Skip to content

Commit

Permalink
Replace resource tools with python scripts
Browse files Browse the repository at this point in the history
May fix pipeline failures on ghactions where makeico or toarray just exit with a non-zero status for no reason.

Also makes it easier (possible, rather) to build TPT using a cross-compiling msvc toolchain on windows; you can't have two different msvc toolchains in PATH on windows because of course you can't.

toarray had been python before, maybe I converted it to cpp to avoid pulling in python as a dependency, I'm not sure. With android vanilla development (hopefully) gaining traction soon, we'll be relying anyway on helper scripts I've written in python, so python will be a dependency sooner or later. Meson implicitly makes python a dependency, but there could be Meson implementations out there that don't rely on python, who knows.
  • Loading branch information
LBPHacker committed Apr 26, 2024
1 parent 4179155 commit 7e674a8
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 197 deletions.
7 changes: 2 additions & 5 deletions meson.build
Expand Up @@ -6,9 +6,6 @@ project(
'c_std=c99',
'cpp_std=c++17',
'cpp_rtti=false',
'build.c_std=c99', # used by to_array
'build.cpp_std=c++17', # used by to_array
'build.cpp_rtti=false', # used by to_array
],
meson_version: '>=0.64.0',
)
Expand All @@ -20,9 +17,9 @@ endif

fs = import('fs')
to_array = generator(
executable('toarray', sources: 'resources/ToArray.cpp', native: true),
find_program('python'),
output: [ '@PLAINNAME@.cpp', '@PLAINNAME@.h' ],
arguments: [ '@OUTPUT0@', '@OUTPUT1@', '@INPUT@', '@EXTRA_ARGS@' ]
arguments: [ join_paths(meson.current_source_dir(), 'resources/to-array.py'), '@OUTPUT0@', '@OUTPUT1@', '@INPUT@', '@EXTRA_ARGS@' ]
)

render_icons_with_inkscape = get_option('render_icons_with_inkscape')
Expand Down
137 changes: 0 additions & 137 deletions resources/MakeIco.cpp

This file was deleted.

52 changes: 0 additions & 52 deletions resources/ToArray.cpp

This file was deleted.

38 changes: 38 additions & 0 deletions resources/make-ico.py
@@ -0,0 +1,38 @@
import struct
import sys

(
script,
output_ico,
*input_pngs,
) = sys.argv

input_pngs_size = len(input_pngs)
assert(input_pngs_size <= 255)

ico_header = b''
ico_data = b''
data_offset = 6 + 16 * input_pngs_size
for input_png in input_pngs:
with open(input_png, 'rb') as input_png_f:
data = input_png_f.read()
data_size = len(data)
assert(data_size >= 0x21)
magic, width, height, bit_depth, color_type = struct.unpack('>QxxxxxxxxLLBBxxxxxxx', data[0 : 0x21])
assert(magic == 0x89504E470D0A1A0A)
assert(width <= 256)
assert(height <= 256)
assert(bit_depth == 8)
assert(color_type == 6)
if width == 256:
width = 0
if height == 256:
height = 0
ico_header += struct.pack('<BBxxHHLL', width, height, 1, 32, data_size, data_offset)
data_offset += data_size
ico_data += data

with open(output_ico, 'wb') as output_ico_f:
output_ico_f.write(struct.pack('<xxHH', 1, input_pngs_size))
output_ico_f.write(ico_header)
output_ico_f.write(ico_data)
4 changes: 2 additions & 2 deletions resources/meson.build
Expand Up @@ -42,15 +42,15 @@ if host_platform == 'windows'
icon_cps_ico_path = ''
winutf8_xml_path = ''
if windows_icons
make_ico = executable('makeico', sources: 'MakeIco.cpp', native: true)
generated_win_icos = {}
win_icos = {
'icon_exe': [ 'icon_exe', 'icon_exe_48', 'icon_exe_32', 'icon_exe_16' ],
'icon_cps': [ 'icon_cps', 'icon_cps_48', 'icon_cps_32', 'icon_cps_16' ],
}
foreach key, icons : win_icos
command = [
make_ico,
find_program('python'),
join_paths(meson.current_source_dir(), 'make-ico.py'),
'@OUTPUT@',
]
foreach ikey : icons
Expand Down
2 changes: 1 addition & 1 deletion resources/powder-res.template.rc
Expand Up @@ -3,7 +3,7 @@
#include "@RESOUCE_H@"
#include <winuser.h>
#include <winver.h>
#include <ntdef.h>
// #include <ntdef.h> // maybe not needed?

#define HAVE_ICONS @HAVE_ICONS@
#define HAVE_UTF8CP @HAVE_UTF8CP@
Expand Down
28 changes: 28 additions & 0 deletions resources/to-array.py
@@ -0,0 +1,28 @@
import sys

(
script,
output_cpp_path,
output_h_path,
input_path,
symbol_name,
) = sys.argv

with open(input_path, 'rb') as input_f:
data = input_f.read()
data_size = len(data)
bytes_str = ', '.join([ str(ch) for ch in data ])

with open(output_cpp_path, 'w') as output_cpp_f:
output_cpp_f.write(f'''
#include "{output_h_path}"
const unsigned char {symbol_name}[] = {{ {bytes_str} }};
const unsigned int {symbol_name}_size = {data_size};
''')

with open(output_h_path, 'w') as output_h_f:
output_h_f.write(f'''
#pragma once
extern const unsigned char {symbol_name}[];
extern const unsigned int {symbol_name}_size;
''')

0 comments on commit 7e674a8

Please sign in to comment.