Beispiel #1
0
 def test_link_dir(self):
     """Test link_dir()"""
     with utils.TempDir() as tmpdir:
         source = os.path.join(tmpdir, 'source')
         os.mkdir(source)
         utils.write_file(os.path.join(source, 'foo'), 'foo')
         utils.write_file(os.path.join(source, 'baz'), 'foo')
         utils.write_file(os.path.join(source, 'CMakeLists.txt'), 'foo')
         target = os.path.join(tmpdir, 'target')
         os.mkdir(target)
         # Add an OK existing symlink
         os.symlink(os.path.join(source, 'foo'),
                    os.path.join(target, 'foo'))
         # Add a bad existing symlink
         os.symlink(os.path.join(source, 'bar'),
                    os.path.join(target, 'badln'))
         # Add a good existing symlink
         os.symlink(os.path.join(source, 'foo'),
                    os.path.join(target, 'goodln'))
         python_tools.link_dir(source, target)
         self.assertRaises(TypeError,
                           python_tools.link_dir,
                           source,
                           target,
                           match='foo')
         # all links should have been removed
         self.assertEqual(sorted(os.listdir(target)), sorted(['foo',
                                                              'baz']))
Beispiel #2
0
    def test_setup_cmake(self):
        """Test setup_cmake.py"""
        subdirs = [
            'src', '.foo', 'gitflow',
            os.path.join('src', 'internal'), 'bar',
            os.path.join('bar', 'test')
        ]
        with utils.TempDir() as tmpdir:
            for s in subdirs:
                os.mkdir(os.path.join(tmpdir, s))
                utils.write_file(os.path.join(tmpdir, s, 'foo.py'), "foo")

            p = subprocess.Popen([setup_cmake], cwd=tmpdir)
            stdout, stderr = p.communicate()
            self.assertEqual(p.returncode, 0)

            fname = os.path.join(tmpdir, 'src', 'Files.cmake')
            f = utils.read_file(fname)
            self.assertEqual(
                f.split('\n')[0], 'set(pyfiles "foo.py;internal/foo.py")')
            os.unlink(fname)

            fname = os.path.join(tmpdir, 'bar', 'test', 'Files.cmake')
            f = utils.read_file(fname)
            self.assertEqual(f.split('\n')[0], 'set(pyfiles "foo.py")')
            os.unlink(fname)
            # Assert that no other files were created (rmdirs would fail)
            for s in subdirs[::-1]:
                os.unlink(os.path.join(tmpdir, s, 'foo.py'))
                os.rmdir(os.path.join(tmpdir, s))
            self.assertEqual(os.listdir(tmpdir), [])
Beispiel #3
0
 def test_get_existing_links(self):
     """Test get_existing_links()"""
     with utils.TempDir() as tmpdir:
         utils.write_file(os.path.join(tmpdir, 'orig'), 'foo')
         os.symlink('orig', os.path.join(tmpdir, 'lnk'))
         self.assertEqual(python_tools.get_existing_links(tmpdir),
                          [os.path.join(tmpdir, 'lnk')])
Beispiel #4
0
 def test_setup_git_repo_no_dev_tools(self):
     """Test setup_git.py script with repo settings, no dev tools"""
     with utils.TempDir() as tmpdir:
         subprocess.check_call(['git', 'init'], cwd=tmpdir)
         p = subprocess.Popen([setup_git], cwd=tmpdir)
         stdout, stderr = p.communicate()
         self.assertEqual(p.returncode, 1)
