This is an archive of the discontinued LLVM Phabricator instance.

Add an internal bit to the XcodeSDK class
ClosedPublic

Authored by aprantl on Apr 22 2020, 2:29 PM.

Details

Summary

For developing the OS itself there exists an "internal" variant of each SDK. This patch adds support for these SDK directories to the XcodeSDK class.

Diff Detail

Event Timeline

aprantl created this revision.Apr 22 2020, 2:29 PM
JDevlieghere added inline comments.Apr 22 2020, 5:00 PM
lldb/include/lldb/Utility/XcodeSDK.h
54–66

I think a struct would be less opaque.

aprantl updated this revision to Diff 259432.Apr 22 2020, 5:26 PM

Address review feedback — added fallback mechanisms.

aprantl marked an inline comment as done.Apr 22 2020, 5:27 PM
aprantl added inline comments.
lldb/include/lldb/Utility/XcodeSDK.h
54–66

Agreed. The tuple was meant to facilitate having the internal bit downstream, but we decided that there's no reason not have it upstream. I'll change it!

aprantl updated this revision to Diff 259446.Apr 22 2020, 5:55 PM

Introduce struct SDKInfo as suggested by @JDevlieghere . Thanks!

friss added inline comments.Apr 22 2020, 6:05 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
354–358

I don't think we need this last fallback. The internal and public SDKs are very different. You should be able to use an internal one to replace a public one, but not the other way around.

lldb/source/Utility/XcodeSDK.cpp
153–159

Why not leave this function as is and try to add both "internal" and ".internal" to the SDK name in GetXcodeSDK() without special-casing macOS? I'm not sure that macOS is actually special.

JDevlieghere added inline comments.Apr 22 2020, 7:34 PM
lldb/include/lldb/Utility/XcodeSDK.h
74

Can this now take an SDKInfo?

aprantl updated this revision to Diff 259612.Apr 23 2020, 9:44 AM
aprantl marked 4 inline comments as done.

Second round of feedback. Thanks everyone!

aprantl updated this revision to Diff 259614.Apr 23 2020, 9:45 AM

Delete extra curly braces.

One more comment but otherwise this LGTM

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

I always find a while like this really suspicious, even though the logic looks correct. Can you achieve the same thing in a less clever way with a lambda and early return from that?

aprantl marked an inline comment as done.Apr 23 2020, 10:49 AM
aprantl added inline comments.
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
332

Not sure. Maybe I'm doing something other than what you were thinking about, but the lambda I came up with looks even more pretentious ;-)

What complicates it is that I need to check the condition at the beginning and want to return out of the function from within the body. Do you have a specific suggestion in mind?

JDevlieghere added inline comments.Apr 23 2020, 3:03 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
332

I'm probably missing something. What I had in mind was

[]() {
    // Try an alternate spelling of the name ("macosx10.9internal").
    if (info.type == XcodeSDK::Type::MacOSX && !info.version.empty() &&
        info.internal) {
      llvm::StringRef fixed(sdk_name);
      if (fixed.consume_back(".internal"))
        sdk_name = fixed.str()+"internal";
      path = find_sdk(sdk_name);
      if (!path.empty())
        return path;
    }

    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
    LLDB_LOGF(log, "Couldn't find SDK %s on host", sdk_name.c_str());

    // Try without the version.
    if (!info.version.empty()) {
      info.version = {};
      sdk_name = XcodeSDK::GetCanonicalName(info);
      path = find_sdk(sdk_name);
      if (!path.empty())
        return path;
    }

    LLDB_LOGF(log, "Couldn't find any matching SDK on host");
    return {};
}
aprantl marked an inline comment as done.Apr 23 2020, 5:52 PM
aprantl added inline comments.
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
332

But for it to work you'd need to wrap it inside

if (path.empty())
  path = [&]() { ... }();
if (path.empty()}
  return {};

And that is three lines longer than the original code, and the sequence [&]() { ... }(), which doesn't meet my threshold for being easier to read. This is all highly subjective of course, so let me know what you think. I'm not married to the loop either, and in the end it doesn't really matter :-)

JDevlieghere accepted this revision.Apr 24 2020, 11:21 AM
JDevlieghere added inline comments.
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
332

You could move the first check into the lambda. But it seems like you thought this true so I trust your judgement, go with the while loop ;-)

This revision is now accepted and ready to land.Apr 24 2020, 11:21 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2020, 1:01 PM