diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
commit | bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch) | |
tree | 1d1df72c0541a59a81439842f46d95396d3e7189 /build/scripts/make_java_srclists.py | |
parent | 8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff) | |
download | ydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz |
add ymake export to ydb
Diffstat (limited to 'build/scripts/make_java_srclists.py')
-rw-r--r-- | build/scripts/make_java_srclists.py | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/build/scripts/make_java_srclists.py b/build/scripts/make_java_srclists.py new file mode 100644 index 0000000000..65174bafd7 --- /dev/null +++ b/build/scripts/make_java_srclists.py @@ -0,0 +1,128 @@ +import os +import sys +import argparse + +import process_command_files as pcf +import java_pack_to_file as jcov + + +def writelines(f, rng): + f.writelines(item + '\n' for item in rng) + + +def add_rel_src_to_coverage(coverage, src, source_root): + rel = os.path.relpath(src, source_root) + if not rel.startswith('..' + os.path.sep): + coverage.append(rel) + + +def main(): + args = pcf.get_args(sys.argv[1:]) + parser = argparse.ArgumentParser() + parser.add_argument('--moddir') + parser.add_argument('--java') + parser.add_argument('--groovy') + parser.add_argument('--kotlin') + parser.add_argument('--coverage') + parser.add_argument('--source-root') + args, remaining_args = parser.parse_known_args(args) + + java = [] + kotlin = [] + groovy = [] + coverage = [] + + cur_resources_list_file = None + cur_jsources_list_file = None + cur_srcdir = None + cur_resources = [] + cur_jsources = [] + + FILE_ARG = 1 + RESOURCES_DIR_ARG = 2 + SRCDIR_ARG = 3 + JSOURCES_DIR_ARG = 4 + + next_arg=FILE_ARG + + for src in remaining_args: + if next_arg == RESOURCES_DIR_ARG: + assert cur_resources_list_file is None + cur_resources_list_file = src + next_arg = FILE_ARG + continue + elif next_arg == JSOURCES_DIR_ARG: + assert cur_jsources_list_file is None + cur_jsources_list_file = src + next_arg = FILE_ARG + continue + elif next_arg == SRCDIR_ARG: + assert cur_srcdir is None + cur_srcdir = src if os.path.isabs(src) else os.path.join(args.moddir, src) + next_arg = FILE_ARG + continue + + if src.endswith(".java"): + java.append(src) + kotlin.append(src) + if args.coverage and args.source_root: + add_rel_src_to_coverage(coverage, src, args.source_root) + elif args.kotlin and src.endswith(".kt"): + kotlin.append(src) + if args.coverage and args.source_root: + add_rel_src_to_coverage(coverage, src, args.source_root) + elif args.groovy and src.endswith(".groovy"): + groovy.append(src) + else: + if src == '--resources': + if cur_resources_list_file is not None: + with open(cur_resources_list_file, 'w') as f: + writelines(f, cur_resources) + cur_resources_list_file = None + cur_srcdir = None + cur_resources = [] + next_arg = RESOURCES_DIR_ARG + continue + if src == '--jsources': + if cur_jsources_list_file is not None: + with open(cur_jsources_list_file, 'w') as f: + writelines(f, cur_jsources) + cur_jsources_list_file = None + cur_jsources = [] + next_arg = JSOURCES_DIR_ARG + continue + elif src == '--srcdir': + next_arg = SRCDIR_ARG + continue + else: + assert cur_srcdir is not None and cur_resources_list_file is not None + cur_resources.append(os.path.relpath(src, cur_srcdir)) + + if cur_jsources_list_file is not None: + assert cur_srcdir is not None + cur_jsources.append(os.path.relpath(src, cur_srcdir)) + + if cur_resources_list_file is not None: + with open(cur_resources_list_file, 'w') as f: + writelines(f, cur_resources) + if cur_jsources_list_file is not None: + with open(cur_jsources_list_file, 'w') as f: + writelines(f, cur_jsources) + + if args.java: + with open(args.java, 'w') as f: + writelines(f, java) + if args.kotlin: + with open(args.kotlin, 'w') as f: + writelines(f, kotlin) + if args.groovy: + with open(args.groovy, 'w') as f: + writelines(f, groovy) + if args.coverage: + jcov.write_coverage_sources(args.coverage, args.source_root, coverage) + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) |