Beispiel #5
0
    def test_header(self):
        """Test make_all_header.py script"""
        with utils.TempDir() as tmpdir:
            topdir = os.path.join(tmpdir, 'include', 'test')
            os.makedirs(topdir)
            os.mkdir(os.path.join(topdir, 'subdir'))
            explicit_h = os.path.join(topdir, 'explicit.h')
            sub_h = os.path.join(topdir, 'subdir', 'sub.h')
            sub_deprec_h = os.path.join(topdir, 'subdir', 'deprecated.h')
            utils.write_file(explicit_h, '')
            utils.write_file(sub_h, "sub_h")
            utils.write_file(sub_deprec_h, "DEPRECATED_HEADER")
            p = subprocess.Popen([header_py, 'include/test.h', 'bar',
                                  'include/test/explicit.h',
                                  'include/test/subdir'], cwd=tmpdir)
            stdout, stderr = p.communicate()
            self.assertEqual(p.returncode, 0)
            self.assertEqual(utils.read_file(os.path.join(tmpdir,
                                                          'include/test.h')),
                             """/**
 *  \\file test.h
 *  \\brief Include all non-deprecated headers in test.
 *
 *  Copyright 2007-2019 IMP Inventors. All rights reserved.
 */

#ifndef TEST_H
#define TEST_H
#include <bar/explicit.h>
#include <bar/sub.h>
#ifdef IMP_SWIG_WRAPPER
#include <bar/deprecated.h>
#endif
#endif /* TEST_H */
""")
Beispiel #6
0
def test_html_images(tmpdir):
    cwd = str(pathlib.Path().absolute())
    with utils.TempDir(tmpdir):

        text = image2html(cwd + "/data/test-image.png")
        assert text.startswith(r'<img src="data:image/png;base64,')
        assert text.endswith(r'" >')
        if not os.path.isdir("_tmp"):
            os.mkdir("_tmp")
        with open("_tmp/html-image-png.html", "w") as f:
            f.write(text)

        text = image2html(cwd + "/data/test-image.jpg")
        assert text.startswith(r'<img src="data:image/jpg;base64,')
        assert text.endswith(r'" >')
        if not os.path.isdir("_tmp"):
            os.mkdir("_tmp")
        with open("_tmp/html-image-jpg.html", "w") as f:
            f.write(text)

        text = image2html(cwd + "/data/test-image.svg")
        if not os.path.isdir("_tmp"):
            os.mkdir("_tmp")
        with open("_tmp/html-image-svg.html", "w") as f:
            f.write(text)
Beispiel #7
0
def masseur(apk,
            dex=None,
            resources=None,
            out=None,
            adb_options=None,
            keystore=None,
            install=False,
            quiet=False):
    if not out:
        out = os.path.basename(apk)
    if not keystore:
        keystore = findKeystore()
    with utils.TempDir() as temp:
        processed_apk = None
        if dex:
            processed_apk = repack(apk, dex, resources, temp, quiet)
        else:
            utils.Print('Signing original APK without modifying dex files',
                        quiet=quiet)
            processed_apk = os.path.join(temp, 'processed.apk')
            shutil.copyfile(apk, processed_apk)
        signed_apk = sign(processed_apk, keystore, temp, quiet=quiet)
        aligned_apk = align(signed_apk, temp, quiet=quiet)
        utils.Print('Writing result to {}'.format(out), quiet=quiet)
        shutil.copyfile(aligned_apk, out)
        if install:
            adb_cmd = ['adb']
            if adb_options:
                adb_cmd.extend(
                    [option for option in adb_options.split(' ') if option])
            adb_cmd.extend(['install', '-t', '-r', '-d', out])
            utils.RunCmd(adb_cmd, quiet=quiet)
Beispiel #8
0
def Main():
    args = parse_arguments()
    if args.maps and args.targets != 'lib':
        raise Exception("Use '--maps' only with '--targets lib.")
    target_root = args.android_root[0]
    jar_targets = JAR_TARGETS_MAP[args.targets]
    if args.commit_hash == None and args.version == None:
        gradle_args = map(lambda t: t[0], jar_targets)
        if args.java_max_memory_size:
            gradle_args.append('-Dorg.gradle.jvmargs=-Xmx' +
                               args.java_max_memory_size)
        gradle.RunGradle(gradle_args)
        copy_jar_targets(utils.LIBS, target_root, jar_targets, args.maps)
        copy_other_targets(utils.GENERATED_LICENSE_DIR, target_root)
    else:
        assert args.commit_hash == None or args.version == None
        targets = map((lambda t: t[0] + '.jar'), jar_targets) + OTHER_TARGETS
        with utils.TempDir() as root:
            for target in targets:
                if args.commit_hash:
                    download_hash(root, args.commit_hash, target)
                    if args.maps and target not in OTHER_TARGETS:
                        download_hash(root, args.commit_hash, target + '.map')
                else:
                    assert args.version
                    download_version(root, args.version, target)
                    if args.maps and target not in OTHER_TARGETS:
                        download_version(root, args.version, target + '.map')
            copy_jar_targets(root, target_root, jar_targets, args.maps)
            copy_other_targets(root, target_root)
