From ca3802e82abb5beea95c279d221afd7087132d25 Mon Sep 17 00:00:00 2001 From: Martin Herkt Date: Wed, 15 Nov 2017 20:40:10 +0100 Subject: [PATCH] =?UTF-8?q?Meson:=20respack.lua=20=E2=86=92=20respack.py;?= =?UTF-8?q?=20works=20out-of-tree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meson.build | 3 --- src/libresrc/meson.build | 8 ++++---- tools/respack.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100755 tools/respack.py diff --git a/meson.build b/meson.build index 86963c88f..8df4b7e7a 100644 --- a/meson.build +++ b/meson.build @@ -105,16 +105,13 @@ else message('System luajit not found; using built-in luajit') endif -lua_names = ['lua', 'luajit', 'lua5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1'] if not deps.contains(luajit) luajit_sp = subproject('luajit') luajit_inc = luajit_sp.get_variable('incdir') deps += luajit_sp.get_variable('luajit_dep') - lua_names += luajit_sp.get_variable('minilua').full_path() else luajit_inc = include_directories(luajit.get_pkgconfig_variable('includedir')) endif -lua = find_program(lua_names, native : true) subdir('vendor/luabins/src') deps += dependency('wxWidgets', version : '>=3.0.0', diff --git a/src/libresrc/meson.build b/src/libresrc/meson.build index b9c5fc906..b0392dc54 100644 --- a/src/libresrc/meson.build +++ b/src/libresrc/meson.build @@ -1,8 +1,8 @@ -respack = [lua, files('../../tools/respack.lua')] +respack = find_program('../../tools/respack.py') resrc = [ custom_target('bitmap.{cpp,h}', - command : respack + ['@INPUT@', '@OUTPUT@'], + command : [respack, '@INPUT@', '@OUTPUT@'], input : files('../bitmaps/manifest.respack'), output : ['bitmap.cpp', 'bitmap.h']) ] @@ -13,12 +13,12 @@ conf_platform_json = configure_file(input: 'default_config_platform.json.in', if host_machine.system() == 'darwin' resrc += custom_target('default_config.{cpp,h}', - command : respack + ['@INPUT0@', '@OUTPUT@'], + command : [respack, '@INPUT0@', '@OUTPUT@'], input : [files('manifest_osx.respack'), conf_platform_json], output : ['default_config.cpp', 'default_config.h']) else resrc += custom_target('default_config.{cpp,h}', - command : respack + ['@INPUT0@', '@OUTPUT@'], + command : [respack, '@INPUT0@', '@OUTPUT@'], input : [files('manifest.respack'), conf_platform_json], output : ['default_config.cpp', 'default_config.h']) endif diff --git a/tools/respack.py b/tools/respack.py new file mode 100755 index 000000000..c1c78fb73 --- /dev/null +++ b/tools/respack.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import sys +import os + +manifestfile, cppfile, hfile = sys.argv[1:] + +with open(manifestfile, 'r') as manifest: + files = dict((x.strip(), None) for x in manifest.readlines() if x.strip() != '') + +sourcepath = os.path.split(manifestfile)[0] +buildpath = os.path.split(cppfile)[0] + +for k in files: + sf = os.path.join(sourcepath, k) + bf = os.path.join(buildpath, k) + + if os.path.isfile(sf): + files[k] = sf + elif os.path.isfile(bf): + files[k] = bf + else: + print("{}: Failed to open '{}'".format(manifestfile, k)) + sys.exit(1) + +with open(cppfile, 'w') as cpp: + cpp.write('#include "libresrc.h"\n') + with open(hfile, 'w') as h: + + for k in files: + with open(files[k], 'rb') as f: + data = [str(int(x)) for x in f.read()] + + datastr = ','.join(data) + name = os.path.splitext(os.path.basename(k))[0] + cpp.write('const unsigned char {}[] = {{{}}};\n'.format(name, datastr)) + h.write('extern const unsigned char {}[{}];\n'.format(name, len(data)))