Browse Source

Let cmake export determine which build/scripts are mandatory

thegeorg 2 years ago
parent
commit
ad2a1b622d

+ 0 - 45
build/scripts/cgo1_wrapper.py

@@ -1,45 +0,0 @@
-import argparse
-import shutil
-import subprocess
-import sys
-
-
-CGO1_SUFFIX='.cgo1.go'
-
-
-def call(cmd, cwd, env=None):
-    # sys.stderr.write('{}\n'.format(' '.join(cmd)))
-    return subprocess.call(cmd, stdin=None, stderr=sys.stderr, stdout=sys.stdout, cwd=cwd, env=env)
-
-
-def process_file(source_root, source_prefix, build_root, build_prefix, src_path, comment_prefix):
-    dst_path = '{}.tmp'.format(src_path)
-    with open(src_path, 'r') as src_file, open(dst_path, 'w') as dst_file:
-        for line in src_file:
-            if line.startswith(comment_prefix):
-                dst_file.write(line.replace(source_root, source_prefix).replace(build_root, build_prefix))
-            else:
-                dst_file.write(line)
-    shutil.move(dst_path, src_path)
-
-
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--build-prefix', default='__ARCADIA_BUILD_ROOT_PREFIX__')
-    parser.add_argument('--build-root', required=True)
-    parser.add_argument('--cgo1-files', nargs='+', required=True)
-    parser.add_argument('--cgo2-files', nargs='+', required=True)
-    parser.add_argument('--source-prefix', default='__ARCADIA_SOURCE_ROOT_PREFIX__')
-    parser.add_argument('--source-root', required=True)
-    parser.add_argument('cgo1_cmd', nargs='*')
-    args = parser.parse_args()
-
-    exit_code = call(args.cgo1_cmd, args.source_root)
-    if exit_code != 0:
-        sys.exit(exit_code)
-
-    for src_path in args.cgo1_files:
-        process_file(args.source_root, args.source_prefix, args.build_root, args.build_prefix, src_path, '//')
-
-    for src_path in args.cgo2_files:
-        process_file(args.source_root, args.source_prefix, args.build_root, args.build_prefix, src_path, '#line')

+ 0 - 89
build/scripts/check_config_h.py

@@ -1,89 +0,0 @@
-import sys
-
-data = """
-#if defined(SIZEOF_LONG)
-static_assert(sizeof(long) == SIZEOF_LONG, "fixme 1");
-#endif
-
-#if defined(SIZEOF_PTHREAD_T)
-#include <pthread.h>
-
-static_assert(sizeof(pthread_t) == SIZEOF_PTHREAD_T, "fixme 2");
-#endif
-
-#if defined(SIZEOF_SIZE_T)
-#include <stddef.h>
-
-static_assert(sizeof(size_t) == SIZEOF_SIZE_T, "fixme 3");
-#endif
-
-#if defined(SIZEOF_TIME_T)
-#include <time.h>
-
-static_assert(sizeof(time_t) == SIZEOF_TIME_T, "fixme 4");
-#endif
-
-#if defined(SIZEOF_UINTPTR_T)
-#include <stdint.h>
-
-static_assert(sizeof(uintptr_t) == SIZEOF_UINTPTR_T, "fixme 5");
-#endif
-
-#if defined(SIZEOF_VOID_P)
-static_assert(sizeof(void*) == SIZEOF_VOID_P, "fixme 6");
-#endif
-
-#if defined(SIZEOF_FPOS_T)
-#include <stdio.h>
-
-static_assert(sizeof(fpos_t) == SIZEOF_FPOS_T, "fixme 7");
-#endif
-
-#if defined(SIZEOF_DOUBLE)
-static_assert(sizeof(double) == SIZEOF_DOUBLE, "fixme 8");
-#endif
-
-#if defined(SIZEOF_LONG_DOUBLE)
-static_assert(sizeof(long double) == SIZEOF_LONG_DOUBLE, "fixme 9");
-#endif
-
-#if defined(SIZEOF_FLOAT)
-static_assert(sizeof(float) == SIZEOF_FLOAT, "fixme 10");
-#endif
-
-#if defined(SIZEOF_INT)
-static_assert(sizeof(int) == SIZEOF_INT, "fixme 11");
-#endif
-
-#if defined(SIZEOF_LONG_LONG)
-static_assert(sizeof(long long) == SIZEOF_LONG_LONG, "fixme 12");
-#endif
-
-#if defined(SIZEOF_OFF_T)
-#include <stdio.h>
-
-static_assert(sizeof(off_t) == SIZEOF_OFF_T, "fixme 13");
-#endif
-
-#if defined(SIZEOF_PID_T)
-#include <unistd.h>
-
-static_assert(sizeof(pid_t) == SIZEOF_PID_T, "fixme 14");
-#endif
-
-#if defined(SIZEOF_SHORT)
-static_assert(sizeof(short) == SIZEOF_SHORT, "fixme 15");
-#endif
-
-#if defined(SIZEOF_WCHAR_T)
-static_assert(sizeof(wchar_t) == SIZEOF_WCHAR_T, "fixme 16");
-#endif
-
-#if defined(SIZEOF__BOOL)
-//TODO
-#endif
-"""
-if __name__ == '__main__':
-    with open(sys.argv[2], 'w') as f:
-        f.write('#include <' + sys.argv[1] + '>\n\n')
-        f.write(data)

+ 0 - 53
build/scripts/clang_wrapper.py

