Skip to content
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

Swift Package Manager support is incomplete #500

Open
scannillo opened this issue Jul 8, 2021 · 6 comments
Open

Swift Package Manager support is incomplete #500

scannillo opened this issue Jul 8, 2021 · 6 comments

Comments

@scannillo
Copy link

Hello. I am trying to use OCMock via Swift Package Manager. I am on XCode Version 13.0 beta (13A5154h).

At first, SPM is able to recognize the URL https://github.com/erikdoe/ocmock.git as an available Swift Package. But once I click Add Package I get a Package Resolution Failed error message, preventing me from properly importing OCMock into my project.

Here is the full screenshot. I highlighted the parts pertaining to OCMock, and not my project.

Screen Shot 2021-07-08 at 11 52 03 AM

@erikdoe
Copy link
Owner

erikdoe commented Jul 20, 2021

This might be related to #496. To be honest, I haven't had a chance to look into that yet, but hopefully I can spend some time on OCMock next week.

@erikdoe
Copy link
Owner

erikdoe commented Oct 26, 2021

As mentioned in the other issue, this took a while but now there's a version (3.9.0) that should support Swift Package Manager.

@erikdoe
Copy link
Owner

erikdoe commented Oct 31, 2021

Versions 3.9.x can now be resolved by Swift Package Manager.

Unfortunately, this still doesn't mean you can use OCMock as a dependency that way. The problem first mentioned in the following comment over a year ago still exists: #379 (comment)

In summary:

In a different issue @paulb777 mentioned that it is possible to use dependencies with unsafe flags by referencing the commit hash, and there seems to be code for that, but I wasn't able to get this to work. Even when I add OCMock by commit hash I get the error message that "the package product 'OCMock' cannot be used as a dependency of this target because it uses unsafe build flags."

It might be an option to distribute OCMock as a binary framework, but given the amount of time I've already invested in trying to support Swift Package Manager, this is nowhere near the top of my list of things to work on.

@erikdoe
Copy link
Owner

erikdoe commented Oct 31, 2021

I'll shorten the title of this issue (because it's not only about resolution any more), and pin it.

@erikdoe erikdoe changed the title Swift Package Manager support - Package Resolution Failed Swift Package Manager support Oct 31, 2021
@erikdoe erikdoe pinned this issue Oct 31, 2021
erikdoe added a commit that referenced this issue Oct 31, 2021
Problem is that OCMock can't really work with SPM. See #500 for details.
@MapaX
Copy link

MapaX commented Nov 19, 2021

About this issue, this works when you use the revision in the swiftpm.
Basically just take the commit from the tag and add ocmock like this:

.package(name: "OCMock", url: "https://github.com/erikdoe/ocmock.git", .revision("afd2c6924e8a36cb872bc475248b978f743c6050"))

@michal-tomlein
Copy link

I can confirm this works as @MapaX says. To use OCMock in an Xcode project, create e.g. an OCMockWrapper folder with a Package.swift file that references a specific OCMock commit such as the following:

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "OCMockWrapper",
    products: [
        .library(name: "OCMockWrapper", targets: ["OCMockWrapper"])
    ],
    dependencies: [
        .package(name: "OCMock", url: "https://github.com/erikdoe/ocmock.git", .revision("afd2c6924e8a36cb872bc475248b978f743c6050"))
    ],
    targets: [
        .target(name: "OCMockWrapper", dependencies: [
            .product(name: "OCMock", package: "OCMock")
        ])
    ]
)

You’ll need a dummy source file in OCMockWrapper/Sources/OCMockWrapper/ and a header at OCMockWrapper/Sources/OCMockWrapper/include/OCMockWrapper.h. Its content is not important; I used #import <OCMock/OCMock.h>.
Then drag the top-level OCMockWrapper folder into your project and add its product to your target.

We’ve been using it this way for a while and it works well. The only downside is that if you use OCMock from other packages of your own in addition to the wrapper, they have to agree on the commit hash, but that hasn’t been a problem for us to ensure.

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

No branches or pull requests

4 participants