Skip to content

Commit 5d3ab23

Browse files
committed
Merge commit 'd6fc7c9a0c16' from apple/stable/20200108 into swift/release/5.3
2 parents c1a7248 + d6fc7c9 commit 5d3ab23

16 files changed

+152
-137
lines changed

lldb/include/lldb/Host/HostInfoBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class HostInfoBase {
9292
static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
9393
llvm::StringRef dir);
9494

95+
static FileSpec GetXcodeContentsDirectory() { return {}; }
96+
static FileSpec GetXcodeDeveloperDirectory() { return {}; }
97+
9598
/// Return the directory containing a specific Xcode SDK.
9699
static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk) { return {}; }
97100

lldb/include/lldb/Host/macosx/HostInfoMacOSX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class HostInfoMacOSX : public HostInfoPosix {
3232
static bool GetOSBuildString(std::string &s);
3333
static bool GetOSKernelDescription(std::string &s);
3434
static FileSpec GetProgramFileSpec();
35-
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
35+
static FileSpec GetXcodeContentsDirectory();
36+
static FileSpec GetXcodeDeveloperDirectory();
3637

3738
/// Query xcrun to find an Xcode SDK directory.
3839
static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk);

lldb/include/lldb/Utility/XcodeSDK.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class XcodeSDK {
8787
static std::string GetCanonicalName(Info info);
8888
/// Return the best-matching SDK type for a specific triple.
8989
static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple);
90+
91+
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
9092
};
9193

9294
} // namespace lldb_private

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,82 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
297297
}
298298
}
299299