@@ -1,53 +0,0 @@
-import subprocess
-import sys
-
-
-def fix(s):
-    # disable dbg DEVTOOLS-2744
-    if s == '-g':
-        return None
-    if s == '/Z7' or s == '/Od' or s == '/Ob0' or s == '/D_DEBUG':
-        return None
-
-    # disable sanitizers for generated code
-    if s.startswith('-fsanitize') or s == '-Dmemory_sanitizer_enabled' or s.startswith('-fsanitize-blacklist'):
-        return None
-
-    # strip gcc toolchain flags (appear when crosscompiling)
-    if s.startswith('-fabi-version'):
-        return None
-
-    # remove arguments unknown to clang-cl
-    if s == '-fcase-insensitive-paths':  # or s == '-fno-lto':  # DEVTOOLSSUPPORT-3966
-        return None
-
-    # Paths under .ya/tools/v3/.../msvc/include are divided with '\'
-    return s.replace('\\', '/')
-
-
-def fix_path(p):
-    try:
-        i = p.rfind('/bin/clang')
-        p = p[:i] + '/bin/clang-cl'
-    except ValueError:
-        pass
-    return p
-
-
-if __name__ == '__main__':
-    is_on_win = sys.argv[1] == 'yes'
-    path = sys.argv[2]
-    args = filter(None, [fix(s) for s in sys.argv[3:]])
-    if is_on_win:
-        path = fix_path(path)
-        try:
-            i = args.index('-emit-llvm')
-            args[i:i+1] = ['-Xclang', '-emit-llvm']
-        except ValueError:
-            pass
-        args.append('-fms-compatibility-version=19')
-
-    cmd = [path] + args
-
-    rc = subprocess.call(cmd, shell=False, stderr=sys.stderr, stdout=sys.stdout)
-    sys.exit(rc)

+ 0 - 102
build/scripts/compile_java.py

@@ -1,102 +0,0 @@
-import optparse
-import contextlib
-import os
-import shutil
-import subprocess as sp
-import tarfile
-import zipfile
-import sys
-
-
-def parse_args(args):
-    parser = optparse.OptionParser()
-    parser.add_option('--javac-bin')
-    parser.add_option('--jar-bin')
-    parser.add_option('--vcs-mf')
-    parser.add_option('--package-prefix')
-    parser.add_option('--jar-output')
-    parser.add_option('--srcs-jar-output')
-    return parser.parse_args(args)
-
-
-def mkdir_p(directory):
-    if not os.path.exists(directory):
-        os.makedirs(directory)
-
-
-def split_cmd_by_delim(cmd, delim='DELIM'):
-    result = [[]]
-    for arg in cmd:
-        if arg == delim:
-            result.append([])
-        else:
-            result[-1].append(arg)
-    return result
-
-
-def main():
-    cmd_parts = split_cmd_by_delim(sys.argv)
-    assert len(cmd_parts) == 3
-    args, javac_opts, peers = cmd_parts
-    opts, jsrcs = parse_args(args)
-
-    jsrcs += list(filter(lambda x: x.endswith('.jsrc'), peers))
-    peers = list(filter(lambda x: not x.endswith('.jsrc'), peers))
-
-    sources_dir = 'src'
-    mkdir_p(sources_dir)
-    for s in jsrcs:
-        if s.endswith('.jsrc'):
-            with contextlib.closing(tarfile.open(s, 'r')) as tf:
-                tf.extractall(sources_dir)
-
-    srcs = []
-    for r, _, files in os.walk(sources_dir):
-        for f in files:
-            srcs.append(os.path.join(r, f))
-    srcs += jsrcs
-    srcs = list(filter(lambda x: x.endswith('.java'), srcs))
-
-    classes_dir = 'cls'
-    mkdir_p(classes_dir)
-    classpath = os.pathsep.join(peers)
-
-    if srcs:
-        temp_sources_file = 'temp.sources.list'
-        with open(temp_sources_file, 'w') as ts:
-            ts.write(' '.join(srcs))
-        sp.check_call([opts.javac_bin, '-nowarn', '-g', '-classpath', classpath, '-encoding', 'UTF-8', '-d', classes_dir] + javac_opts + ['@' + temp_sources_file])
-
-    for s in jsrcs:
-        if s.endswith('-sources.jar'):
-            with zipfile.ZipFile(s) as zf:
-                zf.extractall(sources_dir)
-
-        elif s.endswith('.jar'):
-            with zipfile.ZipFile(s) as zf:
-                zf.extractall(classes_dir)
-
-    if opts.vcs_mf:
-        sp.check_call([opts.jar_bin, 'cfm', opts.jar_output, opts.vcs_mf, os.curdir], cwd=classes_dir)
-    else:
-        sp.check_call([opts.jar_bin, 'cfM', opts.jar_output, os.curdir], cwd=classes_dir)
-
-    if opts.srcs_jar_output:
-        for s in jsrcs:
-            if s.endswith('.java'):
-                if opts.package_prefix:
-                    d = os.path.join(sources_dir, *(opts.package_prefix.split('.') + [os.path.basename(s)]))
-
-                else:
-                    d = os.path.join(sources_dir, os.path.basename(s))
-
-                shutil.copyfile(s, d)
-
-        if opts.vcs_mf:
-            sp.check_call([opts.jar_bin, 'cfm', opts.srcs_jar_output, opts.vcs_mf, os.curdir], cwd=sources_dir)
-        else:
-            sp.check_call([opts.jar_bin, 'cfM', opts.srcs_jar_output, os.curdir], cwd=sources_dir)
-
-
-if __name__ == '__main__':
-    main()

+ 0 - 59
build/scripts/configure_file.py

