ssqls.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from os.path import splitext
  2. import ymake
  3. from _common import resolve_includes
  4. class SSQLSParser(object):
  5. def __init__(self, path, unit):
  6. s = unit.resolve_arc_path(path)
  7. assert s.startswith('$S/') and s.endswith('.ssqls'), s
  8. h = '$B/' + s[3:-6] + '.h'
  9. import xml.etree.cElementTree as ET
  10. try:
  11. doc = ET.parse(path)
  12. except ET.ParseError as e:
  13. unit.message(['error', 'malformed XML {}: {}'.format(path, e)])
  14. doc = ET.Element('DbObject')
  15. xmls, headers = self.parse_doc(doc)
  16. self._includes = resolve_includes(unit, s, xmls)
  17. self._induced = {'cpp': [h], 'h': resolve_includes(unit, h, headers)}
  18. @staticmethod
  19. def parse_doc(doc):
  20. paths = lambda nodes: filter(None, (e.get('path') for e in nodes))
  21. includes = doc.findall('include')
  22. ancestors = paths(doc.findall('ancestors/ancestor'))
  23. headers = [e.text.strip('<>""') for e in includes]
  24. headers += [splitext(s)[0] + '.h' for s in ancestors]
  25. return paths(includes) + ancestors, headers
  26. def includes(self):
  27. return self._includes
  28. def induced_deps(self):
  29. return self._induced
  30. def init():
  31. ymake.addparser('ssqls', SSQLSParser)