Skip to content

Commit

Permalink
engine: Allow signals output file names to be configured
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- Do not write signals_autocompletion.json by default anymore.
  • Loading branch information
cassava committed Apr 22, 2024
1 parent 714e125 commit 2fc33c9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
20 changes: 12 additions & 8 deletions engine/src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,23 +1449,22 @@ cloe::Json dump_signals(cloe::DataBroker& db) {

std::vector<std::string> dump_signals_autocompletion(cloe::DataBroker& db) {
auto result = std::vector<std::string>{};
result.emplace_back("---@meta");
result.emplace_back("---@class signals");
result.emplace_back("--- @meta");
result.emplace_back("--- @class signals");

const auto& signals = db.signals();
for (const auto& [key, signal] : signals) {
const auto* tag = signal->metadata<cloe::LuaAutocompletionTag>();
if (tag) {
const auto lua_type = to_string(tag->datatype);
const auto& lua_helptext = tag->text;
auto line = fmt::format("---@field {} {} {}", key, lua_type, lua_helptext);
auto line = fmt::format("--- @field {} {} {}", key, lua_type, lua_helptext);
result.emplace_back(std::move(line));
} else {
auto line = fmt::format("---@field {}", key);
auto line = fmt::format("--- @field {}", key);
result.emplace_back(std::move(line));
}
}
//
return result;
}

Expand Down Expand Up @@ -1585,8 +1584,13 @@ SimulationResult Simulation::run() {
r.elapsed = ctx.progress.elapsed();
r.triggers = ctx.coordinator->history();
r.report = sol::object(cloe::luat_cloe_engine_state(ctx.lua)["report"]);
r.signals = dump_signals(*ctx.db);
r.signals_autocompletion = dump_signals_autocompletion(*ctx.db);
// Don't create output file data unless the output files are being written
if (ctx.config.engine.output_file_signals) {
r.signals = dump_signals(*ctx.db);
}
if (ctx.config.engine.output_file_signals_autocompletion) {
r.signals_autocompletion = dump_signals_autocompletion(*ctx.db);
}

abort_fn_ = nullptr;
return r;
Expand All @@ -1598,7 +1602,7 @@ size_t Simulation::write_output(const SimulationResult& r) const {
}

size_t files_written = 0;
auto write_file = [&](auto filename, cloe::Json output) {
auto write_file = [&](auto filename, const cloe::Json& output) {
if (!filename) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions engine/src/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ struct EngineConf : public Confable {
std::optional<std::filesystem::path> output_file_result{"result.json"};
std::optional<std::filesystem::path> output_file_triggers{"triggers.json"};
std::optional<std::filesystem::path> output_file_signals{"signals.json"};
std::optional<std::filesystem::path> output_file_signals_autocompletion{
"signals_autocompletion.lua"};
std::optional<std::filesystem::path> output_file_signals_autocompletion;
std::optional<std::filesystem::path> output_file_data_stream;
bool output_clobber_files{true};

Expand Down Expand Up @@ -417,6 +416,8 @@ struct EngineConf : public Confable {
{"config", make_schema(&output_file_config, file_proto(), "file to store config in")},
{"result", make_schema(&output_file_result, file_proto(), "file to store simulation result in")},
{"triggers", make_schema(&output_file_triggers, file_proto(), "file to store triggers in")},
{"signals", make_schema(&output_file_signals, file_proto(), "file to store signals in")},
{"signals_autocompletion", make_schema(&output_file_signals_autocompletion, file_proto(), "file to store signal autocompletion in")},
{"api_recording", make_schema(&output_file_data_stream, file_proto(), "file to store api data stream")},
}},
}},
Expand Down
2 changes: 2 additions & 0 deletions engine/src/stack_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TEST(cloe_stack, serialization_of_empty_stack) {
"files": {
"config": "config.json",
"result": "result.json",
"signals": "signals.json",
"triggers": "triggers.json"
}
},
Expand Down Expand Up @@ -145,6 +146,7 @@ TEST(cloe_stack, serialization_with_logging) {
"files": {
"config": "config.json",
"result": "result.json",
"signals": "signals.json",
"triggers": "triggers.json"
}
},
Expand Down
24 changes: 24 additions & 0 deletions engine/tests/test_engine_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,30 @@
}
]
},
"signals": {
"description": "file to store signals in",
"oneOf": [
{
"type": "null"
},
{
"comment": "path should either not exist or be a file",
"type": "string"
}
]
},
"signals_autocompletion": {
"description": "file to store signal autocompletion in",
"oneOf": [
{
"type": "null"
},
{
"comment": "path should either not exist or be a file",
"type": "string"
}
]
},
"triggers": {
"description": "file to store triggers in",
"oneOf": [
Expand Down
1 change: 1 addition & 0 deletions engine/tests/test_engine_nop_smoketest_dump.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"files": {
"config": "config.json",
"result": "result.json",
"signals": "signals.json",
"triggers": "triggers.json"
},
"path": "${CLOE_SIMULATION_UUID}"
Expand Down

0 comments on commit 2fc33c9

Please sign in to comment.