Beispiel #9
0
def run(dexfile, oatfile=None, version='default', verbose=[]):
    # dex2oat accepts non-existent dex files, check here instead
    if not os.path.exists(dexfile):
        raise Exception('DEX file not found: "{}"'.format(dexfile))
    with utils.TempDir() as temp:
        if not oatfile:
            oatfile = os.path.join(temp, "out.oat")
        base = os.path.join(LINUX_DIR, DIRS[version])
        product = PRODUCTS[version]
        arch = ARCHS[version]
        cmd = [
            os.path.join(base, 'bin', 'dex2oat'),
            '--android-root=' +
            os.path.join(base, 'product', product, 'system'),
            '--runtime-arg',
            '-Xnorelocate',
            '--dex-file=' + dexfile,
            '--oat-file=' + oatfile,
            '--instruction-set=' + arch,
        ]
        for flag in verbose:
            cmd += ['--runtime-arg', '-verbose:' + flag]
        env = {"LD_LIBRARY_PATH": os.path.join(base, 'lib')}
        utils.PrintCmd(cmd)
        subprocess.check_call(cmd, env=env)
def Main():
    (options, args) = parse_options()
    if options.golem:
        golem.link_third_party()
    with utils.TempDir() as temp:
        dex_path = os.path.join(temp, "classes.jar")
        proguard_conf = os.path.join(temp, 'proguard.conf')
        with open(proguard_conf, 'w') as f:
            f.write(PROGUARD_CONF)
        benchmark_jar = get_jar_for_benchmark(options.benchmark)
        r8_args = [
            '--lib',
            utils.get_android_jar(26),  # Only works with api 26
            '--output',
            dex_path,
            '--pg-conf',
            proguard_conf,
            '--min-api',
            str(options.api),
            benchmark_jar
        ]
        toolhelper.run('r8', r8_args, build=not options.golem)
        if options.use_device:
            result = run_art_device(dex_path)
        else:
            result = run_art(dex_path)
        print('Kotlin_{}(RunTimeRaw): {} ms'.format(options.benchmark, result))
Beispiel #11
0
 def test_mkdir(self):
     """Test mkdir()"""
     with utils.TempDir() as tmpdir:
         path = os.path.join(tmpdir, 'foo', 'bar', 'baz')
         python_tools.mkdir(path, clean=True)
         self.assertTrue(os.path.exists(path))
         self.assertTrue(os.path.isdir(path))
Beispiel #12
0
def test_simple_writer(tmpdir):
    with utils.TempDir(tmpdir):
        ass = Assignment()

        with ass.add_question() as q:
            q.text = "q1"
            with q.add_part() as p:
                p.text = "q1p1"
            with q.add_part() as p:
                p.text = "q1p2"

        with ass.add_question() as q:
            q.text = "q2"
            with q.add_part() as p:
                p.text = "q2p1"
            with q.add_part() as p:
                p.text = "q2p2"

        with pytest.raises(RuntimeError):
            w = Writers.Simple()
            w.dump(ass)

        fh = io.StringIO()
        writer = Writers.Simple(fh)
        writer.dump(ass)
