erikberglund / SwiftPrivilegedHelper

Example application using a privileged helper tool with authentication in an unsandboxed application written in Swift
MIT License
180 stars 33 forks source link

Helper tool version not saved into plist #23

Closed jeff-h closed 2 years ago

jeff-h commented 4 years ago

When I change the version (or build) in Xcode, it puts placeholders into the corresponding plist file.

image

The placeholders are: $(MARKETING_VERSION) and $(CURRENT_PROJECT_VERSION).

image

These placeholders are then replaced with their values in the plist (during build, I assume).

This works fine for SwiftPrivilegedHelperApplication, but fails for me when building the helper tool, which reports its short version as, literally, $(MARKETING_VERSION), instead of 1 or whatever. If you place a breakpoint inside func helperStatus you'll see this breaks the version comparison code.

image

I have a feeling it's a bug in Xcode 11 — I'm interested to hear if others are / aren't experiencing this issue.

hk05 commented 4 years ago

Hi Jeff,

Since upgrading to 11.4 I am suffering issues with my helper app as well. I am very confused as to what could be wrong (or if it is a 'undocumented feature' (a.k.a. bug) in xcode. I suspect the latter.

What makes things even more intricate is that there is so little documentation available. It is basically "trial and error', which is frustrating the heck out of me.

I reported to apple already, but expect silence all over the place (as usual).

Might I figure out something sensible I will post it.

jeff-h commented 4 years ago

Thanks for your response; I'm encouraged by the fact you have seen something similar — I think it points to this being a bug in Xcode 11.4, which hopefully means it might be fixed at some point by Apple.

In the meantime I'm working around it by adjusting the versions directly in the helper's plist, but if I forget and change them in the Target > General > Identity section, the helper will be built without the proper version number. Really annoying!

NghiaTranUIT commented 4 years ago

Same situation and it took me a day to debug what wrong 😨

Workaround by hardcoding the Helper Tool version in the plist file.

jeff-h commented 4 years ago

I had hopes that the Xcode update today (in the macOS 10.15.4 update) might have fixed this bug but alas, it does not.

hk05 commented 4 years ago

Just a short update. My problems with the helper tool have not been fixed either. I rolled back my projects to 11.3, since it was taking too much of my time.

Apple finally replied on my bug report, asking for more info. I would like to ask you to report your problems as well, hoping they will check things out. When doing so, please attach a sysdiagnosis report so they can investigate the problems:

After reviewing your feedback, we need more information to continue our investigation.

Please provide a sysdiagnose taken shortly after the failure. There are many items in the sysdiagnose that would be useful to look at including the macOS version, crash reports, the SIP status, the kextstat output, the system.log, and logs from numerous processes and kexts in the system_log.logarchive. Thanks!

macOS sysdiagnose Instructions: https://developer.apple.com/services-account/download?path=/OS_X/OS_X_Logs/sysdiagnose_Logging_Instructions.pdf

Important: Note the date and time the issue occurred and include this information in your bug report.

Note: It's important to trigger the sysdiagnose process as soon as possible after the problem occurs, even if the logs can't be synced off the device until later.

jeff-h commented 4 years ago

QQ: where do you submit the bug report to Apple?

hk05 commented 4 years ago

https://feedbackassistant.apple.com

hk05 commented 4 years ago

Just installed XCode 11.4.1, which seems to solve the problems I have been experiencing.

jeff-h commented 4 years ago

Unfortunately 11.4.1 hasn't fixed the issue for me. Can you confirm that you do have the following in your Helper-Info.plist?

tg_image_403745508

hk05 commented 4 years ago

We may have been suffering different issues.

In my info.plist I manually change the 'My Bundle version String (short)' string. So it does not contain $(MARKETING_VERSION), but I manually set it to my version (for example 1.1) My Bundle version does contain $(CURRENT_PROJECT_VERSION)

On 21 Apr 2020, at 10:05, jeff-h notifications@github.com wrote:

Unfortunately 11.4.1 hasn't fixed the issue for me. Can you confirm that you do have the following in your Helper-Info.plist?

https://user-images.githubusercontent.com/841871/79841358-67405f00-840b-11ea-98b2-44db7a47c73c.jpeg — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erikberglund/SwiftPrivilegedHelper/issues/23#issuecomment-617022824, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUFIPTJ6REJR4TDN4MU7NDRNVHVNANCNFSM4MEQKVBQ.

jeff-h commented 4 years ago

I see; the way you're doing it is like @NghiaTranUIT's workaround above. That method also works for me.

However, if you then change the version number via the Xcode target settings, you'll find Xcode overwrites that entry in the plist. After that, the original issue arises again.

jeff-h commented 4 years ago

Apple have responded, suggesting I check:

INFOPLIST_EXPAND_BUILD_SETTINGS build setting set to NO?

I do already have that set to NO. Might be worth checking if you're experiencing issues.

However I think I have identified the issue, at least for my case:

This project, and all others like it that I've seen, embed the helper tool's Info.plist by using "Other Linker Flags" in Targets > Build Settings (-sectcreate __TEXT __info_plist blah). When embedded using this method, the plist is copied into the binary without being processed.

If instead you remove that and embed it by setting the "Create Info.plist Section in Binary" (CREATE_INFOPLIST_SECTION_IN_BINARY) build setting to Yes, the plist is embedded AND the preprocessing is run, so variables in the plist are populated with their proper values.

@NghiaTranUIT I'm most interested to see if this resolves the issue you've experienced also.

All that said, I'd be surprised if this behaviour was new in Xcode 11.4. I'm still pretty confused about that.

jeff-h commented 2 years ago

I can confirm this is resolved for me so I'll close this. If anyone else has the issue in future please feel free to add a comment here and I should get notified.