This is an archive of the discontinued LLVM Phabricator instance.

[lldb/PlatformMacOSX] Be more robust in computing the SDK path with xcrun
ClosedPublic

Authored by JDevlieghere on Mar 16 2020, 4:47 PM.

Details

Summary

The current implementation isn't very resilient when it comes to the output of xcrun. Currently it cannot deal with:

  • Trailing newlines.
  • Leading newlines and errors/warnings before the Xcode path.
  • Xcode not being named Xcode.app.

This extract the logic into a helper in PlatformMacOSX and fixes those issues.

Diff Detail

Event Timeline

JDevlieghere created this revision.Mar 16 2020, 4:47 PM
aprantl added inline comments.Mar 16 2020, 5:11 PM
lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
225

Ah. We always ask for the macos SDK?

226

There's a global variable for various timeouts that we should use instead. Grep for commits with timeout in the name by me.

250

This looks a lot nicer than the original function.

lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
81 ↗(On Diff #250654)

Can you add a comment like:
/// path/to/Xcode.app/Developer/... so it's easier to visualize what these are?

90 ↗(On Diff #250654)

The comment and the parameter seem to contradict each other about whether xcrun is being used? :-)

Should the function be called, GetDefaultXcodeSDK?
I'm also wondering why a function with this name doesn't take a triple.

lldb/unittests/Platform/PlatformMacOSXTest.cpp
22 ↗(On Diff #250654)

Awesome!

JDevlieghere marked 5 inline comments as done.

Use the same timeout as UtilityExpressionTimeout.

JDevlieghere planned changes to this revision.Mar 16 2020, 6:34 PM

We should be able to avoid most of the post processing by just asking xcrun directly for the right SKD. I'm going to try to implement that and hopefully that removes some of the complexity here.

aprantl added inline comments.Mar 17 2020, 9:11 AM
lldb/unittests/Platform/PlatformMacOSXTest.cpp
25 ↗(On Diff #250659)

This also needs a testcase where the SDK is called MacOSX.sdk, which is actually the more common scenario.

New approach. Test is coming but upload the patch so Adrian can take a look.

Add unit test

aprantl added inline comments.Mar 17 2020, 11:36 AM
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
1272

How about hard-coding this in switch statement instead? The we can't have off-by-one errors quite as easily...

case watchOS: return "watchos"; etc.

1296

Not your fault, but watchOS and tvOS should also be in this list.

1368–1369

Not your fault again, but I find the name of this function super confusing. What is the :"ForModules" part supposed to mean?

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

Technically, I suppose BridgeOS belongs in here, too.

lldb/unittests/Platform/PlatformDarwinTest.cpp
80

Thanks!

JDevlieghere marked 6 inline comments as done.
JDevlieghere added inline comments.
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
1368–1369

It filters out SDK versions that don't support modules. We have something similar in SwiftASTContext, it only returns SDKs that support Swift.

aprantl added inline comments.Mar 17 2020, 1:05 PM
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
1294–1299

The corresponding watchOS and tvOS numbers for iOS 8 should be lower, right? If you are in doubt, just pick the current ones.

1876

empty stringref? That we can at least check for at the call site.

1883

--sdk for symmetry? Or is that the correct option?

JDevlieghere marked 4 inline comments as done.
JDevlieghere added inline comments.
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
1294–1299

tvOS = iOS, but yes watchOS should be 6.

aprantl accepted this revision.Mar 17 2020, 1:55 PM

Thanks!

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

early-exitify?

This revision is now accepted and ready to land.Mar 17 2020, 1:55 PM
JDevlieghere marked 2 inline comments as done.Mar 17 2020, 2:42 PM
JDevlieghere added inline comments.
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
1931

Doesn't work because you want to fallback rather than return.

This revision was automatically updated to reflect the committed changes.
JDevlieghere marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2020, 3:08 PM