Beispiel #13
0
def test_problem_set_builder(tmpdir):
    with utils.TempDir(tmpdir):
        ass = Assignment()
        with ass.add_question() as q:
            q.text += "Question 1"
            with q.add_question() as qq:
                qq.text += "What is the answer to Q1?"
                with qq.add_answer(Answer.Numerical) as a:
                    a.quantity = 1.23

        with ass.add_question() as q:
            q.text += "Question 2"
            with q.add_part() as p:
                p.text += "Question 2, Part 1"
                with p.add_question() as qq:
                    qq.text += "What is the answer to Q2P1?"
                    with qq.add_answer(Answer.Numerical) as a:
                        a.quantity = 2.34

        if os.path.exists("_test"): shutil.rmtree("_test")
        os.mkdir("_test")

        Actions.BuildProblemSetAndBlackboardQuiz(ass, "test")
        shutil.rmtree("_test")

        Actions.BuildProblemSetAndBlackboardQuiz(ass, "test", remove=True)

        assert os.path.isdir("_test")
        assert os.path.isfile("_test/test.tex")
        assert os.path.isfile("_test/test.pdf")
        assert os.path.isfile("_test/test.aux")
        assert os.path.isfile("_test/test-quiz.txt")
Beispiel #14
0
def CreateAndUploadMacInstaller(arch):
    dart_icns = os.path.join('editor', 'tools', 'plugins',
                             'com.google.dart.tools.deploy', 'icons',
                             'dart.icns')
    mac_build_bundle_py = os.path.join('tools', 'mac_build_editor_bundle.sh')
    mac_build_dmg_py = os.path.join('tools', 'mac_build_editor_dmg.sh')
    editor_dir = GetEditorDirectory('Release', arch)
    dart_sdk = GetDartSdkDirectory('Release', arch)
    with utils.TempDir('eclipse') as temp_dir:
        # Get dartium
        dartium_directory = DownloadDartium(temp_dir, 'dartium-mac.zip')
        dartium_bundle_dir = os.path.join(dartium_directory, 'Chromium.app')

        # Build the editor bundle
        darteditor_bundle_dir = os.path.join(temp_dir, 'DartEditor.app')
        args = [
            mac_build_bundle_py, darteditor_bundle_dir, editor_dir, dart_sdk,
            dartium_bundle_dir, dart_icns
        ]
        RunProcess(args)

        # Build the dmg installer from the editor bundle
        dart_editor_dmg = os.path.join(temp_dir, 'DartEditor.dmg')
        args = [
            mac_build_dmg_py, dart_editor_dmg, darteditor_bundle_dir,
            dart_icns, 'Dart Editor'
        ]
        RunProcess(args)

        # Upload the dmg installer
        UploadInstaller(dart_editor_dmg, 'dart-editor-mac-%(revision)s.dmg')
Beispiel #15
0
def Main():
    utils.check_java_version()
    args = parse_arguments()
    output_dir = args.output
    if args.golem:
        golem.link_third_party()
    with utils.TempDir() as temp_dir:

        if not output_dir:
            output_dir = temp_dir

        xmx = None
        if args.tool == 'dx':
            tool_file = DX_JAR
            tool_args = [
                '--dex', '--output=' + output_dir, '--multi-dex',
                '--min-sdk-version=' + MIN_SDK_VERSION
            ]
            xmx = '-Xmx1600m'
        else:
            tool_file = utils.D8_JAR
            tool_args = ['--output', output_dir, '--min-api', MIN_SDK_VERSION]
            if args.tool == 'd8-release':
                tool_args.append('--release')
            xmx = '-Xmx600m'

        cmd = []

        track_memory_file = None
        if args.print_memoryuse:
            track_memory_file = os.path.join(output_dir,
                                             utils.MEMORY_USE_TMP_FILE)
            cmd.extend(['tools/track_memory.sh', track_memory_file])

        if tool_file.endswith('.jar'):
            assert xmx is not None
            cmd.extend(['java', xmx, '-jar'])

        cmd.extend([tool_file] + tool_args + [FRAMEWORK_JAR])

        utils.PrintCmd(cmd)

        t0 = time.time()
        subprocess.check_call(cmd)
        dt = time.time() - t0

        if args.print_memoryuse:
            print('{}-Total(MemoryUse): {}'.format(
                args.name, utils.grep_memoryuse(track_memory_file)))

        dex_files = [f for f in glob(os.path.join(output_dir, '*.dex'))]
        code_size = 0
        for dex_file in dex_files:
            code_size += os.path.getsize(dex_file)

        print('{}-Total(RunTimeRaw): {} ms'.format(args.name, 1000.0 * dt))

        print('{}-Total(CodeSize): {}'.format(args.name, code_size))

        utils.print_dexsegments(args.name, dex_files)
