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

Fix spm licenses gen #150

Merged
merged 19 commits into from
Apr 9, 2021
Merged

Fix spm licenses gen #150

merged 19 commits into from
Apr 9, 2021

Conversation

yosshi4486
Copy link
Contributor

@yosshi4486 yosshi4486 commented Apr 6, 2021

About

I fixed swift package license's generation issue.

What happen?

I had encountered issue that LicensePlist doesn't generate swift package licenses.

Why does the problem occur?

Xcode has its own project.xcworkspace in its subdirectory, and developer can add additional xcworkspace, in most cases it is via Cocoapods.

Reason

Either project.xcworkspace's Package.resolved or YourAdded.xcworkspace's Package.resolved is updated. Not both. Implementation of swift package integration in this repository didn't care the behavior, so old Package.resolved is referred in some situations.

How did you solve it?

Compare modification dates of these files.
(Sources/LicensePlistCore/Entity/FileReader/XcodeProjectFileReader.swift)

guard
    let xcodeprojPackageResolvedModifiedDate = try xcodeprojPackageResolvedPath
        .resourceValues(forKeys: [.attributeModificationDateKey])
        .attributeModificationDate,
    let xcworkspacePackageResolveModifiedDate = try xcworkspacePackageResolvedPath
        .resourceValues(forKeys: [.attributeModificationDateKey])
        .attributeModificationDate
else {
    return try SwiftPackageFileReader(path: defaultPath).read()
}

if xcworkspacePackageResolveModifiedDate >= xcodeprojPackageResolvedModifiedDate {
    return try SwiftPackageFileReader(path: xcworkspacePackageResolvedPath).read()
} else {
    return try SwiftPackageFileReader(path: xcodeprojPackageResolvedPath).read()
}

How did you implement it?

  1. Add test xcode project under Tests/LicensePlistTests/XcodeProjects.
  2. Refactor private "readXxx" methods to FileReader objects for improving testability.
  3. Test them.
  4. Fix the problem.

Who encounter the problem?

A developer who used swift package in early stage of product development, and added cocoapods integration later.

Review Points

🙅‍♂️Changes from Tests/LicensePlistTests/XcodeProjects are not important, They are only test resource files.
🙆‍♂️Changes from Sources/LicensePlistCore/Entity/FileReader and Tests/LicensePlistTests/Entity/FileReader are important. They are core implementations and tests about this PR.

Pass tests?

I run all tests locally by cmd +U.

Related issues?

#140

Other things?

If maintainers allow the refactoring of FileReader, I'd like to rewrite other "readXxx" functions in next pr.

@mono0926
Copy link
Owner

mono0926 commented Apr 7, 2021

@yosshi4486

Thank you, I'll check tomorrow.

Copy link
Owner

@mono0926 mono0926 left a comment

Choose a reason for hiding this comment

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

@yosshi4486

How do you handle this error?

image

And, swiftlint warnings exist. Could you fix that?

