Migrate embedded files to custom targets

Meson generators seem to be a dying feature, evidenced by the fact that they have been in a state of isolation from the rest of the language for several years at this point:

 - very few things accept generator outputs as inputs, not even generators themselves do
 - unlike configured files, their outputs aren't guaranteed to be always synthesized, and yet they can't be passed as dependencies to other targets
 - they accept strictly one input and can't depend on other files

This makes them really hard to work with in a context that would require either a project resource or a target. Custom targets don't have any of these shortcomings, so this commit migrates embedded files over to those. A real shame, considering that generators can be used anywhere and are generally less messy than custom targets.
This commit is contained in:
Tamás Bálint Misius
2024-12-17 14:46:46 +01:00
parent c62f105c85
commit 1ef78c019a
11 changed files with 45 additions and 31 deletions

View File

@@ -14,12 +14,6 @@ python = import('python')
python3_prog = python.find_installation('python3')
fs = import('fs')
to_array = generator(
python3_prog,
output: [ '@PLAINNAME@.cpp', '@PLAINNAME@.h' ],
depfile: '@PLAINNAME@.dep',
arguments: [ join_paths(meson.current_source_dir(), 'resources/to-array.py'), '@OUTPUT0@', '@OUTPUT1@', '@DEPFILE@', '@INPUT@', '@EXTRA_ARGS@' ]
)
render_icons_with_inkscape = get_option('render_icons_with_inkscape')
inkscape = find_program('inkscape', required: render_icons_with_inkscape)
@@ -442,9 +436,23 @@ powder_deps = []
project_export_dynamic = false
embedded_files = []
subdir('src')
subdir('resources')
foreach embedded_file : embedded_files
name = embedded_file[0]
file = embedded_file[1]
data_files += [ custom_target(
'embedded-file-@0@'.format(name),
input: file,
output: [ '@0@.cpp'.format(name), '@0@.h'.format(name) ],
depfile: '@0@.dep'.format(name),
command: [ python3_prog, files('resources/to-array.py'), '@OUTPUT0@', '@OUTPUT1@', '@DEPFILE@', '@INPUT@', name ]
) ]
endforeach
powder_files += data_files
render_files += data_files
font_files += data_files

View File

@@ -99,14 +99,16 @@ elif host_platform == 'darwin'
configuration: conf_data,
)
elif host_platform == 'linux'
data_files += to_array.process(rendered_icons['icon_exe'], extra_args: 'icon_exe_png')
data_files += to_array.process(rendered_icons['icon_cps'], extra_args: 'icon_cps_png')
data_files += to_array.process('save.xml', extra_args: 'save_xml')
data_files += to_array.process(configure_file(
input: 'powder.template.desktop',
output: 'powder.desktop',
configuration: conf_data,
), extra_args: 'powder_desktop')
embedded_files += [
[ 'icon_exe_png', rendered_icons['icon_exe'] ],
[ 'icon_cps_png', rendered_icons['icon_cps'] ],
[ 'save_xml', files('save.xml') ],
[ 'powder_desktop', configure_file(
input: 'powder.template.desktop',
output: 'powder.desktop',
configuration: conf_data,
) ],
]
configure_file(
input: 'appdata.template.xml',
@@ -115,7 +117,9 @@ elif host_platform == 'linux'
)
endif
data_files += to_array.process('save_local.png', extra_args: 'save_local_png')
data_files += to_array.process('save_online.png', extra_args: 'save_online_png')
data_files += to_array.process('font.bz2', extra_args: 'compressed_font_data')
data_files += to_array.process('credits.json', extra_args: 'credits_json')
embedded_files += [
[ 'save_local_png', files('save_local.png') ],
[ 'save_online_png', files('save_online.png') ],
[ 'font_bz2', files('font.bz2') ],
[ 'credits_json', files('credits.json') ],
]

View File

@@ -2,7 +2,7 @@
#include "graphics/VideoBuffer.h"
#include "WindowIcon.h"
#include "icon_exe.png.h"
#include "icon_exe_png.h"
void WindowIcon(SDL_Window *window)
{

View File

@@ -1,8 +1,8 @@
#include "Platform.h"
#include "icon_cps.png.h"
#include "icon_exe.png.h"
#include "save.xml.h"
#include "powder.desktop.h"
#include "icon_cps_png.h"
#include "icon_exe_png.h"
#include "save_xml.h"
#include "powder_desktop.h"
#include "Config.h"
#include <cstring>
#include <ctime>

View File

@@ -1,7 +1,7 @@
#include "FontReader.h"
#include "bzip2/bz2wrap.h"
#include "font.bz2.h"
#include "font_bz2.h"
#include <array>
#include <cstdint>
@@ -23,7 +23,7 @@ static bool InitFontData()
static std::vector<char> fontDataBuf;
static std::vector<int> fontPtrsBuf;
static std::vector< std::array<int, 2> > fontRangesBuf;
if (BZ2WDecompress(fontDataBuf, compressed_font_data.AsCharSpan()) != BZ2WDecompressOk)
if (BZ2WDecompress(fontDataBuf, font_bz2.AsCharSpan()) != BZ2WDecompressOk)
{
return false;
}

View File

@@ -2,7 +2,7 @@
#include <json/json.h>
#include "credits.json.h"
#include "credits_json.h"
#include "gui/Style.h"
#include "common/platform/Platform.h"

View File

@@ -9,7 +9,7 @@
#include "Format.h"
#include "graphics/Pixel.h"
#include "save_local.png.h"
#include "save_local_png.h"
namespace ui
{

View File

@@ -11,7 +11,7 @@
#include "graphics/Pixel.h"
#include "tasks/TaskListener.h"
#include "save_online.png.h"
#include "save_online_png.h"
namespace http
{

View File

@@ -1,7 +1,7 @@
#include "LuaScriptInterface.h"
#include "client/http/Request.h"
#include "common/platform/Platform.h"
#include "compat.lua.h"
#include "compat_lua.h"
#include "Config.h"
#include "gui/dialogues/ErrorMessage.h"
#include "gui/dialogues/InformationMessage.h"

View File

@@ -2,7 +2,7 @@
#include "client/http/Request.h"
#include "common/platform/Platform.h"
#include "common/tpt-rand.h"
#include "compat.lua.h"
#include "compat_lua.h"
#include "gui/game/GameController.h"
#include "gui/game/GameModel.h"
#include "gui/game/GameView.h"

View File

@@ -1 +1,3 @@
luaconsole_files += to_array.process('compat.lua', extra_args: 'compat_lua')
embedded_files += [
[ 'compat_lua', files('compat.lua') ],
]