Beispiel #16
0
def Main():
  options = ParseOptions();
  build_dir = options.build_dir
  if not build_dir:
    print 'Please specify a build directory with "--build_dir".'
    sys.exit(1)
  sdk_dir = join(build_dir, 'dartino-sdk')
  print 'Creating sdk bundle for %s in %s' % (build_dir, sdk_dir)
  deb_package = options.deb_package
  with utils.TempDir() as sdk_temp:
    if options.create_documentation:
      CreateDocumentation()
    CopyBinaries(sdk_temp, build_dir)
    CopyDartSdk(sdk_temp)
    CopyInternalPackages(sdk_temp, build_dir)
    CopyLibs(sdk_temp, build_dir)
    CopyPackagesAndSettingsTemplate(sdk_temp)
    CopyPlatforms(sdk_temp)
    CopyArm(sdk_temp)
    CreateAgentSnapshot(sdk_temp, build_dir)
    CopySTM(sdk_temp)
    CopySamples(sdk_temp)
    CopyAdditionalFiles(sdk_temp)
    if deb_package:
      CopyArmDebPackage(sdk_temp, deb_package)
    EnsureDeleted(sdk_dir)
    if options.include_tools:
      CopyTools(sdk_temp)
    copytree(sdk_temp, sdk_dir)
  print 'Created sdk bundle for %s in %s' % (build_dir, sdk_dir)
Beispiel #17
0
def main(argv):
    options = parse_options(argv)
    outdir = options.out
    if outdir == None:
        print 'Need to supply output dir with --out.'
        exit(1)
    # Build the R8 no deps artifact.
    gradle.RunGradleExcludeDeps([utils.R8])
    # Create directory structure for this version.
    version = determine_version()
    with utils.TempDir() as tmp_dir:
        version_dir = join(tmp_dir, utils.get_maven_path(version))
        makedirs(version_dir)
        # Write the pom file.
        pom_file = join(version_dir, 'r8-' + version + '.pom')
        write_pom_file(version, pom_file)
        # Copy the jar to the output.
        target_jar = join(version_dir, 'r8-' + version + '.jar')
        copyfile(utils.R8_JAR, target_jar)
        # Create check sums.
        write_md5_for(target_jar)
        write_md5_for(pom_file)
        write_sha1_for(target_jar)
        write_sha1_for(pom_file)
        # Zip it up.
        make_archive(join(outdir, 'r8'), 'zip', tmp_dir)
Beispiel #18
0
def track_time_in_memory(options, args):
    # Args will be destroyed
    assert len(args) == 0
    if not options.track_time_in_memory_min:
        raise Exception(
            'You have to specify --track_time_in_memory_min when running with '
            '--track-time-in-memory')
    if not options.track_time_in_memory_max:
        raise Exception(
            'You have to specify --track_time_in_memory_max when running with '
            '--track-time-in-memory')
    if not options.track_time_in_memory_increment:
        raise Exception(
            'You have to specify --track_time_in_memory_increment when running '
            'with --track-time-in-memory')
    current = options.track_time_in_memory_min
    print('Memory (KB)\tTime (ms)')
    with utils.TempDir() as temp:
        stdout = os.path.join(temp, 'stdout')
        stdout_fd = open(stdout, 'w')
        while current <= options.track_time_in_memory_max:
            extra_args = ['-Xmx%sM' % current]
            t0 = time.time()
            exit_code = run_with_options(options, [],
                                         extra_args,
                                         stdout_fd,
                                         quiet=True)
            t1 = time.time()
            total = (1000.0 * (t1 - t0)) if exit_code == 0 else -1
            print('%s\t%s' % (current, total))
            current += options.track_time_in_memory_increment

    return 0
