python: Pass destination dir to generator.py

Simplify usage across build systems.
This commit is contained in:
Jan Alexander Steffens (heftig) 2025-02-20 13:51:26 +01:00 committed by Nick Wellnhofer
parent 82fb5caee5
commit c2e2d76211
3 changed files with 11 additions and 9 deletions

View File

@ -521,9 +521,6 @@ if(LIBXML2_WITH_PYTHON)
COMMAND COMMAND
${Python_EXECUTABLE} ${Python_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/python/generator.py ${CMAKE_CURRENT_SOURCE_DIR}/python/generator.py
${CMAKE_CURRENT_SOURCE_DIR}/doc/libxml2-api.xml
${CMAKE_CURRENT_SOURCE_DIR}/python/libxml2-python-api.xml
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
file(READ python/libxml.py LIBXML_PY) file(READ python/libxml.py LIBXML_PY)

View File

@ -38,7 +38,7 @@ CLEANFILES = libxml2.py $(GENERATED)
all-local: libxml2.py all-local: libxml2.py
$(GENERATED): $(srcdir)/generator.py $(API_DESC) $(GENERATED): $(srcdir)/generator.py $(API_DESC)
$(PYTHON) $(srcdir)/generator.py $(srcdir) $(PYTHON) $(srcdir)/generator.py $(builddir)
# libxml.c #includes libxml2-export.c # libxml.c #includes libxml2-export.c
libxml.$(OBJEXT): libxml2-export.c libxml.$(OBJEXT): libxml2-export.c

View File

@ -13,9 +13,14 @@ import string
if __name__ == "__main__": if __name__ == "__main__":
# launched as a script # launched as a script
srcPref = os.path.dirname(sys.argv[0]) srcPref = os.path.dirname(sys.argv[0])
try:
dstPref = sys.argv[1]
except IndexError:
dstPref = os.getcwd()
else: else:
# imported # imported
srcPref = os.path.dirname(__file__) srcPref = os.path.dirname(__file__)
dstPref = os.getcwd()
####################################################################### #######################################################################
# #
@ -701,11 +706,11 @@ def buildStubs():
failed = 0 failed = 0
skipped = 0 skipped = 0
include = open("libxml2-py.h", "w") include = open(os.path.join(dstPref, "libxml2-py.h"), "w")
include.write("/* Generated */\n\n") include.write("/* Generated */\n\n")
export = open("libxml2-export.c", "w") export = open(os.path.join(dstPref, "libxml2-export.c"), "w")
export.write("/* Generated */\n\n") export.write("/* Generated */\n\n")
wrapper = open("libxml2-py.c", "w") wrapper = open(os.path.join(dstPref, "libxml2-py.c"), "w")
wrapper.write("/* Generated */\n\n") wrapper.write("/* Generated */\n\n")
wrapper.write("#define PY_SSIZE_T_CLEAN\n") wrapper.write("#define PY_SSIZE_T_CLEAN\n")
wrapper.write("#include <Python.h>\n") wrapper.write("#include <Python.h>\n")
@ -1087,8 +1092,8 @@ def buildWrappers():
info = (0, func, name, ret, args, file) info = (0, func, name, ret, args, file)
function_classes['None'].append(info) function_classes['None'].append(info)
classes = open("libxml2class.py", "w") classes = open(os.path.join(dstPref, "libxml2class.py"), "w")
txt = open("libxml2class.txt", "w") txt = open(os.path.join(dstPref, "libxml2class.txt"), "w")
txt.write(" Generated Classes for libxml2-python\n\n") txt.write(" Generated Classes for libxml2-python\n\n")
txt.write("#\n# Global functions of the module\n#\n\n") txt.write("#\n# Global functions of the module\n#\n\n")