diff options
author | svidyuk <svidyuk@yandex-team.com> | 2022-12-16 06:22:08 +0300 |
---|---|---|
committer | svidyuk <svidyuk@yandex-team.com> | 2022-12-16 06:22:08 +0300 |
commit | a94445ea23010c0fccb3a231251d33cb69ac63d8 (patch) | |
tree | 1d0cf5ce16492f6942200008ec7c5ec5f29bb120 /build/scripts/build_info_gen.py | |
parent | 3d8f5faccdca9e6301e9112e127e309a86de8d07 (diff) | |
download | ydb-a94445ea23010c0fccb3a231251d33cb69ac63d8.tar.gz |
Port build_info to py3
Diffstat (limited to 'build/scripts/build_info_gen.py')
-rw-r--r-- | build/scripts/build_info_gen.py | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/build/scripts/build_info_gen.py b/build/scripts/build_info_gen.py index 949e0a1636..d250accb19 100644 --- a/build/scripts/build_info_gen.py +++ b/build/scripts/build_info_gen.py @@ -12,7 +12,7 @@ def escape_special_symbols(strval): if c in ("\\", "\""): retval += "\\" + c elif ord(c) < 0x20: - retval += c.encode("string_escape") + retval += c.encode('unicode_escape').decode('utf-8') else: retval += c return retval @@ -42,22 +42,43 @@ def get_compiler_info(compiler): compiler_ver_cmd = [compiler] if compiler_binary not in ("cl", "cl.exe"): compiler_ver_cmd.append('--version') - compiler_ver_out = subprocess.Popen(compiler_ver_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read() + env = os.environ.copy() + env['LOCALE'] = 'C' + compiler_ver_out = subprocess.Popen(compiler_ver_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env).stdout.read().decode('utf-8') return "\n".join(['{}{}'.format(indent * 2, line.strip()) for line in compiler_ver_out.splitlines() if line.strip()]) +def filterflags(flags_str): + badflgs = { + '-fdebug-prefix-map', + '-DARCADIA_ROOT', + '-DARCADIA_BUILD_ROOT', + '/DARCADIA_ROOT', + '/DARCADIA_BUILD_ROOT', + } + + def flags_iter(): + for flag in flags_str.split(): + if not flag: + continue + if flag.split('=', 1)[0] in badflgs: + continue + yield flag + return ' '.join(flags_iter()) + + def main(): if len(sys.argv) != 4: - print >>sys.stderr, "Usage: build_info_gen.py <output file> <CXX compiler> <CXX flags>" + print("Usage: build_info_gen.py <output file> <CXX compiler> <CXX flags>", file=sys.stderr) sys.exit(1) cxx_compiler = sys.argv[2] - cxx_flags = sys.argv[3] + cxx_flags = filterflags(sys.argv[3]) with open(sys.argv[1], 'w') as result: - print >> result, "#pragma once\n" - print >> result, escaped_define("BUILD_INFO", get_build_info(cxx_compiler, cxx_flags)) - print >> result, escaped_define("BUILD_COMPILER", cxx_compiler) - print >> result, escaped_define("BUILD_COMPILER_VERSION", get_compiler_info(cxx_compiler)) - print >> result, escaped_define("BUILD_COMPILER_FLAGS", cxx_flags) + print("#pragma once\n", file=result) + print(escaped_define("BUILD_INFO", get_build_info(cxx_compiler, cxx_flags)), file=result) + print(escaped_define("BUILD_COMPILER", cxx_compiler), file=result) + print(escaped_define("BUILD_COMPILER_VERSION", get_compiler_info(cxx_compiler)), file=result) + print(escaped_define("BUILD_COMPILER_FLAGS", cxx_flags), file=result) if __name__ == "__main__": main() |