2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/util/build-info.h"
19 #include "hphp/util/embedded-data.h"
21 #include <folly/Conv.h>
22 #include <folly/Range.h>
28 #include <sys/types.h>
32 ////////////////////////////////////////////////////////////////////////////////
36 std::atomic
<bool> inited
;
38 std::string repoSchema
;
41 std::string hhjsbabeltransform
;
43 ////////////////////////////////////////////////////////////////////////////////
46 * Initializes the repo schema id and the compiler id from their special
47 * sections in the hhvm binary.
49 void readBuildInfo() {
50 if (inited
.load(std::memory_order_acquire
)) return;
51 std::unique_lock
<std::mutex
> lock(mtx
);
52 if (inited
.load(std::memory_order_acquire
)) return;
54 auto const get
= [&] (const char* section
) -> std::string
{
55 auto constexpr bad
= "(UNKNOWN)";
58 if (!get_embedded_data(section
, &desc
)) {
62 auto const data
= read_embedded_data(desc
);
70 if (auto const env_schema
= getenv("HHVM_RUNTIME_REPO_SCHEMA")) {
71 repoSchema
= env_schema
;
73 repoSchema
= get("repo_schema_id");
76 compiler
= get("compiler_id");
77 buildid
= get("build_id");
78 hhjsbabeltransform
= get("hhjs_babel_transform");
80 inited
.store(true, std::memory_order_release
);
83 template<typename ValueFn
>
84 void replacePlaceholder(std::string
& target
,
85 const char* placeholder
,
87 auto const pos
= target
.find(placeholder
);
88 if (pos
== std::string::npos
) return;
89 target
.replace(pos
, strlen(placeholder
), value());
94 ////////////////////////////////////////////////////////////////////////////////
96 folly::StringPiece
repoSchemaId() {
101 folly::StringPiece
compilerId() {
106 folly::StringPiece
buildId() {
111 folly::StringPiece
hhjsBabelTransform() {
113 return hhjsbabeltransform
;
116 void replacePlaceholders(std::string
& s
) {
117 replacePlaceholder(s
, "%{schema}", [] { return repoSchemaId().begin(); });
118 replacePlaceholder(s
, "%{euid}", [] {
119 return folly::to
<std::string
>(geteuid());
121 replacePlaceholder(s
, "%{user}", [] {
122 auto user
= getenv("SUDO_USER");
123 if (user
== nullptr) user
= getenv("USER");
124 return user
!= nullptr ? user
: "%{user}";
128 ////////////////////////////////////////////////////////////////////////////////