300+
FileSpec HostInfoMacOSX::GetXcodeContentsDirectory() {
301+
static FileSpec g_xcode_contents_path;
302+
static std::once_flag g_once_flag;
303+
std::call_once(g_once_flag, [&]() {
304+
// Try the shlib dir first.
305+
if (FileSpec fspec = HostInfo::GetShlibDir()) {
306+
if (FileSystem::Instance().Exists(fspec)) {
307+
std::string xcode_contents_dir =
308+
XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
309+
if (!xcode_contents_dir.empty()) {
310+
g_xcode_contents_path = FileSpec(xcode_contents_dir);
311+
return;
312+
}
313+
}
314+
}
315+
316+
if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
317+
FileSpec fspec(developer_dir_env_var);
318+
if (FileSystem::Instance().Exists(fspec)) {
319+
// FIXME: This looks like it couldn't possibly work!
320+
std::string xcode_contents_dir =
321+
XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
322+
if (!xcode_contents_dir.empty()) {
323+
g_xcode_contents_path = FileSpec(xcode_contents_dir);
324+
return;
325+
}
326+
}
327+
}
328+
329+
FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()));
330+
if (fspec) {
331+
if (FileSystem::Instance().Exists(fspec)) {
332+
std::string xcode_contents_dir =
333+
XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
334+
if (!xcode_contents_dir.empty()) {
335+
g_xcode_contents_path = FileSpec(xcode_contents_dir);
336+
return;
337+
}
338+
}
339+
}
340+
});
341+
return g_xcode_contents_path;
342+
}
343+
344+
lldb_private::FileSpec HostInfoMacOSX::GetXcodeDeveloperDirectory() {
345+
static lldb_private::FileSpec g_developer_directory;
346+
static llvm::once_flag g_once_flag;
347+
llvm::call_once(g_once_flag, []() {
348+
if (FileSpec fspec = GetXcodeContentsDirectory()) {
349+
fspec.AppendPathComponent("Developer");
350+
if (FileSystem::Instance().Exists(fspec))
351+
g_developer_directory = fspec;
352+
}
353+
});
354+
return g_developer_directory;
355+
}
356+
300357
static std::string GetXcodeSDK(XcodeSDK sdk) {
301358
XcodeSDK::Info info = sdk.Parse();
302359
std::string sdk_name = XcodeSDK::GetCanonicalName(info);
303360
auto find_sdk = [](std::string sdk_name) -> std::string {
304-
std::string xcrun_cmd = "xcrun --show-sdk-path --sdk " + sdk_name;
361+
std::string xcrun_cmd;
362+
Environment env = Host::GetEnvironment();
363+
std::string developer_dir = env.lookup("DEVELOPER_DIR");
364+
if (developer_dir.empty())
365+
if (FileSpec fspec = HostInfo::GetShlibDir())
366+
if (FileSystem::Instance().Exists(fspec)) {
367+
FileSpec path(
368+
XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath()));
369+
if (path.RemoveLastPathComponent())
370+
developer_dir = path.GetPath();
371+
}
372+
if (!developer_dir.empty())
373+
xcrun_cmd = "/usr/bin/env DEVELOPER_DIR=\"" + developer_dir + "\" ";
374+
xcrun_cmd += "xcrun --show-sdk-path --sdk " + sdk_name;
375+
305376
int status = 0;
306377
int signo = 0;
307378
std::string output_str;

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <mutex>
1616
#include <thread>
1717
#include "lldb/Host/PseudoTerminal.h"
18+
#include "lldb/Host/HostInfo.h"
1819
#include "lldb/Target/Process.h"
1920
#include "lldb/Utility/LLDBAssert.h"
2021
#include "lldb/Utility/Status.h"
@@ -77,7 +78,7 @@ void PlatformAppleSimulator::GetStatus(Stream &strm) {
7778
// simulator
7879
PlatformAppleSimulator::LoadCoreSimulator();
7980

80-
std::string developer_dir = GetXcodeDeveloperDirectory().GetPath();
81+
std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
8182
CoreSimulatorSupport::DeviceSet devices =
8283
CoreSimulatorSupport::DeviceSet::GetAvailableDevices(
8384
developer_dir.c_str());
@@ -124,7 +125,7 @@ Status PlatformAppleSimulator::ConnectRemote(Args &args) {
124125
const char *arg_cstr = args.GetArgumentAtIndex(0);
125126
if (arg_cstr) {
126127
std::string arg_str(arg_cstr);
127-
std::string developer_dir = GetXcodeDeveloperDirectory().GetPath();
128+
std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
128129
CoreSimulatorSupport::DeviceSet devices =
129130
CoreSimulatorSupport::DeviceSet::GetAvailableDevices(
130131
developer_dir.c_str());
@@ -214,7 +215,7 @@ FileSpec PlatformAppleSimulator::GetCoreSimulatorPath() {
214215
#if defined(__APPLE__)
215216
std::lock_guard<std::mutex> guard(m_core_sim_path_mutex);
216217
if (!m_core_simulator_framework_path.hasValue()) {
217-
if (FileSpec fspec = GetXcodeDeveloperDirectory()) {
218+
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
218219
std::string developer_dir = fspec.GetPath();
219220
StreamString cs_path;
220221
cs_path.Printf(
@@ -247,7 +248,7 @@ CoreSimulatorSupport::Device PlatformAppleSimulator::GetSimulatorDevice() {
247248
if (!m_device.hasValue()) {
248249
const CoreSimulatorSupport::DeviceType::ProductFamilyID dev_id =
249250
CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone;
250-
std::string developer_dir = GetXcodeDeveloperDirectory().GetPath();
251+
std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
251252
m_device = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(
252253
developer_dir.c_str())
253254
.GetFanciest(dev_id);

lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
255255
const char *PlatformAppleTVSimulator::GetSDKDirectoryAsCString() {
256256
std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
257257
if (m_sdk_directory.empty()) {
258-
if (FileSpec fspec = GetXcodeDeveloperDirectory()) {
258+
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
259259
std::string developer_dir = fspec.GetPath();
260260
char sdks_directory[PATH_MAX];
261261
char sdk_dirname[PATH_MAX];

lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
255255
const char *PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() {
256256
std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
257257
if (m_sdk_directory.empty()) {
258-
if (FileSpec fspec = GetXcodeDeveloperDirectory()) {
258+
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
259259
std::string developer_dir = fspec.GetPath();
260260
char sdks_directory[PATH_MAX];
261261
char sdk_dirname[PATH_MAX];

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,19 +1133,6 @@ static FileSpec GetXcodeSelectPath() {
11331133
return g_xcode_select_filespec;
11341134
}
11351135

1136-
lldb_private::FileSpec PlatformDarwin::GetXcodeDeveloperDirectory() {
1137-
static lldb_private::FileSpec g_developer_directory;
1138-
static llvm::once_flag g_once_flag;
1139-
llvm::call_once(g_once_flag, []() {
1140-
if (FileSpec fspec = GetXcodeContentsDirectory()) {
1141-
fspec.AppendPathComponent("Developer");
1142-
if (FileSystem::Instance().Exists(fspec))
1143-
g_developer_directory = fspec;
1144-
}
1145-
});
1146-
return g_developer_directory;
1147-
}
1148-
11491136
BreakpointSP PlatformDarwin::SetThreadCreationBreakpoint(Target &target) {
11501137
BreakpointSP bp_sp;
11511138
static const char *g_bp_names[] = {
@@ -1260,7 +1247,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeForModules(XcodeSDK::Type sdk_type,
12601247
}
12611248

12621249
FileSpec PlatformDarwin::GetSDKDirectoryForModules(XcodeSDK::Type sdk_type) {
1263-
FileSpec sdks_spec = GetXcodeContentsDirectory();
1250+
FileSpec sdks_spec = HostInfo::GetXcodeContentsDirectory();
12641251
sdks_spec.AppendPathComponent("Developer");
12651252
sdks_spec.AppendPathComponent("Platforms");
12661253

@@ -1586,7 +1573,7 @@ lldb_private::FileSpec PlatformDarwin::LocateExecutable(const char *basename) {
15861573
llvm::call_once(g_once_flag, []() {
15871574

15881575
// When locating executables, trust the DEVELOPER_DIR first if it is set
1589-
FileSpec xcode_contents_dir = GetXcodeContentsDirectory();
1576+
FileSpec xcode_contents_dir = HostInfo::GetXcodeContentsDirectory();
15901577
if (xcode_contents_dir) {
15911578
FileSpec xcode_lldb_resources = xcode_contents_dir;
15921579
xcode_lldb_resources.AppendPathComponent("SharedFrameworks");
@@ -1738,72 +1725,6 @@ std::string PlatformDarwin::FindComponentInPath(llvm::StringRef path,
17381725
return {};
17391726
}
17401727

1741-
std::string
1742-
PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
1743-
auto begin = llvm::sys::path::begin(path);
1744-
auto end = llvm::sys::path::end(path);
1745-
1746-
// Iterate over the path components until we find something that ends with
1747-
// .app. If the next component is Contents then we've found the Contents
1748-
// directory.
1749-
for (auto it = begin; it != end; ++it) {
1750-
if (it->endswith(".app")) {
1751-
auto next = it;
1752-
if (++next != end && *next == "Contents") {
1753-
llvm::SmallString<128> buffer;
1754-
llvm::sys::path::append(buffer, begin, ++next,
1755-
llvm::sys::path::Style::posix);
1756-
return buffer.str().str();
1757-
}
1758-
}
1759-
}
1760-
1761-
return {};
1762-
}
1763-
1764-
FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
1765-
static FileSpec g_xcode_contents_path;
1766-
static std::once_flag g_once_flag;
1767-
std::call_once(g_once_flag, [&]() {
1768-
// Try the shlib dir first.
1769-
if (FileSpec fspec = HostInfo::GetShlibDir()) {
1770-
if (FileSystem::Instance().Exists(fspec)) {
1771-
std::string xcode_contents_dir =
1772-
FindXcodeContentsDirectoryInPath(fspec.GetPath());
1773-
if (!xcode_contents_dir.empty()) {
1774-
g_xcode_contents_path = FileSpec(xcode_contents_dir);
1775-
return;
1776-
}
1777-
}
1778-
}
1779-
1780-
if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
1781-
FileSpec fspec(developer_dir_env_var);
1782-
if (FileSystem::Instance().Exists(fspec)) {
1783-
std::string xcode_contents_dir =
1784-
FindXcodeContentsDirectoryInPath(fspec.GetPath());
1785-
if (!xcode_contents_dir.empty()) {
1786-
g_xcode_contents_path = FileSpec(xcode_contents_dir);
1787-
return;
1788-
}
1789-
}
1790-
}
1791-
1792-
FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()));
1793-
if (fspec) {
1794-
if (FileSystem::Instance().Exists(fspec)) {
1795-
std::string xcode_contents_dir =
1796-
FindXcodeContentsDirectoryInPath(fspec.GetPath());
1797-
if (!xcode_contents_dir.empty()) {
1798-
g_xcode_contents_path = FileSpec(xcode_contents_dir);
1799-
return;
1800-
}
1801-
}
1802-
}
1803-
});
1804-
return g_xcode_contents_path;
1805-
}
1806-
18071728
FileSpec PlatformDarwin::GetCurrentToolchainDirectory() {
18081729
if (FileSpec fspec = HostInfo::GetShlibDir())
18091730
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ class PlatformDarwin : public PlatformPOSIX {
9090
llvm::Expected<lldb_private::StructuredData::DictionarySP>
9191
FetchExtendedCrashInformation(lldb_private::Process &process) override;
9292

93-
static lldb_private::FileSpec GetXcodeContentsDirectory();
94-
static lldb_private::FileSpec GetXcodeDeveloperDirectory();
95-
96-
/// Return the toolchain directroy the current LLDB instance is located in.
93+
/// Return the toolchain directory the current LLDB instance is located in.
9794
static lldb_private::FileSpec GetCurrentToolchainDirectory();
9895

9996
/// Return the command line tools directory the current LLDB instance is
@@ -166,7 +163,6 @@ class PlatformDarwin : public PlatformPOSIX {
166163

167164
static std::string FindComponentInPath(llvm::StringRef path,
168165
llvm::StringRef component);
169-
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
170166

171167
std::string m_developer_directory;
172168
llvm::StringMap<std::string> m_sdk_path;

lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Core/ModuleSpec.h"
1919
#include "lldb/Core/PluginManager.h"
2020
#include "lldb/Host/Host.h"
21+
#include "lldb/Host/HostInfo.h"
2122
#include "lldb/Interpreter/OptionValueFileSpecList.h"
2223
#include "lldb/Interpreter/OptionValueProperties.h"
2324
#include "lldb/Interpreter/Property.h"
@@ -328,7 +329,7 @@ void PlatformDarwinKernel::CollectKextAndKernelDirectories() {
328329

329330
// DeveloperDirectory is something like
330331
// "/Applications/Xcode.app/Contents/Developer"
331-
std::string developer_dir = GetXcodeDeveloperDirectory().GetPath();
332+
std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
332333
if (developer_dir.empty())
333334
developer_dir = "/Applications/Xcode.app/Contents/Developer";
334335

lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
167167
return {};
168168

169169
// First try to find an SDK that matches the given SDK version.
170-
if (FileSpec fspec = GetXcodeContentsDirectory()) {
170+
if (FileSpec fspec = HostInfo::GetXcodeContentsDirectory()) {
171171
StreamString sdk_path;
172172
sdk_path.Printf("%s/Developer/Platforms/MacOSX.platform/Developer/"
173173
"SDKs/MacOSX%u.%u.sdk",

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "lldb/Core/PluginManager.h"
1616
#include "lldb/Host/FileSystem.h"
1717
#include "lldb/Host/Host.h"
18+
#include "lldb/Host/HostInfo.h"
1819
#include "lldb/Target/Process.h"
1920
#include "lldb/Target/Target.h"
2021
#include "lldb/Utility/FileSpec.h"
@@ -342,7 +343,7 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() {
342343
const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() {
343344
std::string platform_dir = "/Platforms/" + GetPlatformName() + "/DeviceSupport";
344345
if (m_device_support_directory.empty()) {
345-
if (FileSpec fspec = GetXcodeDeveloperDirectory()) {
346+
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
346347
m_device_support_directory = fspec.GetPath();
347348
m_device_support_directory.append(platform_dir.c_str());
348349
} else {

lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
261261
const char *PlatformiOSSimulator::GetSDKDirectoryAsCString() {
262262
std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
263263
if (m_sdk_directory.empty()) {
264-
if (FileSpec fspec = GetXcodeDeveloperDirectory()) {
264+
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
265265
std::string developer_dir = fspec.GetPath();
266266
char sdks_directory[PATH_MAX];
267267
char sdk_dirname[PATH_MAX];

lldb/source/Utility/XcodeSDK.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,25 @@ XcodeSDK::Type XcodeSDK::GetSDKTypeForTriple(const llvm::Triple &triple) {
284284
return XcodeSDK::unknown;
285285
}
286286
}
287+
288+
std::string XcodeSDK::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
289+
auto begin = llvm::sys::path::begin(path);
290+
auto end = llvm::sys::path::end(path);
291+
292+
// Iterate over the path components until we find something that ends with
293+
// .app. If the next component is Contents then we've found the Contents
294+
// directory.
295+
for (auto it = begin; it != end; ++it) {
296+
if (it->endswith(".app")) {
297+
auto next = it;
298+
if (++next != end && *next == "Contents") {
299+
llvm::SmallString<128> buffer;
300+
llvm::sys::path::append(buffer, begin, ++next,
301+
llvm::sys::path::Style::posix);
302+
return buffer.str().str();
303+
}
304+
}
305+
}
306+
307+
return {};
308+
}

0 commit comments

Comments
 (0)