Handling Hier Blocks in Build Process

I’d like to keep a large number of hier blocks organized in the apps
folder (which may not be standard practice for GR). Ideally, I’d like
to
maintain only the GRC files with version control, but allow the build
system to:

  • Compile the .grc files into python/xml files.
  • Install the .py files into the same location as everything else so
    they show up in the OOT module’s namespace.
  • Do the same for .xml files for access to GRC.
  • If there were a way to get around manually adding the resulting .py
    file to init.py, that would be a nice-to-have feature so other
    developers can easily add hier blocks to the module’s namespace.

I was just wondering if someone could tell me if this was possible, has
been done already, or might be an unreasonable thing to do for some
reason. (before I waste an afternoon).

-John

Hi John,

compiling things while building kind of makes sense :wink:
So, yes, this is doable.
In general, you could add the generated python files to the python
install_list in the python/CMakeLists.txt, and have a hook in the
grc/CMakeLists.txt that generates these, but that would break CMake’s
compiling-source tree differentiation.

I’d suggest looking at cmake/Modules/GrPython.cmake of your OOT. You
could have a function similar to GR_PYTHON_INSTALL that does essentially
the same, but instead of just shebanging the python files and adding
them to an installation target, it would create python using "grcc -d
/python " and install that.

The init automatisation was a topic some weeks ago, I don’t know in
which context, though. Yeah, there are python-magical ways to do that,
but they can easily litter module namespaces and cause problem if that
produces naming conflicts, which will not even be caught be QA (since
that happens pre-install…).

Greetings,
Marcus

John,

in one of my OOTs I did just that; I had GRC hier blocks that were
compiled using grcc when running ‘cmake’.

I put these lines into grc/CMakeLists.txt (I stored all the hier blocks
in grc/):

Make sure to add them in a non-dependent order

list(APPEND grc_hier_blocks
file1.grc
# etc. list all grcs here
)

message(“Compiling GRC hier blocks…”)
foreach(grc_file ${grc_hier_blocks})
message("Compiling " ${grc_file})
execute_process(
COMMAND grcc ${grc_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach(grc_file ${grc_hier_blocks})

A bit of a hack, but did the trick.

M