swiftlint result
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths 
Linting 'main.swift' (1/55)
Linting 'Consts.swift' (2/55)
Linting 'SearchRequests.swift' (3/55)
Linting 'RepoRequests.swift' (4/55)
Linting 'Extensions.swift' (5/55)
Linting 'GitHubRequest.swift' (6/55)
Linting 'String.extension.swift' (7/55)
Linting 'CocoaPodsLicense.swift' (8/55)
Linting 'Options.swift' (9/55)
Linting 'Manual.swift' (10/55)
Linting 'Library.swift' (11/55)
Linting 'ResultOperation.swift' (12/55)
Linting 'APIKit.extension.swift' (13/55)
Linting 'HasName.swift' (14/55)
Linting 'URL.extension.swift' (15/55)
Linting 'LicensePlistHolder.swift' (16/55)
Linting 'Config.swift' (17/55)
Linting 'GitHubLibraryConfigFile.swift' (18/55)
Linting 'PlistInfo.swift' (19/55)
Linting 'ManualLicense.swift' (20/55)
Linting 'LicenseHTMLHolder.swift' (21/55)
Linting 'CocoaPods.swift' (22/55)
Linting 'VersionInfo.swift' (23/55)
Linting 'GitHubLicense.swift' (24/55)
Linting 'License.swift' (25/55)
Linting 'LicenseMarkdownHolder.swift' (26/55)
Linting 'GitHub.swift' (27/55)
Linting 'SwiftPackage.swift' (28/55)
Linting 'XcodeProjectFileReader.swift' (29/55)
Linting 'SwiftPackageFileReader.swift' (30/55)
Linting 'FileReader.swift' (31/55)
Linting 'Logger.swift' (32/55)
Linting 'Shell.swift' (33/55)
Linting 'LicensePlist.swift' (34/55)
/Users/mono/Git/LicensePlist/Sources/LicensePlistCore/Entity/FileReader/XcodeProjectFileReader.swift:10:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
Linting 'ViewController.swift' (35/55)
Linting 'AppDelegate.swift' (36/55)
Linting 'SceneDelegate.swift' (37/55)
Linting 'URL.extensionTests.swift' (38/55)
Linting 'RepoRequestsTests.swift' (39/55)
Linting 'SearchRequestsTests.swift' (40/55)
Linting 'ConfigTests.swift' (41/55)
Linting 'GitHubLibraryConfigFileTests.swift' (42/55)
Linting 'LicensePlistHolderTests.swift' (43/55)
Linting 'PlistInfoTests.swift' (44/55)
Linting 'GitHubLibraryConfigFileTypeTests.swift' (45/55)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/SceneDelegate.swift:52:1: warning: Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/SceneDelegate.swift:19:19: warning: Unused Optional Binding Violation: Prefer `!= nil` over `let _ =` (unused_optional_binding)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/SceneDelegate.swift:14:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/SceneDelegate.swift:50:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/ViewController.swift:19:1: warning: Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/ViewController.swift:17:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
Linting 'CocoaPodsTests.swift' (46/55)
Linting 'LicenseTests.swift' (47/55)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/AppDelegate.swift:36:1: warning: Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/AppDelegate.swift:14:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 3. (vertical_whitespace)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject/AppDelegate.swift:34:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
Linting 'SwiftPackageManagerTests.swift' (48/55)
Linting 'GitHubTests.swift' (49/55)
Linting 'GitHubLicense.collectorTests.swift' (50/55)
Linting 'VersionInfoTests.swift' (51/55)
Linting 'TestUtil.swift' (52/55)
Linting 'XcodeProjectFileReaderTests.swift' (53/55)
Linting 'SwiftPackageFileReaderTests.swift' (54/55)
Linting 'ResultOperationTests.swift' (55/55)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/TestUtil.swift:6:1: warning: Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/Entity/FileReader/XcodeProjectFileReaderTests.swift:45:5: warning: Function Body Length Violation: Function body should span 40 lines or less excluding comments and whitespace: currently spans 67 lines (function_body_length)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/Entity/FileReader/XcodeProjectFileReaderTests.swift:116:5: warning: Function Body Length Violation: Function body should span 40 lines or less excluding comments and whitespace: currently spans 76 lines (function_body_length)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/Entity/FileReader/XcodeProjectFileReaderTests.swift:196:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
/Users/mono/Git/LicensePlist/Tests/LicensePlistTests/Entity/FileReader/XcodeProjectFileReaderTests.swift:215:1: warning: Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
Done linting! Found 15 violations, 0 serious in 55 files.

As for SwiftPackageManagerTestProject, it can be ignored by specifying like this at swiftlint.yml.

excluded:
  - Tests/LicensePlistTests/XcodeProjects/SwiftPackageManagerTestProject

@yosshi4486
Copy link
Contributor Author

yosshi4486 commented Apr 8, 2021

@mono0926 Thanks for comments.
I exclude XcodeProjects directory from testTarget and lint in last two commits.
(and I rebase commits to remove unnecessary my xcuserdata directory)

name: "LicensePlistTests",
dependencies: ["LicensePlistCore"],
exclude: [
"XcodeProjects"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could exclude the test xcode-projects directory by specifying it in Package.swift.

@yosshi4486 yosshi4486 requested a review from mono0926 April 8, 2021 09:15
@yosshi4486
Copy link
Contributor Author

@mono0926 Thank you! I've fixed things you reviewed yesterday.

@mono0926 mono0926 merged commit d9016ef into mono0926:master Apr 9, 2021
@mono0926 mono0926 linked an issue Apr 9, 2021 that may be closed by this pull request
@mono0926
Copy link
Owner

mono0926 commented Apr 9, 2021

@yosshi4486
Thanks for your work 🙏

@yosshi4486 yosshi4486 deleted the fix-spm-licenses-gen branch April 9, 2021 05:25
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.

Wrong Docs regarding Package.swift
2 participants