def generate_jar_with_desugar_configuration(configuration, implementation,
                                            conversions, destination):
    with utils.TempDir() as tmp_dir:
        # Add conversion classes.
        with zipfile.ZipFile(conversions, 'r') as conversions_zip:
            conversions_zip.extractall(tmp_dir)

        # Add configuration
        configuration_dir = join(tmp_dir, 'META-INF', 'desugar', 'd8')
        makedirs(configuration_dir)
        copyfile(configuration, join(configuration_dir, 'desugar.json'))

        # Add lint configuartion.
        lint_dir = join(configuration_dir, 'lint')
        makedirs(lint_dir)
        cmd = [
            jdk.GetJavaExecutable(), '-cp', utils.R8_JAR,
            'com.android.tools.r8.GenerateLintFiles', configuration,
            implementation, lint_dir
        ]
        utils.PrintCmd(cmd)
        subprocess.check_call(cmd)

        make_archive(destination, 'zip', tmp_dir)
        move(destination + '.zip', destination)
Beispiel #20
0
 def test_cpp_clang(self):
     """Test cleanup_code script on C++ files with clang-format."""
     # directories that should be ignored
     igdirs = ['dependency', 'eigen3', 'igdir', 'git-repo']
     for args in ['--all', 'test.cpp']:
         with utils.TempDir() as tmpdir:
             env = self.make_dummy_format('clang-format', tmpdir)
             for d in igdirs:
                 os.mkdir(os.path.join(tmpdir, d))
                 utils.write_file(os.path.join(tmpdir, d, 'test.h'), 'bar')
             # git-repo is a git submodule so shouldn't be descended into
             os.mkdir(os.path.join(tmpdir, 'git-repo', '.git'))
             cppfile = os.path.join(tmpdir, 'test.cpp')
             utils.write_file(cppfile, 'bar')
             p = subprocess.Popen([cleanup_py, '-v', '-e', 'igdir', args],
                                  cwd=tmpdir,
                                  env=env)
             stdout, stderr = p.communicate()
             self.assertEqual(p.returncode, 0)
             # dummy clang-format should have written out 'foo'
             self.assertEqual(utils.read_file(cppfile), 'foo\n')
             # ignored directories should be unchanged
             for d in igdirs:
                 con = utils.read_file(os.path.join(tmpdir, d, 'test.h'))
                 self.assertEqual(con, 'bar')
Beispiel #21
0
def Main():
    options = ParseOptions()
    version = options.version
    dryrun = options.dryrun
    gsutil = bot_utils.GSUtil()

    def gsutil_cp(src, target):
        cmd = ['cp', '-a', 'public-read', src, target]
        if dryrun:
            print 'DRY: gsutil %s' % ' '.join(cmd)
        else:
            gsutil.execute(cmd)

    # Currently we only release on dev
    raw_namer = gcs_namer.FletchGCSNamer(channel=bot_utils.Channel.DEV)
    release_namer = gcs_namer.FletchGCSNamer(
        channel=bot_utils.Channel.DEV,
        release_type=bot_utils.ReleaseType.RELEASE)
    for target_version in [version, 'latest']:
        for system in ['linux', 'mac']:
            for arch in ['x64']:
                src = raw_namer.fletch_sdk_zipfilepath(version, system, arch,
                                                       'release')
                target = release_namer.fletch_sdk_zipfilepath(
                    target_version, system, arch, 'release')
                gsutil_cp(src, target)

    with utils.TempDir('version') as temp_dir:
        version_file = os.path.join(temp_dir, 'version')
        target = release_namer.version_filepath('latest')
        with open(version_file, 'w') as f:
            f.write(version)
        gsutil_cp(version_file, target)
Beispiel #22
0
 def test_setup_git_global(self):
     """Test setup_git.py script in global mode"""
     with utils.TempDir() as tmpdir:
         env = self.make_dummy_git(tmpdir)
         p = subprocess.Popen([setup_git, '-g'], cwd=tmpdir, env=env)
         stdout, stderr = p.communicate()
         self.assertEqual(p.returncode, 0)
