aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornumpor <numpor@yandex-team.ru>2022-02-10 16:51:42 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:51:42 +0300
commitd2b794bb633932cc63f615ab82c6ffe29856be1a (patch)
treeab7fbbf3253d4c0e2793218f09378908beb025fb
parent54d3768621e7b304a1cccb26fb8e9bc4b87208f8 (diff)
downloadydb-d2b794bb633932cc63f615ab82c6ffe29856be1a.tar.gz
Restoring authorship annotation for <numpor@yandex-team.ru>. Commit 2 of 2.
-rw-r--r--build/scripts/decimal_md5.py136
-rw-r--r--build/ymake.core.conf10
2 files changed, 73 insertions, 73 deletions
diff --git a/build/scripts/decimal_md5.py b/build/scripts/decimal_md5.py
index 598fbf8401..e70ca80a09 100644
--- a/build/scripts/decimal_md5.py
+++ b/build/scripts/decimal_md5.py
@@ -1,79 +1,79 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import hashlib
-import struct
-import sys
-import os
-import argparse
-
-
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import hashlib
+import struct
+import sys
+import os
+import argparse
+
+
def print_code(checksum, func_name):
if len(func_name) == 0: # safe fallback for old ya.make files
func_name = "DecimalMD5"
print 'const char* ' + func_name + '() {return "' + checksum + '";}'
-
-
-def ensure_paths_exist(paths):
- bad_paths = sorted(
- path for path in paths
- if not os.path.exists(path)
- )
- if bad_paths:
- print >> sys.stderr, "decimal_md5 inputs do not exist:"
- for path in bad_paths:
- print >> sys.stderr, path
- sys.exit(1)
-
-
-def _update_digest_with_file_contents(digest, path, block_size=65535):
- with open(path) as f:
- while True:
- block = f.read(block_size)
- if not block:
- break
- digest.update(block)
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument("--fixed-output", help="don not calculate md5, use this value instead")
- parser.add_argument("--lower-bits", help="use specified count of lower bits", type=int, default=32)
- parser.add_argument("--source-root", help="arcadia source root")
+
+
+def ensure_paths_exist(paths):
+ bad_paths = sorted(
+ path for path in paths
+ if not os.path.exists(path)
+ )
+ if bad_paths:
+ print >> sys.stderr, "decimal_md5 inputs do not exist:"
+ for path in bad_paths:
+ print >> sys.stderr, path
+ sys.exit(1)
+
+
+def _update_digest_with_file_contents(digest, path, block_size=65535):
+ with open(path) as f:
+ while True:
+ block = f.read(block_size)
+ if not block:
+ break
+ digest.update(block)
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--fixed-output", help="don not calculate md5, use this value instead")
+ parser.add_argument("--lower-bits", help="use specified count of lower bits", type=int, default=32)
+ parser.add_argument("--source-root", help="arcadia source root")
parser.add_argument("--func-name", help="custom function name to be defined", default="DecimalMD5")
- parser.add_argument("targets", nargs='*', default=['.'])
-
- args = parser.parse_args()
-
- abs_paths = [
+ parser.add_argument("targets", nargs='*', default=['.'])
+
+ args = parser.parse_args()
+
+ abs_paths = [
os.path.join(args.source_root, target)
- for target in args.targets
- ]
- ensure_paths_exist(abs_paths)
-
- if args.fixed_output:
- try:
+ for target in args.targets
+ ]
+ ensure_paths_exist(abs_paths)
+
+ if args.fixed_output:
+ try:
bitmask = (1 << args.lower_bits) - 1
fmt = '{:0%dd}' % len(str(bitmask))
checksum = fmt.format(int(args.fixed_output) & bitmask)
- except ValueError:
- raise ValueError("decimal_md5: bad value passed via --fixed-output: %s" % args.fixed_output)
+ except ValueError:
+ raise ValueError("decimal_md5: bad value passed via --fixed-output: %s" % args.fixed_output)
print_code(str(checksum), func_name=args.func_name)
- return
-
- md5 = hashlib.md5()
- for path in abs_paths:
- _update_digest_with_file_contents(md5, path)
-
- md5_parts = struct.unpack('IIII', md5.digest())
- md5_int = sum(part << (32 * n) for n, part in enumerate(md5_parts))
- bitmask = (1 << args.lower_bits) - 1
- fmt = '{:0%dd}' % len(str(bitmask))
-
- checksum_str = fmt.format(md5_int & bitmask)
+ return
+
+ md5 = hashlib.md5()
+ for path in abs_paths:
+ _update_digest_with_file_contents(md5, path)
+
+ md5_parts = struct.unpack('IIII', md5.digest())
+ md5_int = sum(part << (32 * n) for n, part in enumerate(md5_parts))
+ bitmask = (1 << args.lower_bits) - 1
+ fmt = '{:0%dd}' % len(str(bitmask))
+
+ checksum_str = fmt.format(md5_int & bitmask)
print_code(checksum_str, func_name=args.func_name)
-
-
-if __name__ == "__main__":
- main()
-
+
+
+if __name__ == "__main__":
+ main()
+
diff --git a/build/ymake.core.conf b/build/ymake.core.conf
index dd9ecac636..081833998b 100644
--- a/build/ymake.core.conf
+++ b/build/ymake.core.conf
@@ -6472,17 +6472,17 @@ macro CREATE_BUILDINFO_FOR(GenHdr) {
.CMD=$YIELD $CXX_COMPILER && $YIELD $CXXFLAGS && $XARGS $YMAKE_PYTHON ${input:BUILDVERSION_SCRIPT} ${output:GenHdr} ${kv;hide:"p BI"} ${kv;hide:"pc yellow"} ${hide;kv:"show_out"} $SVN_DEPENDS_CACHE__NO_UID__
}
-DECIMAL_MD5_SCRIPT=build/scripts/decimal_md5.py
-DECIMAL_MD5_FIXED=
-
+DECIMAL_MD5_SCRIPT=build/scripts/decimal_md5.py
+DECIMAL_MD5_FIXED=
+
### @usage: DECIMAL_MD5_LOWER_32_BITS(<fileName> [FUNCNAME funcName] [inputs...])
###
### Generates .cpp file <fileName> with one defined function 'const char* <funcName>() { return "<calculated_md5_hash>"; }'.
### <calculated_md5_hash> will be md5 hash for all inputs passed to this macro.
macro DECIMAL_MD5_LOWER_32_BITS(File, FUNCNAME="", Opts...) {
.CMD=$YMAKE_PYTHON ${input:DECIMAL_MD5_SCRIPT} --fixed-output=${DECIMAL_MD5_FIXED} --func-name=${FUNCNAME} --lower-bits 32 --source-root=$ARCADIA_ROOT ${input;context=TEXT:Opts} ${output;stdout;chksum:File} ${kv;hide:"p SV"} ${kv;hide:"pc yellow"} ${hide;kv:"show_out"}
-}
-
+}
+
# tag:internal
### @usage $CFG_VARS # internal
###