mono0926 / LicensePlist

A license list generator of all your dependencies for iOS applications
https://www.slideshare.net/mono0926/licenseplist-a-license-list-generator-of-all-your-dependencies-for-ios-applications
MIT License
2.43k stars 146 forks source link

Add '--swift-package-sources-path' option support #211

Closed vladvlasov256 closed 1 year ago

vladvlasov256 commented 1 year ago

Description

Xcode and xcodebuild resolve and check out Swift packages sources before building a project every time it's necessary. Sources include license files as well. Thus LicensePlist may rely not only on GitHub API but directly on the sources.

Motivation

In the sandbox mode, when the tool is used by the Swift package build tool plugin there is no way to use network requests. Using cloned sources is a workaround in this case.

Another example is a CI environment that builds apps with xcodebuild. The CI may specify a folder for cloned Swift package sources and use this folder for acknowledgments generation.

xcodebuild -clonedSourcePackagesDirPath ./SourcePackages ...
license-plist --swift-package-sources-path ./SourcePackages

By default Xcode clones package sources in a folder inside derived data. So it's not that simple to retrieve the path in case of regular Xcode usage.

Implementation

Reading licenses

Packages hold licenses in "LICENSE", "License", "LICENSE.md", or "LICENSE.txt" files. To read them the tool needs two pieces of data:

As a path to cloned sources, the tool uses --package-sources-path (or --swift-package-sources-path) parameter.

All possible license file names are also defined as a parameter whose name is --license-file-names. To simplify different path extensions let's support asterisks in names, ex. LICENSE.*.

Then if the path is specified PlistInfo reads licenses from disk instead of using GitHub API.

Name specified

One another feature that accesses GitHub is resolving nameSpecified. As suggested above, if the tool knows cloned sources path let's not fetch Package.resolved from GitHub but read it from disk.

Restriction

Unlike CocoaPods, Swift packages don't provide reach metadata. There are a couple of discussions on the swift forum about that but no proposals yet. Thus there is no simple way to determine the license type.

I was thinking about:

All these approaches involve too much overhead, in my opinion.

AFAIK, license type is required to filter out licenses using the exclude feature. So I added a warning that this feature is not supported in combination with --package-sources-path.

Fixes

mono0926 commented 1 year ago

@vladvlasov256

Thanks for the PR 🙏

Could you fix the failed test?

vladvlasov256 commented 1 year ago

Hi @mono0926

I believe the test is ok but it's referenced to the actual main branch. So it should be fine after the merge.

If I change the URL:

-        let url = try XCTUnwrap(URL(string: "https://raw.githubusercontent.com/mono0926/LicensePlist/master/Tests/LicensePlistTests/Resources/license_plist.yml"))
+        let url = try XCTUnwrap(URL(string: "https://raw.githubusercontent.com/vladvlasov256/LicensePlist/feature/checkout_path/Tests/LicensePlistTests/Resources/license_plist.yml"))

the test becomes green:

Green `testInit_sample()`

The same situation was in #207

mono0926 commented 1 year ago

@vladvlasov256

Thanks, released 👍 https://github.com/mono0926/LicensePlist/releases/tag/3.24.3