Getting SketchUp to play nicely with RubyGems?
-
Google SketchUp includes a trimmed-down version of MRI 1.8.5, including only part of the Ruby Standard Library. As detailed on
http://cfcl.com/twiki/bin/view/Projects/SketchUp/LibraryUse
I'm trying to use RVM to give my SketchUp plugins access to the full Ruby library, including the wide world of RubyGems.
I seem to have 1.8.5 installed and working, as well as a copy of RubyGems (1.3.4). However, when I try "require 'yaml'" in the SketchUp Ruby Console, I get a nastygram:
> require 'yaml' Error; #<LoadError; /Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib /ruby/1.8/i686-darwin10.4.0/stringio.bundle; Failed to load /Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib /ruby/1.8/i686-darwin10.4.0/stringio.bundle> (eval);1 /Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib /ruby/1.8/yaml.rb;9 (eval);1;in `require' (eval);1
The requested file seems to be present, so I'm not sure what the problem is.
Looking on the web for help, I found the following thread:
http://forums.sketchucation.com/viewtopic.php?f=180&t=25233
This discussion seems to be specific to MS Windows, but it makes me wonder if I need to reply one or more dylibs in SU. That said, I have no idea which one(s) I'd need to replace and I'm not interested in going on a snipe hunt.
Help?
-
Dan Rathbun helped me with this the other day here
I hacked it a bit to make it fit my system and it works fine now.
-
@ben.doherty said:
Dan Rathbun helped me with this the other day here
I have also posted it here at SCF:
[code] Ruby LOAD PATHs script for (Win32)@ben.doherty said:
I hacked it a bit to make it fit my system and it works fine now.
Anything that others might like?
Or just the "tweeker" vars (those are meant to be customized.)
Mac.. is different than Windows. I'd still like to see a Mac version of this script.
-
@richmorin said:
I seem to have 1.8.5 installed and working, as well as a copy of RubyGems (1.3.4). However, when I try "require 'yaml'" in the SketchUp Ruby Console, I get a nastygram:
I checked the yaml.rb and Confirmed line 9 is:
require 'stringio'On my Windows (in Ruby v1.9.1) in the lib dir, there is a lib/yaml subdir. In that subdir, is a 'stringio.rb' file, that says at the top:
%(#008000)[#Limited StringIO if no core lib is available
#]
but the silly thing is you have to run lib/yaml/stringio.rb first because IT trys to load the strinio.bundle (stringio.so on Win32,) and then traps the "no file" error in an internal rescue block (that declares pure ruby stringio methods.)
I'd have done it the other way 'round: trapped the "no file" error in lib/yaml.rb and had a "load 'lib/yaml/stringio.rb'" within the rescue clause in yaml.rb- maybe this should be suggested at ruby's redmine site?
Anyway.. the stringio binary lib is supposed to be in the platform subdir of the ruby/lib dir, and your errors show paths that seem to be looking in the right place, but cannot find the file, or it's corrupted.
Can verify whether the dir:
/Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib/ruby/1.8/i686-darwin10.4.0
has or does not have the 'stringio.bundle' file ? -
Or when you built Ruby... for some reason stringio.c did not get complied.
-
I never did get a direct answer from any of the guys with Macs, to my specific question:
Is there (or not,) a ruby interpreter dylib (or bundle,) within the Sketchup application bin directory, on the Mac ??
All I get are vague assumptions (usually pointing to an equally vague answer on the Google Sketchup FAQ page.)
-
The required bundle exists and is both readable and executable (?). I have updated the gist (http://gist.github.com/473142) to show this and to list all of the dylibs in the "Google SketchUp 7" directory tree. I can't tell from the file names whether any of these is the Ruby interpreter.
-
I'm pretty sure that SU supplies its own copy of the interpreter. For one thing, there's the fact that it sets RUBY_VERSION to '1.8.5' on a machine whose native Ruby is '1.8.7'. Hmmmmm.
$ cd '/Applications/Google/SketchUp 7/SketchUP.app/Contents' $ cd 'Frameworks/Ruby.framework/Versions/A' $ ls -l Ruby -rwxrwxr-x 1 root admin 1768636 Dec 29 2009 Ruby
-
@richmorin said:
... list all of the dylibs in the "Google SketchUp 7" directory tree. I can't tell from the file names whether any of these is the Ruby interpreter.
Thanks Rich..
I don't think any of them are Ruby files.
So (now I am finally a beleiver that,) Sketchup on Mac will load the Ruby installed... but,
EDIT: ok... back to my original belief (head spinnin')Does SU just use ENV vars to find the location of the Ruby/bin directory... or did the SU coders hardcode the location?
On Windows the name of the Ruby DLL is hardcoded (can ya' believe that?) did they do the same on Mac?
-
@richmorin said:
I'm pretty sure that SU supplies its own copy of the interpreter. For one thing, there's the fact that it sets RUBY_VERSION to '1.8.5' on a machine whose native Ruby is '1.8.7'. Hmmmmm.
> $ cd '/Applications/Google/SketchUp 7/SketchUP.app/Contents' > $ cd 'Frameworks/Ruby.framework/Versions/A' > $ ls -l Ruby > -rwxrwxr-x 1 root admin 1768636 Dec 29 2009 Ruby >
ok... back to my original belief (head spinnin')
But at least I positively know the truth now (and what the FAQ page says is wrong, and what some ppl have said is wrong.)
Truth: on both SU editions (Win and Mac) Sketchup does NOT load the default Ruby installation.I now think you have (on Mac,) the same problem we were talking about in that other topic (although Win32 was the platform of discussion.) It's a version mis-match issue. The compiled binary stringio is calling some C function that exists in the core of it's version, but not in the version that Sketchup is loading. (This is why Sketchup cannot load v1.9.x on Win32 because within sketchup.exe the hardcode is calling C function rb_set_kode that was renamed in the 1.9 branch. So we get a nastygram-popup "Entry point not found in "msvcrt-ruby18.dll". [I had to rename 1.9 dll because they hardcoded the filename as well!])
On Win32 we can 'juryrig' Sketchup to load newer versions in the 1.8.x branch, by copying the newer interpreter DLL into the SU program folder. We must do this if we wish to use lib rubies from the newer branch, especially the compiled SO & DLL files. (There's also a compiler issue; from what I've read we need to use files that are all compiled with the same compiler.)
So.. Mac questions:
(1) How many Ruby versions... Just the 'A' version ??
(2) From TBD's Mac ENV dump (he posted it in another topic on Mac,) it does not appear that there are any ENV vars set for Ruby.
How does the Mac Sketchup edition decide what Ruby version to load ...
Is it hardcoded, OR is there a plist file ??(3) Could you 'juryrig' Sketchup to loadanother version, by renaming the 'A' folder to 'Z' or something (or moving it to 'Frameworks/Ruby.backup/Versions/A') and then copy or install the latest Ruby 1.8.7 into 'Frameworks/Ruby.framework/Versions/A' ??
(4) If it works... can it work for the latest v 1.9.x ??
(5) The RVM issue. I can't use RVM, must use pik on Win32. (But at least he's updating it to be as RVM-like as possible. Same commands etc.) There is an override in pik that lets me install Ruby versions to a custom path (instead of %HOMEPATH%/.pik ) Does RVM have this as well ?
I ask because it seems on both SU platforms that the best place for Sketchup specific Ruby seems to be within the application directory hierarchy (as it is now on Mac.) That then leaves the default(s) Ruby installs all alone and separate. I like it that way. I can have a set of Ruby versions on my machine for standard (non-Sketchup) Ruby (ie: Rails, eRuby, whatever;) and a separate set of Ruby versions under Sketchup, tweeked only for use with the SU API. -
(1) How many Ruby versions... Just the 'A' version ??
That's all I see on my system.
(2) How does the Mac SketchUp edition decide what Ruby version to load ...
Is it hard-coded, OR is there a plist file ??There are several plist files that might be relevant, including:
/Applications/Google/SketchUp 7/SketchUP.app/Contents/ Frameworks/Ruby.framework/ Resources/Info.plist Versions/A/Resources/Info.plist
However, a quick inspection didn't reveal any pointers in the plists I examined. I suspect that the determination is made by following this symlink:
.../Ruby.framework/Versions/Current -> A
(3) Could you 'juryrig' SketchUp to load another version ...
(4) If it works... can it work for the latest v 1.9.x ??Maybe, but I'm hoping that someone with access to and/or knowledge about the internals of SketchUp will jump in and tell us what's going on. I dislike snipe hunts...
FWIW, I think we're more likely to be able to use a full copy of MRI 1.8.5 than any later version (less differences to get in the way).
(5) The RVM issue. I can't use RVM, ...
I suspect that RVM could be made to work under CygWin, if that isn't too weird for you. If you're interested in pursuing that goal, I suggest that you chat with the folks on the #rvm IRC channel...
I don't know whether RVM has an override to set a custom path, but I can't imagine it would be very hard to add on, if not.
-
@richmorin said:
I dislike snipe hunts....
Yes, but this is not frivolous. This is the information gathering phase. This info is very helpful to developers wishing to create cross-platfrom plugins. I have never before feasted on such a bounty of Mac Sketchup info.
@richmorin said:
There are several plist files that might be relevant [in loading Ruby,] including:
%(#804000)[**/Applications/Google/SketchUp 7/SketchUP.app/Contents/... .../Frameworks/Ruby.framework/Resources/Info.plist .../Frameworks/Ruby.framework/Versions/A/Resources/Info.plist**]
Could you post each of these to a new gist on you githsite, please.
And as time permits, some nice organized file listings of all the directories:
There's also the Support path:
%(#804000)[**/Library/Application Support/Google SketchUp 7/**]
And the User path:
**%(#804000)[/Users/#{ENV['USER']}/**]
...?- under User we'd be interested in the location and name of the session.dat (Win32 name,) file; and the default names and paths of the Sketchup user directories (ie: Watermarks, Templates, Components, etc.) I realise these locations can be changed, but it's nice to know the defaults. Don't list your personal models, scripts etc. ... just generic directory structure and any generic files (plist etc.)
@richmorin said:
I suspect that the determination is made by following this symlink:
%(#804000)[**.../Ruby.framework/Versions/Current -> A**]
Just for clarity... "Current" is a file and not a directory name? (In other words the link is located in the 'Versions' directory.)
On Win32 we also have these, commonly called "shortcuts", but they are actually .lnk (link) files.@richmorin said:
... I'm hoping that someone with access to and/or knowledge about the internals of SketchUp will jump in and tell us what's going on.
We've asked these questions before, and when we did get answers, they were wrong (to some degree,) or very vague.
The answer to the question on if and when Google would update the Ruby distro'd with Sketchup, was vague also, implying it was low priority.@richmorin said:
FWIW, I think we're more likely to be able to use a full copy of MRI 1.8.5 than any later version (less differences to get in the way).
Perhaps true... you have at least id'd the top question in the flow chart (decision tree.) "Update Ruby version?" Each answer reveals other questions, some will have more than two branches.
One thing is for certain... the 2 platforms are distro'd with different versions. Win32 SU 7.0 - 7.1.MR2 still comes 'out-of-the-box' with the Ruby 1.8.0-p10 interpreter [and none of the Libraries,] so one of the 2 platforms (at least,) will need to be updated if both are to be at the same revision level.
I am hoping for the latest stable release of Ruby 1.8.6.. at the very least. I'm not quite convinced that v1.8.7 is "ready for primetime", but that may be just an unfortunate first impression, on my part, and unwarranted.
I have been yearning for a way to have a set of Ruby versions, AND to be able to test Sketchup and plugins under these several versions and setups easily. RVM and pik may give us this. pik is OpenSource, so could be modified into a special edition for Win32 Sketchup (if it doesn't quite work the way we need.)
-
I agree that it could be useful to have public references for configuration information (eg, directory trees, control files) used by SU on various platforms. I'm a little nervous, however, about posting these files without some sort of permission from Google. Can anyone comment on the legalities here? More generally, where should persistent resources such as this be posted?
"Current" is a symbolic link, pointing at a directory (A). In general, a symlink can be used in place of the referenced item (eg, file, directory), though the user process needs to have permission to access both the symbolic link and the referenced item.
I agree that it would be preferable for both the Mac and Windows versions of SketchUp to have the same (reasonably current) version of Ruby. However, this should be done in a way that keeps existing plugins working smoothly for naive users. So, perhaps we need a way for experienced
users to "opt in" to a newer version of Ruby, etc. -
@richmorin said:
I agree that it could be useful to have public references for configuration information (eg, directory trees, control files) used by SU on various platforms. ... More generally, where should persistent resources such as this be posted?
They should have beeen already posted to the Google API docs, but well the docs appear to be the lowest priority of all. Jim set up an alternate (prototype,) API doc site on the SKX Google Code site. That would be a good place, for now as we can edit it, format it nicely, etc. The GSUT could always cut & paste it over to the main API site, when we have it done, then Jim could replace the content with the link. (If you feel better about having on a Google server, so it could be taken down, if the GSUT requested it. Putting it on Github would mean it would always be there or in some archive, especially if you have the free gith, as opposed to a paid site.)
File directory listings are just listings of files. Anyone can do that. The 'Real' intellectual property is all within compiled files. The terms of use prohibit decompiling and reverse engineering. We're not doing that.
Plist files. The API gives us 2/3 methods for reading and writing into the defaults (Registry on Win32, plist on Mac,) but doesn't enumerate the actually settings. We've had to poke into the Registry ourselves to discover the keys and attribute names. There are numerous posts on this forum where WE and GSUT members have revealed these keys and Attributes, with no 'slap down', because we are expected to know them. (Meaning if we're smart enough to know we need them, we are also smart enough to know how to use REG.exe or the regedt32.exe or the standard Ruby lib Registry to get the info we need. Same on the Mac, for a plist file reader.)
@richmorin said:
I agree that it would be preferable for both the Mac and Windows versions of SketchUp to have the same (reasonably current) version of Ruby. However, this should be done in a way that keeps existing plugins working smoothly for naive users.
Which is WHY, you and I, are experimenting with a Ruby Version Management utility (RVM and pik, respectively.) Developers need to be able to test their code easily with a variety of Ruby packages (versions + libs + gems, etc.) so they can avoid (as much as possible,) the user complaints that could come flooding in after release, is "Your Plugin interfers with gen such-and-such", or "conflicts with standard library Encoding" or whatever.
@richmorin said:
So, perhaps we need a way for experienced users to "opt in" to a newer version of Ruby, etc.
DITTOS!!! It is so hard for me to understand why a programmer would hardcode the loading of a specific Ruby version. It's crazy. On Win32 they could have made it a Registry setting, or even better JUST put the rbconfig.rb (that is created for the Ruby version,) in the Sketchup folder and loaded it. We then could have tweeked that file. (That file really belongs in the ruby/lib/ruby/#{RUBY_VERSION}/#{RUBY_PLATFORM} directory.)
Anyhow, even an .ini/.plist file so we users could tell Sketchup how and what Ruby to use, is a "no-brainer."From what you have said.. it looks like 'redirecting' SU to another version on the Mac is much easier (then Win32,) as they used a symbolic link.
If it was me (with the Mac,) I'd backup everything, install a newer version as 'B' and change the symbolic link 'Current -> B' and see if it works. Either way the results of the test are valuable. (I DO notice that the SAPI is also version 'A', I do not know if they both must be 'in sync' or if there is another SAPI specific symbolic link [you didn't say.]) -
@richmorin said:
Can anyone comment on the legalities here?
reference: The Legal Agreement, entitled: "Terms of Service"
section 10.3 is of most interest, as to what we CAN do and NOT do with the API. (I will not quote it as the actual document should always be refered to. It could be revised, etc., making my quote worthless.)
section 8.2 is of interest to Google's right to filter content on Google's Services (which applies to the Google Codesite as well and is stated in all Google "Terms of Service" agreements.)
So then I think that Jim's SKX codsite API wiki would be the best place to "prototype" the information, and then let the Google SketchUp Team check it out. I know Scott Lininger is a SKX project member so he can edit/delete stuff on the wiki. You would have to join the project, or else email/PM Jim or I the info, and let us post it.
-
Now I got some questions here - is this a plugin that is going to be distributed?
I would not be comfortable with a plugin changing the Ruby version SU loads.
What if another plugin tried to make SU use another version? Sounds like there's potential for a clash. Since the SU Ruby environment is shared by an unknown number of other plugins, any changes to the core is something that can potentially break something else. -
Check this out, a guy named Andre claims to have gotten SU to load 1.8.7 on Mac/OSX:
http://groups.google.com/group/sketchupruby/browse_frm/thread/fc4278c7a2011582#His site with the instructions:
http://superuser.com/questions/167453/I hope he made backups.
-
@thomthom said:
Now I got some questions here - is this a plugin that is going to be distributed?
ThomThom... how can it be a plugin ?
You can't switch horses in mid-stream.
My interest is controlling MY ruby versions, for the purpose of testing code against differing Ruby versions and Patch Levels. In order to do that, a developer needs multi-version ruby installs and a switching utility.
On Win32... it's pik.
On Unix-like (Linux, OSX, etc.) it's RVM. (Ruby Version Management)
Both are command line utilites.
Both are aimed at Standard Ruby use.NOW... I am contemplating having 2 RVM archives. ONE that is normal, that I use for NON-Sketchup Ruby (Rails, eRuby, Distributed Ruby, etc.)
A Second archive, that (like on the Mac,) is installed beneath the Sketchup Application folder (or maybe in the Google folder.) The second would only be used with, or tweeked specially for Sketchup.
So if I wish to test my plugins on v1.8.0 and v1.8.5 and v1.8.6 ..etc.. I need a means of quickly switching back and forth (when Sketchup is NOT running.)Updating the Ruby version that Sketchup loads is up to the user. Currently on Win32 it's a manual task.
I strongly believe that Sketchup should be "Ruby Version Agile", but that will require a change in the exe source.
-
Will all these 'investegations' also lead to a directory structure of the ruby lib?
I think there are a lot of interesting tools (like an xml parser) which could be used in plugins, but making it work atm is something i have not been able to.
To much files needed spread over several places. -
@pout said:
Will all these 'investegations' also lead to a directory structure of the ruby lib?
I think it's best to keep the dir layouts the same (I in fact have manually copied a whole ruby install into the Sketchup folder.)
So the Sketchup copy just begins in dir:
C:/Programs/Google/Google Sketchup 7/ruby
instead of:
C:/ruby
Advertisement