summaryrefslogtreecommitdiff
path: root/src/other_tools
diff options
context:
space:
mode:
authorSascha Roloff <sascha.roloff@huawei.com>2025-05-08 13:39:53 +0200
committerSascha Roloff <sascha.roloff@huawei.com>2025-05-08 16:32:18 +0200
commitdd6be011609937477516344d217a24aadf92fcd2 (patch)
tree5801534afd5f88e1d1ad84453630909bf46b89a8 /src/other_tools
parenta10dd9a098cc0887e27da17496a7b18a31f131c7 (diff)
downloadjustbuild-dd6be011609937477516344d217a24aadf92fcd2.tar.gz
Invocation logging: add new field context variables
It allows to specify a list of environment variables, which are captured at invocation time and stored as key-value pairs in the metadata file. This allows to get some information about the invocation context such as username, merge-request ID or source branch (on a CI runner), or others.
Diffstat (limited to 'src/other_tools')
-rw-r--r--src/other_tools/just_mr/cli.hpp1
-rw-r--r--src/other_tools/just_mr/launch.cpp9
-rw-r--r--src/other_tools/just_mr/rc.cpp10
3 files changed, 20 insertions, 0 deletions
diff --git a/src/other_tools/just_mr/cli.hpp b/src/other_tools/just_mr/cli.hpp
index d8ad0366..df952957 100644
--- a/src/other_tools/just_mr/cli.hpp
+++ b/src/other_tools/just_mr/cli.hpp
@@ -93,6 +93,7 @@ struct MultiRepoGcArguments {
struct InvocationLogArguments {
std::optional<std::filesystem::path> directory{std::nullopt};
std::optional<std::string> invocation_msg{std::nullopt};
+ std::vector<std::string> context_vars{};
std::optional<std::string> project_id{std::nullopt};
std::optional<std::string> metadata{std::nullopt};
std::optional<std::string> graph_file{std::nullopt};
diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp
index ca21e268..dc861c11 100644
--- a/src/other_tools/just_mr/launch.cpp
+++ b/src/other_tools/just_mr/launch.cpp
@@ -371,6 +371,15 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file,
meta["configuration"] = mr_config_pair->second;
}
meta["cmdline"] = cmd;
+ if (not invocation_log.context_vars.empty()) {
+ auto context = nlohmann::json::object();
+ for (auto const& env_var : invocation_log.context_vars) {
+ auto* env_value = std::getenv(env_var.c_str());
+ context[env_var] =
+ env_value != nullptr ? env_value : nlohmann::json{};
+ }
+ meta["context"] = context;
+ }
// "configuration" -- the blob-identifier of the multi-repo
// configuration
auto file_name = *log_dir / *invocation_log.metadata;
diff --git a/src/other_tools/just_mr/rc.cpp b/src/other_tools/just_mr/rc.cpp
index 51813dfb..7d7f6f5a 100644
--- a/src/other_tools/just_mr/rc.cpp
+++ b/src/other_tools/just_mr/rc.cpp
@@ -635,6 +635,16 @@ namespace {
if (msg->IsString()) {
clargs->invocation_log.invocation_msg = msg->String();
}
+ auto context_vars =
+ invocation_log->Get("context variables", Expression::none_t{});
+ if (context_vars->IsList()) {
+ for (auto const& env_var : context_vars->List()) {
+ if (env_var->IsString()) {
+ clargs->invocation_log.context_vars.emplace_back(
+ env_var->String());
+ }
+ }
+ }
}
}
// read config lookup order