SwiftGenPlugin icon indicating copy to clipboard operation
SwiftGenPlugin copied to clipboard

Add XcodePlugin support

Open tboogh opened this issue 2 years ago • 29 comments

First thanks for the awesome addition of a build plugin!

This PR is pretty basic and just cope-pastes the existing code with a few modifications to add support for Xcode 14 XcodeProject build plugins.

I tried to keep as much as possible, one thing I'm unsure about is the PRODUCT_MODULE_NAME which I couldn't find a counterpart to.

tboogh avatar Sep 09 '22 17:09 tboogh

I'm not in a position to review this PR, but I'd like a solution to the problem that this PR seeks to solve. Wether that is accepting this as-is or moving it forward in some direction, I don't know.

Can someone please either merge, or give feedback so this can move forward?

sveinhal avatar Oct 04 '22 08:10 sveinhal

@djbe can this PR get some ❤️ ?

scsinke avatar Oct 12 '22 09:10 scsinke

I'd like to see this merged. I've confirmed the PRODUCT_MODULE_NAME environment variable would be available to SwiftGen without being explicitly configured (I modified the value in my project file's build settings to distinguish it from the target / product name).

It would also be good to update the command plugin to support Xcode projects but one step at a time!

knellr avatar Oct 26 '22 01:10 knellr

I hope it will be integrated soon 👍 I've tried your branch but I couldn't find a way to make the generation work. The yaml is in root folder, and works when using command line. (I couldn't find the log of the plugin execution, do you have any idea where it can be found?)

st4rrk avatar Nov 02 '22 17:11 st4rrk

This works as expected for me:

  1. Add the Package Plugin from the branch locally to Xcode image
  2. Add the Package Plugin as a Build Tool Plugin image
  3. Verified that it works when changing the Localizable.strings file image

Would love to see this merged.

pietbrauer avatar Nov 02 '22 19:11 pietbrauer

I think the difference is that I forked his projet and used the remote reference of the plugin module in xCode, I was not using it locally. 🤔 Is it thought to be integrated locally? And do you know how to check the plugin logs in case of a problem? (btw xCode 14.1 resolves the cpu usage problem (in case you were using it locally because of that))

st4rrk avatar Nov 03 '22 10:11 st4rrk

For more details

The xCode hierarchy:

xcode file manager

The yaml conf:

yaml file

The working command line:

command line

Then I use the plugin: launch plugin

Here I tried both, not sure which one I am supposed to use tho

choose target

Finally, the xCode plugin command is running:

xCode Command is running

(the file Generated string file was previously emptied again, to ensure the plugin does the job)

But here I'm blocked, because the command looks like it runs and works, but my file still end up being empty. Any insight?

ps: I also tried to put the yaml inside the LocasliationExploration folder instead of root, but still same results

ps2: adding the plugin as pietbrauer did in the Build Phrases -> Run Build Tool Plug-ins DOES WORK, so it looks like only the instanciation from the Project Navigator isn't working? (but these are different usage :/ )

st4rrk avatar Nov 03 '22 10:11 st4rrk

@st4rrk have you tried adding the ${DERIVED_SOURCES_DIR}/ prefix to your output files or output_dir in the yml as described in the README? https://github.com/SwiftGen/SwiftGenPlugin#add-a-swiftgen-config

knellr avatar Nov 03 '22 16:11 knellr

@knellr I try to generate code into the xcodeproj's location (in the "Generated/" folder idealy), so that I can track it with git. I don't want to only generate file directly into the working_directory, and the README seems to only cover the case where you use the plugin within a Package+working_directory context.

Maybe I missunderstand the goal of the "SwiftGen-Generate" command? (which goal would be to manually trigger the generation into a working_directory?)

st4rrk avatar Nov 10 '22 15:11 st4rrk

@st4rrk this PR only updates the build tool plugin, and unfortunately build tool plugins aren't permitted to write the source directory. Command plugins are permitted to do this once you give explicit permission, but have to be manually invoked.

As you mention the SwiftGen-Generate command it sounds like maybe your issues are unrelated to this PR?

From past experience it's possible that you haven't given permission for the command plugin to access the package directory?

knellr avatar Nov 10 '22 15:11 knellr

Any reason this PR can't get merged? Checking out the fork and using this branch, my setup works and everything is great. Using the main repo, nothing else changed, and I always get the error Plugin doesn't support Xcode projects (it doesn't use the XcodeProjectPlugin library)

romero-ios avatar Nov 10 '22 19:11 romero-ios

This PR can now be merged ?

MaxencemPro avatar Nov 23 '22 14:11 MaxencemPro

@djbe could we get a heads up if this is the correct approach, or if you know anyone else able to review/approve it? It works well for me and would be good to see it merged in.

ckuburlis avatar Jan 12 '23 01:01 ckuburlis

It would be great if this could be merged. I could use this as well.

ehyche avatar Jan 13 '23 14:01 ehyche

I tested it on my local machine and it works very well, if this PR could be merged that would be great.

n-giaccone avatar Jan 20 '23 15:01 n-giaccone

It would be great if this could be merged :)

captainhaddockfr35 avatar Jan 23 '23 15:01 captainhaddockfr35

Please merge this pull request :pray:

edoardop13 avatar Jan 27 '23 11:01 edoardop13

Bumping this. @djbe can you please review? 🙏🏼

p4checo avatar Apr 12 '23 08:04 p4checo

bumping again

rrroyal avatar Jun 09 '23 14:06 rrroyal

bump

tomasharkema avatar Jul 29 '23 00:07 tomasharkema

bump

bloxidge avatar Aug 31 '23 13:08 bloxidge

please merge this PR

prateekMindTickle avatar Sep 18 '23 13:09 prateekMindTickle

Hi, we need a merge of this PR too :)

NameX44 avatar Sep 27 '23 08:09 NameX44

I see @AliSoftware is also one of the main maintainers and hasn't been tagged yet. Could you take a look at this PR? 🙏

Svantulden avatar Nov 03 '23 14:11 Svantulden

Has this been tested on Xcode 15? Seem Xcode 15 has some stricter rules around write permissions to outputFilesDirectory

markst avatar Nov 27 '23 02:11 markst

has there been any updates on this? This PR has been open for quite some time and it seems like the owners of this repo are nowhere to be seen.

BrentMifsud avatar Feb 21 '24 18:02 BrentMifsud

Has this been tested on Xcode 15? Seem Xcode 15 has some stricter rules around write permissions to outputFilesDirectory

just tested this. Seems like the permissions are an issue in Xcode 15.

Getting the following message:

Error: You don’t have permission to save the file “Strings.swift” in the folder “Generated”.

EDIT:

I figured it out.

There is a new environment variable that points to a work directory that build plugins can access: ${DERIVED_SOURCES_DIR}/

The simplest solution is to make note in the readme that you need to use that env variable as your work directory root.

Alternatively, this PR can set that as the work directory for the plugins. And any directory provided in the swift gen configuration file can be appended to the end of that path.

BrentMifsud avatar Feb 21 '24 18:02 BrentMifsud

bump

Flatout73 avatar Jul 23 '24 11:07 Flatout73

Bump

duszmox avatar Aug 16 '24 10:08 duszmox

Has this been tested on Xcode 15? Seem Xcode 15 has some stricter rules around write permissions to outputFilesDirectory

just tested this. Seems like the permissions are an issue in Xcode 15.

Getting the following message:

Error: You don’t have permission to save the file “Strings.swift” in the folder “Generated”.

EDIT:

I figured it out.

There is a new environment variable that points to a work directory that build plugins can access: ${DERIVED_SOURCES_DIR}/

The simplest solution is to make note in the readme that you need to use that env variable as your work directory root.

Alternatively, this PR can set that as the work directory for the plugins. And any directory provided in the swift gen configuration file can be appended to the end of that path.

I'll have a look into it

tboogh avatar Oct 03 '24 05:10 tboogh