def MakeLocalCommit(repo_root, files_to_commit, message):
    '''Makes a local git commit.'''

    logging.debug('Staging files (%s) for commit.', files_to_commit)
    if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0:
        raise Exception('The local commit failed.')

    logging.debug('Committing.')
    if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0:
        raise Exception('The local commit failed.')
Ejemplo n.º 2
0
  def _DownloadArtifact(self, group_id, artifact_id, version, file_type):
    '''
    Downloads the specified artifact using maven, to its standard location, see
    MavenDownloader._DEFAULT_REPO_PATH.
    '''
    cmd = ['mvn',
           'org.apache.maven.plugins:maven-dependency-plugin:RELEASE:get',
           '-DremoteRepositories={}'.format(self._download_manager.remote_url),
           '-Dartifact={}:{}:{}:{}'.format(group_id, artifact_id, version,
                                           file_type)]

    stdout = None if self._download_manager.debug else open(os.devnull, 'wb')

    try:
      ret_code = cmd_helper.Call(cmd, stdout=stdout)
      if ret_code != 0:
        raise Exception('Command "{}" failed'.format(' '.join(cmd)))
    except OSError as e:
      if e.errno == os.errno.ENOENT:
        raise Exception('mvn command not found. Please install Maven.')
      raise

    return os.path.join(os.path.join(*group_id.split('.')),
                        artifact_id,
                        version,
                        '{}-{}.{}'.format(artifact_id, version, file_type))
def IsRepoDirty(repo_root):
    '''Returns True if there are no staged or modified files, False otherwise.'''

    # diff-index returns 1 if there are staged changes or modified files,
    # 0 otherwise
    cmd = ['git', 'diff-index', '--quiet', 'HEAD']
    return cmd_helper.Call(cmd, cwd=repo_root) == 1
Ejemplo n.º 4
0
def UpdateSdk(args):
  '''
  Uses the Android SDK Manager to download the latest Google Play services SDK
  locally. Its usual installation path is
  //third_party/android_tools/sdk/extras/google/m2repository
  '''

  # This should function should not run on bots and could fail for many user
  # and setup related reasons. Also, exceptions here are not caught, so we
  # disable breakpad to avoid spamming the logs.
  breakpad.IS_ENABLED = False

  # `android update sdk` fails if the library is not installed yet, but it does
  # not allow to install it from scratch using the command line. We then create
  # a fake outdated installation.
  paths = PlayServicesPaths(args.sdk_root, 'no_version_number', [])
  if not os.path.isfile(paths.source_prop):
    if not os.path.exists(os.path.dirname(paths.source_prop)):
      os.makedirs(os.path.dirname(paths.source_prop))
    with open(paths.source_prop, 'w') as prop_file:
      prop_file.write('Pkg.Revision=0.0.0\n')

  sdk_manager = os.path.join(args.sdk_root, 'tools', 'android')
  cmd = [sdk_manager, 'update', 'sdk', '--no-ui', '--filter', GMS_PACKAGE_ID]
  cmd_helper.Call(cmd)
  # If no update is needed, it still returns successfully so we just do nothing

  return 0
Ejemplo n.º 5
0
def main(raw_args):
  parser = argparse.ArgumentParser()
  subparsers = parser.add_subparsers()

  def add_common_arguments(p):
    script_common.AddDeviceArguments(p)
    p.add_argument(
        '--adb-path', help='Path to the adb binary.')
    p.add_argument(
        '-v', '--verbose', action='count', default=0,
        help='Print more information.')
    p.add_argument('command', nargs='*')

  @contextlib.contextmanager
  def remove_system_app(device, args):
    RemoveSystemApps(device, args.packages)
    yield

  remove_parser = subparsers.add_parser('remove')
  remove_parser.add_argument(
      '--package', dest='packages', nargs='*', required=True,
      help='The system package(s) to remove.')
  add_common_arguments(remove_parser)
  remove_parser.set_defaults(func=remove_system_app)

  @contextlib.contextmanager
  def replace_system_app(device, args):
    with ReplaceSystemApp(device, args.package, args.replace_with):
      yield

  replace_parser = subparsers.add_parser('replace')
  replace_parser.add_argument(
      '--package', required=True,
      help='The system package to replace.')
  replace_parser.add_argument(
      '--replace-with', metavar='APK', required=True,
      help='The APK with which the existing system app should be replaced.')
  add_common_arguments(replace_parser)
  replace_parser.set_defaults(func=replace_system_app)

  args = parser.parse_args(raw_args)

  run_tests_helper.SetLogLevel(args.verbose)

  devil_dynamic_config = devil_env.EmptyConfig()
  if args.adb_path:
    devil_dynamic_config['dependencies'].update(
        devil_env.LocalConfigItem(
            'adb', devil_env.GetPlatform(), args.adb_path))

  devil_env.config.Initialize(configs=[devil_dynamic_config])

  devices = script_common.GetDevices(args.devices, args.blacklist_file)
  parallel_devices = parallelizer.SyncParallelizer(
      [args.func(d, args) for d in devices])
  with parallel_devices:
    if args.command:
      return cmd_helper.Call(args.command)
    return 0
