I encountered a particular issue over the last couple of days when I
decided to test trial a package process using Ocra and WxRuby/Wx_sugar.
I already solved the issue but I wanted to get some clarification, or
make sure that I’m performing best practices.
In the case of my issue, wx_sugar has a program called xrcise which
automatically reads xrc source files and creates a ruby file that
attaches listener events and extends some of the events through custom
modules.
After porting my code to a quick app.exe format using Ocra, I noticed
that it would work fine in the directory, but anywhere else on my system
it would not. So, I dug deep into the code and into some external
testing/debugging scripts.
It turned out that one piece of the ruby file that was automatically
generated by xrcise was placing the following statement for loading xml:
xml.load(‘ui/ui.xrc’)
Now, I knew that this was the issue but I wanted to see how the working
directories were truly working on windows with the executable. When
Ocra packages the exe file and you open it, it automatically unpacks the
exe into the temp directory. So, in my case the directory was
C:\users\joel\appdata\temp\ocra43.tmp\src…etc.
All of the app worked great except for this one piece. When diagnosing
the working directory for this xml.load, the working directory was the
desktop directory where the file was launched. This meant that it was
trying to find a ui directory on the desktop with the xrc source file
within.
So, I changed the ruby file that was created from:
xml.load(‘ui/ui.xrc’)
To: xml.load(File.join(File.dirname(FILE),“ui.xrc”))
… which fixed the issue and forced an absolute path directly to where
the file was located.
Looking at the Ruby api, it says that when using load it resolves to an
absolute path.
So, am I correct to assume that require is realistically for relative
paths and load should be formally used with absolute paths? Given the
issue that just occurred with a file that was created and is heavily
used by other WxRuby people, wouldn’t it be more prudent to use only
absolute paths with load statements? Or, is this more of a case by case
basis, depending on whether or not you are packaging/porting your code?
My thanks.