README 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. This is a placeholder package for logging messages of various modules
  2. in the form of python scripts. This package is expected to be installed
  3. somewhere like <top-install-dir>/python3.x/site-packages/isc/log_messages
  4. and each message script is expected to be imported as
  5. "isc.log_messages.some_module_messages".
  6. We also need to allow in-source test code to get access to the message
  7. scripts in the same manner. That's why the package is stored in the
  8. directory that shares the same trailing part as the install directory,
  9. i.e., isc/log_messages.
  10. Furthermore, we need to support a build mode using a separate build
  11. tree (such as in the case with 'make distcheck'). In that case if an
  12. application (via a test script) imports "isc.log_messages.xxx", it
  13. would try to import the module under the source tree, where the
  14. generated message script doesn't exist. So, in the source directory
  15. (i.e., here) we provide dummy scripts that subsequently import the
  16. same name of module under the "work" sub-package. The caller
  17. application is assumed to have <top_builddir>/src/lib/python/isc/log_messages
  18. in its module search path (this is done by including
  19. $(COMMON_PYTHON_PATH) in the PYTHONPATH environment variable),
  20. which ensures the right directory is chosen.
  21. A python module or program that defines its own log messages needs to
  22. make sure that the setup described above is implemented. It's a
  23. complicated process, but can generally be done by following a common
  24. pattern. The following are a sample snippet for Makefile.in for a
  25. module named "mymodule" (which is supposed to be generated from a file
  26. "mymodule_messages.mes"). In many cases it should work simply by
  27. replacing 'mymodule' with the actual module name.
  28. ==================== begin Makefile.am additions ===================
  29. nodist_pylogmessage_PYTHON = $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py
  30. pylogmessagedir = $(pyexecdir)/isc/log_messages/
  31. CLEANFILES = $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py
  32. CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.pyc
  33. EXTRA_DIST = mymodule_messages.mes
  34. BUILT_SOURCES = $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py
  35. CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py
  36. CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.pyc
  37. EXTRA_DIST += $(PYTHON_LOGMSGPKG_SRCDIR)/mymodule_messages.py
  38. $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py : mymodule_messages.mes
  39. $(top_builddir)/src/lib/log/compiler/message \
  40. -d $(PYTHON_LOGMSGPKG_DIR) -p $(srcdir)/mymodule_messages.mes
  41. $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py: Makefile
  42. echo "from work.mymodule_messages import *" > $@
  43. # This rule ensures mymodule_messages.py is (re)generated as a result of
  44. # 'make'. If there's no other appropriate target, specify
  45. # mymodule_messages.py in BUILT_SOURCES.
  46. mymodule: <other source files> $(PYTHON_LOGMSGPKG_DIR)/mymodule_messages.py
  47. ===================== end Makefile.am additions ====================
  48. Notes:
  49. - "nodist_" prefix is important. Without this, 'make distcheck' tries
  50. to make _messages.py before actually starting the main build, which
  51. would fail because the message compiler isn't built yet.
  52. - "pylogmessage" is a prefix for python scripts that define log
  53. messages and are expected to be installed in the common isc/log_messages
  54. directory. It's intentionally named differently from the common
  55. "python" prefix (as in python_PYTHON), because the latter may be
  56. used for other scripts in the same Makefile.am file.
  57. - $(PYTHON_LOGMSGPKG_DIR) should be set to point to this directory (or
  58. the corresponding build directory if it's different) by the
  59. configure script. $(PYTHON_LOGMSGPKG_SRCDIR) should be set to point
  60. to this directory by the configure script.
  61. - The four lines starting from BUILT_SOURCES and the second make rule
  62. are for preparing the dummy python file under the source tree.
  63. Note that EXTRA_DIST is specified so that the python script is
  64. placed in the source tree (not only in the build tree when these
  65. two are different). If you don't like this trick, you could
  66. directly add the file in this directory alternatively.