def Main(): args = parse_arguments() if isdir(args.output_dir): rmdir(args.output_dir) # make sure to write only to empty out dir utils.makedirs_if_needed(join(args.output_dir, IN_SUBDIR)) # create the first lines of the replay script replay_script = \ """#!/usr/bin/env python import os import shutil import subprocess import sys SCRIPT_DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, '..'))) IN_SUBDIR = '{}' OUT_SUBDIR = '{}' def call_dx(input_counter, args, inputs): out_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, str(input_counter)) if not os.path.isdir(out_dir): os.makedirs(out_dir) full_inputs = [os.path.join(SCRIPT_DIR, IN_SUBDIR, i) for i in inputs] subprocess.check_call(sys.argv[1:] + args + ['--output=' + out_dir] + full_inputs) if len(sys.argv) < 2: raise IOError('Usage: create_dx_replay.py <dx-command>' ' # can be multiple args') abs_out_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR) if os.path.isdir(abs_out_dir): shutil.rmtree(abs_out_dir) """.format(IN_SUBDIR, OUT_SUBDIR) with open(args.dx_call_log) as f: lines = f.read().splitlines() input_counter = 1 for line in lines: replay_script += \ process_line(args.output_dir, input_counter, line.split('\t')) input_counter += 1 script_file = join(args.output_dir, REPLAY_SCRIPT_NAME) with open(script_file, 'w') as f: f.write(replay_script) # chmod +x for script_file st = os.stat(script_file) os.chmod(script_file, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
def checkout_aosp(aosp_root, url, branch, manifest_xml, concurrency): utils.makedirs_if_needed(aosp_root) command = ['repo', 'init', '-u', url, '--depth=1'] if (branch): command.extend(['-b', branch]) else: manifests_dir = join(aosp_root, '.repo', 'manifests') utils.makedirs_if_needed(manifests_dir) copy2(manifest_xml, manifests_dir) command.extend(['-m', basename(manifest_xml)]) check_call(command, cwd=aosp_root) check_call(['repo', 'sync', '-dq', '-j' + concurrency], cwd=aosp_root)
def checkout_aosp(): # checkout AOSP source manifests_dir = join(AOSP_ROOT, '.repo', 'manifests') utils.makedirs_if_needed(manifests_dir) copy2(AOSP_MANIFEST_XML, manifests_dir) check_call([ 'repo', 'init', '-u', AOSP_MANIFEST_URL, '-m', 'aosp_manifest.xml', '--depth=1' ], cwd=AOSP_ROOT) check_call(['repo', 'sync', '-dq', J_OPTION], cwd=AOSP_ROOT)
def generate_test(class_name, compiler_under_test, compiler_under_test_enum, relative_package): filename = join(DESTINATION_DIR, compiler_under_test, relative_package.replace('.', os.sep), class_name + '.java') utils.makedirs_if_needed(dirname(filename)) full_class_name = '{}{}.{}'.format(PACKAGE_PREFIX, relative_package, class_name) contents = TEMPLATE.substitute( compilerUnderTest = compiler_under_test, relativePackage = relative_package, name = full_class_name, testClassName = class_name, compilerUnderTestEnum = compiler_under_test_enum, classFile = full_class_name.replace('.', '/') + '.class', nameWithoutPackagePrefix = '{}.{}'.format(relative_package, class_name)) with open(fix_long_path(filename), 'w') as f: f.write(contents)
def setup_and_clean(tool_is_d8, clean_dex): # Two output dirs, one for the android image and one for cts tests. # The output is compiled with d8 and jack, respectively. utils.makedirs_if_needed(AOSP_ROOT) utils.makedirs_if_needed(OUT_IMG) utils.makedirs_if_needed(OUT_CTS) # remove dex files older than the current d8 tool counter = 0 if tool_is_d8 or clean_dex: if not clean_dex: d8jar_mtime = os.path.getmtime(utils.D8_JAR) dex_files = (chain.from_iterable( glob(join(x[0], '*.dex')) for x in os.walk(OUT_IMG))) for f in dex_files: if clean_dex or os.path.getmtime(f) <= d8jar_mtime: os.remove(f) counter += 1 if counter > 0: print('Removed {} dex files.'.format(counter))
def get_bin_path(app): bin_path = os.path.join(get_build_dir(app), 'bin') utils.makedirs_if_needed(bin_path) return bin_path
def get_gen_path(app): gen_path = os.path.join(get_build_dir(app), 'gen') utils.makedirs_if_needed(gen_path) return gen_path