Beispiel #23
0
def Main():
    (options, args) = parse_options()
    if len(args) is not 2:
        print args
        print('Takes exactly two arguments, the two apps to compare')
        return 1
    app1 = args[0]
    app2 = args[1]
    ensure_exists([app1, app2])
    with utils.TempDir() as temporary:
        # If a temp dir is passed in, use that instead of the generated temporary
        output = options.temp if options.temp else temporary
        ensure_exists([output])
        app1_input = [app1]
        app2_input = [app2]
        if app1.endswith('apk'):
            app1_input = extract_apk(app1, os.path.join(output, 'app1'))
        if app2.endswith('apk'):
            app2_input = extract_apk(app2, os.path.join(output, 'app2'))
        app1_classes_dir = os.path.join(output, 'app1_classes')
        app2_classes_dir = os.path.join(output, 'app2_classes')

        extract_classes(app1_input, app1_classes_dir)
        extract_classes(app2_input, app2_classes_dir)
        compare(app1_classes_dir, app2_classes_dir, app1, app2, options.report)
Beispiel #24
0
def run(out, is_r8lib=False):
    if out == None:
        print 'Need to supply output zip with --out.'
        exit(1)
    # Build the R8 no deps artifact.
    if not is_r8lib:
        gradle.RunGradleExcludeDeps([utils.R8])
    else:
        gradle.RunGradle([utils.R8LIB, '-Pno_internal'])
    # Create directory structure for this version.
    version = determine_version()
    with utils.TempDir() as tmp_dir:
        version_dir = join(tmp_dir, utils.get_maven_path('r8', version))
        makedirs(version_dir)
        # Write the pom file.
        pom_file = join(version_dir, 'r8-' + version + '.pom')
        write_pom_file(version, pom_file, is_r8lib)
        # Copy the jar to the output.
        target_jar = join(version_dir, 'r8-' + version + '.jar')
        copyfile(utils.R8LIB_JAR if is_r8lib else utils.R8_JAR, target_jar)
        # Create check sums.
        write_md5_for(target_jar)
        write_md5_for(pom_file)
        write_sha1_for(target_jar)
        write_sha1_for(pom_file)
        # Zip it up - make_archive will append zip to the file, so remove.
        assert out.endswith('.zip')
        base_no_zip = out[0:len(out) - 4]
        make_archive(base_no_zip, 'zip', tmp_dir)
Beispiel #25
0
def execute(cmd, archive, env=None):
    utils.PrintCmd(cmd)
    with utils.TempDir() as temp:
        try:
            stderr_fd = None
            stdout_fd = None
            exitcode = 0
            stderr = os.path.join(temp, 'stderr')
            stderr_fd = open(stderr, 'w')
            stdout = os.path.join(temp, 'stdout')
            stdout_fd = open(stdout, 'w')
            popen = subprocess.Popen(cmd,
                                     bufsize=1024 * 1024 * 10,
                                     stdout=stdout_fd,
                                     stderr=stderr_fd,
                                     env=env)
            begin = time.time()
            timed_out = False
            while popen.poll() == None:
                if time.time() - begin > RUN_TIMEOUT:
                    popen.terminate()
                    timed_out = True
                time.sleep(2)
            exitcode = popen.returncode
        finally:
            if stderr_fd:
                stderr_fd.close()
            if stdout_fd:
                stdout_fd.close()
            if exitcode != 0:
                handle_output(archive, stderr, stdout, popen.returncode,
                              timed_out, ' '.join(cmd))
        return exitcode
Beispiel #26
0
def test_CLGrader_grader_script(tmpdir):
    with utils.TempDir(tmpdir):
        g = CLGrader()

        with g.add_test() as t:
            t.NS.FILE = "file1.txt"
            t.command = "touch {FILE}"

        with g.add_test() as t:
            t.command = "test 1 -eq 0"
            t.description = "test that will fail"

        with g.add_test() as t:
            t.command = "tst 1 -eq 0"
            t.description = "another test that will fail"

            with t.add_on_fail_test() as ft:
                ft.command = "missing"
                ft.description = "sub test that will fail"

                with ft.add_on_fail_test() as fft:
                    fft.command = "missing"
                    fft.description = "sub-sub test that will fail"

        with g.add_test() as t:
            t.command = "pwd"

        g.write_grader_script("grader.py")
