def onresource(unit, *args): unit.onpeerdir(['library/resource']) outs = [] for part_args in split(args, 8000): srcs_gen = [] raw_gen = [] raw_inputs = [] compressed = [] compressed_input = [] compressed_output = [] for p, n in iterpair(part_args): if unit.enabled('ARCH_AARCH64') or unit.enabled( 'ARCH_ARM') or unit.enabled('ARCH_PPC64LE'): raw_gen += [p, n] if p != '-': raw_inputs.append(p) continue lid = '_' + pathid(p + n + unit.path()) output = lid + '.rodata' if p == '-': n, p = n.split('=', 1) compressed += ['-', p, output] else: compressed += [p, output] compressed_input.append(p) compressed_output.append(output) srcs_gen.append('{}={}'.format(lid, n)) if compressed: lid = listid(part_args) fake_yasm = '_' + lid + '.yasm' cmd = ['tools/rescompressor', fake_yasm ] + gen_ro_flags(unit) + compressed if compressed_input: cmd += ['IN'] + compressed_input cmd += ['OUT_NOAUTO', fake_yasm] + compressed_output unit.onrun_program(cmd) unit.onsrcs(['GLOBAL', tobuilddir(unit.path() + '/' + fake_yasm)]) if srcs_gen: output = listid(part_args) + '.cpp' unit.onrun_program(['tools/rorescompiler', output] + srcs_gen + ['OUT_NOAUTO', output]) outs.append(output) if raw_gen: output = listid(part_args) + '_raw.cpp' if raw_inputs: raw_inputs = ['IN'] + raw_inputs unit.onrun_program(['tools/rescompiler', output] + raw_gen + raw_inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output]) if outs: if len(outs) > 1: unit.onjoin_srcs_global(['join_' + listid(outs) + '.cpp'] + outs) else: unit.onsrcs(['GLOBAL'] + outs)
def onfat_resource(unit, *args): unit.onpeerdir(['library/cpp/resource']) # Since the maximum length of lpCommandLine string for CreateProcess is 8kb (windows) characters, # we make several calls of rescompiler # https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms682425.aspx for part_args in split(args, 8000): output = listid(part_args) + '.cpp' inputs = [x for x, y in iterpair(part_args) if x != '-'] if inputs: inputs = ['IN'] + inputs unit.onrun_program(['tools/rescompiler', output] + part_args + inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output])
def onfat_resource(unit, *args): unit.onpeerdir(['library/resource']) # Since the maximum length of lpCommandLine string for CreateProcess is 8kb (windows) characters, # we make several calls of rescompiler # https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms682425.aspx for part_args in split(args, 8000): output = listid(part_args) + '.cpp' inputs = [x for x, y in iterpair(part_args) if x != '-'] if inputs: inputs = ['IN'] + inputs unit.onrun_program(['tools/rescompiler', output] + part_args + inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output])
def onro_resource(unit, *args): unit.onpeerdir(['library/resource']) for part_args in split(args, 8000): srcs_gen = [] raw_gen = [] raw_inputs = [] ro_gen = [] for p, n in iterpair(part_args): if p == '-': raw_gen += [p, n] continue if unit.enabled('ARCH_AARCH64') or unit.enabled( 'ARCH_ARM') or unit.enabled('ARCH_PPC64LE'): raw_gen += [p, n] raw_inputs.append(p) continue lid = '_' + pathid(p + n + unit.path()) srcs_gen.append('{}={}'.format(n, lid)) output = lid + '.roresource' unit.onrun_program([ 'tools/rescompressor', p, output, 'IN', p, 'OUT_NOAUTO', output ]) ro_gen.append(output) if ro_gen: output = listid(part_args) + '.asm' unit.onbuiltin_python([ 'build/scripts/gen_rodata.py', '--out-file', output, '--yasm', '${tool:"contrib/tools/yasm"}' ] + gen_ro_flags(unit) + ro_gen + ['IN'] + ro_gen + ['OUTPUT_INCLUDES'] + ro_gen + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', tobuilddir(unit.path() + '/' + output)]) if srcs_gen: output = listid(part_args) + '.cpp' unit.onrun_program(['tools/rorescompiler', output] + srcs_gen + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output]) if raw_gen: output = listid(part_args) + '_raw.cpp' if raw_inputs: raw_inputs = ['IN'] + raw_inputs unit.onrun_program(['tools/rescompiler', output] + raw_gen + raw_inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output])
def onro_resource(unit, *args): unit.onpeerdir(['library/resource']) for part_args in split(args, 8000): srcs_gen = [] for p, n in iterpair(part_args): if p == '-': continue lid = '_' + pathid(p) compressed_out = lid + '.rodata' unit.onrun_program([ 'tools/rescompressor', p, compressed_out, 'IN', p, 'OUT', compressed_out ]) srcs_gen.append('{}={}'.format(n, lid)) output = listid(part_args) + '.cpp' unit.onrun_program(['tools/rorescompiler', output] + srcs_gen + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output])
def onresource(unit, *args): def split(lst, limit): # paths are specified with replaceable prefix # real length is unknown at the moment, that why we use root_lenght # as a rough estimation root_lenght = 200 filepath = None lenght = 0 bucket = [] for item in lst: if filepath: lenght += root_lenght + len(filepath) + len(item) if lenght > limit and bucket: yield bucket bucket = [] lenght = 0 bucket.append(filepath) bucket.append(item) filepath = None else: filepath = item if bucket: yield bucket unit.onpeerdir(['library/resource']) # Since the maximum length of lpCommandLine string for CreateProcess is 8kb (windows) characters, # we make several calls of rescompiler # https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms682425.aspx for part_args in split(args, 8000): output = listid(part_args) + '.cpp' inputs = [x for x, y in iterpair(part_args) if x != '-'] if inputs: inputs = ['IN'] + inputs unit.onrun_program(['tools/rescompiler', output] + part_args + inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output])
def onresource(unit, *args): """ @usage: RESOURCE(file name file name...) Add data (resources, random files) to the program) This is a simpler but less flexible option than ARCHIVE(), because in the case of ARCHIVE(), you have to use the data explicitly, and in the case of RESOURCE(), the data falls through SRCS(GLOBAL). Therefore, there is no static data library from RESOURCE(), they are added only at the program linking stage. @example: https://wiki.yandex-team.ru/yatool/howtowriteyamakefiles/#a2ispolzujjtekomanduresource @example: LIBRARY() OWNER(user1) RESOURCE( path/to/file1 /key/in/program/1 path/to/file2 /key2 ) END() """ unit.onpeerdir(['library/resource']) outs = [] # https://st.yandex-team.ru/DEVTOOLS-4037 # compressed_outs = [] for part_args in split(args, 8000): srcs_gen = [] raw_gen = [] raw_inputs = [] compressed = [] compressed_input = [] compressed_output = [] for p, n in iterpair(part_args): if unit.enabled('ARCH_AARCH64') or unit.enabled( 'ARCH_ARM') or unit.enabled('ARCH_PPC64LE'): raw_gen += [p, n] if p != '-': raw_inputs.append(p) continue lid = '_' + pathid(p + n + unit.path()) output = lid + '.rodata' if p == '-': n, p = n.split('=', 1) compressed += ['-', p, output] else: compressed += [p, output] compressed_input.append(p) compressed_output.append(output) srcs_gen.append('{}={}'.format(lid, n)) if compressed: lid = listid(part_args) fake_yasm = '_' + lid + '.yasm' cmd = ['tools/rescompressor', fake_yasm ] + gen_ro_flags(unit) + compressed if compressed_input: cmd += ['IN'] + compressed_input cmd += ['OUT_NOAUTO', fake_yasm] + compressed_output unit.onrun_program(cmd) # https://st.yandex-team.ru/DEVTOOLS-4037 # compressed_outs.append(fake_yasm) unit.onsrcs(['GLOBAL', tobuilddir(unit.path() + '/' + fake_yasm)]) if srcs_gen: output = listid(part_args) + '.cpp' unit.onrun_program(['tools/rorescompiler', output] + srcs_gen + ['OUT_NOAUTO', output]) outs.append(output) if raw_gen: output = listid(part_args) + '_raw.cpp' if raw_inputs: raw_inputs = ['IN'] + raw_inputs unit.onrun_program(['tools/rescompiler', output] + raw_gen + raw_inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output]) if outs: if len(outs) > 1: unit.onjoin_srcs_global(['join_' + listid(outs) + '.cpp'] + outs) else: unit.onsrcs(['GLOBAL'] + outs)
def onresource(unit, *args): unit.onpeerdir(['library/resource']) outs = [] for part_args in split(args, 8000): srcs_gen = [] raw_gen = [] raw_inputs = [] compressed = [] compressed_input = [] compressed_output = [] for p, n in iterpair(part_args): if unit.enabled('ARCH_AARCH64') or unit.enabled('ARCH_ARM') or unit.enabled('ARCH_PPC64LE'): raw_gen += [p, n] if p != '-': raw_inputs.append(p) continue lid = '_' + pathid(p + n + unit.path()) output = lid + '.rodata' if p == '-': n, p = n.split('=', 1) compressed += ['-', p, output] else: compressed += [p, output] compressed_input.append(p) compressed_output.append(output) srcs_gen.append('{}={}'.format(lid, n)) if compressed: lid = listid(part_args) fake_yasm = '_' + lid + '.yasm' cmd = ['tools/rescompressor', fake_yasm] + gen_ro_flags(unit) + compressed if compressed_input: cmd += ['IN'] + compressed_input cmd += ['OUT_NOAUTO', fake_yasm] + compressed_output unit.onrun_program(cmd) if compressed_output: fake_out = lid + '.yasm' cmd = ['build/scripts/fs_tools.py', 'link_or_copy', fake_yasm, fake_out] + ['IN', fake_yasm] cmd += ['OUTPUT_INCLUDES'] + compressed_output cmd += ['OUT_NOAUTO', fake_out] unit.onbuiltin_python(cmd) else: fake_out = fake_yasm unit.onsrcs(['GLOBAL', tobuilddir(unit.path() + '/' + fake_out)]) if srcs_gen: output = listid(part_args) + '.cpp' unit.onrun_program(['tools/rorescompiler', output] + srcs_gen + ['OUT_NOAUTO', output]) outs.append(output) if raw_gen: output = listid(part_args) + '_raw.cpp' if raw_inputs: raw_inputs = ['IN'] + raw_inputs unit.onrun_program(['tools/rescompiler', output] + raw_gen + raw_inputs + ['OUT_NOAUTO', output]) unit.onsrcs(['GLOBAL', output]) if outs: if len(outs) > 1: unit.onjoin_srcs_global(['join_' + listid(outs) + '.cpp'] + outs) else: unit.onsrcs(['GLOBAL'] + outs)