Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metafile: handle instance #3034

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
platform: ['x86_64', 'x86', 'armhf', 'armv7', 'aarch64', 'ppc64le', 'riscv64']
platform: ['x86_64', 'x86', 'armhf', 'armv7', 'aarch64', 'ppc64le']
branch: ['latest-stable']
include:
- platform: 'riscv64'
branch: 'edge'
defaults:
run:
shell: alpine.sh {0}
steps:
- uses: actions/checkout@v4
- uses: jirutka/setup-alpine@v1
with:
branch: edge
branch: ${{matrix.branch}}
arch: ${{matrix.platform}}
packages: >
build-base
Expand Down
2 changes: 1 addition & 1 deletion src/content/import_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void ImportService::initLayout(LayoutType layoutType)
playlistParserScript = std::make_unique<PlaylistParserScript>(content, rootPath.string());
}
if (!metafileParserScript) {
metafileParserScript = std::make_unique<MetafileParserScript>(content);
metafileParserScript = std::make_unique<MetafileParserScript>(content, rootPath.string());
}
#endif
}
Expand Down
11 changes: 6 additions & 5 deletions src/content/scripting/metafile_parser_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@
#include "scripting_runtime.h"
#include "util/string_converter.h"

MetafileParserScript::MetafileParserScript(const std::shared_ptr<ContentManager>& content)
: ParserScript(content, "", "metafile", "obj")
MetafileParserScript::MetafileParserScript(const std::shared_ptr<ContentManager>& content, const std::string& parent)
: ParserScript(content, parent, "metafile", "obj")
{
std::string scriptPath = config->getOption(CFG_IMPORT_SCRIPTING_METAFILE_SCRIPT);
defineFunction("updateCdsObject", jsUpdateCdsObject, 1);
if (!scriptPath.empty()) {
load(scriptPath);
scriptMode = true;
} else {
metafileFunction = config->getOption(CFG_IMPORT_SCRIPTING_IMPORT_FUNCTION_METAFILE);
}
}

void MetafileParserScript::processObject(const std::shared_ptr<CdsObject>& obj, const fs::path& path)
{
if ((currentObjectID != INVALID_OBJECT_ID) || currentHandle || currentLine) {
throw_std_runtime_error("Recursion in playlists not allowed");
if (currentObjectID != INVALID_OBJECT_ID || currentHandle || currentLine) {
throw_std_runtime_error("Recursion in metafiles is not allowed");
}

if (!obj->isPureItem()) {
Expand All @@ -81,7 +83,6 @@ void MetafileParserScript::processObject(const std::shared_ptr<CdsObject>& obj,
if (scriptMode) {
execute(obj, path);
} else {
auto metafileFunction = config->getOption(CFG_IMPORT_SCRIPTING_IMPORT_FUNCTION_METAFILE);
call(obj, nullptr, metafileFunction, path, "");
}
} catch (const std::runtime_error&) {
Expand Down
4 changes: 3 additions & 1 deletion src/content/scripting/metafile_parser_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@

class MetafileParserScript : public ParserScript {
public:
MetafileParserScript(const std::shared_ptr<ContentManager>& content);
MetafileParserScript(const std::shared_ptr<ContentManager>& content, const std::string& parent);
void processObject(const std::shared_ptr<CdsObject>& obj, const fs::path& path);

std::pair<std::shared_ptr<CdsObject>, int> createObject2cdsObject(const std::shared_ptr<CdsObject>& origObject, const std::string& rootPath) override;
bool setRefId(const std::shared_ptr<CdsObject>& cdsObj, const std::shared_ptr<CdsObject>& origObject, int pcdId) override;

protected:
std::string metafileFunction;

std::shared_ptr<CdsObject> createObject(const std::shared_ptr<CdsObject>& pcd) override;
void handleObject2cdsItem(duk_context* ctx, const std::shared_ptr<CdsObject>& pcd, const std::shared_ptr<CdsItem>& item) override;
};
Expand Down
5 changes: 3 additions & 2 deletions src/content/scripting/playlist_parser_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ PlaylistParserScript::PlaylistParserScript(const std::shared_ptr<ContentManager>
if (!scriptPath.empty()) {
load(scriptPath);
scriptMode = true;
} else {
playlistFunction = config->getOption(CFG_IMPORT_SCRIPTING_IMPORT_FUNCTION_PLAYLIST);
}
}

Expand Down Expand Up @@ -155,7 +157,7 @@ void PlaylistParserScript::handleObject2cdsItem(duk_context* ctx, const std::sha

void PlaylistParserScript::processPlaylistObject(const std::shared_ptr<CdsObject>& obj, std::shared_ptr<GenericTask> task, const std::string& rootPath)
{
if ((currentObjectID != INVALID_OBJECT_ID) || currentHandle || currentLine) {
if (currentObjectID != INVALID_OBJECT_ID || currentHandle || currentLine) {
throw_std_runtime_error("Recursion in playlists not allowed");
}

Expand Down Expand Up @@ -186,7 +188,6 @@ void PlaylistParserScript::processPlaylistObject(const std::shared_ptr<CdsObject
if (scriptMode) {
execute(obj, rootPath);
} else {
auto playlistFunction = config->getOption(CFG_IMPORT_SCRIPTING_IMPORT_FUNCTION_PLAYLIST);
call(obj, nullptr, playlistFunction, rootPath, "");
}
} catch (const std::runtime_error&) {
Expand Down
2 changes: 2 additions & 0 deletions src/content/scripting/playlist_parser_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class PlaylistParserScript : public ParserScript {
bool setRefId(const std::shared_ptr<CdsObject>& cdsObj, const std::shared_ptr<CdsObject>& origObject, int pcdId) override;

protected:
std::string playlistFunction;

void handleObject2cdsItem(duk_context* ctx, const std::shared_ptr<CdsObject>& pcd, const std::shared_ptr<CdsItem>& item) override;
void handleObject2cdsContainer(duk_context* ctx, const std::shared_ptr<CdsObject>& pcd, const std::shared_ptr<CdsContainer>& cont) override;
};
Expand Down
5 changes: 3 additions & 2 deletions src/content/scripting/script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ void Script::load(const fs::path& scriptPath)
{
ScriptingRuntime::AutoLock lock(runtime->getMutex());
duk_push_thread_stash(ctx, ctx);
log_debug("Loading file {}", scriptPath.c_str());
_load(scriptPath);
duk_put_prop_string(ctx, -2, "script");
duk_pop(ctx);
Expand Down Expand Up @@ -582,9 +583,9 @@ void Script::call(const std::shared_ptr<CdsObject>& obj, const std::shared_ptr<C
// Note: The invoked function will be blamed for execution errors, not the actual offending line of code
// https://github.com/svaarala/duktape/blob/master/doc/error-objects.rst
#if DUK_VERSION > 20399
log_error("javascript runtime error: {}() - {}\n", functionName, duk_safe_to_stacktrace(ctx, -1));
log_error("javascript {} runtime error: {}() - {}\n", contextName, functionName, duk_safe_to_stacktrace(ctx, -1));
#else
log_error("javascript runtime error: {}() - {}\n", functionName, duk_safe_to_string(ctx, -1));
log_error("javascript {} runtime error: {}() - {}\n", contextName, functionName, duk_safe_to_string(ctx, -1));
#endif
duk_pop(ctx);
throw_std_runtime_error("javascript runtime error");
Expand Down