Projects
home:Kaguya
bazel
_service:tar_scm:linux-bazel-path-from-getauxva...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:linux-bazel-path-from-getauxval.patch of Package bazel
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
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2