Skip to content

Commit 0ae7caf

Browse files
authored
[k2] update k2-header.h (#1626)
1 parent ce02869 commit 0ae7caf

4 files changed

Lines changed: 38 additions & 13 deletions

File tree

compiler/code-gen/files/init-scripts.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

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

7+
#include <chrono>
8+
#include <string>
9+
10+
#include <fmt/chrono.h>
11+
712
#include "compiler/code-gen/common.h"
813
#include "compiler/code-gen/const-globals-batched-mem.h"
914
#include "compiler/code-gen/declarations.h"
@@ -293,15 +298,24 @@ void CppMainFile::compile(CodeGenerator &W) const {
293298
}
294299

295300
void ComponentInfoFile::compile(CodeGenerator &W) const {
301+
auto build_time{std::chrono::system_clock::to_time_t(G->settings().build_tp)};
302+
auto date_str{fmt::format("{:%b %e %Y %T %Z}", fmt::localtime(build_time))};
303+
296304
kphp_assert(G->is_output_mode_k2());
297-
G->settings().get_version();
298305
W << OpenFile("image_info.cpp");
299306
W << ExternInclude(G->settings().runtime_headers.get());
300307
W << "__attribute__((visibility(\"default\"))) const ImageInfo *k2_describe() " << BEGIN << "static ImageInfo imageInfo {\""
301-
<< G->settings().k2_component_name.get() << "\"" << "," << G->settings().build_timestamp.get() << ","
308+
<< G->settings().k2_component_name.get() << "\"" << ","
309+
<< (G->is_output_mode_k2_multishot() ? "0" : "1") << ","
310+
<< std::to_string(
311+
std::chrono::duration_cast<std::chrono::seconds>(G->settings().build_tp.time_since_epoch()).count()
312+
) << ","
302313
<< "K2_PLATFORM_HEADER_H_VERSION, "
303314
<< "{}," // todo:k2 add commit hash
304-
<< "{}," // todo:k2 add compiler hash?
305-
<< (G->is_output_mode_k2_multishot() ? "0" : "1") << "};" << NL << "return &imageInfo;" << NL << END;
315+
<< "\"" << G->settings().k2_component_name.get() << " compiled at " << date_str << " by " // todo:k2 add commit hash of target into version
316+
<< G->settings().get_version() << "\","
317+
<< "0" << ","
318+
<< "nullptr"
319+
<< "};" << NL << "return &imageInfo;" << NL << END;
306320
W << CloseFile();
307321
}

compiler/compiler-settings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ void CompilerSettings::init() {
222222
option_as_dir(kphp_src_path);
223223
functions_file.value_ = get_full_path(functions_file.get());
224224
runtime_sha256_file.value_ = get_full_path(runtime_sha256_file.get());
225-
const auto now{std::chrono::system_clock::now()};
226-
build_timestamp.value_ = std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count());
225+
build_timestamp.value_ = std::to_string(
226+
std::chrono::duration_cast<std::chrono::milliseconds>(build_tp.time_since_epoch()).count()
227+
);
227228

228229
bool is_k2_mode = mode.get().substr(0, 3) == "k2-";
229230
if (link_file.value_.empty()) {

compiler/compiler-settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include <chrono>
78
#include <cstdint>
89
#include <string>
910
#include <tuple>
@@ -196,6 +197,8 @@ class CompilerSettings : vk::not_copyable {
196197
KphpImplicitOption tl_namespace_prefix;
197198
KphpImplicitOption tl_classname_prefix;
198199

200+
std::chrono::system_clock::time_point build_tp{std::chrono::system_clock::now()};
201+
199202
std::string get_version() const;
200203
bool is_composer_enabled() const; // reports whether composer compatibility mode is on
201204
color_settings get_color_settings() const;

runtime-light/k2-platform/k2-header.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <time.h>
2828
#endif
2929

30-
#define K2_PLATFORM_HEADER_H_VERSION 13
30+
#define K2_PLATFORM_HEADER_H_VERSION 14
3131

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

@@ -98,17 +98,24 @@ enum UpdateStatus {
9898
};
9999

100100
struct ImageInfo {
101-
// TODO: null terminated string is OK?
102-
// TODO: namespaces?
101+
// Base
103102
const char* image_name;
103+
uint8_t is_oneshot;
104104

105+
// DSO specific
105106
uint64_t build_timestamp;
106107
uint64_t header_h_version;
107108
uint8_t commit_hash[40];
108-
// TODO: more informative?
109-
uint8_t compiler_hash[64];
110-
// bool
111-
uint8_t is_oneshot;
109+
const char* version;
110+
111+
// Extra
112+
struct KeyValuePair {
113+
const char* key;
114+
const char* value;
115+
};
116+
117+
size_t extra_info_size;
118+
const struct KeyValuePair* extra_info;
112119
};
113120

114121
/**

0 commit comments

Comments
 (0)