JamitLabs / Accio

A dependency manager driven by SwiftPM that works for iOS/tvOS/watchOS/macOS projects.
MIT License
664 stars 32 forks source link

No dependencies specified for target ... #72

Closed yoiang closed 5 years ago

yoiang commented 5 years ago

Hello! I'm excited to use Accio and I've started converting a project over to using SwiftPM's Package.swift to be able to.

However one of the dependencies of the project can't be resolved automatically (it doesn't use default folder structure, has targets using overlapping source...). I've tried creating a simple Package.swift to specify custom source folders (and only support one target 🙄) but it seems SwiftPM requires my target have at least one dependency. When I test the dependency's Package.swift file against Accio I get this:

❯ accio install
✨  Reverting any changes in the checkouts directory ...
✨  Resolving dependencies ...
✨  Reading package manifest at /Users/ian/Documents/Adorkable/Eunomia/Package.swift ...
✨  Generating dependency graph ...
⚠️  No dependencies specified for target 'Eunomia-iOS'. Please add at least one dependency scheme to the 'dependencies' array of the target in Package.swift.
Error: The file “Package.resolved” couldn’t be opened because there is no such file.

For reference the dependency can be found here.

This is likely more a lack of understanding of how I should be writing for SwiftPM and me not fully grasping its usage, let me know if this is the right or wrong place to have this discussion.

Jeehut commented 5 years ago

@yoiang Hey, thanks for asking the question. Sure, I will try to help you, although usually such questions should be asked on sites like StackOverflow (where it's easier for people to find the answer later) – but here's also okay.

To understand the problem at hand, let me differentiate between two different kinds of Package.swift manifest files: App Manifest (AM) files and Dependency Manifest (DM) files.

AMs always look like this (copied from the README):

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "XcodeProjectName",
    products: [],
    dependencies: [
        .package(url: "https://github.com/Flinesoft/HandySwift.git", from: "2.8.0"),
        .package(url: "https://github.com/Flinesoft/HandyUIKit.git", from: "1.9.1"),
        .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", from: "1.6.2"),
        .package(url: "https://github.com/radex/SwiftyUserDefaults.git", from: "4.0.0"),
    ],
    targets: [
        .target(
            name: "AppTargetName",
            dependencies: [
                "HandySwift",
                "HandyUIKit",
                "SwiftyBeaver",
                "SwiftyUserDefaults",
            ],
            path: "AppTargetName"
        ),
    ]
)

Please note that AMs are placed within your App project (e.g. iOS project) in the root and usually created with the accio init command. Their goal is to specify which targets of your project have which dependency requirements.

Next, there's DMs which can look different depending on the structure of the dependency. E.g.:

// swift-tools-version:4.2
import PackageDescription

let package = Package(
    name: "LibraryName",
    // platforms: [.iOS("8.0"), .macOS("10.10"), .tvOS("9.0"), .watchOS("2.0")],
    products: [
        .library(name: "LibraryName", targets: ["LibraryName"])
    ],
    targets: [
        .target(
            name: "LibraryName",
            path: "LibraryName"
        )
    ]
)

This is an example DM of a dependency which doesn't have any subdependencies. The linked project (Eunomia) doesn't have any subdependencies, so a structure like this should be fine for it. If it had dependencies, then (and only then) you would need to define dependencies, which then could look something like this:

// swift-tools-version:4.2
import PackageDescription

let package = Package(
    name: "LibraryName",
    // platforms: [.iOS("8.0"), .macOS("10.10"), .tvOS("9.0"), .watchOS("2.0")],
    products: [
        .library(name: "LibraryName", targets: ["LibraryName"])
    ],
    dependencies: [
        .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "4.1.0")),
        .package(url: "https://github.com/antitypical/Result.git", .upToNextMajor(from: "4.0.0")),
    ],
    targets: [
        .target(
            name: "LibraryName",
            dependencies: ["Alamofire", "Result"],
            path: "LibraryName"
        )
    ]
)

I hope this clarifies things a little. But unfortunately I couldn't find a fork of the linked Eunomia project in order to check if anything's wrong with your manifest. Please, could you both post the DM of the dependency and also your AM contents of your app, so I could help better?

yoiang commented 5 years ago

It does! It means I was creating the DM Package.swift correctly (now pushed into https://github.com/Adorkable/Eunomia/tree/feature/SwiftPM), I was receiving this error running Accio in the dependency root to validate it's format locally before pushing it but I guess SwiftPM/Accio install isn't really the right method. Is there a method for testing/linting a DM Package.swift locally?

However from my main project's Package.swift I am now getting: Error: The operation couldn’t be completed. (XcodeProj.XCodeProjError error 1.) after it generates the full dependency graph.

The full file for the project's own framework (with name redactions) is:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "ProjectFramework",
    products: [
        .library(name: "ProjectFramework", targets: ["ProjectFramework"]),
    ],
    dependencies: [
        .package(url: "https://github.com/Adorkable/Eunomia.git", .branch("feature/SwiftPM")),
        .package(url: "https://github.com/Adorkable-forkable/KeyboardAdjuster.git", .branch("feature/SwiftPM")),
        .package(url: "https://github.com/Adorkable-forkable/FontAwesome.swift.git", .branch("feature/SwiftPM")),
    ],
    targets: [
        .target(
            name: "ProjectFramework",
            dependencies: [
                "Eunomia",
                "KeyboardAdjuster",
                "FontAwesome"
            ],
            path: "ProjectFramework"
        ),
    ]
)

Aside, does an AM require a .executable product?

yoiang commented 5 years ago

I figured it out, unknown to me some tool added *.xcodeproj to the .gitignore therefore my project was missing its contents. Thanks for your help!