JamitLabs / Accio

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

Support modularization within app project #28

Closed Jeehut closed 5 years ago

Jeehut commented 5 years ago

Currently, Accio supports modularization of frameworks and using those in App projects. But sometimes one might want to modularize the app itself into several parts, for example consider this:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "App",
    products: [
        .library(name: "AppKit", targets: ["AppKit"])
    ],
    dependencies: [],
    targets: [
        .target(
            name: "App",
            dependencies: ["AppKit"],
            path: "App"
        ),
        .target(
            name: "AppKit",
            dependencies: [],
            path: "AppKit"
        ),
    ]
)

When we run accio update today with such a setup, we get this error output:

❌  DependencyGraph: Could not find library product with name 'AppKit' in package manifest for project 'App'.
Jeehut commented 5 years ago

Okay, after thinking about it a second time, I came to the conclusion that solving such situations by providing a local library is far too complicated and would result in too many issues. The much easier and less error prone fix for such situations is to add any helper modules to the "Target Dependencies" of the app target within Xcode without using Accio. Then, in the Package.swift file, make sure that all dependencies of the helper modules are also listed in the app target. For example:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "App",
    products: [
        .library(name: "AppKit", targets: ["AppKit"])
    ],
    dependencies: [/* ... */],
    targets: [
        .target(
            name: "App",
            dependencies: ["A", "B"],
            path: "App"
        ),
        .target(
            name: "AppKit",
            dependencies: ["A", "B"],
            path: "AppKit"
        ),
    ]
)

Unless someone has an idea of how this situation could be solved within Accio without making development a hassle (e.g. needing to re-run Accio each time a change is made in a module), I will mark this as "won't fix" and ask everyone running into this situation to accept the redundancy in specifying subdependencies. Note that the Package.swift is like any other Swift file and you could create a variable for the array of your modules dependencies to prevent any redundancy if you like.