Skip to content

[Toolchains] - Generalize lookup routines as a Toolchain extension. #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

JhonnyBillM
Copy link
Contributor

This generalizeslookup(exec:) and exposes envVar(forExecutable:).

Due to the generalization, the following tests were failing in Linux:

  1. testDSYMGeneration: unableToFind(tool: "dsymutil")
  2. testLinking: unableToFind(tool: "libtool")
  3. testStandardCompileJobs: unableToFind(tool: "dsymutil")

testLinking also failed in macOS when specifying the linux target.

So, I ifdef them out, but if we need to do anything else in the test suit, just please let me know.

Once swift-driver is installed in the Toolchain, we can look for tools right next to it's executable path, this help us to be more platform agnostic while locating the toolchain.

This is the first step in this direction, we will need to make this more robust to get rid of xcrun if possible, and get a proper linux implementation.
func lookup(exec: String) throws -> AbsolutePath {
if let overrideString = envVar(forExecutable: exec) {
return try AbsolutePath(validating: overrideString)
} else if let path = lookupExecutablePath(filename: exec, searchPaths: [executableDir]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be lookupExecutablePath(filename: exec, searchPaths: [executableDir] + searchPaths)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for searchPaths in macOS was crashing. Later today I will dig into it to find the real reason and will provide a detailed response or the fix.

Copy link
Contributor Author

@JhonnyBillM JhonnyBillM Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that after we find the swift compiler path in the searchPaths, we cannot find the resource directory under ~/usr/lib/swift/.

is macOS supposed to have a resource directory at ~/usr/lib/swift/, or what is the correct way to handle this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the resource directory is in the Xcode toolchain on macOS, inside /Applications/Xcode.app/Contents/Developer/Toolchains/<dir>.xctoolchain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we first look in the executable path, then go to xcrun, and finally look into the searchPaths.

This is the "best" approach right now because in macOS the toolchain lives under Xcode, not under the Swift executable in ~/usr/lib/swift/.

@harlanhaskins
Copy link
Contributor

We definitely want to un-#if those tests. Were you able to figure out why it couldn't find the tools on Linux?

@harlanhaskins
Copy link
Contributor

@DougGregor some of your comments in #25 are addressed here.

@JhonnyBillM JhonnyBillM force-pushed the SWIFT-DRIVER-OVERRIDES-YOU-AND-ME branch from 17ff55d to 6640ed5 Compare November 24, 2019 20:56
@JhonnyBillM
Copy link
Contributor Author

  1. Updated how we look for executables.
  2. Tests are working on Linux, so I removed the #if clause.

Why were those tests failing?

They were failing in my Docker instance¹ because it doesn't have dsymutil nor libtool.

I was looking to see if those tools are in GNU, and I thiiiink they are, but I am not sure about dsymutil (I kind-of saw in LLVM that dsymutil is only available in Darwin, but again, I am not 100 % sure).

Tests are working because of this hack, and although this is outside the scope of this PR, in order to get rid of the previously mentioned hack in a future PR, I would like to know:

• Does swift-driver requires dsymutil and libtool to be installed and in the PATH in linux?

¹ Configured following this steps

@harlanhaskins
Copy link
Contributor

dsymutil and libtool are Darwin-only tools, so we should conditionalize checks for them.

@JhonnyBillM
Copy link
Contributor Author

Ok so, can we move forward with this PR and discuss those things in a future PR when trying to remove the aforementioned hack ?

@harlanhaskins
Copy link
Contributor

@swift-ci please test

@harlanhaskins
Copy link
Contributor

Hmm.

clang: error: unknown argument: '-print-target-triple'

Makes me wonder if we picked an old clang instead of the one next to swift? Can you add some tests that we find a clang path that’s relative to the swift path for a given toolchain?

@JhonnyBillM
Copy link
Contributor Author

Done. This was interesting, moved the hack to lookup(exec:). Once this PR and #25 are merged the hack will depend on how we would like to handle the tests that needs dsymutil and libtool .


This work will benefit from #25, should I keep that as a separate PR, or should we merge those changes into this PR and move forward with "1 big change"?

@DougGregor
Copy link
Member

@swift-ci please test

@DougGregor
Copy link
Member

This is looking good; I'll go ahead and merge this and we can iterate on #25 separately.

@DougGregor DougGregor merged commit 95d7f4e into swiftlang:master Dec 3, 2019
@JhonnyBillM
Copy link
Contributor Author

Thank you @harlanhaskins for all your help in this PR. And thanks @DougGregor for reviewing + merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants