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/Range.h>
27 ////////////////////////////////////////////////////////////////////////////////
31 std::atomic
<bool> inited
;
33 std::string repoSchema
;
36 std::string hhjsbabeltransform
;
38 ////////////////////////////////////////////////////////////////////////////////
41 * Initializes the repo schema id and the compiler id from their special
42 * sections in the hhvm binary.
44 void readBuildInfo() {
45 if (inited
.load(std::memory_order_acquire
)) return;
46 std::unique_lock
<std::mutex
> lock(mtx
);
47 if (inited
.load(std::memory_order_acquire
)) return;
49 auto const get
= [&] (const char* section
) -> std::string
{
50 auto constexpr bad
= "(UNKNOWN)";
53 if (!get_embedded_data(section
, &desc
)) {
57 auto const data
= read_embedded_data(desc
);
65 if (auto const env_schema
= getenv("HHVM_RUNTIME_REPO_SCHEMA")) {
66 repoSchema
= env_schema
;
68 repoSchema
= get("repo_schema_id");
71 compiler
= get("compiler_id");
72 buildid
= get("build_id");
73 hhjsbabeltransform
= get("hhjs_babel_transform");
75 inited
.store(true, std::memory_order_release
);
80 ////////////////////////////////////////////////////////////////////////////////
82 folly::StringPiece
repoSchemaId() {
87 folly::StringPiece
compilerId() {
92 folly::StringPiece
buildId() {
97 folly::StringPiece
hhjsBabelTransform() {
99 return hhjsbabeltransform
;
102 const char* kSchemaPlaceholder
= "%{schema}";
104 std::string
insertSchema(const char* path
) {
105 assert(strstr(repoSchemaId().begin(), kSchemaPlaceholder
) == nullptr);
106 std::string result
= path
;
108 if ((idx
= result
.find(kSchemaPlaceholder
)) != std::string::npos
) {
109 result
.replace(idx
, strlen(kSchemaPlaceholder
), repoSchemaId().begin());
114 ////////////////////////////////////////////////////////////////////////////////