Ejemplo n.º 1
0
    def install_xcode(self, xcode_build_version, mac_toolchain_cmd,
                      xcode_app_path):
        """Installs the requested Xcode build version.

    Args:
      xcode_build_version: (string) Xcode build version to install.
      mac_toolchain_cmd: (string) Path to mac_toolchain command to install Xcode
      See https://chromium.googlesource.com/infra/infra/+/master/go/src/infra/cmd/mac_toolchain/
      xcode_app_path: (string) Path to install the contents of Xcode.app.

    Returns:
      True if installation was successful. False otherwise.
    """
        try:
            if not mac_toolchain_cmd:
                raise test_runner.MacToolchainNotFoundError(mac_toolchain_cmd)
            # Guard against incorrect install paths. On swarming, this path
            # should be a requested named cache, and it must exist.
            if not os.path.exists(xcode_app_path):
                raise test_runner.XcodePathNotFoundError(xcode_app_path)

            xcode.install(mac_toolchain_cmd, xcode_build_version,
                          xcode_app_path)
            xcode.select(xcode_app_path)
        except subprocess.CalledProcessError as e:
            # Flush buffers to ensure correct output ordering.
            sys.stdout.flush()
            sys.stderr.write('Xcode build version %s failed to install: %s\n' %
                             (xcode_build_version, e))
            sys.stderr.flush()
            return False

        return True
Ejemplo n.º 2
0
    def install_xcode(self):
        """Installs the requested Xcode build version.

    Returns:
      (bool, bool)
        First bool: True if installation was successful. False otherwise.
        Second bool: True if Xcode is legacy package. False if it's new.
    """
        try:
            if not self.args.mac_toolchain_cmd:
                raise test_runner.MacToolchainNotFoundError(
                    self.args.mac_toolchain_cmd)
            # Guard against incorrect install paths. On swarming, this path
            # should be a requested named cache, and it must exist.
            if not os.path.exists(self.args.xcode_path):
                raise test_runner.XcodePathNotFoundError(self.args.xcode_path)

            runtime_cache_folder = None
            # Runner script only utilizes runtime cache when it's a simulator task.
            if self.args.version:
                runtime_cache_folder = xcode.construct_runtime_cache_folder(
                    self.args.runtime_cache_prefix, self.args.version)
                if not os.path.exists(runtime_cache_folder):
                    # Depending on infra project, runtime named cache might not be
                    # deployed. Create the dir if it doesn't exist since xcode_util
                    # assumes it exists.
                    # TODO(crbug.com/1191260): Raise error instead of creating dirs after
                    # runtime named cache is deployed everywhere.
                    os.makedirs(runtime_cache_folder)
            # xcode.install() installs the Xcode & iOS runtime, and returns a bool
            # indicating if the Xcode version in CIPD is a legacy Xcode package (which
            # includes iOS runtimes).
            is_legacy_xcode = xcode.install(
                self.args.mac_toolchain_cmd,
                self.args.xcode_build_version,
                self.args.xcode_path,
                runtime_cache_folder=runtime_cache_folder,
                ios_version=self.args.version)
            xcode.select(self.args.xcode_path)
        except subprocess.CalledProcessError as e:
            # Flush buffers to ensure correct output ordering.
            sys.stdout.flush()
            sys.stderr.write('Xcode build version %s failed to install: %s\n' %
                             (self.args.xcode_build_version, e))
            sys.stderr.flush()
            return (False, False)
        else:
            return (True, is_legacy_xcode)
Ejemplo n.º 3
0
  def test_new_mactoolchain_legacy_xcode(self, mock_install_xcode,
                                         mock_install_runtime,
                                         mock_move_runtime):
    self.mock(xcode_util, '_using_new_mac_toolchain', lambda cmd: True)
    self.mock(xcode_util, '_is_legacy_xcode_package', lambda path: True)

    is_legacy_xcode = xcode_util.install(self.mac_toolchain,
                                         self.xcode_build_version,
                                         self.xcode_app_path)

    self.assertTrue(is_legacy_xcode, 'install should return true')
    mock_install_xcode.assert_called_with('mac_toolchain', 'TestXcodeVersion',
                                          'test/path/Xcode.app', True)
    self.assertFalse(mock_install_runtime.called,
                     '_install_runtime shouldn\'t be called')
    self.assertFalse(mock_move_runtime.called,
                     'move_runtime shouldn\'t be called')
Ejemplo n.º 4
0
  def test_legacy_mactoolchain_new_xcode(self, mock_install_xcode,
                                         mock_install_runtime,
                                         mock_move_runtime):
    self.mock(xcode_util, '_using_new_mac_toolchain', lambda cmd: False)
    self.mock(xcode_util, '_is_legacy_xcode_package', lambda path: False)

    with self.assertRaises(test_runner_errors.XcodeMacToolchainMismatchError):
      is_legacy_xcode = xcode_util.install(self.mac_toolchain,
                                           self.xcode_build_version,
                                           self.xcode_app_path)
      self.assertTrue(is_legacy_xcode, 'install should return true')

    mock_install_xcode.assert_called_with('mac_toolchain', 'TestXcodeVersion',
                                          'test/path/Xcode.app', False)
    self.assertFalse(mock_install_runtime.called,
                     '_install_runtime shouldn\'t be called')
    self.assertFalse(mock_move_runtime.called,
                     'move_runtime shouldn\'t be called')
Ejemplo n.º 5
0
  def test_new_mactoolchain_new_xcode_no_runtime(self, mock_install_xcode,
                                                 mock_install_runtime,
                                                 mock_move_runtime):
    self.mock(xcode_util, '_using_new_mac_toolchain', lambda cmd: True)
    self.mock(xcode_util, '_is_legacy_xcode_package', lambda path: False)

    is_legacy_xcode = xcode_util.install(
        self.mac_toolchain,
        self.xcode_build_version,
        self.xcode_app_path,
        runtime_cache_folder=None,
        ios_version=None)

    self.assertFalse(is_legacy_xcode, 'install should return False')
    mock_install_xcode.assert_called_with('mac_toolchain', 'TestXcodeVersion',
                                          'test/path/Xcode.app', True)
    self.assertFalse(mock_install_runtime.called)
    self.assertFalse(mock_move_runtime.called)