[macruby-changes] [4038] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 6 21:45:46 PDT 2010
Revision: 4038
http://trac.macosforge.org/projects/ruby/changeset/4038
Author: lsansonetti at apple.com
Date: 2010-05-06 21:45:45 -0700 (Thu, 06 May 2010)
Log Message:
-----------
in case we are in a .app with MacRuby.framework embedded inside, relocate the load paths accordingly
Modified Paths:
--------------
MacRuby/trunk/objc.h
MacRuby/trunk/objc.m
MacRuby/trunk/vm.cpp
Modified: MacRuby/trunk/objc.h
===================================================================
--- MacRuby/trunk/objc.h 2010-05-07 04:43:39 UTC (rev 4037)
+++ MacRuby/trunk/objc.h 2010-05-07 04:45:45 UTC (rev 4038)
@@ -261,6 +261,7 @@
bool rb_objc_ignore_sel(SEL sel);
void rb_objc_force_class_initialize(Class klass);
+void rb_objc_fix_relocatable_load_path(void);
#if defined(__cplusplus)
}
Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m 2010-05-07 04:43:39 UTC (rev 4037)
+++ MacRuby/trunk/objc.m 2010-05-07 04:45:45 UTC (rev 4038)
@@ -665,7 +665,37 @@
return 0; // never reached
}
+static NSString *
+relocated_load_path(NSString *path, NSString *macruby_path)
+{
+ NSRange r = [path rangeOfString:@"MacRuby.framework"];
+ if (r.location == NSNotFound) {
+ return nil;
+ }
+ r = NSMakeRange(0, r.location + r.length);
+ return [path stringByReplacingCharactersInRange:r withString:macruby_path];
+}
+
void
+rb_objc_fix_relocatable_load_path(void)
+{
+ NSString *path = [[NSBundle mainBundle] privateFrameworksPath];
+ path = [path stringByAppendingPathComponent:@"MacRuby.framework"];
+
+ NSFileManager *fm = [NSFileManager defaultManager];
+ if ([fm fileExistsAtPath:path]) {
+ VALUE ary = rb_vm_load_path();
+ for (long i = 0, count = RARRAY_LEN(ary); i < count; i++) {
+ NSString *p1 = (NSString *)RARRAY_AT(ary, i);
+ NSString *p2 = relocated_load_path(p1, path);
+ if (p2 != nil) {
+ rb_ary_store(ary, i, (VALUE)p2);
+ }
+ }
+ }
+}
+
+void
Init_ObjC(void)
{
rb_objc_define_method(rb_mKernel, "load_bridge_support_file",
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2010-05-07 04:43:39 UTC (rev 4037)
+++ MacRuby/trunk/vm.cpp 2010-05-07 04:45:45 UTC (rev 4038)
@@ -5033,34 +5033,29 @@
int
macruby_main(const char *path, int argc, char **argv)
{
- char **newargv;
- char *p1, *p2;
- int n, i;
+ // Transform the original argv into something like this:
+ // argv[0] = original value
+ // argv[1] = -I/path-to-app-dir/(...)/Resources
+ // argv[2] = main .rb file
+ // argv[3 .. N] = rest of original argv
- /*
- * Transform the original argv into something like this:
- * argv[0] = original value
- * argv[1] = -I/path-to-app-dir/(...)/Resources
- * argv[2] = main .rb file
- * argv[3 .. N] = rest of original argv
- */
-
- newargv = (char **)malloc(sizeof(char *) * (argc + 2));
+ char **newargv = (char **)malloc(sizeof(char *) * (argc + 2));
newargv[0] = argv[0];
- p1 = (char *)malloc(PATH_MAX);
+ char *p1 = (char *)malloc(PATH_MAX);
newargv[1] = (char *)resources_path(p1, PATH_MAX);
- p2 = (char *)malloc(PATH_MAX);
+ char *p2 = (char *)malloc(PATH_MAX);
snprintf(p2, PATH_MAX, "%s/%s", (path[0] != '/') ? &p1[2] : "", path);
newargv[2] = p2;
-
- for (i = 1, n = 3; i < argc; i++) {
+
+ int n = 3;
+ for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-psn_", 5) != 0) {
newargv[n++] = argv[i];
}
}
-
+
argv = newargv;
argc = n;
@@ -5074,6 +5069,7 @@
free(newargv);
free(p1);
free(p2);
+ rb_objc_fix_relocatable_load_path();
return ruby_run_node(tree);
}
catch (...) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100506/1cfc6545/attachment.html>
More information about the macruby-changes
mailing list