10

I have custom frameworks in my app bundle for WebKit, WebCore, and JavaScriptCore. I would like all other frameworks that depend on the system versions of WebKit, WebCore, or JavaScriptCore to use my custom versions also. For instance my custom version of Webkit loads private system frameworks that in turn depend on the system version of WebKit. This means both my WebKit and the system WebKit get loaded, and usually a crash happens shortly after.

The way I understand this should be done, is to set the DYLD_FRAMEWORK_PATH environmental variable before your app bundle begins execution (Search order for loading frameworks can be found here: http://code.google.com/p/macdependency/wiki/SearchPaths). You can set environmental variables in code with setenv, but it won't take effect for the currently running process. I would have to re-launch the process again for it to take effect. I would like to avoid this too.

So my question is what is the best way to set the DYLD_FRAMEWORK_PATH before the execution of the my app bundle? This has to work in a release app bundle too. Is there a way to run a script whenever someone clicks on my app bundle before the executable starts running. Or is there any other suggestions out there?

Thanks in advance.

Michael Wildermuth
  • 5,762
  • 3
  • 29
  • 48
  • What do you mean by ‘all other frameworks’? If it’s only your private frameworks, can’t you just build them linking to your private WebKit and related frameworks? –  Feb 07 '12 at 20:13
  • Well somewhere in the mountain of code that is my custom Webkit, DataDectors.framework gets loaded if you right click on a window (Only on OSX Lion), and DataDectors is a private system framework (not built by me). When this happens DataDectors depends on the system versions of WebKit and JavaScriptCore, so once this happens there is now 2 copies of WebKit loaded, mine and the systems. This cause unexpected results and a crash. – Michael Wildermuth Feb 08 '12 at 00:45
  • 1
    Did you ever manage to get this working? I'm looking to do something similar, and am not having much luck with any of the suggested approaches. – J. Perkins May 27 '14 at 16:34
  • I ended up in code setting the environmental variables during execution and then launching a second version of my process from the first process. The first process then finishes executing leaving the 2nd process executing in an environment with the DYLD_FRAMEWORK_PATH set. FYI sometimes the debugger had issues attaching to the second process properly, typically I had to leave a break point in main to catch the 2nd process. – Michael Wildermuth May 29 '14 at 20:31

4 Answers4

2

Jeff Wolski has the right idea by referring directly to Apple's documentation on the subject. This thread also provides excellent advice on how to get that going in Xcode, including corner cases associated with alternative methods of specification (for example, by using ~/.bash_profile directly for your user).

My reason for chiming in is you also asked for a script that might be able to assist you (and a bounty provider appears to have the same issue). It turns out Webkit references such a script in its documentation, which you might want to pick apart from the applicable Webkit source code. This should give you additional guidance on how, at least according to the developers, you should do this properly.

Best of luck with your project(s).

Community
  • 1
  • 1
MrGomez
  • 23,788
  • 45
  • 72
  • I took a look at the run-safari script and the script would work, but the I am not sure how to force a script to run whenever someone clicks on a app bundle. I need the environmental variables set for the session of the executable inside my app bundle. – Michael Wildermuth Apr 09 '12 at 18:14
  • @MichaelWildermuth According to [this question](http://stackoverflow.com/questions/281372/executing-shell-scripts-from-the-os-x-dock), a plethora of options exist. At least one of these will meet your needs, be it [through a `.command` file](http://stackoverflow.com/a/281386/517815) or [the marginally more elaborate Script Editor approach](http://stackoverflow.com/a/310183/517815). If these don't work for you, we'll discuss some of the other options. :) – MrGomez Apr 09 '12 at 19:55
1

I would recommend environment.plist or the LSEnvironment key in the info.plist. Check out the link below.

https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
  • 1
    The info.plist only takes absolute paths, and I need the path to be inside my app bundle, which technically can be moved around. If I set it in my environment.plist is this global, because if it is that also wouldn't be good, because other applications might use the environmental variable. – Michael Wildermuth Apr 09 '12 at 15:50
0

WebKit currently has a script to do this for you, called run-webkit-app. See http://trac.webkit.org/browser/trunk/Tools/Scripts/run-webkit-app

Litherum
  • 22,564
  • 3
  • 23
  • 27
0

Newer versions of ld understand the -dyld_env flag, which inserts a LC_DYLD_ENVIRONMENT load command into the binary (and as such applies essentially as early as possible in app execution). Perhaps adding -Wl,-dyld_env,DYLD_FRAMEWORK_PATH=/folder/encosing/WebKit/and/related/frameworks to your compiler flags might do what you want?

saagarjha
  • 2,221
  • 1
  • 20
  • 37