diff --git a/compiler/code-gen/files/init-scripts.cpp b/compiler/code-gen/files/init-scripts.cpp index 682fe320f0..619fff628e 100644 --- a/compiler/code-gen/files/init-scripts.cpp +++ b/compiler/code-gen/files/init-scripts.cpp @@ -5,8 +5,10 @@ #include "compiler/code-gen/files/init-scripts.h" #include +#include #include +#include "common/algorithms/string-algorithms.h" #include "compiler/code-gen/common.h" #include "compiler/code-gen/const-globals-batched-mem.h" #include "compiler/code-gen/declarations.h" @@ -297,6 +299,16 @@ void CppMainFile::compile(CodeGenerator &W) const { void ComponentInfoFile::compile(CodeGenerator &W) const { kphp_assert(G->is_output_mode_k2()); + std::string php_code_commit_hash; + if (!G->settings().php_code_commit_hash.get().empty()) { + php_code_commit_hash.reserve(40 * 3 + 39 * 2); + php_code_commit_hash.append(std::to_string(static_cast(G->settings().php_code_commit_hash.get().front()))); + for (size_t i{1}; i != 40 && i != G->settings().php_code_commit_hash.get().size(); ++i) { + php_code_commit_hash + .append(", ") + .append(std::to_string(static_cast(G->settings().php_code_commit_hash.get()[i]))); + } + } W << OpenFile("image_info.cpp"); W << ExternInclude(G->settings().runtime_headers.get()); W << "__attribute__((visibility(\"default\"))) const ImageInfo *k2_describe() " << BEGIN @@ -308,7 +320,7 @@ void ComponentInfoFile::compile(CodeGenerator &W) const { std::chrono::duration_cast(G->settings().build_tp.time_since_epoch()).count() ) << "," << "K2_PLATFORM_HEADER_H_VERSION, " - << "{}," // todo:k2 add commit hash + << "{" << php_code_commit_hash << "}," << "\"" << G->settings().php_code_version.get() << "\"," << "extraInfo.size()" << "," << "extraInfo.data()" diff --git a/compiler/compiler-settings.h b/compiler/compiler-settings.h index cd1615c72d..b4f42d0557 100644 --- a/compiler/compiler-settings.h +++ b/compiler/compiler-settings.h @@ -153,6 +153,7 @@ class CompilerSettings : vk::not_copyable { KphpOption compilation_metrics_file; KphpOption override_kphp_version; KphpOption php_code_version; + KphpOption php_code_commit_hash; KphpOption k2_component_name; diff --git a/compiler/kphp2cpp.cpp b/compiler/kphp2cpp.cpp index 9557fb3dab..2bf0f3310c 100644 --- a/compiler/kphp2cpp.cpp +++ b/compiler/kphp2cpp.cpp @@ -266,6 +266,8 @@ int main(int argc, char *argv[]) { "kphp-version-override", "KPHP_VERSION_OVERRIDE"); parser.add("Specify the compiled php code version", settings->php_code_version, "php-code-version", "KPHP_PHP_CODE_VERSION", "unknown"); + parser.add("Specify the compiled php code commit hash", settings->php_code_commit_hash, + "php-code-commit-hash", "KPHP_PHP_CODE_COMMIT_HASH", "0000000000000000000000000000000000000000"); parser.add("C++ compiler for building the output binary", settings->cxx, "cxx", "KPHP_CXX", get_default_cxx()); parser.add("Directory for c++ compiler toolchain. Will be passed to cxx via -B option", settings->cxx_toolchain_dir,