Ejemplo n.º 6
0
def main(raw_args):
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers()

    def add_common_arguments(p):
        script_common.AddDeviceArguments(p)
        script_common.AddEnvironmentArguments(p)
        p.add_argument('-v',
                       '--verbose',
                       action='count',
                       default=0,
                       help='Print more information.')
        p.add_argument('command', nargs='*')

    @contextlib.contextmanager
    def remove_system_app(device, args):
        RemoveSystemApps(device, args.packages)
        yield

    remove_parser = subparsers.add_parser('remove')
    remove_parser.add_argument('--package',
                               dest='packages',
                               nargs='*',
                               required=True,
                               help='The system package(s) to remove.')
    add_common_arguments(remove_parser)
    remove_parser.set_defaults(func=remove_system_app)

    @contextlib.contextmanager
    def replace_system_app(device, args):
        with ReplaceSystemApp(device, args.package, args.replace_with):
            yield

    replace_parser = subparsers.add_parser('replace')
    replace_parser.add_argument('--package',
                                required=True,
                                help='The system package to replace.')
    replace_parser.add_argument(
        '--replace-with',
        metavar='APK',
        required=True,
        help='The APK with which the existing system app should be replaced.')
    add_common_arguments(replace_parser)
    replace_parser.set_defaults(func=replace_system_app)

    args = parser.parse_args(raw_args)

    run_tests_helper.SetLogLevel(args.verbose)
    script_common.InitializeEnvironment(args)

    devices = script_common.GetDevices(args.devices, args.denylist_file)
    parallel_devices = parallelizer.SyncParallelizer(
        [args.func(d, args) for d in devices])
    with parallel_devices:
        if args.command:
            return cmd_helper.Call(args.command)
        return 0
Ejemplo n.º 7
0
def UpdateSdk(args):
    '''
  Uses the Android SDK Manager to download the latest Google Play services SDK
  locally. Its usual installation path is
  //third_party/android_tools/sdk/extras/google/google_play_services
  '''

    # This should function should not run on bots and could fail for many user
    # and setup related reasons. Also, exceptions here are not caught, so we
    # disable breakpad to avoid spamming the logs.
    breakpad.IS_ENABLED = False

    sdk_manager = os.path.join(args.sdk_root, 'tools', 'android')
    cmd = [sdk_manager, 'update', 'sdk', '--no-ui', '--filter', GMS_PACKAGE_ID]
    cmd_helper.Call(cmd)
    # If no update is needed, it still returns successfully so we just do nothing

    return 0
Ejemplo n.º 8
0
def main(raw_args):
    parser = argparse.ArgumentParser()

    def add_common_arguments(p):
        script_common.AddDeviceArguments(p)
        script_common.AddEnvironmentArguments(p)
        p.add_argument('-v',
                       '--verbose',
                       action='count',
                       default=0,
                       help='Print more information.')
        p.add_argument('command', nargs='*')

    @contextlib.contextmanager
    def use_webview_provider(device, args):
        with UseWebViewProvider(device, args.apk, args.expected_package):
            yield

    parser.add_argument('--apk',
                        required=True,
                        help='The apk to use as the provider.')
    parser.add_argument(
        '--expected-package',
        default='',
        help="Verify apk's package name matches value, disabled by default.")
    add_common_arguments(parser)
    parser.set_defaults(func=use_webview_provider)

    args = parser.parse_args(raw_args)

    run_tests_helper.SetLogLevel(args.verbose)
    script_common.InitializeEnvironment(args)

    devices = script_common.GetDevices(args.devices, args.denylist_file)
    parallel_devices = parallelizer.SyncParallelizer(
        [args.func(d, args) for d in devices])
    with parallel_devices:
        if args.command:
            return cmd_helper.Call(args.command)
        return 0