@@ -1,59 +0,0 @@
-#!/usr/bin/env python2.7
-
-import sys
-import os.path
-import re
-
-cmakeDef01 = "#cmakedefine01"
-cmakeDef = "#cmakedefine"
-
-
-def replaceLine(l, varDict, define):
-    words = l.split()
-    if words:
-        if words[0] == cmakeDef:
-            sPos = l.find(cmakeDef)
-            ePos = sPos + len(cmakeDef)
-            l = l[:sPos] + define + l[ePos:] + '\n'
-        if words[0] == cmakeDef01:
-            var = words[1]
-            cmakeValue = varDict.get(var)
-            if cmakeValue == 'yes':
-                val = '1'
-            else:
-                val = '0'
-            sPos = l.find(cmakeDef01)
-            ePos = l.find(var) + len(var)
-            l = l[:sPos] + define + ' ' + var + ' ' + val + l[ePos + 1:] + '\n'
-
-    finder = re.compile(".*?(@[a-zA-Z0-9_]+@).*")
-    while True:
-        re_result = finder.match(l)
-        if not re_result:
-            return l
-        key = re_result.group(1)[1:-1]
-        l = l[:re_result.start(1)] + varDict.get(key, '') + l[re_result.end(1):]
-
-
-def main(inputPath, outputPath, varDict):
-    define = '#define' if os.path.splitext(outputPath)[1] != '.asm' else '%define'
-    with open(outputPath, 'w') as output:
-        with open(inputPath, 'r') as input:
-            for l in input:
-                output.write(replaceLine(l, varDict, define))
-
-
-def usage():
-    print "usage: configure_file.py inputPath outputPath key1=value1 ..."
-    exit(1)
-
-
-if __name__ == "__main__":
-    if len(sys.argv) < 3:
-        usage()
-    varDict = {}
-    for x in sys.argv[3:]:
-        key, value = str(x).split('=', 1)
-        varDict[key] = value
-
-    main(sys.argv[1], sys.argv[2], varDict)

+ 0 - 138
build/scripts/copy_docs_files_to_dir.py

@@ -1,138 +0,0 @@
-import argparse
-import errno
-import os
-import process_command_files as pcf
-import shutil
-import sys
-
-
-def parse_args():
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--bin-dir', nargs='*')
-    parser.add_argument('--build-root', required=True)
-    parser.add_argument('--dest-dir', required=True)
-    parser.add_argument('--docs-dir', action='append', nargs=2, dest='docs_dirs', default=None)
-    parser.add_argument('--existing', choices=('skip', 'overwrite'), default='overwrite')
-    parser.add_argument('--source-root', required=True)
-    parser.add_argument('--src-dir', action='append', nargs='*', dest='src_dirs', default=None)
-    parser.add_argument('files', nargs='*')
-    return parser.parse_args(pcf.get_args(sys.argv[1:]))
-
-
-def makedirs(dirname):
-    try:
-        os.makedirs(dirname)
-    except OSError as e:
-        if e.errno == errno.EEXIST and os.path.isdir(dirname):
-            pass
-        else:
-            raise
-
-
-def copy_file(src, dst, overwrite=False, orig_path=None, generated=False):
-    if os.path.exists(dst) and not overwrite:
-        return
-
-    makedirs(os.path.dirname(dst))
-
-    with open(src, 'r') as fsrc, open(dst, 'w') as fdst:
-        # if (orig_path or generated) and src.endswith('.md'):
-        #    fdst.write('---\n{}\n\n---\n'.format('generated: true' if generated else 'vcsPath: {}'.format(orig_path)))
-        shutil.copyfileobj(fsrc, fdst)
-
-
-def main():
-    args = parse_args()
-
-    dest_dir = os.path.normpath(args.dest_dir)
-    makedirs(dest_dir)
-
-    source_root = os.path.normpath(args.source_root) + os.path.sep
-    build_root = os.path.normpath(args.build_root) + os.path.sep
-
-    is_overwrite_existing = args.existing == 'overwrite'
-
-    if args.docs_dirs:
-        for item in args.docs_dirs:
-            assert len(item) == 2
-            docs_dir, nm = item[0], item[1]
-            assert not os.path.isabs(docs_dir)
-            if nm and nm != '.':
-                assert not os.path.isabs(nm)
-                dst = os.path.join(dest_dir, nm)
-            else:
-                dst = dest_dir
-
-            abs_docs_dir = os.path.join(args.source_root, docs_dir)
-
-            for root, _, files in os.walk(abs_docs_dir):
-                for f in files:
-                    if os.path.islink(os.path.join(root, f)):
-                        continue
-                    file_src = os.path.join(root, f)
-                    assert file_src.startswith(source_root)
-                    file_dst = os.path.join(dst, os.path.relpath(root, abs_docs_dir), f)
-                    copy_file(file_src, file_dst, overwrite=is_overwrite_existing, orig_path=file_src[len(source_root):])
-
-    if args.src_dirs:
-        for item in args.src_dirs:
-            assert len(item) > 1
-            src_dir, nm = os.path.normpath(item[0]), item[1]
-            assert os.path.isabs(src_dir)
-            if nm and nm != '.':
-                assert not os.path.isabs(nm)
-                dst = os.path.join(dest_dir, nm)
-            else:
-                dst = dest_dir
-
-            if src_dir.startswith(source_root):
-                root = source_root
-                is_from_source_root = True
-            else:
-                assert src_dir.startswith(build_root)
-                root = build_root
-                is_from_source_root = False
-
-            for f in item[2:]:
-                file_src = os.path.normpath(f)
-                assert file_src.startswith(root)
-                rel_path = file_src[len(root):] if is_from_source_root else None
-                file_dst = os.path.join(dst, file_src[len(src_dir):])
-                copy_file(file_src, file_dst, overwrite=is_overwrite_existing, orig_path=rel_path)
-
-    if args.bin_dir:
-        assert len(args.bin_dir) > 1
-        bin_dir, bin_dir_namespace = os.path.normpath(args.bin_dir[0]) + os.path.sep, args.bin_dir[1]
-        assert bin_dir.startswith(build_root)
-        if bin_dir_namespace and bin_dir_namespace != '.':
-            assert not os.path.isabs(bin_dir_namespace)
-            dst = os.path.join(dest_dir, bin_dir_namespace)
-        else:
-            dst = dest_dir
-
-        for file_src in args.bin_dir[2:]:
-            assert os.path.isfile(file_src)
-            assert file_src.startswith(bin_dir)
-            file_dst = os.path.join(dst, file_src[len(bin_dir):])
-            copy_file(file_src, file_dst, overwrite=is_overwrite_existing, orig_path=None)
-
-    for src in args.files:
-        generated = False
-        file_src = os.path.normpath(src)
-        assert os.path.isfile(file_src), 'File [{}] does not exist...'.format(file_src)
-        rel_path = file_src
-        if file_src.startswith(source_root):
-            rel_path = file_src[len(source_root):]
-        elif file_src.startswith(build_root):
-            # generated = True
-            # rel_path = file_src[len(build_root):]
-            rel_path = None
-        else:
-            raise Exception('Unexpected file path [{}].'.format(file_src))
-        assert not os.path.isabs(rel_path)
-        file_dst = os.path.join(args.dest_dir, rel_path)
-        copy_file(file_src, file_dst, is_overwrite_existing, rel_path, generated)
-
-
-if __name__ == '__main__':
-    main()

