aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/vcs_info.py
diff options
context:
space:
mode:
authorsvidyuk <svidyuk@yandex-team.com>2022-12-20 10:35:35 +0300
committersvidyuk <svidyuk@yandex-team.com>2022-12-20 10:35:35 +0300
commitd238c469aadb562f79ff0c394c83d6918197c606 (patch)
treea72f9bc9050fcb20ab939e3af74532d6298f7bb7 /build/scripts/vcs_info.py
parent84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9 (diff)
downloadydb-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.
Diffstat (limited to 'build/scripts/vcs_info.py')
-rw-r--r--build/scripts/vcs_info.py37
1 files changed, 11 insertions, 26 deletions
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__':