10 de diciembre de 2014

Racket, Dropbox and .zo files

I have my .rkt Racket files in my Dropbox directory. So all copies are automatically kept in sync on my computers. (Do I really need to explain what is Dropbox?) One of the machines is a slightly slow netbook, so I usually compile all files of the programs to make them start faster later. (This does not change the speed at which they run, only decrease the boot time.)

To compile, I use a mini program in Racket:
#lang racket/base
(require compiler/compiler)
(requires setup/getinfo)

(compile-directory-zos (current-directory)
                       (get-info / full (current-directory)))

This creates a compiled subdirectory with the corresponding .dep and .zo files. The problem is that if the program has a (require "something.rkt"), then these files have the absolute path of the file something.rkt. Then when they are copied to another computer, they are bad and a strange error appears, which is fixed by deleting the .zo. But now the new .zo doesn't work in the other computer ...

I started using the selective synchronization options in Dropbox. I simply marked the compiled directories as non-synchronized. Well, I had to mark allll the compiled directories as non-synchronized and then go to the other computer and repeat the operation. Every time I added a new directory had to add the respective compiled   subdirectory on both machines. Every time I added a machine, I had to mark all directories again (fortunately this does not happen very often, but a disk reformatting is more usual).

However, the biggest problem was deleting (or moving) a subdirectory. As Dropbox had the directory marked as not synchronized, it recreate the directory just after I delete it. So I had to go to both computers and ununsyncronize it and then delete the directory. This operation was not so common, but it was a headache.

The Solution

It turns out that there is an environment variable PLTCOMPILEDROOTS that lets you choose where .zo files are saved (reference, original discussion). I chose to put them inside %USERPROFILE%\AppData\Local\Racket_Compiled; (With a ; at the end to indicate that if the .zo is not there, look in the original directory. For Linux you must use a : instead of a ; .) The temporary directory is %USERPROFILE%\AppData\Local\Temp so this seemed a good place and I hope it does not deserve any reproach :).

The other advantage of this method is that it doesn't mix the compiled directories with the normal directories and programs, so everything is cleaner and tidier.

(It's always hard for me to find the window to change the environment variables. (I miss the DOS days.) There are many pages with instructions. And the usual warning: Don't change the environment variables unless you know what you are doing .)