Ejemplo n.º 1
0
  def setup_default_config(cls, path):
    """Create the default keystore config file for Android targets.

    :param string path: Full path for the created default config file.
    """
    # TODO(mateor): Hook into pants global setup instead of relying on building an Android target.
    try:
      AndroidConfigUtil.setup_keystore_config(path)
    except AndroidConfigUtil.AndroidConfigError as e:
      raise TaskError('Failed to setup default keystore config: {0}'.format(e))
Ejemplo n.º 2
0
  def setup_default_config(cls, path):
    """Create the default keystore config file for Android targets.

    :param string path: Full path for the created default config file.
    """
    # TODO(mateor): Hook into pants global setup instead of relying on building an Android target.
    try:
      AndroidConfigUtil.setup_keystore_config(path)
    except AndroidConfigUtil.AndroidConfigError as e:
      raise TaskError('Failed to setup default keystore config: {0}'.format(e))
Ejemplo n.º 3
0
  def execute(self):
    targets = self.context.targets(self.is_signtarget)
    # Check for Android keystore config file (where the default keystore definition is kept).
    config_file = os.path.join(self.context.config.getdefault('pants_bootstrapdir'),
                               self._DEFAULT_KEYSTORE_CONFIG)
    if not os.path.isfile(config_file):
      try:
        AndroidConfigUtil.setup_keystore_config(config_file)
      except OSError as e:
        raise TaskError('Failed to setup keystore config: {0}'.format(e))

    with self.invalidated(targets) as invalidation_check:
      invalid_targets = []
      for vt in invalidation_check.invalid_vts:
        invalid_targets.extend(vt.targets)
      for target in invalid_targets:

        def get_products_path(target):
          """Get path of target's unsigned apks as created by AaptBuilder."""
          unsigned_apks = self.context.products.get('apk')
          packages = unsigned_apks.get(target)
          if packages:
            for tgts, products in packages.items():
              for prod in products:
                yield os.path.join(tgts, prod)

        packages = list(get_products_path(target))
        for unsigned_apk in packages:
          keystores = KeystoreResolver.resolve(self.config_file)
          for key in keystores:

            outdir = self.sign_apk_out(target, keystores[key].build_type)
            safe_mkdir(outdir)
            args = self._render_args(target, keystores[key], unsigned_apk, outdir)
            with self.context.new_workunit(name='sign_apk',
                                           labels=[WorkUnit.MULTITOOL]) as workunit:
              returncode = subprocess.call(args, stdout=workunit.output('stdout'),
                                           stderr=workunit.output('stderr'))
              if returncode:
                raise TaskError('The SignApk jarsigner process exited non-zero: {0}'
                                .format(returncode))

    for target in targets:
      release_path = self.sign_apk_out(target, 'release')
      release_apk = self.package_name(target, 'release')

      if os.path.isfile(os.path.join(release_path, release_apk)):
        self.context.products.get('release_apk').add(target, release_path).append(release_apk)
Ejemplo n.º 4
0
 def test_no_permission_keystore_config(self):
   with temporary_file() as temp:
     os.chmod(temp.name, 0o400)
     with self.assertRaises(AndroidConfigUtil.AndroidConfigError):
       AndroidConfigUtil.setup_keystore_config(temp.name)
Ejemplo n.º 5
0
 def test_setup_keystore_config(self):
   with temporary_file() as config:
     AndroidConfigUtil.setup_keystore_config(config.name)
     self.assertEquals(config.read(), self.contents())
Ejemplo n.º 6
0
 def test_no_permission_keystore_config(self):
     with self.assertRaises(AndroidConfigUtil.AndroidConfigError):
         with temporary_file() as temp:
             os.chmod(temp.name, 0o400)
             AndroidConfigUtil.setup_keystore_config(temp.name)
Ejemplo n.º 7
0
 def test_setup_keystore_config(self):
     with temporary_file() as config:
         AndroidConfigUtil.setup_keystore_config(config.name)
         self.assertEquals(config.read(), self.contents())
Ejemplo n.º 8
0
 def test_no_permission_keystore_config(self):
   with self.assertRaises(AndroidConfigUtil.AndroidConfigError):
     AndroidConfigUtil.setup_keystore_config('/outside/home/directory')