+ 0 - 43
build/scripts/extract_docs.py

@@ -1,43 +0,0 @@
-import argparse
-import os
-import process_command_files as pcf
-import tarfile
-import sys
-
-
-def parse_args():
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--dest-dir', required=True)
-    parser.add_argument('--skip-prefix', dest='skip_prefixes', action='append', default=[])
-    parser.add_argument('docs', nargs='*')
-    return parser.parse_args(pcf.get_args(sys.argv[1:]))
-
-
-def main():
-    args = parse_args()
-
-    prefixes = ['{}{}'.format(os.path.normpath(p), os.path.sep) for p in args.skip_prefixes]
-
-    def _valid_docslib(path):
-        base = os.path.basename(path)
-        return base.endswith(('.docslib', '.docslib.fake')) or base == 'preprocessed.tar.gz'
-
-    for src in [p for p in args.docs if _valid_docslib(p)]:
-        if src == 'preprocessed.tar.gz':
-            rel_dst = os.path.dirname(os.path.normpath(src))
-            for prefix in prefixes:
-                if src.startswith(prefix):
-                    rel_dst = rel_dst[len(prefix):]
-                    continue
-            assert not os.path.isabs(rel_dst)
-            dest_dir = os.path.join(args.dest_dir, rel_dst)
-        else:
-            dest_dir = args.dest_dir
-        if not os.path.exists(dest_dir):
-            os.makedirs(dest_dir)
-        with tarfile.open(src, 'r') as tar_file:
-            tar_file.extractall(dest_dir)
-
-
-if __name__ == '__main__':
-    main()

+ 0 - 375
build/scripts/fetch_from.py

