2

I'm having a problem while using OcaIDE in ocamlbuild mode. I'm trying to compile my own JoCaml sources. According to the JoCaml manual (bottom of page), to use ocamlbuild with JoCaml, I just need to add the -use-jocaml argument to ocamlbuild. Indeed, if I go to the root of my project and write

ocamlbuild -use-jocaml foo.native

it generates my executable just fine.

However, in OcaIDE I get

/bin/sh: jocamldep: command not found

In OcaIDE, the -use-jocaml flag is passed in the "Other Flags" box (in Project Properties). And that certainly is working, as the complaint is precisely that it doesn't find jocaml stuff. The puzzling thing is that jocaml is installed and can be accessed from any random terminal window. For example, running

jocamldep -modules foo.ml > foo.ml.depends

on my project does generate the desired dependency file.

So, it would seem I would have to configure OcaIDE and tell it where JoCaml executables are or something. This is done for OCaml, for example. But there is no place to do that for JoCaml. And it's really strange that, if jocamldep/jocamlc/etc are all accessible from anywhere, OcaIDE wouldn't be able to pick them.

Any ideas?

(I am aware I can do an ocamlbuild plugin and pass the flag in a "myocamlbuild.ml" file. I'll probably use that a latter stage after I get familiar with ocamlbuild plugins. But here the question is about OcaIDE. EDIT: Actually, ocamlbuild plugins don't seem to be a solution as, although there is an option -use-jocaml in ocamlbuild to enforce jocaml use (and it works fine), the plugin system doesn't support it, i.e. use_jocaml (or something involving jocaml) is not in the list of options.)

Surikator
  • 1,463
  • 9
  • 26
  • If you've compiled your own JoCaml, it might not be in your `$PATH`, or more precisely the `$PATH` in OcaIDE. – Gilles 'SO- stop being evil' Mar 15 '11 at 21:29
  • I'm not sure what you mean by "the $PATH in OcaIDE". There's a dialog editor to set paths, but it's just for OCaml stuff, not for JoCaml. – Surikator Mar 15 '11 at 22:38
  • 1
    Eclipse is running a shell script which invokes `jocamldep`. If that doesn't work, but invoking `jocamldep` from your shell prompt works, the most likely explanation is that either OcaIDE or you has changed the `PATH` environment variable. What directory is `jocamldep` in? Can you confirm that OcaIDE (or perhaps Eclipse in general) has this directory in its `PATH`? – Gilles 'SO- stop being evil' Mar 15 '11 at 22:47
  • I don't know of a way to set the $PATH environment variable on either OcaIDE or Eclipse. OcaIDE, as I mentioned, has a dialog window to set paths but just for OCaml (not JoCaml) and in Eclipse couldn't find any way to edit the path. – Surikator Mar 16 '11 at 00:02
  • I have no idea about the Eclipse part. But, again, it might be useful to know where you've installed JoCaml. What does `type jocamldep` show (typed in a terminal)? And if it's something other than `/usr/bin/jocamldep` or `/usr/local/bin/jocamldep`, how did you add that directory to your `PATH`? – Gilles 'SO- stop being evil' Mar 16 '11 at 00:10
  • Sorry, forgot to answer that. It is `/usr/local/bin/`. It's my manual installation. – Surikator Mar 16 '11 at 00:11
  • @Gilles With the help of Teraokay (below) I've managed to see the path Eclipse was using and, as you pointed out, that was the problem. Thanks for your help! – Surikator Mar 17 '11 at 00:38

1 Answers1

2

When you start a build on an ocamlbuild project, OcaIDE calls:

ocaml.exec.ExecHelper#execMerge

which creates a new java.lang.ProcessBuilder, and uses its default environment (ProcessBuilder#environment()).

To help debug your problem, please run the following Java program in your Eclipse:

public static void main(String[] args) {
    Map<String, String> environment = new ProcessBuilder().environment();
    for (Entry<String, String> entry : environment.entrySet()) {
        if ("path".equalsIgnoreCase(entry.getKey())) {
            System.out.println("PATH = " + entry.getValue());
        }
    }
}

It should display the same path that is passed to OcamlBuild.

You could also import the OcaIDE plug-in source in your workspace and run it in debug mode, with a breakpoint in ocaml.exec.ExecHelper#execMerge to see how ocamlbuild is called.


You could try to create a shell script to start Eclipse with the correct path:

Something like startEclipse.sh (located in the same folder as the eclipse executable):

#!/bin/bash
export PATH=<your path to JoCaml>:$PATH
./eclipse
Teraokay
  • 120
  • 6
  • @Teraokay Thanks a lot. This is really helpful. I've edited your answer (hope that's OK) to have the complete Java class (import Map and class statement) and changed Entry to Map.Entry to compile. Now, the result of running this yielded `PATH = /usr/bin:/bin:/usr/sbin:/sbin`. So, yes, the problem is that the Eclipse environment doesn't have `/usr/local/bin/` in the path which I'd need. Two options: (1) change the path in Eclipse (don't know how to do this and it would be my preference); (2) put links (unix `ln`)to `jocaml` tools in `/usr/bin` (did it and it's working fine now). Thanks a lot! – Surikator Mar 17 '11 at 00:33
  • @Teraokay If you know how to change the Eclipse path, please let me know, as I'd prefer that than having links to JoCaml executables. Thanks! – Surikator Mar 17 '11 at 00:40
  • You could try to create a script that starts Eclipse with your path (I've edited my answer, because I couldn't format code properly in this comment). – Teraokay Mar 17 '11 at 06:43
  • @Teraokay OK, I know how to set the PATH in Unix. I thought Eclipse would have some other place where the PATH is set, since in the terminal/bash environment (just before running Eclipse) I know `/usr/local/bin` is accessible from anywhere but Eclipse doesn't see it. If I just set my PATH in the bash like you suggest, Eclipse still doesn't see `/usr/local/bin` -- I removed all my links in `/usr/bin`, exported the PATH and ran Eclipse and it doesn't compile again with the same complaint that it doesn't see jocaml. And the Java program above shows exactly the same as in my comment above. – Surikator Mar 17 '11 at 07:05
  • I don't understand why the environment variables wouldn't be passed to Eclipse. Which operating system are you using? – Teraokay Mar 17 '11 at 08:25
  • @Teraokay Mac OS X 10.6.4 (Snow Leopard) – Surikator Mar 17 '11 at 08:26
  • @Teraokay Sorry, I did something wrong before. It's working fine now, the new path is in Eclipse and OcaIDE knows where to find jocaml (/usr/local/bin). Thanks a lot! – Surikator Mar 17 '11 at 08:39