JamitLabs / Accio

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

Unable to successfully compile the sample project #71

Closed tin4g closed 5 years ago

tin4g commented 5 years ago

# OS
ProductName:    Mac OS X
ProductVersion: 10.14.5
BuildVersion:   18F132

# Xcode
Xcode 10.2.1
Build version 10E1001
iOS SDK 12.2

# Swift
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0

Procedure

  1. Create the sample project
$ mkdir -p SwiftDemo && cd SwiftDemo && swift package init --type library

(structures) =>
.
├── Package.swift
├── README.md
├── Sources
│   └── SwiftDemo
│       └── SwiftDemo.swift
└── Tests
    ├── LinuxMain.swift
    └── SwiftDemoTests
        ├── SwiftDemoTests.swift
        └── XCTestManifests.swift

4 directories, 6 files
  1. Add Alamofire as dependency
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "SwiftDemo",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "SwiftDemo",
            targets: ["SwiftDemo"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.0.0-beta.5"),
    ],
    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: "SwiftDemo",
            dependencies: ["Alamofire"]),
        .testTarget(
            name: "SwiftDemoTests",
            dependencies: ["SwiftDemo"]),
    ]
)
  1. Generate the Xcode project
$ swift package generate-xcodeproj
  1. Initialize Accio
$ accio init -p SwiftDemo -t SwiftDemo

(outputs) =>
⚠️  A non-empty Package.swift file already exists, skipping template based creation.
✨  Adding .gitignore entries for build & dependencies directories.
✨  Successfully initialized project.
  1. Install or update using Accio
$ accio install

(outputs) =>
Fetching https://github.com/Alamofire/Alamofire.git
Completed resolution in 40.34s
Cloning https://github.com/Alamofire/Alamofire.git
Resolving https://github.com/Alamofire/Alamofire.git at 5.0.0-beta.6
✨  Reading package manifest at ~/SwiftDemo/Package.swift ...
✨  Generating dependency graph ...
✨  Resolving dependencies for target 'SwiftDemo' on platform 'macOS' ...
✨  Found cached build products for Alamofire in local cache - skipping build.
✨  Resolving dependencies for target 'SwiftDemoTests' on platform 'macOS' ...
❌  DependencyGraph: Could not find library product with name 'SwiftDemo' in package manifest for project 'SwiftDemo'.
An error occurred: libraryNotFound

Solutions:

// Remove `SwiftDemo` from `SwiftDemoTests`'s dependencies

...
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: "SwiftDemo",
        dependencies: ["Alamofire"]),
    // .testTarget(
    //  name: "SwiftDemoTests",
    //  dependencies: ["SwiftDemo"]),
]
...

OR

#  Start over and change target to SwiftDemoPackageDescription
$ accio init -p SwiftDemo -t SwiftDemoPackageDescription
  1. Install or update using Accio again
$ accio update

(outputs) =>
✨  Reverting any changes in the checkouts directory ...
✨  Updating dependencies ...
Updating https://github.com/Alamofire/Alamofire.git
Completed resolution in 2.66s
Everything is already up-to-date
✨  Reading package manifest at ~/SwiftDemo/Package.swift ...
✨  Generating dependency graph ...
✨  Resolving dependencies for target 'SwiftDemo' on platform 'macOS' ...
✨  Found cached build products for Alamofire in local cache - skipping build.
✨  Copying build products of target 'SwiftDemo' into folder 'Dependencies' ...
✨  Adding frameworks ["Alamofire"] to project navigator group 'Dependencies/SwiftDemo' & linking with target 'SwiftDemo' ...
✨  Creating new copy build script phase 'Accio' for target 'SwiftDemo'...
✨  Updating input paths in copy build script phase 'Accio' for target 'SwiftDemo' ...
✨  Removing frameworks ["Package.swift"] from project navigator group 'Dependencies/Alamofire 5.0.0-beta.6' ...
✨  Removing empty groups ["Alamofire 5.0.0-beta.6"] from project navigator group 'Dependencies' ...
✨  Successfully updated dependencies.

Wanted

  1. Where can I find the SwiftDemo.Framework? (Or does the swift command line not support creating frameworks?)

  2. How do I compile for multiple platforms (iOS, watchOS and etc.) at once? ( If I don't manually modify the generated Xcode project.)

Thanks!

Jeehut commented 5 years ago

I think there's a general misunderstanding here. You are using Accio to handle your dependencies in a SwiftPM project. But actually, SwiftPM can do that already, there's no need to manage dependencies with Accio in SwiftPM projects. That's what SwiftPM already aims to do.

Accio is for apps targeting iOS, tvOS, macOS or watchOS to include dependencies that support either SwiftPM or Carthage. So all the questions you're asking are questions for the SwiftPM project itself and should probably be asked on a site like SO.

Does this clarify the situation for you? Or maybe I misunderstood something?

tin4g commented 5 years ago

Sorry, I misunderstood. Anyway, thank you. And I temporarily solved my problem with xcodebuild.