Example #1
0
def build(ctx):
    scala = fbuild.builders.scala.Builder(ctx)

    lib = scala.build_lib('lib.jar', ['world.scala'])

    ctx.logger.log(' * running script.scala:')
    scala.run_script('script.scala', classpaths=[lib])

    exe = scala.build_lib('exe.jar', ['compiled.scala'], classpaths=[lib])
    ctx.logger.log(' * running %s:' % exe)
    scala.run_class('HelloWorld', classpaths=[lib, exe])
Example #2
0
def build(ctx):
    scala = fbuild.builders.scala.Builder(ctx)

    lib = scala.build_lib('lib.jar', ['world.scala'])

    ctx.logger.log(' * running script.scala:')
    scala.run_script('script.scala', classpaths=[lib])

    exe = scala.build_lib('exe.jar', ['compiled.scala'], classpaths=[lib])
    ctx.logger.log(' * running %s:' % exe)
    scala.run_class('HelloWorld', classpaths=[lib, exe])
Example #3
0
File: speed.py Project: arowM/felix
def run_test(ctx, path, dst, srcs:fbuild.db.SRCS, expect:fbuild.db.OPTIONAL_SRC,
        *,
        c,
        cxx,
        felix,
        java,
        ocaml,
        scala):
    lang = path.name.rsplit(':')[0]

    # Compile the executable
    try:
        if lang == 'c':
            exe = c.build_exe(dst, srcs)
        elif lang == 'c++':
            exe = cxx.build_exe(dst, srcs)
        elif lang == 'felix':
            # All the felix tests are named test.flx
            exe = felix.compile(path / 'test.flx', static=True)
        elif lang == 'java':
            # Exit early if java isn't supported
            if java is None:
                return None, None
            exe = java.build_lib(dst + '.jar', srcs, cwd=dst.parent)
        elif lang == 'ocaml':
            exe = ocaml.build_exe(dst, srcs, external_libs=['unix'])
        elif lang == 'scala':
            # Exit early if scala isn't supported
            if scala is None:
                return None, None
            exe = scala.build_lib(dst + '.jar', srcs, cwd=dst.parent)
        else:
            ctx.logger.check('do not know how to build', path,
                color='yellow')
            return None, None
    except fbuild.ExecutionError:
        # If we failed to compile, just move on
        return None, None

    ctx.db.add_external_dependencies_to_call(dsts=[exe])

    # Run the executable and measure the wall clock time
    ctx.logger.check('running ' + exe)
    t0 = time.time()
    try:
        if lang == 'java':
            stdout, stderr = java.run_class('Test',
                classpaths=[exe.name],
                cwd=exe.parent,
                timeout=60,
                quieter=1)
        elif lang == 'scala':
            # We have to be careful with scala since it doesn't
            # like ':'s in it's classpaths.
            stdout, stderr = scala.run_class('Test',
                classpaths=[exe.name],
                cwd=exe.parent,
                timeout=60,
                quieter=1)
        else:
            stdout, stderr = ctx.execute(exe, timeout=60, quieter=1)
    except fbuild.ExecutionTimedOut as e:
        t1 = time.time()
        ctx.logger.failed('failed: timed out')

        ctx.logger.log(e, verbose=1)
        if e.stdout:
            ctx.logger.log(e.stdout.decode().strip(), verbose=1)
        if e.stderr:
            ctx.logger.log(e.stderr.decode().strip(), verbose=1)

        internal_time = None
        wall_time = time.time() - t0
    else:
        wall_time = time.time() - t0

        if expect is None:
            internal_time = float(stdout.decode())

            ctx.logger.passed('ok: %.4f time %.4f total' %
                (internal_time, wall_time))
        else:
            stdout = stdout.replace(b'\r\n', b'\n').replace(b'\r', b'\n')
            stdout, internal_time, _ = stdout.rsplit(b'\n', 2)
            stdout = stdout + b'\n'

            with open(expect, 'rb') as f:
                s = f.read().replace(b'\r\n', b'\n').replace(b'\r', b'\n')

            if stdout == s:
                internal_time = float(internal_time.decode())

                ctx.logger.passed('ok: %.4f time %.4f total' %
                    (internal_time, wall_time))
            else:
                internal_time = None

                ctx.logger.failed('failed: output does not match')

                for line in difflib.ndiff(
                        stdout.decode().split('\n'),
                        s.decode().split('\n')):
                    ctx.logger.log(line)

    return internal_time, wall_time