Hello to all,
I frequently consult the forum to find very precious information when I program my extensions in ruby. I take this opportunity to thank the community that shares its encyclopedic knowledge. On my side, I would like to make a small contribution by reporting a recent experience. For some, what I describe will be trivial, for others, it may save time.
I recently encountered bugs in my code when deploying an extension on MAC and some of them were quite difficult to understand. I have been developing an extension under a Windows environment but I want it to work on MAC. So before its distribution I test the extension on a MAC (currently MacOS Monterey) by loading .rb files located on my computer under Windows (Windows 10) and I bring the required corrections. Tests are performed on SketchUp 2017 to 2022.
Bug 1: require " UPPERCASE_NAME "
The first bug I encountered was related to a following code line:
require 'JSON'
A ruby programmer will immediately say that ājsonā should be written in lower case of course. Thatās right and I donāt understand myself what this āJSONā was doing in my code (a 3am programming, I guess). But Windows is not case sensitive and this does not cause a bug. Mac is case sensitive (in some case: see Danās answer below) and it causes the .rb file to stop loading. This bug is quite easy to identify when testing under Mac.
Bug 2 : call to a file with a letter in upper case when it should be in lower case.
File.read('G:/path/File_name') # the file to read is 'file_name'
The second bug is also related to case sensitivity. But it was much more difficult to identify. In my code, I was referring to a file āfile_nameā but one of the letters was faulty typed with a capital letter in the code (for example āFile_nameā).
During the first tests on MAC no problem was encountered because even if I was using SketchUp on MacOS Monterey, the loaded files were on a Windows server. It is only when creating a .rbz file and installing the installation via this file (and thus with all the files on the MAC) that the bug was declared. Written like this it may seem simple but it may take some time to understand why switching to an .rbz triggers a bug.
Bug 3 : File instruction in a .rbe package
file_path = __File__
The __File__instruction that allows to get the path of the loaded code file works on Windows with encrypted .rbe package but I got a bug when testing the .rbe on my MAC. The bug was known in the .rbs packages but I thought it was totally solved with .rbe packages. I couldnāt find anything on the forum about it but maybe I looked wrong.
Again itās a pretty insidious bug since you test your extension and everything goes fine and itās only when encrypting .rbe that everything crashes.
I hope that my experience will be useful to you.