예제 #1
0
def main(stack):
    remainder = common.splitRemainder()
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=description.format(
            annotation=default_annotation,
            delegate_function=default_delegate_function),
        parents=[
            common.commonArguments(needsBackend=False),
            skip_native_compile.arguments(),
        ],
    )
    parser.add_argument(
        "program",
        type=str,
        help="The program for which tests should be run (project:unit)",
    )
    parser.add_argument("--backend",
                        default=os.environ.get("BACKEND", "native"))
    parser.add_argument("--timeout",
                        type=int,
                        default=os.environ.get("SKIP_TEST_TIMEOUT", "300"))
    parser.add_argument("--watch", default=False, action="store_true")

    args = common.parse_args(parser)
    mainFilePath = build_main_file(stack, args.program, args.backend)

    args.srcs = [args.program, mainFilePath]

    if args.backend == "native":
        binFile = skip_native_compile.compile(stack, args)
        cmd = (binFile.name, )
        if args.watch:
            cmd += ("--watch", )
    else:
        print("Uknown backend %s" % (args.backend))
        exit(2)

    cmd += tuple(remainder)
    logger.debug("Running: " + ' '.join(map(pipes.quote, cmd)))
    with common.PerfTimer("skip_native_exec.test_runtime"):
        res = subprocess.call(
            ("ulimit -t %d ; " % (args.timeout, )) +
            ' '.join(map(pipes.quote, cmd)),
            shell=True,
            env=os.environ,
        )
    if res != 0:
        sys.exit(res)
예제 #2
0
def compile(stack, args):
    extraOpts = []
    skip_flags = os.environ.get('SKIP_FLAGS', '')
    if skip_flags:
        extraOpts += skip_flags.split(',')

    output = stack.enter_context(common.tmpdir(prefix='tmp.js_exec.'))
    cmd = [
        os.path.join(common.build_dir, 'bin/skip_to_js'), '--output',
        output + '/sk.js', '--no-source-map'
    ] + extraOpts + args.srcs

    logger.debug('Running: ' + ' '.join(map(pipes.quote, cmd)))

    with common.PerfTimer('skip_to_js.runtime'):
        common.callHelper(cmd)

    return [
        common.root_dir + '/tools/run_js', '--no-unhandled-exception-stack',
        output
    ]
예제 #3
0
def compile(stack, args):
    if not args.preamble:
        args.preamble = os.path.join(binary_dir,
                                     'runtime/native/lib/preamble.ll')

    CC = common.cmakeCacheGet('CMAKE_CXX_COMPILER')
    CFLAGS = tuple(
        subprocess.check_output(
            ('pkg-config', '--cflags',
             os.path.join(binary_dir,
                          'runtime/native/native_cc.pc'))).strip().split(' '))
    LIBS = tuple(
        subprocess.check_output(
            ('pkg-config', '--libs',
             os.path.join(binary_dir,
                          'runtime/native/native_cc.pc'))).strip().split(' '))

    # Run skip_to_native to generate our .o file
    objFile = stack.enter_context(common.tmpfile('tmp.gen_object.', '.o'))

    SKFLAGS = tuple(
        filter(
            # Because for some reason gcc decided that linker flags should start
            # with the same prefix as warnings.
            lambda x: not x.startswith('-Wl,'),
            filter(lambda x: x.startswith(('-m', '-f', '-W', '-g', '-O')),
                   CFLAGS)))

    PROFILE_FLAGS = ('--profile', args.profile) if args.profile else ()

    PARALLEL_FLAGS = (('--parallel',
                       str(args.parallel)) if args.parallel is not None else
                      ())

    PRINT_SKIP_TO_LLVM = (
        '--print-skip-to-llvm', ) if args.print_skip_to_llvm else ()

    cmd = (
        os.path.join(source_dir, 'runtime/tools/skip_to_native'),
        '--preamble',
        args.preamble,
        '--output',
        objFile.name,
        '--via-backend',
        args.via_backend,
    ) + PROFILE_FLAGS + PARALLEL_FLAGS + tuple(
        args.srcs) + SKFLAGS + PRINT_SKIP_TO_LLVM

    logger.debug('Running: ' + ' '.join(map(pipes.quote, cmd)))
    common.callHelper(cmd)

    # do not continue compilation if we are just printing skip_to_llvm
    if args.print_skip_to_llvm:
        exit(0)

    # Compile the .o into the final binary
    binFile = stack.enter_context(common.tmpfile('tmp.gen_binary.', ''))
    binFile.close()

    # For each file that we're compiling look to see if it has an associated
    # .cpp file.  For a directory the associated .cpp is named testhelper.cpp.
    # For a file.sk the associated .cpp is named file_testhelper.cpp.
    def testCpp(x):
        if os.path.isdir(x):
            return os.path.join(x, 'testhelper.cpp')
        else:
            return os.path.splitext(x)[0] + '_testhelper.cpp'

    cppSrcs = tuple(
        filter(lambda x: os.path.isfile(x), map(testCpp, args.srcs)))
    sk_standalone = (args.sk_standalone or os.path.join(
        source_dir, 'runtime/native/src/sk_standalone.cpp'))
    cmd = (CC, '-o', binFile.name, '-g', sk_standalone,
           objFile.name) + cppSrcs + CFLAGS + LIBS
    logger.debug('Running: ' + ' '.join(map(pipes.quote, cmd)))

    with common.PerfTimer('clang.runtime'):
        common.callHelper(cmd)

    common.logPerfData('binary_size', ['skip_compiler'],
                       os.path.getsize(binFile.name))

    # if we want to create a named executable at the location of args.output
    if args.output:
        shutil.copy(os.path.join(source_dir, binFile.name), args.output)

    return binFile