split_codegen.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from _common import sort_by_keywords
  2. # This hard-coded many times in CppParts in various codegens
  3. _DEFAULT_CPP_PARTS = 20
  4. # See TCodegenParams::MethodStream usage in factor codegen
  5. _ADDITIONAL_STREAM_COUNT = 5
  6. def onsplit_codegen(unit, *args):
  7. '''
  8. @usage: SPLIT_CODEGEN(tool prefix opts... [OUT_NUM num] [OUTPUT_INCLUDES output_includes...])
  9. Generator of a certain number of parts of the .cpp file + one header .h file from .in
  10. Supports keywords:
  11. 1. OUT_NUM <the number of generated Prefix.N.cpp default 25 (N varies from 0 to 24)>
  12. 2. OUTPUT_INCLUDES <path to files that will be included in generalnyj of macro files>
  13. '''
  14. keywords = {"OUT_NUM": 1}
  15. flat_args, spec_args = sort_by_keywords(keywords, args)
  16. num_outputs = _DEFAULT_CPP_PARTS + _ADDITIONAL_STREAM_COUNT
  17. if "OUT_NUM" in spec_args:
  18. num_outputs = int(spec_args["OUT_NUM"][0])
  19. tool = flat_args[0]
  20. prefix = flat_args[1]
  21. cmd = [tool, prefix, 'OUT']
  22. for num in range(num_outputs):
  23. cmd.append('{}.{}.cpp'.format(prefix, num))
  24. cpp_parts = int(num_outputs) - _ADDITIONAL_STREAM_COUNT
  25. cpp_parts_args = ['--cpp-parts', str(cpp_parts)]
  26. if len(flat_args) > 2:
  27. if flat_args[2] != 'OUTPUT_INCLUDES':
  28. cmd.append('OPTS')
  29. cmd += cpp_parts_args + flat_args[2:]
  30. else:
  31. cmd += ['OPTS'] + cpp_parts_args
  32. unit.on_split_codegen_base(cmd)