2
0

depfile.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # coding=utf-8
  2. #
  3. # QEMU depfile generation extension
  4. #
  5. # Copyright (c) 2020 Red Hat, Inc.
  6. #
  7. # This work is licensed under the terms of the GNU GPLv2 or later.
  8. # See the COPYING file in the top-level directory.
  9. """depfile is a Sphinx extension that writes a dependency file for
  10. an external build system"""
  11. import os
  12. import sphinx
  13. __version__ = '1.0'
  14. def get_infiles(env):
  15. for x in env.found_docs:
  16. yield env.doc2path(x)
  17. yield from ((os.path.join(env.srcdir, dep)
  18. for dep in env.dependencies[x]))
  19. def write_depfile(app, env):
  20. if not env.config.depfile:
  21. return
  22. # Using a directory as the output file does not work great because
  23. # its timestamp does not necessarily change when the contents change.
  24. # So create a timestamp file.
  25. if env.config.depfile_stamp:
  26. with open(env.config.depfile_stamp, 'w') as f:
  27. pass
  28. with open(env.config.depfile, 'w') as f:
  29. print((env.config.depfile_stamp or app.outdir) + ": \\", file=f)
  30. print(*get_infiles(env), file=f)
  31. for x in get_infiles(env):
  32. print(x + ":", file=f)
  33. def setup(app):
  34. app.add_config_value('depfile', None, 'env')
  35. app.add_config_value('depfile_stamp', None, 'env')
  36. app.connect('env-updated', write_depfile)
  37. return dict(
  38. version = __version__,
  39. parallel_read_safe = True,
  40. parallel_write_safe = True
  41. )