Skip to content

build: support building against Foundation.framework #296

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
merged 1 commit into from
Feb 6, 2020

Conversation

compnerd
Copy link
Member

This enables building XCTest against the System Foundation.framework on
macOS. This requires that the executable path is computed using URL
(NSURL) as the lastPathComponent has been explicitly made
unavailable.

/Users/compnerd/SourceCache/swift-corelibs-xctest/Sources/XCTest/Public/XCTestMain.swift:99:48: error: 'lastPathComponent' is unavailable: Use lastPathComponent on URL instead.
        let exeName = CommandLine.arguments[0].lastPathComponent
                                               ^~~~~~~~~~~~~~~~~
Foundation.StringProtocol:7:16: note: 'lastPathComponent' has been explicitly marked unavailable here
    public var lastPathComponent: String { get }
               ^

This enables building XCTest against the System Foundation.framework on
macOS.  This requires that the executable path is computed using `URL`
(`NSURL`) as the `lastPathComponent` has been explicitly made
unavailable.

```
/Users/compnerd/SourceCache/swift-corelibs-xctest/Sources/XCTest/Public/XCTestMain.swift:99:48: error: 'lastPathComponent' is unavailable: Use lastPathComponent on URL instead.
        let exeName = CommandLine.arguments[0].lastPathComponent
                                               ^~~~~~~~~~~~~~~~~
Foundation.StringProtocol:7:16: note: 'lastPathComponent' has been explicitly marked unavailable here
    public var lastPathComponent: String { get }
               ^
```
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

CC: @briancroom

So, with this work, I can actually build XCTest easily on macOS. This has the benefit of being able to easily write tests for macOS/Linux/Windows as XCTest on macOS does not have XCTMain and testCase available in Swift. There isn't a XCTest runner on Windows, and on Linux, you either need to use either swift-package-manager to generate the scaffolding or use XCTMain. So, on Windows and Linux (to run from the command line) you need that. On macOS, you need to build up the bundle if you want to use XCTest from the system. For a little bit more work, you can have the same code run on all three platforms from the console without having to setup the bundle.

Copy link
Contributor

@stmontgomery stmontgomery left a comment

Choose a reason for hiding this comment

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

This seems fine to me, and I see CI has succeeded on both macOS and Linux. @briancroom feel free to jump in if you object, or have follow-up comments to this in relation to the previous PR

@compnerd compnerd merged commit cd95abc into swiftlang:master Feb 6, 2020
@compnerd compnerd deleted the system-foundation branch February 6, 2020 17:25
@briancroom
Copy link
Contributor

Ok, cool. Yeah, I think using SwiftPM as the cross-platform workflow entry point is the recommended path, but if you find it helpful/convenient to be able to use Corelibs XCTest on macOS, I don't see any particular reason to put up roadblocks for that.

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