res.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from _common import iterpair, listid, pathid, rootrel_arc_src, tobuilddir, filter_out_by_keyword
  2. def split(lst, limit):
  3. # paths are specified with replaceable prefix
  4. # real length is unknown at the moment, that why we use root_lenght
  5. # as a rough estimation
  6. root_lenght = 200
  7. filepath = None
  8. lenght = 0
  9. bucket = []
  10. for item in lst:
  11. if filepath:
  12. lenght += root_lenght + len(filepath) + len(item)
  13. if lenght > limit and bucket:
  14. yield bucket
  15. bucket = []
  16. lenght = 0
  17. bucket.append(filepath)
  18. bucket.append(item)
  19. filepath = None
  20. else:
  21. filepath = item
  22. if bucket:
  23. yield bucket
  24. def remove_prefix(text, prefix):
  25. if text.startswith(prefix):
  26. return text[len(prefix):]
  27. return text
  28. def onfat_resource(unit, *args):
  29. unit.onpeerdir(['library/cpp/resource'])
  30. # Since the maximum length of lpCommandLine string for CreateProcess is 8kb (windows) characters,
  31. # we make several calls of rescompiler
  32. # https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms682425.aspx
  33. for part_args in split(args, 8000):
  34. output = listid(part_args) + '.cpp'
  35. inputs = [x for x, y in iterpair(part_args) if x != '-']
  36. if inputs:
  37. inputs = ['IN'] + inputs
  38. unit.onrun_program(['tools/rescompiler', output] + part_args + inputs + ['OUT_NOAUTO', output])
  39. unit.onsrcs(['GLOBAL', output])
  40. def onresource_files(unit, *args):
  41. """
  42. @usage: RESOURCE_FILES([DONT_PARSE] [PREFIX {prefix}] [STRIP prefix_to_strip] {path})
  43. This macro expands into
  44. RESOURCE([DONT_PARSE] {path} resfs/file/{prefix}{path}
  45. - resfs/src/resfs/file/{prefix}{remove_prefix(path, prefix_to_strip)}={rootrel_arc_src(path)}
  46. )
  47. resfs/src/{key} stores a source root (or build root) relative path of the
  48. source of the value of the {key} resource.
  49. resfs/file/{key} stores any value whose source was a file on a filesystem.
  50. resfs/src/resfs/file/{key} must store its path.
  51. DONT_PARSE disables parsing for source code files (determined by extension)
  52. Please don't abuse: use separate DONT_PARSE macro call only for files subject to parsing
  53. This form is for use from other plugins:
  54. RESOURCE_FILES([DEST {dest}] {path}) expands into RESOURCE({path} resfs/file/{dest})
  55. @see: https://wiki.yandex-team.ru/devtools/commandsandvars/resourcefiles/
  56. """
  57. prefix = ''
  58. prefix_to_strip = None
  59. dest = None
  60. res = []
  61. first = 0
  62. if args and not unit.enabled('_GO_MODULE'):
  63. # GO_RESOURCE currently doesn't support DONT_PARSE
  64. res.append('DONT_PARSE')
  65. if args and args[0] == 'DONT_PARSE':
  66. first = 1
  67. args = iter(args[first:])
  68. for arg in args:
  69. if arg == 'PREFIX':
  70. prefix, dest = next(args), None
  71. elif arg == 'DEST':
  72. dest, prefix = next(args), None
  73. elif arg == 'STRIP':
  74. prefix_to_strip = next(args)
  75. else:
  76. path = arg
  77. key = 'resfs/file/' + (dest or (prefix + (path if not prefix_to_strip else remove_prefix(path, prefix_to_strip))))
  78. src = 'resfs/src/{}={}'.format(key, rootrel_arc_src(path, unit))
  79. res += ['-', src, path, key]
  80. if unit.enabled('_GO_MODULE'):
  81. unit.on_go_resource(res)
  82. else:
  83. unit.onresource(res)