diff options
author | svidyuk <svidyuk@yandex-team.com> | 2022-12-20 10:35:35 +0300 |
---|---|---|
committer | svidyuk <svidyuk@yandex-team.com> | 2022-12-20 10:35:35 +0300 |
commit | d238c469aadb562f79ff0c394c83d6918197c606 (patch) | |
tree | a72f9bc9050fcb20ab939e3af74532d6298f7bb7 | |
parent | 84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9 (diff) | |
download | ydb-d238c469aadb562f79ff0c394c83d6918197c606.tar.gz |
Resore port of vcs_info.py to pyton3
* Atomic commit swiching vcs_info.py to py3.
* Keeping java build part py2 compatible (it can be dropped when maven-export is switched to new java build engine for all projects).
* Last external build system generator release 7 with code assuming that vcs_info.py is py3 compatible redeployed.
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | build/scripts/vcs_info.py | 37 | ||||
-rw-r--r-- | cmake/common.cmake (renamed from cmake/yandex_common.cmake) | 5 |
3 files changed, 14 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 59b3db065a..c7c7d91ae2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,11 +23,11 @@ enable_testing() include(cmake/antlr.cmake) include(cmake/archive.cmake) include(cmake/bison.cmake) +include(cmake/common.cmake) include(cmake/conan.cmake) include(cmake/global_flags.cmake) include(cmake/llvm-tools.cmake) include(cmake/protobuf.cmake) -include(cmake/yandex_common.cmake) include(cmake/global_vars.cmake) if (CMAKE_CROSSCOMPILING) diff --git a/build/scripts/vcs_info.py b/build/scripts/vcs_info.py index a91aa9792c..8b4de2cd0c 100644 --- a/build/scripts/vcs_info.py +++ b/build/scripts/vcs_info.py @@ -12,17 +12,11 @@ import zipfile class _Formatting(object): @staticmethod def is_str(strval): - if sys.version_info >= (3, 0, 0): - return isinstance(strval, (bytes, str)) - else: - return isinstance(strval, basestring) + return isinstance(strval, (bytes, str)) @staticmethod def encoding_needed(strval): - if sys.version_info >= (3, 0, 0): - return isinstance(strval, str) - else: - return isinstance(strval, unicode) + return isinstance(strval, str) @staticmethod def escape_special_symbols(strval): @@ -30,8 +24,7 @@ class _Formatting(object): c_str = strval.encode('utf-8') if encoding_needed else strval retval = b"" for c in c_str: - if sys.version_info >= (3, 0, 0): - c = bytes([c]) + c = bytes([c]) if c in ("\\", "\""): retval += "\\" + c elif ord(c) < ord(' '): @@ -93,12 +86,12 @@ def get_json(file_name): out = json.load(f) # TODO: check 'tar+svn' parsing - for i in ['ARCADIA_SOURCE_REVISION', 'ARCADIA_SOURCE_LAST_CHANGE', 'SVN_REVISION']: - if i in out and _Formatting.is_str(out[i]): + for num_var in ['ARCADIA_SOURCE_REVISION', 'ARCADIA_SOURCE_LAST_CHANGE', 'SVN_REVISION']: + if num_var in out and _Formatting.is_str(out[num_var]): try: - out[i] = int(out[i]) + out[num_var] = int(out[num_var]) except: - out[i] = -1 + out[num_var] = -1 return out except: return get_default_json() @@ -109,20 +102,12 @@ def print_c(json_file, output_file, argv): json file output file $(SOURCE_ROOT)/build/scripts/c_templates/svn_interface.c""" - def gen_header(info): - lines = [] - for k, v in info.items(): - lines.append(_Formatting.escaped_define(k, v)) - return lines - interface = argv[0] with open(interface) as c: c_file = c.read() with open(output_file, 'w') as f: - header = '\n'.join(gen_header(json_file)) - if sys.version_info < (3, 0, 0): - header = header.encode('utf-8') + header = '\n'.join(_Formatting.escaped_define(k, v) for k, v in json_file.items()) f.write(header + '\n' + c_file) @@ -214,8 +199,8 @@ def print_java_mf(info): return [] return wrapper.wrap(key + val) - lines = wrap('Program-Version-String: ', base64.b64encode(info['PROGRAM_VERSION'].encode('utf-8'))) - lines += wrap('SCM-String: ', base64.b64encode(info['SCM_DATA'].encode('utf-8'))) + lines = wrap('Program-Version-String: ', base64.b64encode(info['PROGRAM_VERSION'].encode('utf-8')).decode('utf-8')) + lines += wrap('SCM-String: ', base64.b64encode(info['SCM_DATA'].encode('utf-8')).decode('utf-8')) lines += wrap('Arcadia-Source-Path: ', info['ARCADIA_SOURCE_PATH']) lines += wrap('Arcadia-Source-URL: ', info['ARCADIA_SOURCE_URL']) lines += wrap('Arcadia-Source-Revision: ', str(info['ARCADIA_SOURCE_REVISION'])) @@ -262,7 +247,7 @@ def print_go(json_file, output_file): ['func init() {', ' buildinfo.InitBuildInfo(buildinfomap)', '}'] - ).encode('utf-8') + '\n') + ) + '\n') if __name__ == '__main__': diff --git a/cmake/yandex_common.cmake b/cmake/common.cmake index 1c136d5804..aedd887a20 100644 --- a/cmake/yandex_common.cmake +++ b/cmake/common.cmake @@ -1,6 +1,5 @@ # Set of common macros -find_package(Python2 REQUIRED) find_package(Python3 REQUIRED) add_compile_definitions(CATBOOST_OPENSOURCE=yes) @@ -39,7 +38,7 @@ function(target_joined_source TgtName Out) endforeach() add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${Out} - COMMAND Python2::Interpreter ${CMAKE_SOURCE_DIR}/build/scripts/gen_join_srcs.py ${CMAKE_CURRENT_BINARY_DIR}/${Out} ${IncludesList} + COMMAND Python3::Interpreter ${CMAKE_SOURCE_DIR}/build/scripts/gen_join_srcs.py ${CMAKE_CURRENT_BINARY_DIR}/${Out} ${IncludesList} DEPENDS ${CMAKE_SOURCE_DIR}/build/scripts/gen_join_srcs.py ${ARGN} ) target_sources(${TgtName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${Out}) @@ -137,7 +136,7 @@ endfunction() function(vcs_info Tgt) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/__vcs_version__.c - COMMAND Python2::Interpreter ${CMAKE_SOURCE_DIR}/build/scripts/vcs_info.py no-vcs dummy.json ${CMAKE_CURRENT_BINARY_DIR}/__vcs_version__.c ${CMAKE_SOURCE_DIR}/build/scripts/c_templates/svn_interface.c + COMMAND Python3::Interpreter ${CMAKE_SOURCE_DIR}/build/scripts/vcs_info.py no-vcs dummy.json ${CMAKE_CURRENT_BINARY_DIR}/__vcs_version__.c ${CMAKE_SOURCE_DIR}/build/scripts/c_templates/svn_interface.c DEPENDS ${CMAKE_SOURCE_DIR}/build/scripts/vcs_info.py ${CMAKE_SOURCE_DIR}/build/scripts/c_templates/svn_interface.c ) target_sources(${Tgt} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/__vcs_version__.c) |