Exemplo n.º 1
0
  def _Build(self):
    """Update the chroot, then merge the requested packages."""
    if self.chroot_update and self.host:
      chroot_util.UpdateChroot()

    chroot_util.Emerge(self.build_pkgs, self.sysroot,
                       with_deps=self.options.deps,
                       rebuild_deps=self.options.rebuild_deps,
                       use_binary=self.options.binary, jobs=self.options.jobs,
                       debug_output=(self.options.log_level.lower() == 'debug'))
Exemplo n.º 2
0
    def testEmerge(self):
        """Tests correct invocation of emerge."""
        packages = ['foo-app/bar', 'sys-baz/clap']
        self.PatchObject(cros_list_modified_packages,
                         'ListModifiedWorkonPackages',
                         return_value=[packages[0]])

        toolchain_packages = [
            'sys-devel/binutils', 'sys-devel/gcc', 'sys-kernel/linux-headers',
            'sys-libs/glibc', 'sys-devel/gdb'
        ]
        self.PatchObject(chroot_util,
                         '_GetToolchainPackages',
                         return_value=toolchain_packages)
        toolchain_package_list = ' '.join(toolchain_packages)

        input_values = [
            ['/', '/build/thesysrootname'],  # sysroot
            [True, False],  # with_deps
            [True, False],  # rebuild_deps
            [True, False],  # use_binary
            [0, 1, 2, 3],  # jobs
            [True, False],  # debug_output
        ]
        inputs = itertools.product(*input_values)
        for (sysroot, with_deps, rebuild_deps, use_binary, jobs,
             debug_output) in inputs:
            chroot_util.Emerge(packages,
                               sysroot=sysroot,
                               with_deps=with_deps,
                               rebuild_deps=rebuild_deps,
                               use_binary=use_binary,
                               jobs=jobs,
                               debug_output=debug_output)
            cmd = self.rc.call_args_list[-1][0][-1]
            self.assertEquals(sysroot != '/',
                              any(p.startswith('--sysroot') for p in cmd))
            self.assertEquals(with_deps, '--deep' in cmd)
            self.assertEquals(not with_deps, '--nodeps' in cmd)
            self.assertEquals(rebuild_deps, '--rebuild-if-unbuilt' in cmd)
            self.assertEquals(use_binary, '-g' in cmd)
            self.assertEquals(use_binary, '--with-bdeps=y' in cmd)
            self.assertEquals(
                use_binary and sysroot == '/',
                '--useoldpkg-atoms=%s' % toolchain_package_list in cmd)
            self.assertEquals(bool(jobs), '--jobs=%d' % jobs in cmd)
            self.assertEquals(debug_output, '--show-output' in cmd)
Exemplo n.º 3
0
def main(argv):
    opts = ParseArgs(argv)

    cros_build_lib.AssertInsideChroot()

    sysroot = opts.sysroot or cros_build_lib.GetSysroot(opts.board)
    package_blacklist = set()
    if opts.package_blacklist:
        package_blacklist |= set(opts.package_blacklist.split())

    packages = set()
    # The list of packages to test can be passed as a file containing a
    # space-separated list of package names.
    # This is used by the builder to test only the packages that were upreved.
    if opts.package_file and os.path.exists(opts.package_file):
        packages = set(osutils.ReadFile(opts.package_file).split())

    if opts.packages:
        packages |= set(opts.packages.split())

    # If no packages were specified, use all testable packages.
    if not (opts.packages or opts.package_file) and not opts.empty_sysroot:
        workon = workon_helper.WorkonHelper(sysroot)
        packages = (workon.InstalledWorkonAtoms() if opts.installed else set(
            workon.ListAtoms(use_all=True)))

    if opts.empty_sysroot:
        packages |= determine_board_packages(sysroot, BOARD_VIRTUAL_PACKAGES)
        workon = workon_helper.WorkonHelper(sysroot)
        workon_packages = set(workon.ListAtoms(use_all=True))
        packages &= workon_packages

    for cp in packages & package_blacklist:
        logging.info('Skipping blacklisted package %s.', cp)

    packages = packages - package_blacklist
    pkg_with_test = portage_util.PackagesWithTest(sysroot, packages)

    if packages - pkg_with_test:
        logging.warning('The following packages do not have tests:\n  %s',
                        '\n  '.join(sorted(packages - pkg_with_test)))

    if not pkg_with_test:
        if opts.testable_packages_optional:
            logging.warning('No testable packages found!')
            return 0
        logging.error('No testable packages found!')
        return 1

    if opts.pretend:
        print('\n'.join(sorted(pkg_with_test)))
        return 0

    env = None
    if opts.nowithdebug:
        use_flags = os.environ.get('USE', '')
        use_flags += ' -cros-debug'
        env = {'USE': use_flags}

    if opts.empty_sysroot:
        try:
            chroot_util.Emerge(list(IMPLICIT_TEST_DEPS),
                               sysroot,
                               rebuild_deps=False,
                               use_binary=False)
            chroot_util.Emerge(list(pkg_with_test),
                               sysroot,
                               rebuild_deps=False,
                               use_binary=False)
        except cros_build_lib.RunCommandError:
            logging.error('Failed building dependencies for unittests.')
            return 1

    try:
        chroot_util.RunUnittests(sysroot,
                                 pkg_with_test,
                                 extra_env=env,
                                 jobs=opts.jobs)
    except cros_build_lib.RunCommandError:
        logging.error('Unittests failed.')
        return 1