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 Scripting: error: unknown package 'Apollo' in dependencies of target 'Codegen' #1102

Closed
alexandrethsilva opened this issue Mar 29, 2020 · 7 comments

Comments

@alexandrethsilva
Copy link

Hi @designatednerd!
First of all, thanks for the great effort on this script. It's really great to have someone looking into how to improve the existing process and making it better.

I'm not sure what may be up as I'm relatively new to Swift and Xcode development in general, but there's a problem when doing the setup described in the docs that is really cryptic as I can't find much about it somewhere else.

As for the setup, I'm currently on Xcode Version 11.4 (11E146) and therefore swift-tools 5.2.

When getting to the step 4 in the process (Update the dependencies section to grab the Apollo iOS library), I get the following message on the sidebar:

Showing All Messages: dependency 'Apollo' is not used by any target

Okay, makes sense, since I didn't add the target dependency yet. So I go ahead and do it. But then, immediately after adding it, I get the following:

unknown package 'Apollo' in dependencies of target 'Codegen'

My Package.swift currently looks like this:

// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Codegen",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/apollographql/apollo-ios.git",
        from: "0.22.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(name: "Codegen",
            dependencies: [
            .product(name: "ApolloCodegenLib", package: "Apollo")
            ]),
        .testTarget(
            name: "CodegenTests",
            dependencies: ["Codegen"]),
    ]
)

As a sidenote, if I comment the dependency out, Xcode downloads the package from github and adds the deps to the sidebar, like here:

image

But when I add it:

image

I'm afraid I'm missing something rather simple, but then again, I couldn't get the process to work on Xcode 11.3.1 either as it was showing a similar error. I thought updating it would give me better chances, but no luck.

Do you think you have any tips on this?

Thanks again for the help! Cheers

@alexandrethsilva alexandrethsilva changed the title error: unknown package 'Apollo' in dependencies of target 'Codegen' Swift Scripting: error: unknown package 'Apollo' in dependencies of target 'Codegen' Mar 29, 2020
@alexandrethsilva
Copy link
Author

As a sidenote, I've tried recreating the issue by adding some other package (e.g. SwifterSwift) as I reckon it should probably work the same for any package and it didn't error. 👀

image

@designatednerd
Copy link
Contributor

OK so I can see from the screenshots you fixed my first thought, which is that you need to be on 0.23.0 or higher, which is when the swift codegen stuff was released.

It won't work with 11.3.1 unless you're explicitly using the Swift 5.2 toolchain, since the swift-tools-version that comes with that is 5.1.

As far as I can tell, you've got things set up here mostly the same way I've got them in the SwiftScripts project's Package.swift, the only difference is that you're using the repo from a remote rather than from local. Since that's working fine, I'm not super-sure why yours isn't working.

I would try the obvious solutions (clean build, Derived Data Dance (quit xcode, delete derived data, reopen xcode, rebuild)). If none of that works let me know, I'll poke it some more.

@ordazgustavo
Copy link

Hi @designatednerd, I'm having the same problem, I tried the suggested "Derived Data Dance" but it still shows the same error :(

@designatednerd
Copy link
Contributor

@ordazgustavo

  1. To confirm, you are also using Xcode 11.4/Swift 5.2, correct?
  2. (also for @alexandrethsilva) Do you have the same issue if you pull off master instead of 0.24.0? Hoping to kick a new version out the door tomorrow with an update to the CLI, but would be useful to know if this problem still exists on master.

@ordazgustavo
Copy link

@designatednerd
That is correct, I'm using Xcode 11.4 and Swift 5.2

image

image

@alexandrethsilva
Copy link
Author

Hi @designatednerd, sorry for the late feedback and thanks for the quick reply on your side!

I tried doing the cleanups you suggested, but no luck. When pulling master I still get the same, even when doing it right after the cleanup.

image

On a sidenote, when I was on Xcode 11.3.1 I was indeed trying it with swift-tools 5.1, but was stuck with a very similar error (slightly different wording) as I mentioned. 😞

@alexandrethsilva
Copy link
Author

alexandrethsilva commented Mar 30, 2020

@designatednerd, @ordazgustavo it seems I figured it out after trying something rather obvious. 😬🎉

Apparently the problem is that the Package Name is not being automatically identified by the SPM and you have to add it manually. So, this worked:

image

I tried a number of combinations successfully after that, so all of these ran without problems for me:

.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", from: "0.23.0"),
.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", .exact("0.23.0")),
.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", from: "0.24.0"),
.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", .exact("0.24.0")),
.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", .branch("master")),

Sidenote for the unaware: .exact("0.22.0") doesn't work, but that's expected as you mentioned the first release with the feature is 0.23.0, so this would fail:

.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", .exact("0.22.0")),

But this works, as it ends up pulling 0.24.0 instead:

.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", from: "0.22.0"),

Quick question to @designatednerd: would you like me to open a PR updating the docs?

Cheers and thanks again!

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

3 participants