Archived

This forum has been archived. Please start a new discussion on GitHub.

slice2freeze correct header with --output-dir option

Hi,

Here is a patch to 2.1.0 to fix the locations of slice output header files in the source generated by slice2freeze. The 2.1.0 code ignores the --output-dir option when inserting #include directives into its output. This patch corrects this oversight.

This fix assumes that if you use the --output-dir option for slice2freeze, you will use the same option for slice2cpp. This may not be the best assumption, but I believe it's better than what is currently done. This has been tested a little on gcc/Solaris, but it's portable code, so it should work elsewhere.

This patch should also work on version 2.1.2, but this hasn't been tested.

Cheers,

-- Andrew Bell
andrew.bell.ia@gmail.com

Comments

  • Not in 3.0 - Another Solution?

    Hi,

    This patch didn't make it into 3.0. Did you code another solution? I didn't see anything obvious with a really quick look at the source. Do you have another recommendation for working around the problem?

    Thanks,
  • What exactly is the problem? --output-dir is not supposed to modify the #include statements. --include-dir is used for this purpose.
  • More Info

    When you generate an index, you get two files, a .cpp and a .h. When you specify --include-dir, the specified directory is inserted in the #include statement in the .cpp so that the corresponding .h can be located.

    The problem is that also included in the slice2freeze generated header file is a reference to a generated header that is built separately by slice2cpp. If you are using --output-dir when you run slice2cpp and slice2freeze, it puts all of the generated files in the location specified by output-dir, but there are header references to files generated by slice2freeze that don't respect this option. Instead, it uses the directory where the slice file was located. This isn't where the generated files are -- things won't build.

    Here is an example. Put an ice file in a directory other than the one in which you are building. Run slice2freeze and slice2cpp on the file in the other directory with the --output-dir option set to ".". Take a look at the header file generated by slice2freeze and you will see that it tries to include files from the location of the ice file, rather than the location of the ouput directory, ".".

    Hope this doesn't confuse too much :)

    Thanks,
  • mes
    mes California
    Hi Andrew,

    The proper way to control the directories in a generated #include statement is to use -I options. For example, if I run the following command

    $ slice2freeze ... MyMap slice/Ice/Identity.ice

    then the generated file MyMap.h contains

    #include <slice/Ice/Identity.h>

    Essentially, the pathname of the Slice file is transferred directly to the #include statement.

    However, if I use this command instead

    $ slice2freeze ... -Islice MyMap slice/Ice/Identity.ice

    then the generated file contains

    #include <Ice/Identity.h>

    The translator removes the include path "slice" from the generated #include statement. You must then use the proper compiler options that allow the preprocessor to find Ice/Identity.h.

    Take care,
    - Mark
  • mes
    mes California
    As a clarification, the C++ translators (slice2cpp and slice2freeze) assume that the Slice files and the generated include files have the same directory structure (e.g., slice/Ice/Identity.ice and include/Ice/Identity.h). You control the contents of the #include statements that the translators emit using -I options, and you use equivalent -I options for the C++ compiler. The --output-dir option is simply a convenience for relocating the generated files, but has no affect on the pathnames of #include statements.

    - Mark
  • I think that this assumption about layout is unfortunate.

    I believe that what you say about --output-dir not modifying the #include directives is incorrect. If you say:

    slice2freeze --output-dir .. [junk omitted] foo_index foo.ice

    The file foo_index.cpp, which is put in the directory one level above the current working directory, includes the line:

    #include <../foo_index.h>

    The ".." in the above construct comes from the --output-dir option, not from the --include-dir option. But this option has NO effect on the include directive for the slice2cpp-generated file in foo_index.h. The patch I offered treats the stuff in the header file the same as the stuff in the .cpp with respect to the --output-dir argument. The assumption is that if you are using --output-dir for slice2freeze, you are also using it for slice2cpp. Perhaps this isn't a good assumption, but I didn't see any way to deal with it without another option.

    I'm really confused here. Is there a way to have a slice file in some other arbitrary directory and put all the generated code into the current working directory?

    Thanks as always,
  • Bad Patch

    Hi,

    Just found that this patch doesn't work it you are using the --include-dir option. I'm not sure how the two (include-dir and output-dir) should interact, if at all.

    I still wonder how to handle the case of the ice file being in some arbitrary directory and have output go to the current directory.
  • mes
    mes California
    acbell wrote:
    I think that this assumption about layout is unfortunate.
    The behavior of the translators is driven by our own needs in the Ice source tree, and we try to make them flexible enough to suit the needs of Ice developers.
    I believe that what you say about --output-dir not modifying the #include directives is incorrect. If you say:

    slice2freeze --output-dir .. [junk omitted] foo_index foo.ice

    The file foo_index.cpp, which is put in the directory one level above the current working directory, includes the line:

    #include <../foo_index.h>
    You're right. What I described is the intended behavior, but clearly slice2freeze is not behaving as we intended. We'll investigate this further.
    I'm really confused here. Is there a way to have a slice file in some other arbitrary directory and put all the generated code into the current working directory?
    The translators generate files into the current working directory by default, so there is no need to use the --output-dir option if that's where you want the files to go. For example:

    $ slice2freeze -I/path/to/slice ... MyMap /path/to/slice/Types.ice

    This generates MyMap.h and MyMap.cpp in the current working directory. Because I specified the -I option, MyMap.h contains

    #include <Types.h>

    And since I did not use --output-dir, MyMap.cpp contains

    #include <MyMap.h>

    Is that what you are trying to achieve?

    Take care,
    - Mark
  • Thanks

    Thanks for this. I guess that when I saw the --output-dir changing the include path, I ran with it. What I wasn't aware of was that -I would influence the creation of the include paths. This isn't what is in the documentation (at least in 2.1.2 docs section 4.18). This should be stressed somewhere, and some small note should be placed in the help for the preprocessors (slice2freeze -?). This explanation is super-helpful:

    http://www.zeroc.com/vbulletin/showthread.php?t=319

    Thanks, and sorry for the hassle.