Ejemplo n.º 9
0
  def SetUpWorkdir(self,
                   bot_env=False,
                   config_version=DEFAULT_CONFIG_VERSION,
                   existing_license=None,
                   existing_zip_sha1=None,
                   gms_lib=False,
                   populate_bucket=False,
                   source_prop=None):
    '''Prepares workdir by putting it in the specified state

    Args:
      - general
        bot_env: sets or unsets CHROME_HEADLESS

      - bucket
        populate_bucket: boolean. Populate the bucket with a zip and license
                         file. The sha1s will be copied to the config directory

      - config
        config_version: number. Version of the current SDK. Defaults to
                        `self.DEFAULT_CONFIG_VERSION`

      - sdk_root
        existing_license: string. Create a LICENSE file setting the specified
                          text as content of the currently accepted license.
        existing_zip_sha1: string. Create a sha1 file setting the specified
                           hash as hash of the SDK supposed to be installed
        gms_lib: boolean. Create a dummy file in the location of the play
                 services SDK.
        source_prop: boolean. Create a source.properties file that contains
                     the license to upload.
    '''
    client_name = 'client'
    self.paths = Paths(self.workdir, config_version, [client_name])

    # Create the main directories
    _MakeDirs(self.paths.gms.sdk_root)
    _MakeDirs(self.paths.config_dir)
    _MakeDirs(self.paths.bucket)

    # is not configured via argument.
    update.SHA1_DIRECTORY = self.paths.config_dir

    os.environ['CHROME_HEADLESS'] = '1' if bot_env else ''

    if config_version:
      _MakeDirs(os.path.dirname(self.paths.config_file))
      with open(self.paths.config_file, 'w') as stream:
        stream.write(('{"clients": ["%s"],'
                      '"version_number": "%s"}'
                      '\n') % (client_name, config_version))

    if existing_license:
      _MakeDirs(self.paths.gms.package)
      with open(self.paths.gms.license, 'w') as stream:
        stream.write(existing_license)

    if existing_zip_sha1:
      _MakeDirs(self.paths.gms.package)
      with open(self.paths.gms.lib_zip_sha1, 'w') as stream:
        stream.write(existing_zip_sha1)

    if gms_lib:
      _MakeDirs(os.path.dirname(self.paths.gms.client_paths[0]))
      with open(self.paths.gms.client_paths[0], 'w') as stream:
        stream.write('foo\n')

    if source_prop:
      _MakeDirs(os.path.dirname(self.paths.gms.source_prop))
      with open(self.paths.gms.source_prop, 'w') as stream:
        stream.write('Foo=Bar\n'
                     'Pkg.License=%s\n'
                     'Baz=Fizz\n' % self.DEFAULT_LICENSE)

    if populate_bucket:
      _MakeDirs(self.paths.config_dir)
      bucket_dir = os.path.join(self.paths.bucket, str(config_version))
      _MakeDirs(bucket_dir)

      # TODO(dgn) should we use real sha1s? comparison with the real sha1 is
      # done but does not do anything other than displaying a message.
      config_license_sha1 = 'license0and0filling0to0forty0chars000000'
      with open(self.paths.config_license_sha1, 'w') as stream:
        stream.write(config_license_sha1)

      with open(os.path.join(bucket_dir, config_license_sha1), 'w') as stream:
        stream.write(self.DEFAULT_LICENSE)

      config_zip_sha1 = self.DEFAULT_ZIP_SHA1
      with open(self.paths.config_zip_sha1, 'w') as stream:
        stream.write(config_zip_sha1)

      pre_zip_client = os.path.join(
          self.workdir,
          'pre_zip_lib',
          os.path.relpath(self.paths.gms.client_paths[0],
                          self.paths.gms.package))
      pre_zip_lib = os.path.dirname(pre_zip_client)
      post_zip_lib = os.path.join(bucket_dir, config_zip_sha1)
      print(pre_zip_lib, post_zip_lib)
      _MakeDirs(pre_zip_lib)
      with open(pre_zip_client, 'w') as stream:
        stream.write('foo\n')

      # pylint: disable=protected-access
      update._ZipLibrary(post_zip_lib, [pre_zip_client], os.path.join(
          self.workdir, 'pre_zip_lib'))

    if logging.getLogger().isEnabledFor(logging.DEBUG):
      cmd_helper.Call(['tree', self.workdir])
def _GenerateCombinedJar(tmp_paths):
    out_file_name = tmp_paths['combined_jar']
    working_dir = tmp_paths['extracted_jars']
    cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.'])