yonaskolb / XcodeGen

A Swift command line tool for generating your Xcode project
MIT License
6.88k stars 809 forks source link

`swift run xcodegen` fails #1440

Closed 417-72KI closed 4 months ago

417-72KI commented 5 months ago

I'm using XcodeGen as a package dependency like

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

import PackageDescription

let package = Package(
    name: "Tools",
    platforms: [.macOS(.v12)],
    products: [],
    dependencies: [
        .package(url: "https://github.com/yonaskolb/XcodeGen", from: "2.38.0"),
    ],
    targets: []
)

and run by a command like

xcrun --sdk macosx swift run --package-path Tools xcodegen

Recently, running this command fails by compile error.

/path/to/project/.build/checkouts/XcodeGen/Sources/XcodeGenKit/PBXProjGenerator.swift:313:20: error: cannot assign to property: 'packages' is a get-only property
        pbxProject.packages = packageReferences.sorted { $0.key < $1.key }.map { $1 }
        ~~~~~~~~~~~^~~~~~~~
[269/272] Compiling XcodeGenKit InfoPlistGenerator.swift
/path/to/project/.build/checkouts/XcodeGen/Sources/XcodeGenKit/PBXProjGenerator.swift:313:20: error: cannot assign to property: 'packages' is a get-only property
        pbxProject.packages = packageReferences.sorted { $0.key < $1.key }.map { $1 }
        ~~~~~~~~~~~^~~~~~~~
[270/272] Compiling XcodeGenKit PBXProjGenerator.swift
/path/to/project/.build/checkouts/XcodeGen/Sources/XcodeGenKit/PBXProjGenerator.swift:313:20: error: cannot assign to property: 'packages' is a get-only property
        pbxProject.packages = packageReferences.sorted { $0.key < $1.key }.map { $1 }
        ~~~~~~~~~~~^~~~~~~~
[271/272] Compiling XcodeGenKit ProjectGenerator.swift
/path/to/project/.build/checkouts/XcodeGen/Sources/XcodeGenKit/PBXProjGenerator.swift:313:20: error: cannot assign to property: 'packages' is a get-only property
        pbxProject.packages = packageReferences.sorted { $0.key < $1.key }.map { $1 }
        ~~~~~~~~~~~^~~~~~~~

It seems to be something changed in PBXProject class.

yonaskolb commented 4 months ago

This seems to be because XcodeProj introduced a breaking change in a minor release https://github.com/tuist/XcodeProj/pull/799 Packages used as dependencies don't use their Package.resolved, so XcodeProj updated to that version. You can fix it locally by including XcodeProj as a dependency with version 8.13.0.

We should fix this locally by updating and resolving the issue, but then making the version exact so this doesn't happen again in the future.