@@ -1,375 +0,0 @@
-import datetime as dt
-import errno
-import hashlib
-import json
-import logging
-import os
-import platform
-import random
-import shutil
-import socket
-import string
-import sys
-import tarfile
-import urllib2
-
-import retry
-
-
-def make_user_agent():
-    return 'fetch_from: {host}'.format(host=socket.gethostname())
-
-
-def add_common_arguments(parser):
-    parser.add_argument('--copy-to')  # used by jbuild in fetch_resource
-    parser.add_argument('--rename-to')  # used by test_node in inject_mds_resource_to_graph
-    parser.add_argument('--copy-to-dir')
-    parser.add_argument('--untar-to')
-    parser.add_argument('--rename', action='append', default=[], metavar='FILE', help='rename FILE to the corresponding output')
-    parser.add_argument('--executable', action='store_true', help='make outputs executable')
-    parser.add_argument('--log-path')
-    parser.add_argument('-v', '--verbose', action='store_true', default=os.environ.get('YA_VERBOSE_FETCHER'), help='increase stderr verbosity')
-    parser.add_argument('outputs', nargs='*', default=[])
-
-
-def ensure_dir(path):
-    if not (path == '' or os.path.isdir(path)):
-        os.makedirs(path)
-
-
-# Reference code: library/python/fs/__init__.py
-def hardlink_or_copy(src, dst):
-    ensure_dir(os.path.dirname(dst))
-
-    if os.name == 'nt':
-        shutil.copy(src, dst)
-    else:
-        try:
-            os.link(src, dst)
-        except OSError as e:
-            if e.errno == errno.EEXIST:
-                return
-            elif e.errno in (errno.EXDEV, errno.EMLINK, errno.EINVAL, errno.EACCES):
-                sys.stderr.write("Can't make hardlink (errno={}) - fallback to copy: {} -> {}\n".format(e.errno, src, dst))
-                shutil.copy(src, dst)
-            else:
-                raise
-
-
-def rename_or_copy_and_remove(src, dst):
-    ensure_dir(os.path.dirname(dst))
-
-    try:
-        os.rename(src, dst)
-    except OSError:
-        shutil.copy(src, dst)
-        os.remove(src)
-
-
-class BadChecksumFetchError(Exception):
-    pass
-
-
-class IncompleteFetchError(Exception):
-    pass
-
-
-class ResourceUnpackingError(Exception):
-    pass
-
-
-class ResourceIsDirectoryError(Exception):
-    pass
-
-
-class OutputIsDirectoryError(Exception):
-    pass
-
-
-class OutputNotExistError(Exception):
-    pass
-
-
-def setup_logging(args, base_name):
-    def makedirs(path):
-        try:
-            os.makedirs(path)
-        except OSError:
-            pass
-
-    if args.log_path:
-        log_file_name = args.log_path
-    else:
-        log_file_name = base_name + ".log"
-
-    args.abs_log_path = os.path.abspath(log_file_name)
-    makedirs(os.path.dirname(args.abs_log_path))
-    logging.basicConfig(filename=args.abs_log_path, level=logging.DEBUG)
-    if args.verbose:
-        logging.getLogger().addHandler(logging.StreamHandler(sys.stderr))
-
-
-def is_temporary(e):
-
-    def is_broken(e):
-        return isinstance(e, urllib2.HTTPError) and e.code in (410, 404)
-
-    if is_broken(e):
-        return False
-
-    if isinstance(e, (BadChecksumFetchError, IncompleteFetchError, urllib2.URLError, socket.error)):
-        return True
-
-    import error
-
-    return error.is_temporary_error(e)
-
-
-def uniq_string_generator(size=6, chars=string.ascii_lowercase + string.digits):
-    return ''.join(random.choice(chars) for _ in range(size))
-
-
-def report_to_snowden(value):
-    def inner():
-        body = {
-            'namespace': 'ygg',
-            'key': 'fetch-from-sandbox',
-            'value': json.dumps(value),
-        }
-
-        urllib2.urlopen(
-            'https://back-snowden.qloud.yandex-team.ru/report/add',
-            json.dumps([body, ]),
-            timeout=5,
-        )
-
-    try:
-        inner()
-    except Exception as e:
-        logging.warning('report_to_snowden failed: %s', e)
-
-
-def copy_stream(read, *writers, **kwargs):
-    chunk_size = kwargs.get('size', 1024*1024)
-    while True:
-        data = read(chunk_size)
-        if not data:
-            break
-        for write in writers:
-            write(data)
-
-
-def md5file(fname):
-    res = hashlib.md5()
-    with open(fname, 'rb') as f:
-        copy_stream(f.read, res.update)
-    return res.hexdigest()
-
-
-def git_like_hash_with_size(filepath):
-    """
-    Calculate git like hash for path
-    """
-    sha = hashlib.sha1()
-
-    file_size = 0
-
-    with open(filepath, 'rb') as f:
-        while True:
-            block = f.read(2 ** 16)
-
-            if not block:
-                break
-
-            file_size += len(block)
-            sha.update(block)
-
-    sha.update('\0')
-    sha.update(str(file_size))
-
-    return sha.hexdigest(), file_size
-
-
-def size_printer(display_name, size):
-    sz = [0]
-    last_stamp = [dt.datetime.now()]
-
-    def printer(chunk):
-        sz[0] += len(chunk)
-        now = dt.datetime.now()
-        if last_stamp[0] + dt.timedelta(seconds=10) < now:
-            if size:
-                print >>sys.stderr, "##status##{} - [[imp]]{:.1f}%[[rst]]".format(display_name, 100.0 * sz[0] / size if size else 0)
-            last_stamp[0] = now
-
-    return printer
-
-
-def fetch_url(url, unpack, resource_file_name, expected_md5=None, expected_sha1=None, tries=10, writers=None):
-    logging.info('Downloading from url %s name %s and expected md5 %s', url, resource_file_name, expected_md5)
-    tmp_file_name = uniq_string_generator()
-
-    request = urllib2.Request(url, headers={'User-Agent': make_user_agent()})
-    req = retry.retry_func(lambda: urllib2.urlopen(request, timeout=30), tries=tries, delay=5, backoff=1.57079)
-    logging.debug('Headers: %s', req.headers.headers)
-    expected_file_size = int(req.headers.get('Content-Length', 0))
-    real_md5 = hashlib.md5()
-    real_sha1 = hashlib.sha1()
-
-    with open(tmp_file_name, 'wb') as fp:
-        copy_stream(
-            req.read,
-            fp.write,
-            real_md5.update,
-            real_sha1.update,
-            size_printer(resource_file_name, expected_file_size),
-            *([] if writers is None else writers)
-        )
-
-    real_md5 = real_md5.hexdigest()
-    real_file_size = os.path.getsize(tmp_file_name)
-    real_sha1.update('\0')
-    real_sha1.update(str(real_file_size))
-    real_sha1 = real_sha1.hexdigest()
-
-    if unpack:
-        tmp_dir = tmp_file_name + '.dir'
-        os.makedirs(tmp_dir)
-        with tarfile.open(tmp_file_name, mode="r|gz") as tar:
-            tar.extractall(tmp_dir)
-        tmp_file_name = os.path.join(tmp_dir, resource_file_name)
-        real_md5 = md5file(tmp_file_name)
-
-    logging.info('File size %s (expected %s)', real_file_size, expected_file_size or "UNKNOWN")
-    logging.info('File md5 %s (expected %s)', real_md5, expected_md5)
-    logging.info('File sha1 %s (expected %s)', real_sha1, expected_sha1)
-
-    if expected_md5 and real_md5 != expected_md5:
-        report_to_snowden(
-            {
-                'headers': req.headers.headers,
-                'expected_md5': expected_md5,
-                'real_md5': real_md5
-            }
-        )
-
-        raise BadChecksumFetchError(
-            'Downloaded {}, but expected {} for {}'.format(
-                real_md5,
-                expected_md5,
-                url,
-            )
-        )
-
-    if expected_sha1 and real_sha1 != expected_sha1:
-        report_to_snowden(
-            {
-                'headers': req.headers.headers,
-                'expected_sha1': expected_sha1,
-                'real_sha1': real_sha1
-            }
-        )
-
-        raise BadChecksumFetchError(
-            'Downloaded {}, but expected {} for {}'.format(
-                real_sha1,
-                expected_sha1,
-                url,
-            )
-        )
-
-    if expected_file_size and expected_file_size != real_file_size:
-        report_to_snowden({'headers': req.headers.headers, 'file_size': real_file_size})
-
-        raise IncompleteFetchError(
-            'Downloaded {}, but expected {} for {}'.format(
-                real_file_size,
-                expected_file_size,
-                url,
-            )
-        )
-
-    return tmp_file_name
-
-
-def chmod(filename, mode):
-    if platform.system().lower() == 'windows':
-        # https://docs.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions:
-        # hard to reset read-only attribute for removal if there are multiple hardlinks
-        return
-    stat = os.stat(filename)
-    if stat.st_mode & 0o777 != mode:
-        try:
-            os.chmod(filename, mode)
-        except OSError:
-            import pwd
-            sys.stderr.write("{} st_mode: {} pwuid: {}\n".format(filename, stat.st_mode, pwd.getpwuid(os.stat(filename).st_uid)))
-            raise
-
-
-def process(fetched_file, file_name, args, remove=True):
-    assert len(args.rename) <= len(args.outputs), (
-        'too few outputs to rename', args.rename, 'into', args.outputs)
-
-    # Forbid changes to the loaded resource
-    chmod(fetched_file, 0o444)
-
-    if not os.path.isfile(fetched_file):
-        raise ResourceIsDirectoryError('Resource must be a file, not a directory: %s' % fetched_file)
-
-    if args.copy_to:
-        hardlink_or_copy(fetched_file, args.copy_to)
-        if not args.outputs:
-            args.outputs = [args.copy_to]
-
-    if args.rename_to:
-        args.rename.append(fetched_file)
-        if not args.outputs:
-            args.outputs = [args.rename_to]
-
-    if args.copy_to_dir:
-        hardlink_or_copy(fetched_file, os.path.join(args.copy_to_dir, file_name))
-
-    if args.untar_to:
-        ensure_dir(args.untar_to)
-        # Extract only requested files
-        try:
-            with tarfile.open(fetched_file, mode='r:*') as tar:
-                inputs = set(map(os.path.normpath, args.rename + args.outputs[len(args.rename):]))
-                members = [entry for entry in tar if os.path.normpath(os.path.join(args.untar_to, entry.name)) in inputs]
-                tar.extractall(args.untar_to, members=members)
-            # Forbid changes to the loaded resource data
-            for root, _, files in os.walk(args.untar_to):
-                for filename in files:
-                    chmod(os.path.join(root, filename), 0o444)
-        except tarfile.ReadError as e:
-            logging.exception(e)
-            raise ResourceUnpackingError('File {} cannot be untared'.format(fetched_file))
-
-    for src, dst in zip(args.rename, args.outputs):
-        if src == 'RESOURCE':
-            src = fetched_file
-        if os.path.abspath(src) == os.path.abspath(fetched_file):
-            logging.info('Copying %s to %s', src, dst)
-            hardlink_or_copy(src, dst)
-        else:
-            logging.info('Renaming %s to %s', src, dst)
-            if os.path.exists(dst):
-                raise ResourceUnpackingError("Target file already exists ({} -> {})".format(src, dst))
-            if remove:
-                rename_or_copy_and_remove(src, dst)
-            else:
-                hardlink_or_copy(src, dst)
-
-    for path in args.outputs:
-        if not os.path.exists(path):
-            raise OutputNotExistError('Output does not exist: %s' % os.path.abspath(path))
-        if not os.path.isfile(path):
-            raise OutputIsDirectoryError('Output must be a file, not a directory: %s' % os.path.abspath(path))
-        if args.executable:
-            chmod(path, os.stat(path).st_mode | 0o111)
-        if os.path.abspath(path) == os.path.abspath(fetched_file):
-            remove = False
-
-    if remove:
-        os.remove(fetched_file)

