def PerformStage(self):
        """Uploads prebuilts for master and slave builders."""
        prebuilt_type = self._prebuilt_type
        board = self._current_board

        # Whether we publish public or private prebuilts.
        public = self._run.config.prebuilts == constants.PUBLIC
        # Common args we generate for all types of builds.
        generated_args = self.GenerateCommonArgs()
        # Args we specifically add for public/private build types.
        public_args, private_args = [], []
        # Public / private builders.
        public_builders, private_builders = [], []

        common_kwargs = {
            'buildroot': self._build_root,
            'category': prebuilt_type,
            'version': self.prebuilts_version,
        }

        # Upload the public prebuilts, if any.
        if public_builders or public:
            public_board = board if public else None
            prebuilts.UploadPrebuilts(private_bucket=False,
                                      board=public_board,
                                      extra_args=generated_args + public_args,
                                      **common_kwargs)

        # Upload the private prebuilts, if any.
        if private_builders or not public:
            private_board = board if not public else None
            prebuilts.UploadPrebuilts(private_bucket=True,
                                      board=private_board,
                                      extra_args=generated_args + private_args,
                                      **common_kwargs)
 def testUploadPrebuilts(self, builder_type=constants.PFQ_TYPE, private=False,
                         chrome_rev=None, version=None):
   """Test UploadPrebuilts with a public location."""
   prebuilts.UploadPrebuilts(builder_type, chrome_rev, private,
                             buildroot=self._buildroot, board=self._board,
                             version=version)
   self.assertCommandContains([builder_type, 'gs://chromeos-prebuilt'])
  def PerformStage(self):
    """Uploads prebuilts for master and slave builders."""
    prebuilt_type = self._prebuilt_type
    board = self._current_board
    binhosts = []

    # Whether we publish public or private prebuilts.
    public = self._run.config.prebuilts == constants.PUBLIC
    # Common args we generate for all types of builds.
    generated_args = self.GenerateCommonArgs()
    # Args we specifically add for public/private build types.
    public_args, private_args = [], []
    # Public / private builders.
    public_builders, private_builders = [], []

    # Distributed builders that use manifest-versions to sync with one another
    # share prebuilt logic by passing around versions.
    if config_lib.IsPFQType(prebuilt_type):
      # Public pfqs should upload host preflight prebuilts.
      if prebuilt_type != constants.CHROME_PFQ_TYPE:
        public_args.append('--sync-host')

      # Deduplicate against previous binhosts.
      binhosts.extend(self._GetPortageEnvVar(_PORTAGE_BINHOST, board).split())
      binhosts.extend(self._GetPortageEnvVar(_PORTAGE_BINHOST, None).split())
      for binhost in filter(None, binhosts):
        generated_args.extend(['--previous-binhost-url', binhost])

      if self._run.config.master and board == self._boards[-1]:
        # The master builder updates all the binhost conf files, and needs to do
        # so only once so as to ensure it doesn't try to update the same file
        # more than once. As multiple boards can be built on the same builder,
        # we arbitrarily decided to update the binhost conf files when we run
        # upload_prebuilts for the last board. The other boards are treated as
        # slave boards.
        generated_args.append('--sync-binhost-conf')
        for c in self._GetSlaveConfigs():
          if c['prebuilts'] == constants.PUBLIC:
            public_builders.append(c['name'])
            public_args.extend(self._AddOptionsForSlave(c, board))
          elif c['prebuilts'] == constants.PRIVATE:
            private_builders.append(c['name'])
            private_args.extend(self._AddOptionsForSlave(c, board))

    common_kwargs = {
        'buildroot': self._build_root,
        'category': prebuilt_type,
        'chrome_rev': self._chrome_rev,
        'version': self.prebuilts_version,
    }

    # Upload the public prebuilts, if any.
    if public_builders or public:
      public_board = board if public else None
      prebuilts.UploadPrebuilts(
          private_bucket=False, board=public_board,
          extra_args=generated_args + public_args,
          **common_kwargs)

    # Upload the private prebuilts, if any.
    if private_builders or not public:
      private_board = board if not public else None
      prebuilts.UploadPrebuilts(
          private_bucket=True, board=private_board,
          extra_args=generated_args + private_args,
          **common_kwargs)
Example #4
0
    def testSdkPrebuilts(self):
        """Test UploadPrebuilts for SDK builds."""
        # A magical date for a magical time.
        version = '1994.04.02.000000'

        # Fake out toolchains overlay tarballs.
        tarball_dir = os.path.join(self._buildroot,
                                   constants.DEFAULT_CHROOT_DIR,
                                   constants.SDK_OVERLAYS_OUTPUT)
        osutils.SafeMakedirs(tarball_dir)

        toolchain_overlay_tarball_args = []
        # Sample toolchain combos, corresponding to x86-alex and daisy.
        toolchain_combos = (
            ('i686-pc-linux-gnu', ),
            ('armv7a-cros-linux-gnueabi', 'arm-none-eabi'),
        )
        for toolchains in [
                '-'.join(sorted(combo)) for combo in toolchain_combos
        ]:
            tarball = 'built-sdk-overlay-toolchains-%s.tar.xz' % toolchains
            tarball_path = os.path.join(tarball_dir, tarball)
            osutils.Touch(tarball_path)
            tarball_arg = '%s:%s' % (toolchains, tarball_path)
            toolchain_overlay_tarball_args.append(
                ['--toolchains-overlay-tarball', tarball_arg])

        # Fake out toolchain tarballs.
        tarball_dir = os.path.join(self._buildroot,
                                   constants.DEFAULT_CHROOT_DIR,
                                   constants.SDK_TOOLCHAINS_OUTPUT)
        osutils.SafeMakedirs(tarball_dir)

        toolchain_tarball_args = []
        for tarball_base in ('i686', 'arm-none-eabi'):
            tarball = '%s.tar.xz' % tarball_base
            tarball_path = os.path.join(tarball_dir, tarball)
            osutils.Touch(tarball_path)
            tarball_arg = '%s:%s' % (tarball_base, tarball_path)
            toolchain_tarball_args.append(['--toolchain-tarball', tarball_arg])

        prebuilts.UploadPrebuilts(constants.CHROOT_BUILDER_TYPE,
                                  False,
                                  buildroot=self._buildroot,
                                  board=self._board,
                                  version=version)
        self.assertCommandContains(
            [constants.CHROOT_BUILDER_TYPE, 'gs://chromeos-prebuilt'])

        self.assertCommandContains([
            '--toolchains-overlay-upload-path',
            '1994/04/cros-sdk-overlay-toolchains-%%(toolchains)s-'
            '%(version)s.tar.xz'
        ])
        self.assertCommandContains([
            '--toolchain-upload-path', '1994/04/%%(target)s-%(version)s.tar.xz'
        ])
        for args in toolchain_overlay_tarball_args + toolchain_tarball_args:
            self.assertCommandContains(args)
        self.assertCommandContains(['--set-version', version])
        self.assertCommandContains([
            '--prepackaged-tarball',
            os.path.join(self._buildroot, 'built-sdk.tar.xz')
        ])