Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions compiler/code-gen/files/init-scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "compiler/code-gen/files/init-scripts.h"

#include <chrono>
#include <string>

#include <fmt/chrono.h>

#include "compiler/code-gen/common.h"
#include "compiler/code-gen/const-globals-batched-mem.h"
#include "compiler/code-gen/declarations.h"
Expand Down Expand Up @@ -293,15 +298,24 @@ void CppMainFile::compile(CodeGenerator &W) const {
}

void ComponentInfoFile::compile(CodeGenerator &W) const {
auto build_time{std::chrono::system_clock::to_time_t(G->settings().build_tp)};
auto date_str{fmt::format("{:%b %e %Y %T %Z}", fmt::localtime(build_time))};

kphp_assert(G->is_output_mode_k2());
G->settings().get_version();
W << OpenFile("image_info.cpp");
W << ExternInclude(G->settings().runtime_headers.get());
W << "__attribute__((visibility(\"default\"))) const ImageInfo *k2_describe() " << BEGIN << "static ImageInfo imageInfo {\""
<< G->settings().k2_component_name.get() << "\"" << "," << G->settings().build_timestamp.get() << ","
<< G->settings().k2_component_name.get() << "\"" << ","
<< (G->is_output_mode_k2_multishot() ? "0" : "1") << ","
<< std::to_string(
std::chrono::duration_cast<std::chrono::seconds>(G->settings().build_tp.time_since_epoch()).count()
) << ","
<< "K2_PLATFORM_HEADER_H_VERSION, "
<< "{}," // todo:k2 add commit hash
<< "{}," // todo:k2 add compiler hash?
<< (G->is_output_mode_k2_multishot() ? "0" : "1") << "};" << NL << "return &imageInfo;" << NL << END;
<< "\"" << G->settings().k2_component_name.get() << " compiled at " << date_str << " by " // todo:k2 add commit hash of target into version
<< G->settings().get_version() << "\","
<< "0" << ","
<< "nullptr"
<< "};" << NL << "return &imageInfo;" << NL << END;
W << CloseFile();
}
5 changes: 3 additions & 2 deletions compiler/compiler-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ void CompilerSettings::init() {
option_as_dir(kphp_src_path);
functions_file.value_ = get_full_path(functions_file.get());
runtime_sha256_file.value_ = get_full_path(runtime_sha256_file.get());
const auto now{std::chrono::system_clock::now()};
build_timestamp.value_ = std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count());
build_timestamp.value_ = std::to_string(
std::chrono::duration_cast<std::chrono::milliseconds>(build_tp.time_since_epoch()).count()
);

bool is_k2_mode = mode.get().substr(0, 3) == "k2-";
if (link_file.value_.empty()) {
Expand Down
3 changes: 3 additions & 0 deletions compiler/compiler-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <chrono>
#include <cstdint>
#include <string>
#include <tuple>
Expand Down Expand Up @@ -196,6 +197,8 @@ class CompilerSettings : vk::not_copyable {
KphpImplicitOption tl_namespace_prefix;
KphpImplicitOption tl_classname_prefix;

std::chrono::system_clock::time_point build_tp{std::chrono::system_clock::now()};

std::string get_version() const;
bool is_composer_enabled() const; // reports whether composer compatibility mode is on
color_settings get_color_settings() const;
Expand Down
21 changes: 14 additions & 7 deletions runtime-light/k2-platform/k2-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <time.h>
#endif

#define K2_PLATFORM_HEADER_H_VERSION 13
#define K2_PLATFORM_HEADER_H_VERSION 14

// Always check that enum value is a valid value!

Expand Down Expand Up @@ -98,17 +98,24 @@ enum UpdateStatus {
};

struct ImageInfo {
// TODO: null terminated string is OK?
// TODO: namespaces?
// Base
const char* image_name;
uint8_t is_oneshot;

// DSO specific
uint64_t build_timestamp;
uint64_t header_h_version;
uint8_t commit_hash[40];
// TODO: more informative?
uint8_t compiler_hash[64];
// bool
uint8_t is_oneshot;
const char* version;

// Extra
struct KeyValuePair {
const char* key;
const char* value;
};

size_t extra_info_size;
const struct KeyValuePair* extra_info;
};

/**
Expand Down
Loading