+ 0 - 269
build/scripts/fetch_from_sandbox.py

@@ -1,269 +0,0 @@
-import itertools
-import json
-import logging
-import argparse
-import os
-import random
-import subprocess
-import sys
-import time
-import urllib2
-import uuid
-
-import fetch_from
-
-
-ORIGIN_SUFFIX = '?origin=fetch-from-sandbox'
-MDS_PREFIX = 'http://storage-int.mds.yandex.net/get-sandbox/'
-TEMPORARY_ERROR_CODES = (429, 500, 503, 504)
-
-
-def parse_args():
-    parser = argparse.ArgumentParser()
-    fetch_from.add_common_arguments(parser)
-    parser.add_argument('--resource-id', type=int, required=True)
-    parser.add_argument('--custom-fetcher')
-    parser.add_argument('--resource-file')
-    return parser.parse_args()
-
-
-class ResourceInfoError(Exception):
-    pass
-
-
-class UnsupportedProtocolException(Exception):
-    pass
-
-
-def _sky_path():
-    return "/usr/local/bin/sky"
-
-
-def _is_skynet_avaliable():
-    if not os.path.exists(_sky_path()):
-        return False
-    try:
-        subprocess.check_output([_sky_path(), "--version"])
-        return True
-    except subprocess.CalledProcessError:
-        return False
-    except OSError:
-        return False
-
-
-def download_by_skynet(resource_info, file_name):
-    def sky_get(skynet_id, target_dir, timeout=None):
-        cmd_args = [_sky_path(), 'get', "-N", "Backbone", "--user", "--wait", "--dir", target_dir, skynet_id]
-        if timeout is not None:
-            cmd_args += ["--timeout", str(timeout)]
-        logging.info('Call skynet with args: %s', cmd_args)
-        stdout = subprocess.check_output(cmd_args).strip()
-        logging.debug('Skynet call with args %s is finished, result is %s', cmd_args, stdout)
-        return stdout
-
-    if not _is_skynet_avaliable():
-        raise UnsupportedProtocolException("Skynet is not available")
-
-    skynet_id = resource_info.get("skynet_id")
-    if not skynet_id:
-        raise ValueError("Resource does not have skynet_id")
-
-    temp_dir = os.path.abspath(fetch_from.uniq_string_generator())
-    os.mkdir(temp_dir)
-    sky_get(skynet_id, temp_dir)
-    return os.path.join(temp_dir, file_name)
-
-
-def _urlopen(url, data=None, headers=None):
-    n = 10
-    tout = 30
-    started = time.time()
-    reqid = uuid.uuid4()
-
-    request = urllib2.Request(url, data=data, headers=headers or {})
-    request.add_header('X-Request-Timeout', str(tout))
-    request.add_header('X-Request-Id', str(reqid))
-    request.add_header('User-Agent', 'fetch_from_sandbox.py')
-    for i in xrange(n):
-        retry_after = i
-        try:
-            request.add_header('X-Request-Duration', str(int(time.time() - started)))
-            return urllib2.urlopen(request, timeout=tout).read()
-
-        except urllib2.HTTPError as e:
-            logging.warning('failed to fetch URL %s with HTTP code %d: %s', url, e.code, e)
-            retry_after = int(e.headers.get('Retry-After', str(retry_after)))
-
-            if e.code not in TEMPORARY_ERROR_CODES:
-                raise
-
-        except Exception as e:
-            logging.warning('failed to fetch URL %s: %s', url, e)
-
-        if i + 1 == n:
-            raise e
-
-        time.sleep(retry_after)
-
-
-def _query(url):
-    return json.loads(_urlopen(url))
-
-
-_SANDBOX_BASE_URL = 'https://sandbox.yandex-team.ru/api/v1.0'
-
-
-def get_resource_info(resource_id, touch=False, no_links=False):
-    url = ''.join((_SANDBOX_BASE_URL, '/resource/', str(resource_id)))
-    headers = {}
-    if touch:
-        headers.update({'X-Touch-Resource': '1'})
-    if no_links:
-        headers.update({'X-No-Links': '1'})
-    return _query(url)
-
-
-def get_resource_http_links(resource_id):
-    url = ''.join((_SANDBOX_BASE_URL, '/resource/', str(resource_id), '/data/http'))
-    return [r['url'] + ORIGIN_SUFFIX for r in _query(url)]
-
-
-def fetch_via_script(script, resource_id):
-    return subprocess.check_output([script, str(resource_id)]).rstrip()
-
-
-def fetch(resource_id, custom_fetcher):
-    try:
-        resource_info = get_resource_info(resource_id, touch=True, no_links=True)
-    except Exception as e:
-        sys.stderr.write(
-            "Failed to fetch resource {}: {}\n".format(resource_id, str(e))
-        )
-        raise
-
-    if resource_info.get('state', 'DELETED') != 'READY':
-        raise ResourceInfoError("Resource {} is not READY".format(resource_id))
-
-    logging.info('Resource %s info %s', str(resource_id), json.dumps(resource_info))
-
-    resource_file_name = os.path.basename(resource_info["file_name"])
-    expected_md5 = resource_info.get('md5')
-
-    proxy_link = resource_info['http']['proxy'] + ORIGIN_SUFFIX
-
-    mds_id = resource_info.get('attributes', {}).get('mds')
-    mds_link = MDS_PREFIX + mds_id if mds_id else None
-
-    def get_storage_links():
-        storage_links = get_resource_http_links(resource_id)
-        random.shuffle(storage_links)
-        return storage_links
-
-    skynet = _is_skynet_avaliable()
-
-    if not skynet:
-        logging.info("Skynet is not available, will try other protocols")
-
-    def iter_tries():
-        if skynet:
-            yield lambda: download_by_skynet(resource_info, resource_file_name)
-
-        if custom_fetcher:
-            yield lambda: fetch_via_script(custom_fetcher, resource_id)
-
-        # Don't try too hard here: we will get back to proxy later on
-        yield lambda: fetch_from.fetch_url(proxy_link, False, resource_file_name, expected_md5, tries=2)
-        for x in get_storage_links():
-            # Don't spend too much time connecting single host
-            yield lambda: fetch_from.fetch_url(x, False, resource_file_name, expected_md5, tries=1)
-            if mds_link is not None:
-                # Don't try too hard here: we will get back to MDS later on
-                yield lambda: fetch_from.fetch_url(mds_link, True, resource_file_name, expected_md5, tries=2)
-        yield lambda: fetch_from.fetch_url(proxy_link, False, resource_file_name, expected_md5)
-        if mds_link is not None:
-            yield lambda: fetch_from.fetch_url(mds_link, True, resource_file_name, expected_md5)
-
-    if resource_info.get('attributes', {}).get('ttl') != 'inf':
-        sys.stderr.write('WARNING: resource {} ttl is not "inf".\n'.format(resource_id))
-
-    exc_info = None
-    for i, action in enumerate(itertools.islice(iter_tries(), 0, 10)):
-        try:
-            fetched_file = action()
-            break
-        except UnsupportedProtocolException:
-            pass
-        except subprocess.CalledProcessError as e:
-            logging.warning('failed to fetch resource %s with subprocess: %s', resource_id, e)
-            time.sleep(i)
-        except urllib2.HTTPError as e:
-            logging.warning('failed to fetch resource %s with HTTP code %d: %s', resource_id, e.code, e)
-            if e.code not in TEMPORARY_ERROR_CODES:
-                exc_info = exc_info or sys.exc_info()
-            time.sleep(i)
-        except Exception as e:
-            logging.exception(e)
-            exc_info = exc_info or sys.exc_info()
-            time.sleep(i)
-    else:
-        if exc_info:
-            raise exc_info[0], exc_info[1], exc_info[2]
-        else:
-            raise Exception("No available protocol and/or server to fetch resource")
-
-    return fetched_file, resource_info['file_name']
-
-
-def _get_resource_info_from_file(resource_file):
-    if resource_file is None or not os.path.exists(resource_file):
-        return None
-
-    RESOURCE_INFO_JSON = "resource_info.json"
-    RESOURCE_CONTENT_FILE_NAME = "resource"
-
-    resource_dir, resource_file = os.path.split(resource_file)
-    if resource_file != RESOURCE_CONTENT_FILE_NAME:
-        return None
-
-    resource_json = os.path.join(resource_dir, RESOURCE_INFO_JSON)
-    if not os.path.isfile(resource_json):
-        return None
-
-    try:
-        with open(resource_json, 'r') as j:
-            resource_info = json.load(j)
-        resource_info['file_name']  # check consistency
-        return resource_info
-    except:
-        logging.debug('Invalid %s in %s', RESOURCE_INFO_JSON, resource_dir)
-
-    return None
-
-
-def main(args):
-    custom_fetcher = os.environ.get('YA_CUSTOM_FETCHER')
-
-    resource_info = _get_resource_info_from_file(args.resource_file)
-    if resource_info:
-        fetched_file = args.resource_file
-        file_name = resource_info['file_name']
-    else:
-        # This code should be merged to ya and removed.
-        fetched_file, file_name = fetch(args.resource_id, custom_fetcher)
-
-    fetch_from.process(fetched_file, file_name, args, remove=not custom_fetcher and not resource_info)
-
-
-if __name__ == '__main__':
-    args = parse_args()
-    fetch_from.setup_logging(args, os.path.basename(__file__))
-
-    try:
-        main(args)
-    except Exception as e:
-        logging.exception(e)
-        print >>sys.stderr, open(args.abs_log_path).read()
-        sys.stderr.flush()
-
-        import error
-        sys.exit(error.ExitCodes.INFRASTRUCTURE_ERROR if fetch_from.is_temporary(e) else 1)

