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

Swift Package fixes #444

Merged
merged 6 commits into from
Jun 16, 2019
Merged

Swift Package fixes #444

merged 6 commits into from
Jun 16, 2019

Conversation

yonaskolb
Copy link
Collaborator

@yonaskolb yonaskolb commented Jun 7, 2019

  • makes some properties in the new swift package classes public and in the inits so they can be used in other tools
  • adds the .swiftpm directory to .gitignore for when opening the Package.swift in Xcode 11
  • make PBXProject.packages and PBXTarget.packageProductDependencies
    • public
    • non optional
    • available in init

@codecov
Copy link

codecov bot commented Jun 7, 2019

Codecov Report

Merging #444 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #444   +/-   ##
=======================================
  Coverage   80.37%   80.37%           
=======================================
  Files         149      149           
  Lines        7635     7635           
=======================================
  Hits         6137     6137           
  Misses       1498     1498
Impacted Files Coverage Δ
...SwiftPackage/XCSwiftPackageProductDependency.swift 93.75% <ø> (ø) ⬆️
...s/SwiftPackage/XCRemoteSwiftPackageReference.swift 87% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72657d8...bb25dc6. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 7, 2019

Codecov Report

Merging #444 into master will increase coverage by 0.02%.
The diff coverage is 76.47%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #444      +/-   ##
=========================================
+ Coverage   80.37%   80.4%   +0.02%     
=========================================
  Files         149     149              
  Lines        7635    7635              
=========================================
+ Hits         6137    6139       +2     
+ Misses       1498    1496       -2
Impacted Files Coverage Δ
...SwiftPackage/XCSwiftPackageProductDependency.swift 93.75% <ø> (ø) ⬆️
...s/SwiftPackage/XCRemoteSwiftPackageReference.swift 87% <100%> (ø) ⬆️
Sources/xcodeproj/Utils/ReferenceGenerator.swift 86.43% <100%> (ø) ⬆️
Sources/xcodeproj/Objects/Project/PBXProject.swift 64.43% <62.5%> (+0.84%) ⬆️
Sources/xcodeproj/Objects/Targets/PBXTarget.swift 72.22% <83.33%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72657d8...22215cc. Read the comment docs.

@yonaskolb
Copy link
Collaborator Author

I don't like that Danger requires a changelog. Many things don't require an entry, and some PR's like this aren't new features they are just fixing what is in a previous one that has not been released yet

@yonaskolb yonaskolb requested a review from pepicrft June 8, 2019 00:03
@yonaskolb
Copy link
Collaborator Author

yonaskolb commented Jun 8, 2019

@pepibumur was there a reason that XCRemoteSwiftPackageReference.VersionRules isn't called XCRemoteSwiftPackageReference.Requirement like the actual encoded property name?
Having a plural as a type name is also a bit strange

@@ -125,15 +125,15 @@ public final class PBXProject: PBXObject {
}

/// Package references.
var packageReferences: [PBXObjectReference]?
Copy link
Contributor

Choose a reason for hiding this comment

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

What we've been doing for deciding whether a property should be optional or not is whether Xcode is able to open a project without that attribute. If I'm not wrong, Xcode is able to open a project that doesn't have this attribute. If that's the case, I'd keep this property as optional. It also ensures that we are not adding attributes to Xcode 10 projects that are are not readable by Xcode 10.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just changed it to an empty array if there is nothing to decode, and only encode if there's something in it. I'm not sure I understand you, does this mess up a specific use case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd say this change makes sense - optional arrays are often troubling when it comes to accessing their contents. I can't see a situation where this will cause a problem.

If you want to check the presence of a package inside the Xcodeproj it's possible to by calling packageReferences.count > 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's take the following scenario:

  • The user edits a Xcode project that doesn't have the packageReferences attribute.
  • We decode the attribute to an empty array.
  • After saving the project, the user will see in the diff that a new attribute is added.

Xcode 10.x will ignore the attribute, but we are introducing unexpected modifications to the project. That's something we've always avoided, and I don't think it's solvable by not writing the array when it's empty, because that's another possible value for the attribute.

If I'm not wrong, I think Xcode 11 updates some attribute in the project to say that the project is compatible with version X of Xcode. What about using that value to decide whether the attribute should be written or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pepibumur What do you mean by attribute? The packageReferences? If the array is empty we don't write it to the project, exactly as if it was nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, let me put it on a table:

Project in disk Read project Diff?
No packageReferences Empty packageReferences Yes
Empty packageReferences Empty packageReferences No
Non-empty packageReferences Non-empty packageReferences No

By turning nil into an empty array we'll get a diff after writing the project to disk in the first scenario.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume'd we wouldn't write Empty packageReferences. Is there a benefit to doing so? If we assume empty means we don't write it then we don't have to worry about the truth table above since we only handle two scenarios, empty and non-empty

Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't any difference for Xcode. The point is that users don't want to see git diffs if the project hasn't been modified, and with the current implementation they will. I suggest the following modification:

// This one remains optional
var packageReferences: [PBXObjectReference]?

// We define this one as non-optional
public var packages: [XCRemoteSwiftPackageReference] {
  set {
    packageReferences = newValue.references()
  }
  get {
     return packageReferences.objects() ?? []
  }
}

Does that look good @ollieatkinson / @yonaskolb ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense - 👍

@@ -111,17 +111,17 @@ public class XCRemoteSwiftPackageReference: PBXContainerItem, PlistSerializable
}

/// Repository url.
var repositoryURL: String?
public var repositoryURL: String?
Copy link
Contributor

Choose a reason for hiding this comment

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

Ouch! Good catch

ollieatkinson
ollieatkinson previously approved these changes Jun 8, 2019
@ollieatkinson
Copy link
Collaborator

I don't like that Danger requires a changelog. Many things don't require an entry, and some PR's like this aren't new features they are just fixing what is in a previous one that has not been released yet

As far as I'm aware the Danger rule is a warning for the CHANGELOG file - not a requirement for merge. Is that not the case?

@pepicrft
Copy link
Contributor

pepicrft commented Jun 8, 2019

That's why Danger is a warning and not erroring. We can't determine whether changes need documentation. The developer opening the PR is responsible for making the call here.

@pepicrft pepicrft mentioned this pull request Jun 10, 2019
6 tasks
@pepicrft
Copy link
Contributor

@pepibumur was there a reason that XCRemoteSwiftPackageReference.VersionRules isn't called XCRemoteSwiftPackageReference.Requirement like the actual encoded property name?
Having a plural as a type name is also a bit strange

I used the name that Xcode uses but you are right, it makes more sense to use the name of the property in the project. I'll update it.

@pepicrft pepicrft merged commit 59b3f09 into master Jun 16, 2019
@pepicrft pepicrft deleted the spm_fixes branch June 16, 2019 18:42
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.

3 participants