[Lldb-commits] [lldb] f28177d - Factor out GetEnvDeveloperDir() (NFC)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 5 13:50:53 PDT 2020
Author: Adrian Prantl
Date: 2020-06-05T13:50:37-07:00
New Revision: f28177dbe8d2e2955f7ca0a0ffdb1a44fefe092d
URL: https://github.com/llvm/llvm-project/commit/f28177dbe8d2e2955f7ca0a0ffdb1a44fefe092d
DIFF: https://github.com/llvm/llvm-project/commit/f28177dbe8d2e2955f7ca0a0ffdb1a44fefe092d.diff
LOG: Factor out GetEnvDeveloperDir() (NFC)
Differential Revision: https://reviews.llvm.org/D81289
Added:
Modified:
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
Removed:
################################################################################
diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index cf2f2dcb3aff..37bcff24ba23 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -297,6 +297,19 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
}
}
+/// Return and cache $DEVELOPER_DIR if it is set and exists.
+static std::string GetEnvDeveloperDir() {
+ static std::string g_env_developer_dir;
+ static std::once_flag g_once_flag;
+ std::call_once(g_once_flag, [&]() {
+ if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
+ FileSpec fspec(developer_dir_env_var);
+ if (FileSystem::Instance().Exists(fspec))
+ g_env_developer_dir = fspec.GetPath();
+ }});
+ return g_env_developer_dir;
+}
+
FileSpec HostInfoMacOSX::GetXcodeContentsDirectory() {
static FileSpec g_xcode_contents_path;
static std::once_flag g_once_flag;
@@ -313,16 +326,14 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
}
}
- if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
- FileSpec fspec(developer_dir_env_var);
- if (FileSystem::Instance().Exists(fspec)) {
- // FIXME: This looks like it couldn't possibly work!
- std::string xcode_contents_dir =
- XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
- if (!xcode_contents_dir.empty()) {
- g_xcode_contents_path = FileSpec(xcode_contents_dir);
- return;
- }
+ std::string env_developer_dir = GetEnvDeveloperDir();
+ if (!env_developer_dir.empty()) {
+ // FIXME: This looks like it couldn't possibly work!
+ std::string xcode_contents_dir =
+ XcodeSDK::FindXcodeContentsDirectoryInPath(env_developer_dir);
+ if (!xcode_contents_dir.empty()) {
+ g_xcode_contents_path = FileSpec(xcode_contents_dir);
+ return;
}
}
@@ -359,8 +370,7 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
std::string sdk_name = XcodeSDK::GetCanonicalName(info);
auto find_sdk = [](std::string sdk_name) -> std::string {
std::string xcrun_cmd;
- Environment env = Host::GetEnvironment();
- std::string developer_dir = env.lookup("DEVELOPER_DIR");
+ std::string developer_dir = GetEnvDeveloperDir();
if (developer_dir.empty())
if (FileSpec fspec = HostInfo::GetShlibDir())
if (FileSystem::Instance().Exists(fspec)) {
More information about the lldb-commits
mailing list