-
Notifications
You must be signed in to change notification settings - Fork 823
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
Support Local Swift Package by packages:
#808
Support Local Swift Package by packages:
#808
Conversation
@yonaskolb , Thank you for discussing new format of [Q] Do we need to set old I asked because this new format will be replacement of |
CHANGELOG.md
Outdated
@@ -3,6 +3,7 @@ | |||
## Next Version | |||
|
|||
#### Added | |||
- Add support non-mirrored local Swift Packages in `packages`. [#808](https://github.com/yonaskolb/XcodeGen/pull/808) @freddi-kit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge these 2 entries as they will be released together, with references to both PRs
Add support for local Swift Packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs/ProjectSpec.md
Outdated
- [ ] **packages**: **[String: [Swift Package](#swift-package)]** - a map of Swift packages by name | ||
- [ ] **localPackages**: **[String: [Local Swift Package](#local-swift-package)]** - a map of local Swift packages by name. The paths must be directories with a `Package.swift` file in them. If same name remote repo is listed in `packages`, remote repo will be overridden to a local version in `localPackages` for development purposes. | ||
- [ ] **packages**: **[String: [Swift Package](#swift-package)]** - a map of Swift packages by name. The paths must be directories with a `Package.swift` file if specified as local package by `path`. | ||
- [ ] **localPackages**: **[String: [Local Swift Package](#local-swift-package)]** - a map of local Swift packages by name. This is same with local package at **packages** by `path`. The paths must be directories with a `Package.swift` file in them. If same name remote repo is listed in `packages`, the repo will be overridden to a package in `localPackages` for development purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this localPackages section, and the LocalPackage
struct itself. When parsing we can still support the [String]
from the existing version. No need to support LocalPackage
though.
Docs/ProjectSpec.md
Outdated
@@ -49,8 +49,8 @@ You can also use environment variables in your configuration file, by using `${S | |||
- [ ] **fileGroups**: **[String]** - A list of paths to add to the root of the project. These aren't files that will be included in your targets, but that you'd like to include in the project hierachy anyway. For example a folder of xcconfig files that aren't already added by any target sources, or a Readme file. | |||
- [ ] **schemes**: **[Scheme](#scheme)** - A list of schemes by name. This allows more control over what is found in [Target Scheme](#target-scheme) | |||
- [ ] **targetTemplates**: **[String: [Target Template](#target-template)]** - a list of targets that can be used as templates for actual targets which reference them via a `template` property. They can be used to extract common target settings. Works great in combination with `include`. | |||
- [ ] **packages**: **[String: [Swift Package](#swift-package)]** - a map of Swift packages by name | |||
- [ ] **localPackages**: **[String: [Local Swift Package](#local-swift-package)]** - a map of local Swift packages by name. The paths must be directories with a `Package.swift` file in them. If same name remote repo is listed in `packages`, remote repo will be overridden to a local version in `localPackages` for development purposes. | |||
- [ ] **packages**: **[String: [Swift Package](#swift-package)]** - a map of Swift packages by name. The paths must be directories with a `Package.swift` file if specified as local package by `path`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave this comment to the #swift-package
section
Docs/ProjectSpec.md
Outdated
targets: | ||
App: | ||
dependencies: | ||
- package: Yams | ||
- package: RxClient | ||
``` | ||
|
||
## Local Swift Package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this whole section
targets: | ||
App: | ||
dependencies: | ||
# by default the package product that is linked to is the same as the package name | ||
- package: Yams | ||
- package: SwiftPM | ||
- package: RxClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't add a comment but lets remove the You can also include local Swift Packages by referencing them by paths...
section below
Sources/ProjectSpec/Project.swift
Outdated
self.localPackages = localPackages.reduce(into: [String: LocalSwiftPackage](), { $0[$1] = LocalSwiftPackage(path: $1) }) | ||
} else { | ||
self.localPackages = [:] | ||
packages.merge(localPackages.reduce(into: [String: SwiftPackage](), { $0[$1] = SwiftPackage(kind: .local(path: $1)) })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use the last path component as the name
@@ -7,24 +7,38 @@ public struct SwiftPackage: Equatable { | |||
|
|||
public typealias VersionRequirement = XCRemoteSwiftPackageReference.VersionRequirement | |||
|
|||
public let url: String | |||
public let versionRequirement: VersionRequirement | |||
public enum Kind: Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just make the whole SwiftPackage
the enum, without a need for a Kind
@@ -802,7 +803,7 @@ public class PBXProjGenerator { | |||
|
|||
// If package's reference is none and there is no specified package in localPackages, | |||
// then ignore the package specified as dependency. | |||
if packageReference == nil, !project.localPackages.keys.contains(dependency.reference) { | |||
if packageReference == nil, !localPackageReferences.contains(dependency.reference) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still work? Can you have just a local Package with a path, without having an actual remove and then a mirrored local package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work as is. In the first place, this validation should always be false
because of project validation at SpecValidation.swift
↓.
This validation is insurance to not generate invalid projects, I think.
XcodeGen/Sources/ProjectSpec/SpecValidation.swift
Lines 176 to 178 in 59ab223
if packages[dependency.reference] == nil, localPackages[dependency.reference] == nil { | |
errors.append(.invalidSwiftPackage(name: dependency.reference, target: target.name)) | |
} |
note) localPackages
is merged into packages
at this PR
@@ -97,7 +97,7 @@ class ProjectSpecTests: XCTestCase { | |||
project.settings = invalidSettings | |||
project.configFiles = ["invalidConfig": "invalidConfigFile"] | |||
project.fileGroups = ["invalidFileGroup"] | |||
project.localPackages = ["invalidLocalPackage" : LocalSwiftPackage(path: "invalidLocalPackage")] | |||
project.packages = ["invalidLocalPackage" : SwiftPackage(kind: .local(path: "invalidLocalPackage"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once SwiftPackage.Kind
is removed and SwiftPackage
becomes the enum, this because simpler throughout:
project.packages = ["invalidLocalPackage" : SwiftPackage(kind: .local(path: "invalidLocalPackage"))] | |
project.packages = ["invalidLocalPackage" : .local(path: "invalidLocalPackage")] |
], | ||
"localPackages": ["../../Package"], | ||
"localPackages": [ | ||
"package10": ["path": "../XcodeGen"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this way of specifying local packages
url = try jsonDictionary.json(atKeyPath: "url") | ||
versionRequirement = try VersionRequirement(jsonDictionary: jsonDictionary) | ||
try validateVersion() | ||
if let url: String = jsonDictionary.json(atKeyPath: "url") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's reverse this so if path
is present, parse as local, otherwise remote. This let's people simply add a path to a remote definition to temporarily make it local, without having to remove url and version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Idea!
- Also, added Comment
@yonaskolb Thank you for your reviewing, I added comments and fixes. I checked but please tell me if I miss something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @freddi-kit! I'll merge and do a release once we fix the last very minor copy change above
Co-Authored-By: Yonas Kolb <yonaskolb@users.noreply.github.com>
Thank you, @yonaskolb ! |
Released in 2.15.0 |
Summary
Add Support Local Swift Package as Dependency by
packages
Related: #796
(Refer: #796 (comment))
What Changed?
packages:
for Local Swift Package as Dependencypackages:
for local swift packagesSo we can use local Swift Package by ...
note) This PR still keeps old formats of
localPackages
Motivation
As we discussed at here, it might be better to support local packages not only by
localPackages
but also bypackages
.So I added the new format for
packages
.New format of
package
As I mentioned, I create new format of
packages
like ...For Testing
You can test this Pull Request by it -> https://github.com/freddi-kit/TestRepoForXcodeGenPR