Skip to content
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

Merged
merged 26 commits into from
Mar 25, 2020
Merged

Support Local Swift Package by packages: #808

merged 26 commits into from
Mar 25, 2020

Conversation

freddi-kit
Copy link
Collaborator

@freddi-kit freddi-kit commented Mar 18, 2020

Summary

Add Support Local Swift Package as Dependency by packages
Related: #796
(Refer: #796 (comment))

What Changed?

  • Add Support packages: for Local Swift Package as Dependency
    • I added new format of packages: for local swift packages

So we can use local Swift Package by ...

name: GennedProj
...
packages:
  MyLibrary: 
    path: Packages/MyLibrary
targets:
  GennedProj:
    ...
    dependencies:
      - package: MyLibrary

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 by packages.

So I added the new format for packages.

New format of package

As I mentioned, I create new format of packages like ...

name: GennedProj
...
packages:
  MyLibrary: 
    path: Packages/MyLibrary
targets:
  GennedProj:
    ...
    dependencies:
      - package: Packages/MyLibrary

For Testing

You can test this Pull Request by it -> https://github.com/freddi-kit/TestRepoForXcodeGenPR

@freddi-kit
Copy link
Collaborator Author

freddi-kit commented Mar 18, 2020

@yonaskolb , Thank you for discussing new format of packages before. I have question about it.

[Q] Do we need to set old localPackages: as deprecated?

I asked because this new format will be replacement of localPackages.
It can be removed in the future. I also designed this PR as easy to remove decoding localPackages part.

@brentleyjones brentleyjones requested a review from yonaskolb March 18, 2020 14:27
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
Copy link
Owner

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

Copy link
Collaborator Author

@freddi-kit freddi-kit Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I'll do it.

However, it might be better to refer only #808 here. It is because localPackages:'s support will be removed in this PR and I want to prevent user's from being confused by not refering #796 .

- [ ] **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.
Copy link
Owner

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.

@@ -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`.
Copy link
Owner

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

targets:
App:
dependencies:
- package: Yams
- package: RxClient
```

## Local Swift Package
Copy link
Owner

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
Copy link
Owner

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

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)) }))
Copy link
Owner

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 {
Copy link
Owner

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) {
Copy link
Owner

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

Copy link
Collaborator Author

@freddi-kit freddi-kit Mar 19, 2020

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.

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"))]
Copy link
Owner

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:

Suggested change
project.packages = ["invalidLocalPackage" : SwiftPackage(kind: .local(path: "invalidLocalPackage"))]
project.packages = ["invalidLocalPackage" : .local(path: "invalidLocalPackage")]

],
"localPackages": ["../../Package"],
"localPackages": [
"package10": ["path": "../XcodeGen"]
Copy link
Owner

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") {
Copy link
Owner

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Idea!

@freddi-kit
Copy link
Collaborator Author

@yonaskolb Thank you for your reviewing, I added comments and fixes. I checked but please tell me if I miss something.

@freddi-kit freddi-kit requested a review from yonaskolb March 23, 2020 09:59
Copy link
Owner

@yonaskolb yonaskolb left a 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

Docs/ProjectSpec.md Outdated Show resolved Hide resolved
Co-Authored-By: Yonas Kolb <yonaskolb@users.noreply.github.com>
@yonaskolb yonaskolb merged commit e784ed7 into yonaskolb:master Mar 25, 2020
@freddi-kit
Copy link
Collaborator Author

Thank you, @yonaskolb !

@freddi-kit freddi-kit deleted the support-local-sp-with-packages branch March 25, 2020 00:21
@yonaskolb
Copy link
Owner

Released in 2.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants