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.42k stars 145 forks source link

Add Swift package plugins support #212

Closed vladvlasov256 closed 1 year ago

vladvlasov256 commented 1 year ago

Description

This PR adds three Swift package plugins for LicensePlist.

Build Tool Plugin

LicensePlistBuildTool allows using LicensePlist in "Run Build Tool Plug-ins" section in project build phases.

run_build_tool_plugins

Build tool plugins operate with product build directory files. For a common use case with Settings.bundle, it's impossible just to specify the output directory. An additional step is running a script in build phases that copy acknowledgments files:

ACKNOWLEDGEMENTS_DIR=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/com.mono0926.LicensePlist.Output
DESTINATION_PATH=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Settings.bundle/
cp -r ${ACKNOWLEDGEMENTS_DIR}/* ${DESTINATION_PATH}
rm -rf ${ACKNOWLEDGEMENTS_DIR}

To simplify the build tool plug-in setup, AddAcknowledgementsCopyScriptCommand has been added.

AddAcknowledgementsCopyScriptCommand

AddAcknowledgementsCopyScriptCommand automatically adds the script to copy files to Settings.bundle. The command is accessible in the project contextual menu and in the File -> Packages menu.

copy_script_command

GenerateAcknowledgementsCommand

Unlike automatic build phases, GenerateAcknowledgementsCommand allows users to manually run LicensePlist from Xcode.

generate_acknowledgements_command

Fixes

A few notes for @mono0926

The plugins depend on a binary artifact with the new functionality. Thus when PR is ready it will require you to upload a new artifact and update the binary target definition. Hopefully, it should work automatically with the release script.

Also, the previous issue exists with testInit_sample() because it depends on a new config example. Should be fixed automatically after the merge.

Link to an uploaded artifact from my branch for test purposes:

.binaryTarget(
  name: "LicensePlistBinary",
  url: "https://github.com/vladvlasov256/LicensePlist/releases/download/3.23.4/LicensePlistBinary-macos.artifactbundle.zip",
  checksum: "fcf92eea659387cbd95ff8ae92a3a3aa6666a0b6b2d78d30a1f30472b39e8c4e"
)
mono0926 commented 1 year ago

@vladvlasov256

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

spipau commented 1 year ago

This is great and thank you so much! 🥳

I would also suggest to update the Readme.md as this will probably be the future way to go. E.g. there is still

Warning SPM(Swift Package Manager) are not supported.

listed while further down there is a section on how to use it with SPM. If this really works well then I'd suggest to move it to the top and recommend SPM integration.

vladvlasov256 commented 1 year ago

SPM(Swift Package Manager) are not supported @spipau, as I understood, that means using LicensePlist inside a package is not supported. And this is true.

Even with this PR, GenerateAcknowledgementsCommand is not implemented for packages. It can be used only in Xcode project build phases.

And LicensePlist is most helpful for iOS/macOS projects, right? Because the guidelines tell us to provide the acknowledgments somehow.

I may be missing a case when acknowledgments are required for a package. Then it'll need a few lines of code to support SPM.

r00li commented 1 year ago

I was just trying to use this new feature in one of our projects and I think the binary that is included with the SPM package isn't built correctly for Intel macs. If I run the "GenerateAcknowledgementsCommand" manually I can see an error in Xcode with: "Bad CPU type in executable". And I get the same error if I try and run the binary manually from terminal.

I tried copying the portable binary from the releases page and replacing the included one with that. This one seems to be working fine.

acevif commented 1 year ago

@r00li Hi.

Could you create a new issue for it? Or I can create one referring to your comment above if you don't mind.

r00li commented 1 year ago

No problem. Issue created.

spipau commented 1 year ago

@vladvlasov256 apologies for the long silence but I am currently working on a release and had no time yet to further investigate. Back then I tried to set it up with the new plugin and failed, maybe because of the same reason as @r00li. I ran out of time and could not yet try it again.

Nevertheless, I guess this was a misunderstanding. I thought that in general LicensePlist doesn't support SPM. Maybe it was is the phrasing or I read all too fast. Of course, this lib only makes sense in applications and not packages.

Thanks for your amazing work! I just dropped the project a donation, enjoy your :beer: , :coffee: or :tea: !

Econa77 commented 1 year ago

@vladvlasov256 Thanks for the Plugin support. When I applied it to my own project, it seemed that the auto-generated file path and the source file path were specified differently.

Generated path:

/Users/{user_name}/Library/Developer/Xcode/DerivedData/{project_name}-ciujnnzdcobfnfayygxuttwqbkna/SourcePackages/plugins/{project_name}.output/{project_name}/LicensePlistBuildTool/com.mono0926.LicensePlist.Output

Copy from:

/Users/{user_name}/Library/Developer/Xcode/DerivedData/{project_name}-ciujnnzdcobfnfayygxuttwqbkna/Build/Products/Debug-iphonesimulator/{project_name}.app/com.mono0926.LicensePlist.Output

Is the script generated by AddAcknowledgedgementsCopyScriptCommand a temporary path?

vladvlasov256 commented 1 year ago

Hi @Econa77

Xcode plugins produce outputs in their sandboxes. In the case of LicensePlist it happens in: .../SourcePackages/plugins/{project_name}.output/{project_name}/LicensePlistBuildTool/com.mono0926.LicensePlist.Output

Next, in the build log you can see a message:

Copy com.mono0926.LicensePlist.Output 0.1 seconds

Xcode copies the result folder to the app folder. The path is: .../Build/Products/Debug-iphonesimulator/{project_name}.app/com.mono0926.LicensePlist.Output.

This happens automatically. So whatever a plugin generates Xcode copies as is to the result app folder. And this is a reason why AddAcknowledgedgementsCopyScriptCommand exists. The plugin might have generated Settings.bundle folder. But Xcode doesn't merge folders. It treats having two folders with the same name as a compilation issue.

Thus Settings.bundle lives in the project directory and the script copies the acknowledgments from the temporary folder.

Econa77 commented 1 year ago

@vladvlasov256 I understand. Thank you for your explanation.

My mistake seems to have been an error because I deleted Settings.bundle with the SPM migration and there was no copy destination. When I made the correct configuration, it was copied and worked without problems.