Beispiel #27
0
def minify_tool(mainclass=None, input_jar=utils.R8_JAR, output_jar=None,
                lib=utils.RT_JAR, debug=True, build=True, benchmark_name=None,
                track_memory_file=None):
  if output_jar is None:
    output_jar = generate_output_name(input_jar, mainclass)
  with utils.TempDir() as path:
    if mainclass:
      tmp_input_path = os.path.join(path, 'input.jar')
      repackage(input_jar, tmp_input_path, mainclass)
    else:
      tmp_input_path = input_jar
      mainclass = extract_mainclass(input_jar)
    keep_path = os.path.join(path, 'keep.txt')
    with open(keep_path, 'w') as fp:
      fp.write(KEEP % mainclass)
    args = ('--lib', lib,
            '--classfile',
            '--output', output_jar,
            '--pg-conf', keep_path,
            '--release',
            tmp_input_path)
    start_time = time.time()
    return_code = toolhelper.run('r8', args, debug=debug, build=build,
                                 track_memory_file=track_memory_file)
    if benchmark_name:
      elapsed_ms = 1000 * (time.time() - start_time)
      print('%s(RunTimeRaw): %s ms' % (benchmark_name, elapsed_ms))
      if track_memory_file:
        print('%s(MemoryUse): %s' %
              (benchmark_name, utils.grep_memoryuse(track_memory_file)))

    return return_code
Beispiel #28
0
def Main():
    args = parse_arguments()
    if args.golem:
        golem.link_third_party()
    utils.check_java_version()

    with utils.TempDir() as temp_dir:
        cmd_prefix = []
        output_dir = args.output if args.output else temp_dir
        temp_dir = os.path.join(args.output,
                                'tmp') if args.output else temp_dir

        track_memory_file = None
        if args.print_memoryuse:
            track_memory_file = os.path.join(output_dir,
                                             utils.MEMORY_USE_TMP_FILE)
            cmd_prefix.extend(['tools/track_memory.sh', track_memory_file])

        name = 'CompileHelloExample'

        tool = args.tool
        output_mode = args.output_mode
        lib = None
        if output_mode == 'dex':
            name += 'Dex'
            lib = utils.get_android_jar(28)
        else:
            lib = utils.RT_JAR

        extra = []
        if args.large:
            name += 'Large'
            extra = EXTRA_INPUTS

        if args.noopt:
            name += 'NoOpt'

        cmds = Compile(
            tool,
            output_mode,
            lib,
            extra,
            output_dir,
            args.noopt,
            temp_dir,
        )

        t0 = time.time()
        for cmd in cmds:
            fullcmd = cmd_prefix + cmd
            utils.PrintCmd(fullcmd)
            subprocess.check_output(fullcmd)
        dt = time.time() - t0

        if args.print_memoryuse:
            print('{}(MemoryUse): {}'.format(
                name, utils.grep_memoryuse(track_memory_file)))

        print('{}(RunTimeRaw): {} ms'.format(name, 1000.0 * dt))
Beispiel #29
0
 def test_get_file(self):
     """Test get_file function"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, 'foo')
         utils.write_file(fname, 'foobar')
         fh, fn = check_standards.get_file(fname)
         self.assertEqual(fn, fname)
         self.assertEqual(fh.read(), 'foobar')
Beispiel #30
0
 def test_mkdir_no_clean_file(self):
     """Test mkdir(clean=False) with an existing file in the way"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, 'orig')
         utils.write_file(fname, 'foo')
         python_tools.mkdir(fname, clean=False)
         self.assertTrue(os.path.exists(fname))
         self.assertTrue(os.path.isdir(fname))