1 Star 0 Fork 30

zhangzikang/bazel

forked from src-openEuler/bazel 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
linux-bazel-path-from-getauxval.patch 6.85 KB
一键复制 编辑 原始数据 按行查看 历史
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index a7cbde7..cf32dec 100755
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1586,12 +1586,6 @@ int Main(int argc, const char *const *argv, WorkspaceLayout *workspace_layout,
new blaze_util::BazelLogHandler());
blaze_util::SetLogHandler(std::move(default_handler));
- const string self_path = GetSelfPath(argv[0]);
-
- if (argc == 2 && strcmp(argv[1], "--version") == 0) {
- PrintVersionInfo(self_path, option_processor->GetLowercaseProductName());
- return blaze_exit_code::SUCCESS;
- }
string cwd = GetCanonicalCwd();
LoggingInfo logging_info(CheckAndGetBinaryPath(cwd, argv[0]), start_time);
@@ -1622,6 +1616,12 @@ int Main(int argc, const char *const *argv, WorkspaceLayout *workspace_layout,
ParseOptionsOrDie(cwd, workspace, *option_processor, argc, argv);
StartupOptions *startup_options = option_processor->GetParsedStartupOptions();
startup_options->MaybeLogStartupOptionWarnings();
+ const string self_path = GetSelfPath(argv[0], *startup_options);
+
+ if (argc == 2 && strcmp(argv[1], "--version") == 0) {
+ PrintVersionInfo(self_path, option_processor->GetLowercaseProductName());
+ return blaze_exit_code::SUCCESS;
+ }
SetDebugLog(startup_options->client_debug);
// If client_debug was false, this is ignored, so it's accurate.
diff --git a/src/main/cpp/blaze_util_bsd.cc b/src/main/cpp/blaze_util_bsd.cc
index a9b81df..0aebf8f 100755
--- a/src/main/cpp/blaze_util_bsd.cc
+++ b/src/main/cpp/blaze_util_bsd.cc
@@ -46,6 +46,7 @@
#include "src/main/cpp/blaze_util.h"
#include "src/main/cpp/blaze_util_platform.h"
+#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/file.h"
@@ -89,7 +90,7 @@ void WarnFilesystemType(const blaze_util::Path &output_base) {
}
}
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
#if defined(__FreeBSD__)
char buffer[PATH_MAX] = {};
auto pid = getpid();
diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc
index c2e8e1f..33d1a96 100755
--- a/src/main/cpp/blaze_util_darwin.cc
+++ b/src/main/cpp/blaze_util_darwin.cc
@@ -124,7 +124,7 @@ void WarnFilesystemType(const blaze_util::Path &output_base) {
}
}
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
char pathbuf[PROC_PIDPATHINFO_MAXSIZE] = {};
int len = proc_pidpath(getpid(), pathbuf, sizeof(pathbuf));
if (len == 0) {
diff --git a/src/main/cpp/get_self_path_linux.cc b/src/main/cpp/get_self_path_linux.cc
index 2183d43..3e75ef0 100755
--- a/src/main/cpp/get_self_path_linux.cc 2023-09-07 09:45:41.310000000 +0000
+++ b/src/main/cpp/get_self_path_linux.cc 2023-09-07 09:47:28.512000000 +0000
@@ -14,8 +14,10 @@
#include <unistd.h>
#include <limits.h>
+#include <sys/auxv.h>
#include "src/main/cpp/blaze_util_platform.h"
+#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/logging.h"
@@ -25,7 +27,14 @@ namespace blaze {
using blaze_util::GetLastErrorString;
using std::string;
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
+ // Sometimes /proc/self/exec isn't valid (binfmt_misc + qemu)
+ // so we provide an alternate API. e.g. Linux aarch64 running
+ // bazel-x86_64-linux
+ if (options.linux_bazel_path_from_getauxval) {
+ return reinterpret_cast<const char *>(getauxval(AT_EXECFN));
+ }
+
char buffer[PATH_MAX] = {};
ssize_t bytes = readlink("/proc/self/exe", buffer, sizeof(buffer));
if (bytes == sizeof(buffer)) {
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index 42075f1..54afa8e 100755
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -22,6 +22,7 @@
#include <vector>
#include "src/main/cpp/blaze_util.h"
+#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/server_process_info.h"
#include "src/main/cpp/util/path.h"
#include "src/main/cpp/util/port.h"
@@ -113,7 +114,7 @@ std::string Which(const std::string& executable);
// Gets an absolute path to the binary being executed that is guaranteed to be
// readable.
-std::string GetSelfPath(const char* argv0);
+std::string GetSelfPath(const char* argv0, const StartupOptions &options);
// Returns the directory Bazel can use to store output.
std::string GetOutputRoot();
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index 7cd1881..e84f92c 100755
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -383,7 +383,7 @@ string GetProcessIdAsString() {
return blaze_util::ToString(GetCurrentProcessId());
}
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
WCHAR buffer[kWindowsPathBufferSize] = {0};
if (!GetModuleFileNameW(0, buffer, kWindowsPathBufferSize)) {
BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index d1e2f08..5112755 100755
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -97,7 +97,8 @@ StartupOptions::StartupOptions(const string &product_name,
macos_qos_class(QOS_CLASS_UNSPECIFIED),
#endif
unlimit_coredumps(false),
- windows_enable_symlinks(false) {
+ windows_enable_symlinks(false),
+ linux_bazel_path_from_getauxval(false) {
if (blaze::IsRunningWithinTest()) {
output_root = blaze_util::MakeAbsolute(blaze::GetPathEnv("TEST_TMPDIR"));
max_idle_secs = 15;
@@ -148,6 +149,8 @@ StartupOptions::StartupOptions(const string &product_name,
RegisterNullaryStartupFlag("write_command_log", &write_command_log);
RegisterNullaryStartupFlag("windows_enable_symlinks",
&windows_enable_symlinks);
+ RegisterNullaryStartupFlag("linux_bazel_path_from_getauxval",
+ &linux_bazel_path_from_getauxval);
RegisterUnaryStartupFlag("command_port");
RegisterUnaryStartupFlag("connect_timeout_secs");
RegisterUnaryStartupFlag("local_startup_timeout_secs");
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index d6c8d02..2c60ffd 100755
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -279,6 +279,10 @@ class StartupOptions {
// developer mode to be enabled.
bool windows_enable_symlinks;
+ // Accomodate bazel running via Linux's binfmt_misc which
+ // defeats /proc/self/exe path-finding
+ bool linux_bazel_path_from_getauxval;
+
protected:
// Constructor for subclasses only so that site-specific extensions of this
// class can override the product name. The product_name must be the
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangzikang1992/bazel.git
git@gitee.com:zhangzikang1992/bazel.git
zhangzikang1992
bazel
bazel
master

搜索帮助