Пример #1
0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option('--android-sdk-tools', help='Path to Android SDK tools.')
    parser.add_option('--apk-path', help='Path to .apk to install.')
    parser.add_option('--stamp', help='Path to touch on success.')
    options, _ = parser.parse_args()

    # TODO(cjhopman): Should this install to all devices/be configurable?
    install_cmd = [
        os.path.join(options.android_sdk_tools, 'adb'), 'install', '-r',
        options.apk_path
    ]

    serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber()
    md5_stamp = '%s.%s.md5' % (options.apk_path, serial_number)

    md5_checker = md5_check.Md5Checker(stamp=md5_stamp,
                                       inputs=[options.apk_path],
                                       command=install_cmd)
    if md5_checker.IsStale():
        build_utils.CheckCallDie(install_cmd)
        md5_checker.Write()

    if options.stamp:
        build_utils.Touch(options.stamp)
Пример #2
0
def DoJavac(options):
    output_dir = options.output_dir

    src_dirs = build_utils.ParseGypList(options.src_dirs)
    java_files = build_utils.FindInDirectories(src_dirs, '*.java')
    if options.javac_includes:
        javac_includes = build_utils.ParseGypList(options.javac_includes)
        filtered_java_files = []
        for f in java_files:
            for include in javac_includes:
                if fnmatch.fnmatch(f, include):
                    filtered_java_files.append(f)
                    break
        java_files = filtered_java_files

    # Compiling guava with certain orderings of input files causes a compiler
    # crash... Sorted order works, so use that.
    # See https://code.google.com/p/guava-libraries/issues/detail?id=950
    java_files.sort()
    classpath = build_utils.ParseGypList(options.classpath)

    jar_inputs = []
    for path in classpath:
        if os.path.exists(path + '.TOC'):
            jar_inputs.append(path + '.TOC')
        else:
            jar_inputs.append(path)

    javac_cmd = [
        'javac',
        '-g',
        '-source',
        '1.5',
        '-target',
        '1.5',
        '-classpath',
        ':'.join(classpath),
        '-d',
        output_dir,
        '-Xlint:unchecked',
        '-Xlint:deprecation',
    ] + java_files

    md5_stamp = '%s/javac.md5' % options.output_dir
    md5_checker = md5_check.Md5Checker(stamp=md5_stamp,
                                       inputs=java_files + jar_inputs,
                                       command=javac_cmd)
    if md5_checker.IsStale():
        # Delete the classes directory. This ensures that all .class files in the
        # output are actually from the input .java files. For example, if a .java
        # file is deleted or an inner class is removed, the classes directory should
        # not contain the corresponding old .class file after running this action.
        build_utils.DeleteDirectory(output_dir)
        build_utils.MakeDirectory(output_dir)
        suppress_output = not options.chromium_code
        build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output)
        md5_checker.Write()
Пример #3
0
def DoJarToc(options):
  jar_path = options.jar_path
  toc_path = options.toc_path
  md5_stamp_path = '%s.md5' % toc_path
  md5_checker = md5_check.Md5Checker(stamp=md5_stamp_path, inputs=[jar_path])
  if md5_checker.IsStale():
    UpdateToc(jar_path, toc_path)
    md5_checker.Write()
  else:
    build_utils.Touch(toc_path)
Пример #4
0
def DoDex(options, paths):
    dx_binary = os.path.join(options.android_sdk_root, 'platform-tools', 'dx')
    dex_cmd = [dx_binary, '--dex', '--output', options.dex_path] + paths

    md5_stamp = '%s.md5' % options.dex_path
    md5_checker = md5_check.Md5Checker(stamp=md5_stamp,
                                       inputs=paths,
                                       command=dex_cmd)
    if md5_checker.IsStale():
        build_utils.CheckCallDie(dex_cmd, suppress_output=True)
    else:
        build_utils.Touch(options.dex_path)
    md5_checker.Write()
Пример #5
0
def CreateLinks(options):
    libraries = build_utils.ReadJson(options.libraries_json)
    apk_package = apk_helper.GetPackageName(options.apk)

    adb = android_commands.AndroidCommands()
    serial_number = adb.Adb().GetSerialNumber()
    for lib in libraries:
        host_path = os.path.join(options.libraries_dir, lib)

        md5_stamp = '%s.%s.link.md5' % (host_path, serial_number)
        md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[host_path])
        if md5_checker.IsStale():
            link = '/data/data/' + apk_package + '/lib/' + lib
            target = options.target_dir + '/' + lib
            RunLinkCommand(adb, target, link)
            md5_checker.Write()
Пример #6
0
def DoPush(options):
    libraries = build_utils.ReadJson(options.libraries_json)

    adb = android_commands.AndroidCommands()
    serial_number = adb.Adb().GetSerialNumber()
    needs_directory = True
    for lib in libraries:
        device_path = os.path.join(options.device_dir, lib)
        host_path = os.path.join(options.libraries_dir, lib)

        md5_stamp = '%s.%s.push.md5' % (host_path, serial_number)
        md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[host_path])
        if md5_checker.IsStale():
            if needs_directory:
                adb.RunShellCommand('mkdir ' + options.device_dir)
                needs_directory = False
            adb.PushIfNeeded(host_path, device_path)
            md5_checker.Write()
Пример #7
0
def DoJar(options):
  class_files = build_utils.FindInDirectory(options.classes_dir, '*.class')
  for exclude in build_utils.ParseGypList(options.excluded_classes):
    class_files = filter(
        lambda f: not fnmatch.fnmatch(f, exclude), class_files)

  jar_path = os.path.abspath(options.jar_path)

  # The paths of the files in the jar will be the same as they are passed in to
  # the command. Because of this, the command should be run in
  # options.classes_dir so the .class file paths in the jar are correct.
  jar_cwd = options.classes_dir
  class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files]
  jar_cmd = ['jar', 'cf0', jar_path] + class_files_rel


  md5_stamp = '%s.md5' % options.jar_path
  md5_checker = md5_check.Md5Checker(
      stamp=md5_stamp, inputs=class_files, command=jar_cmd)
  if md5_checker.IsStale():
    build_utils.CheckCallDie(jar_cmd, cwd=jar_cwd)
  else:
    build_utils.Touch(options.jar_path)
  md5_checker.Write()