+ 0 - 104
build/scripts/fs_tools.py

@@ -1,104 +0,0 @@
-from __future__ import print_function
-
-import os
-import platform
-import sys
-import shutil
-import errno
-
-import process_command_files as pcf
-
-
-def link_or_copy(src, dst):
-    try:
-        if platform.system().lower() == 'windows':
-            shutil.copy(src, dst)
-        else:
-            os.link(src, dst)
-    except OSError as e:
-        if e.errno == errno.EEXIST:
-            print('link_or_copy: destination file already exists: {}'.format(dst), file=sys.stderr)
-        if e.errno == errno.ENOENT:
-            print('link_or_copy: source file doesn\'t exists: {}'.format(src), file=sys.stderr)
-        raise
-
-
-if __name__ == '__main__':
-    mode = sys.argv[1]
-    args = pcf.get_args(sys.argv[2:])
-
-    if mode == 'copy':
-        shutil.copy(args[0], args[1])
-    elif mode == 'copy_tree_no_link':
-        dst = args[1]
-        shutil.copytree(args[0], dst, ignore=lambda dirname, names: [n for n in names if os.path.islink(os.path.join(dirname, n))])
-    elif mode == 'copy_files':
-        src = args[0]
-        dst = args[1]
-        files = open(args[2]).read().strip().split()
-        for f in files:
-            s = os.path.join(src, f)
-            d = os.path.join(dst, f)
-            if os.path.exists(d):
-                continue
-            try:
-                os.makedirs(os.path.dirname(d))
-            except OSError:
-                pass
-            shutil.copy(s, d)
-    elif mode == 'copy_all_files':
-        src = args[0]
-        dst = args[1]
-        for root, _, files in os.walk(src):
-            for f in files:
-                if os.path.islink(os.path.join(root, f)):
-                    continue
-                file_dst = os.path.join(dst, os.path.relpath(root, src), f)
-                if os.path.exists(file_dst):
-                    continue
-                try:
-                    os.makedirs(os.path.dirname(file_dst))
-                except OSError:
-                    pass
-                shutil.copy(os.path.join(root, f), file_dst)
-    elif mode == 'rename_if_exists':
-        if os.path.exists(args[0]):
-            shutil.move(args[0], args[1])
-    elif mode == 'rename':
-        targetdir = os.path.dirname(args[1])
-        if targetdir and not os.path.exists(targetdir):
-            os.makedirs(os.path.dirname(args[1]))
-        shutil.move(args[0], args[1])
-    elif mode == 'remove':
-        for f in args:
-            try:
-                if os.path.isfile(f) or os.path.islink(f):
-                    os.remove(f)
-                else:
-                    shutil.rmtree(f)
-            except OSError:
-                pass
-    elif mode == 'link_or_copy':
-        link_or_copy(args[0], args[1])
-    elif mode == 'link_or_copy_to_dir':
-        assert len(args) > 1
-        start = 0
-        if args[0] == '--no-check':
-            if args == 2:
-                sys.exit()
-            start = 1
-        dst = args[-1]
-        for src in args[start:-1]:
-            link_or_copy(src, os.path.join(dst, os.path.basename(src)))
-    elif mode == 'cat':
-        with open(args[0], 'w') as dst:
-            for input_name in args[1:]:
-                with open(input_name) as src:
-                    dst.write(src.read())
-    elif mode == 'md':
-        try:
-            os.makedirs(args[0])
-        except OSError:
-            pass
-    else:
-        raise Exception('unsupported tool %s' % mode)

Some files were not shown because too many files changed in this diff