LicenseGenerator-iOS icon indicating copy to clipboard operation
LicenseGenerator-iOS copied to clipboard

Add support for Swift Package Manager

Open carloe opened this issue 7 years ago • 10 comments

Should add support for SPM in addition to CocoaPods

carloe avatar Nov 09 '17 07:11 carloe

Would be happy to see this happen!

Schaefers avatar Oct 30 '19 13:10 Schaefers

You can just point directly at the path where SPM packages are downloaded:

./credits.py -s "$CONFIGURATION_BUILD_DIR/../../../SourcePackages/checkouts" -o "$SRCROOT/Credits.plist"

colejd avatar Sep 16 '20 18:09 colejd

But how to combine both? Cocoapods and SPM?

Update: Got it working by the changes from @colejd... Thanks for that!

chrizstone avatar Oct 06 '20 08:10 chrizstone

@chrizstone How did you manage it to work? Can you share? thanks

svoip avatar Nov 05 '20 15:11 svoip

@svoip Use my PR (#38), which lets you specify multiple paths as inputs. Then you can do something like this:

./credits.py -s "$SRCROOT, $CONFIGURATION_BUILD_DIR/../../../SourcePackages/checkouts" -o "$SRCROOT/Credits.plist"
  • $SRCROOT will let it find the license files for your pods
  • $CONFIGURATION_BUILD_DIR/../../../SourcePackages/checkouts will let it find the license files in your Swift packages. It's basically a weird way to access the DerivedData folder since I don't know a better way and there doesn't appear to be a macro for it.

(sorry @chrizstone, tagged you by mistake)

colejd avatar Nov 05 '20 15:11 colejd

Works great, thanks @colejd

svoip avatar Nov 05 '20 16:11 svoip

Hey-- Thanks! I've got this working with SPM now.

This is probably difficult but in one of my SPM dependencies, in its Package.swift, I make use of conditional dependencies:

            dependencies: [
                "ServerShared",
                // For new condition feature, see https://forums.swift.org/t/package-manager-conditional-target-dependencies/31306/26
                .product(name: "Kitura", package: "Kitura", condition: .when(platforms: [.linux, .macOS])),
                .product(name: "HeliumLogger", package: "HeliumLogger", condition: .when(platforms: [.linux, .macOS])),
                .product(name: "Credentials", package: "Kitura-Credentials", condition: .when(platforms: [.linux, .macOS])),
            ],

however, at least with Xcode, it looks like all checkout are done first (i.e., to $CONFIGURATION_BUILD_DIR/../../../SourcePackages/checkouts), and then the conditional rules are applied. So while my iOS app doesn't actually use some of the packages, they show up in my Acknowledgements. Not a big deal. Just makes for an inflated Acknowledgements in my Settings for the app.

Cheers!

crspybits avatar Jan 01 '21 18:01 crspybits

Yeah, this looks to be SPM's behavior so it'd need to be changed by the Swift team. You could evaluate the Package.swift using this repo's Python script somehow, then ignore the corresponding directories that don't match, but that does sound like a lot of work.

colejd avatar Jan 02 '21 03:01 colejd

It looks like this path $CONFIGURATION_BUILD_DIR/../../../SourcePackages/checkouts doesn't work when archiving with Xcode. I get:

Showing All Messages
Error: Invalid source path: /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/ArchiveIntermediates/Neebla/BuildProductsPath/Release-iphoneos/../../../SourcePackages/checkouts

Command PhaseScriptExecution failed with a nonzero exit code

A workaround is to put a conditional around it like:

if [ "${CONFIGURATION}" != "Release" ]; then
  ./credits.py -s "$SRCROOT, $CONFIGURATION_BUILD_DIR/../../../SourcePackages/checkouts" -o "$SRCROOT/Credits.plist"
fi

Seems a bit of a hack though. And if you really want to generate the credits on an archive, wouldn't be suitable.

crspybits avatar Jan 29 '21 07:01 crspybits