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') python3_prog = python.find_installation('python3')
fs = import('fs') 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') render_icons_with_inkscape = get_option('render_icons_with_inkscape')
inkscape = find_program('inkscape', required: render_icons_with_inkscape) inkscape = find_program('inkscape', required: render_icons_with_inkscape)
@@ -442,9 +436,23 @@ powder_deps = []
project_export_dynamic = false project_export_dynamic = false
embedded_files = []
subdir('src') subdir('src')
subdir('resources') 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 powder_files += data_files
render_files += data_files render_files += data_files
font_files += data_files font_files += data_files

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
#include "FontReader.h" #include "FontReader.h"
#include "bzip2/bz2wrap.h" #include "bzip2/bz2wrap.h"
#include "font.bz2.h" #include "font_bz2.h"
#include <array> #include <array>
#include <cstdint> #include <cstdint>
@@ -23,7 +23,7 @@ static bool InitFontData()
static std::vector<char> fontDataBuf; static std::vector<char> fontDataBuf;
static std::vector<int> fontPtrsBuf; static std::vector<int> fontPtrsBuf;
static std::vector< std::array<int, 2> > fontRangesBuf; 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; return false;
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,7 +2,7 @@
#include "client/http/Request.h" #include "client/http/Request.h"
#include "common/platform/Platform.h" #include "common/platform/Platform.h"
#include "common/tpt-rand.h" #include "common/tpt-rand.h"
#include "compat.lua.h" #include "compat_lua.h"
#include "gui/game/GameController.h" #include "gui/game/GameController.h"
#include "gui/game/GameModel.h" #include "gui/game/GameModel.h"
#include "gui/game/GameView.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') ],
]