Esempio n. 1
0
    def _NeedsInstall(self, cpv, slot, build_time, optional):
        """Returns whether a package needs to be installed on the target.

    Args:
      cpv: Fully qualified CPV (string) of the package.
      slot: Slot identifier (string).
      build_time: The BUILT_TIME value (string) of the binpkg.
      optional: Whether package is optional on the target.

    Returns:
      A tuple (install, update) indicating whether to |install| the package and
      whether it is an |update| to an existing package.

    Raises:
      ValueError: if slot is not provided.
    """
        # If not checking installed packages, always install.
        if not self.target_db:
            return True, False

        cp = self._GetCP(cpv)
        target_pkg_info = self.target_db.get(cp, dict()).get(slot)
        if target_pkg_info is not None:
            if cpv != target_pkg_info.cpv:
                attrs = package_info.SplitCPV(cpv)
                target_attrs = package_info.SplitCPV(target_pkg_info.cpv)
                logging.debug(
                    'Updating %s: version (%s) different on target (%s)', cp,
                    attrs.version, target_attrs.version)
                return True, True

            if build_time != target_pkg_info.build_time:
                logging.debug(
                    'Updating %s: build time (%s) different on target (%s)',
                    cpv, build_time, target_pkg_info.build_time)
                return True, True

            logging.debug('Not updating %s: already up-to-date (%s, built %s)',
                          cp, target_pkg_info.cpv, target_pkg_info.build_time)
            return False, False

        if optional:
            logging.debug('Not installing %s: missing on target but optional',
                          cp)
            return False, False

        logging.debug('Installing %s: missing on target and non-optional (%s)',
                      cp, cpv)
        return True, False
Esempio n. 2
0
    def testPackageBuildFailure(self):
        """Test handling of raised BuildPackageFailure."""
        tempdir = osutils.TempDir(base_dir=self.tempdir)
        self.PatchObject(osutils, 'TempDir', return_value=tempdir)

        pkgs = ['cat/pkg', 'foo/bar']
        expected = [('cat', 'pkg'), ('foo', 'bar')]

        result = test_service.BuildTargetUnitTestResult(1, None)
        result.failed_cpvs = [
            package_info.SplitCPV(p, strict=False) for p in pkgs
        ]
        self.PatchObject(test_service,
                         'BuildTargetUnitTest',
                         return_value=result)

        input_msg = self._GetInput(board='board', result_path=self.tempdir)
        output_msg = self._GetOutput()

        rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
                                                 self.api_config)

        self.assertEqual(
            controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
        self.assertTrue(output_msg.failed_packages)
        failed = []
        for pi in output_msg.failed_packages:
            failed.append((pi.category, pi.package_name))
        self.assertCountEqual(expected, failed)
def PackageInfoToCPV(package_info_msg):
  """Helper to translate a PackageInfo message into a CPV."""
  if not package_info_msg or not package_info_msg.package_name:
    return None

  return package_info.SplitCPV(PackageInfoToString(package_info_msg),
                               strict=False)
Esempio n. 4
0
def _BuildTargetUnitTestFailedResponse(_input_proto, output_proto, _config):
    """Add failed packages to a failed response."""
    packages = ['foo/bar', 'cat/pkg']
    failed_cpvs = [package_info.SplitCPV(p, strict=False) for p in packages]
    for cpv in failed_cpvs:
        package_info_msg = output_proto.failed_packages.add()
        controller_util.CPVToPackageInfo(cpv, package_info_msg)
Esempio n. 5
0
    def _InputProto(self,
                    build_target=None,
                    sysroot_path=None,
                    build_source=False,
                    goma_dir=None,
                    goma_log_dir=None,
                    goma_stats_file=None,
                    goma_counterz_file=None,
                    package_indexes=None,
                    packages=None):
        """Helper to build an input proto instance."""
        instance = sysroot_pb2.InstallPackagesRequest()

        if build_target:
            instance.sysroot.build_target.name = build_target
        if sysroot_path:
            instance.sysroot.path = sysroot_path
        if build_source:
            instance.flags.build_source = build_source
        if goma_dir:
            instance.goma_config.goma_dir = goma_dir
        if goma_log_dir:
            instance.goma_config.log_dir.dir = goma_log_dir
        if goma_stats_file:
            instance.goma_config.stats_file = goma_stats_file
        if goma_counterz_file:
            instance.goma_config.counterz_file = goma_counterz_file
        if package_indexes:
            instance.package_indexes.extend(package_indexes)
        if packages:
            for pkg in packages:
                pkg_info = instance.packages.add()
                cpv = package_info.SplitCPV(pkg, strict=False)
                controller_util.CPVToPackageInfo(cpv, pkg_info)
        return instance
def List(input_proto: depgraph_pb2.ListRequest,
         output_proto: depgraph_pb2.ListResponse,
         _config: api_config.ApiConfig):
    """Get a list of package dependencies.

  Args:
    input_proto: The input arguments message.
    output_proto: The empty output message.
    _config: The API call config.
  """
    build_target = controller_util.ParseBuildTarget(
        input_proto.sysroot.build_target)
    sysroot_path = input_proto.sysroot.path
    src_paths = [src_path.path for src_path in input_proto.src_paths]
    packages = [
        controller_util.PackageInfoToCPV(x) for x in input_proto.packages
    ]

    package_deps = dependency.GetDependencies(sysroot_path,
                                              build_target=build_target,
                                              src_paths=src_paths,
                                              packages=packages)
    for package in package_deps:
        pkg_info = output_proto.package_deps.add()
        cpv = package_info.SplitCPV(package, strict=False)
        controller_util.CPVToPackageInfo(cpv, pkg_info)
Esempio n. 7
0
    def testPackageFailure(self):
        """Test package failure handling."""
        failed = ['cat/pkg', 'foo/bar']
        cpvs = [package_info.SplitCPV(p, strict=False) for p in failed]
        self.PatchObject(portage_util,
                         'ParseDieHookStatusFile',
                         return_value=cpvs)

        config = sysroot.BuildPackagesRunConfig()
        command = self.base_command + config.GetBuildPackagesArgs()

        result = cros_build_lib.CommandResult(cmd=command, returncode=1)
        error = cros_build_lib.RunCommandError('Error', result)

        self.rc.AddCmdResult(command, side_effect=error)

        try:
            sysroot.BuildPackages(self.target, self.sysroot, config)
        except sysroot_lib.PackageInstallError as e:
            self.assertEqual(cpvs, e.failed_packages)
            self.assertEqual(result, e.result)
        except Exception as e:
            self.fail('Unexpected exception type: %s' % type(e))
        else:
            self.fail('Expected an exception to be thrown.')
Esempio n. 8
0
    def _FindPackageMatches(self, cpv_pattern):
        """Returns list of binpkg (CP, slot) pairs that match |cpv_pattern|.

    This is breaking |cpv_pattern| into its C, P and V components, each of
    which may or may not be present or contain wildcards. It then scans the
    binpkgs database to find all atoms that match these components, returning a
    list of CP and slot qualifier. When the pattern does not specify a version,
    or when a CP has only one slot in the binpkgs database, we omit the slot
    qualifier in the result.

    Args:
      cpv_pattern: A CPV pattern, potentially partial and/or having wildcards.

    Returns:
      A list of (CPV, slot) pairs of packages in the binpkgs database that
      match the pattern.
    """
        attrs = package_info.SplitCPV(cpv_pattern, strict=False)
        cp_pattern = os.path.join(attrs.category or '*', attrs.package or '*')
        matches = []
        for cp, cp_slots in self.binpkgs_db.items():
            if not fnmatch.fnmatchcase(cp, cp_pattern):
                continue

            # If no version attribute was given or there's only one slot, omit the
            # slot qualifier.
            if not attrs.version or len(cp_slots) == 1:
                matches.append((cp, None))
            else:
                cpv_pattern = '%s-%s' % (cp, attrs.version)
                for slot, pkg_info in cp_slots.items():
                    if fnmatch.fnmatchcase(pkg_info.cpv, cpv_pattern):
                        matches.append((cp, slot))

        return matches
def AugmentDepGraphProtoFromJsonMap(json_map, graph):
    """Augment package deps from |json_map| to graph object.

  Args:
    json_map: the json object that stores the portage package. This is
      generated from chromite.lib.service.dependency.GetBuildDependency()
    graph: the proto object that represents the dependency graph (see DepGraph
      message in chromite/api/depgraph.proto)
  """
    graph.sysroot.build_target.name = json_map['target_board']
    graph.sysroot.path = json_map['sysroot_path']
    # TODO(crbug/1081828): Drop this when no longer used.
    graph.build_target.name = json_map['target_board']

    for data in json_map['package_deps'].values():
        package_dep_info = graph.package_deps.add()
        package_info_msg = package_dep_info.package_info
        package_info_msg.package_name = data['name']
        package_info_msg.category = data['category']
        package_info_msg.version = data['version']
        for dep in data['deps']:
            cpv = package_info.SplitCPV(dep, strict=False)
            dep_package = package_dep_info.dependency_packages.add()
            dep_package.package_name = cpv.package
            dep_package.category = cpv.category
            if cpv.version:
                dep_package.version = cpv.version

        package_CPV = '%s/%s-%s' % (package_info_msg.category,
                                    package_info_msg.package_name,
                                    package_info_msg.version)
        for path in json_map['source_path_mapping'][package_CPV]:
            source_path = package_dep_info.dependency_source_paths.add()
            source_path.path = path
Esempio n. 10
0
def determine_android_version(boards=None):
    """Determine the current Android version in buildroot now and return it.

  This uses the typical portage logic to determine which version of Android
  is active right now in the buildroot.

  Args:
    boards: List of boards to check version of.

  Returns:
    The Android build ID of the container for the boards.

  Raises:
    NoAndroidVersionError: if no unique Android version can be determined.
  """
    if not boards:
        return None
    # Verify that all boards have the same version.
    version = None
    for board in boards:
        package = determine_android_package(board)
        if not package:
            return None
        cpv = package_info.SplitCPV(package)
        if not cpv:
            raise NoAndroidVersionError(
                'Android version could not be determined for %s' % board)
        if not version:
            version = cpv.version_no_rev
        elif version != cpv.version_no_rev:
            raise NoAndroidVersionError(
                'Different Android versions (%s vs %s) for %s' %
                (version, cpv.version_no_rev, boards))
    return version
Esempio n. 11
0
    def testFailureOutputHandling(self):
        """Test failed package handling."""
        # Prevent argument validation error.
        self.PatchObject(sysroot_lib.Sysroot,
                         'IsToolchainInstalled',
                         return_value=True)

        in_proto = self._InputProto(build_target=self.build_target,
                                    sysroot_path=self.sysroot)
        out_proto = self._OutputProto()

        # Failed package info and expected list for verification.
        err_pkgs = ['cat/pkg', 'cat2/pkg2']
        err_cpvs = [
            package_info.SplitCPV(cpv, strict=False) for cpv in err_pkgs
        ]
        expected = [('cat', 'pkg'), ('cat2', 'pkg2')]

        # Force error to be raised with the packages.
        error = sysroot_lib.PackageInstallError('Error',
                                                cros_build_lib.CommandResult(),
                                                packages=err_cpvs)
        self.PatchObject(sysroot_service, 'BuildPackages', side_effect=error)

        rc = sysroot_controller.InstallPackages(in_proto, out_proto,
                                                self.api_config)
        # This needs to return 2 to indicate the available error response.
        self.assertEqual(
            controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
        for package in out_proto.failed_packages:
            cat_pkg = (package.category, package.package_name)
            self.assertIn(cat_pkg, expected)
Esempio n. 12
0
    def _ObservePatches(self, temp_space, deps_map):
        for cpv in deps_map:
            split = package_info.SplitCPV(cpv)
            if self.Ignored(split.cp):
                continue
            cmd = self.equery_cmd[:]
            cmd.extend(['which', cpv])
            ebuild_path = self._invoke_command(cmd,
                                               print_cmd=False,
                                               stdout=True).output.rstrip()
            # Some of these packages will be from other portdirs. Since we are
            # only interested in extracting the patches from one particular
            # overlay, we skip ebuilds not from that overlay.
            if self.overlay_dir != os.path.commonprefix(
                [self.overlay_dir, ebuild_path]):
                continue

            # By running 'ebuild blah.ebuild prepare', we get logs in PORT_LOGDIR
            # of what patches were applied. We clean first, to ensure we get a
            # complete log, and clean again afterwards to avoid leaving a mess.
            cmd = self.ebuild_cmd[:]
            cmd.extend([ebuild_path, 'clean', 'prepare', 'clean'])
            self._invoke_command(cmd, print_cmd=False, stdout=True)
            self.package_count += 1

        # Done with ebuild. Now just harvest the logs and we're finished.
        # This regex is tuned intentionally to ignore a few unhelpful cases.
        # E.g. elibtoolize repetitively applies a set of sed/portage related
        # patches. And media-libs/jpeg says it is applying
        # "various patches (bugfixes/updates)", which isn't very useful for us.
        # So, if you noticed these omissions, it was intentional, not a bug. :-)
        patch_regex = r'^ [*] Applying ([^ ]*) [.][.][.].*'
        output = cros_build_lib.run(['egrep', '-r', patch_regex, temp_space],
                                    print_cmd=False,
                                    stdout=True).output
        lines = output.splitlines()
        patches = []
        patch_regex = re.compile(patch_regex)
        for line in lines:
            cat, pv, _, patchmsg = line.split(':')
            cat = os.path.basename(cat)
            split = package_info.SplitCPV('%s/%s' % (cat, pv))
            patch_name = re.sub(patch_regex, r'\1', patchmsg)
            patches.append('%s/%s %s' % (cat, split.package, patch_name))

        return patches
def GenerateCPEList(deps_list, sysroot):
    """Generate all CPEs for the packages included in deps_list and SDK packages

  Args:
    deps_list: A flattened dependency tree (cros_extract_deps format).
    sysroot: The board directory to use when finding SDK packages.

  Returns:
    A list of CPE info for packages in deps_list and SDK packages, e.g.
    [
      {
        "ComponentName": "app-admin/sudo",
        "Repository": "cros",
        "Targets": [
          "cpe:/a:todd_miller:sudo:1.8.19p2"
        ]
      },
      {
        "ComponentName": "sys-libs/glibc",
        "Repository": "cros",
        "Targets": [
          "cpe:/a:gnu:glibc:2.23"
        ]
      }
    ]
  """
    cpe_dump = []

    # Generage CPEs for SDK packages.
    for sdk_cpv in sorted(GenerateSDKCPVList(sysroot)):
        # Only add CPE for SDK CPVs missing in deps_list.
        if deps_list.get(sdk_cpv) is not None:
            continue

        split = package_info.SplitCPV(sdk_cpv)
        cpes = GetCPEFromCPV(split.category, split.package,
                             split.version_no_rev)
        if cpes:
            cpe_dump.append({
                'ComponentName': '%s' % split.cp,
                'Repository': 'cros',
                'Targets': sorted(cpes)
            })
        else:
            logging.warning('No CPE entry for %s', sdk_cpv)

    # Generage CPEs for packages in deps_list.
    for cpv, record in sorted(deps_list.items()):
        if record['cpes']:
            name = '%s/%s' % (record['category'], record['name'])
            cpe_dump.append({
                'ComponentName': name,
                'Repository': 'cros',
                'Targets': sorted(record['cpes'])
            })
        else:
            logging.warning('No CPE entry for %s', cpv)
    return sorted(cpe_dump, key=lambda k: k['ComponentName'])
Esempio n. 14
0
    def testNoVersion(self):
        """Test handling when no version given."""
        pi = common_pb2.PackageInfo()
        cpv = package_info.SplitCPV('cat/pkg', strict=False)

        controller_util.CPVToPackageInfo(cpv, pi)
        self.assertEqual('cat', pi.category)
        self.assertEqual('pkg', pi.package_name)
        self.assertEqual('', pi.version)
Esempio n. 15
0
    def testPackageOnly(self):
        """Test handling when only given the package name."""
        pi = common_pb2.PackageInfo()
        cpv = package_info.SplitCPV('pkg', strict=False)

        controller_util.CPVToPackageInfo(cpv, pi)
        self.assertEqual('', pi.category)
        self.assertEqual('pkg', pi.package_name)
        self.assertEqual('', pi.version)
Esempio n. 16
0
    def testAllFields(self):
        """Test handling when all fields present."""
        pi = common_pb2.PackageInfo()
        cpv = package_info.SplitCPV('cat/pkg-2.0.0', strict=False)

        controller_util.CPVToPackageInfo(cpv, pi)
        self.assertEqual('cat', pi.category)
        self.assertEqual('pkg', pi.package_name)
        self.assertEqual('2.0.0', pi.version)
Esempio n. 17
0
def _GetPackagesPaths(pkgs, strip, sysroot):
    """Returns paths to binary |pkgs|.

  Args:
    pkgs: List of package CPVs string.
    strip: Whether or not to run strip_package for CPV packages.
    sysroot: The sysroot path.

  Returns:
    List of paths corresponding to |pkgs|.
  """
    cpvs = [package_info.SplitCPV(p) for p in pkgs]
    return _GetPackagesByCPV(cpvs, strip, sysroot)
Esempio n. 18
0
    def test_determine_chrome_version(self):
        """Tests that a valid chrome version is returned."""
        # Mock PortageqBestVisible to return a valid chrome version string.
        r1_cpf = 'chromeos-base/chromeos-chrome-78.0.3900.0_rc-r1'
        r1_cpv = package_info.SplitCPV(r1_cpf)
        self.PatchObject(portage_util,
                         'PortageqBestVisible',
                         return_value=r1_cpv)

        chrome_version = packages.determine_chrome_version(self.build_target)
        version_numbers = chrome_version.split('.')
        self.assertEqual(len(version_numbers), 4)
        self.assertEqual(int(version_numbers[0]), 78)
Esempio n. 19
0
 def _FindKernelVersion(self):
     """Returns a string containing the kernel version for this build."""
     try:
         packages = portage_util.GetPackageDependencies(
             self._current_board, 'virtual/linux-sources')
     except cros_build_lib.RunCommandError:
         logging.warning('Unable to get package list for metadata.')
         return None
     for package in packages:
         if package.startswith('sys-kernel/chromeos-kernel-'):
             kernel_version = package_info.SplitCPV(package).version
             logging.info('Found active kernel version: %s', kernel_version)
             return kernel_version
     return None
Esempio n. 20
0
    def __init__(self, return_code, failed_packages):
        """Init method.

    Args:
      return_code (int): The build return code.
      failed_packages (list[str]): A list of failed packages as strings.
    """
        self.failed_packages = []
        for package in failed_packages or []:
            self.failed_packages.append(
                package_info.SplitCPV(package, strict=False))

        # The return code should always be non-zero if there's any failed packages,
        # but it's cheap insurance, so check it.
        self.success = return_code == 0 and not self.failed_packages
Esempio n. 21
0
    def testFailure(self):
        """Test non-zero return code and failed package handling."""
        packages = ['foo/bar', 'cat/pkg']
        cpvs = [package_info.SplitCPV(p, strict=False) for p in packages]
        self.PatchObject(portage_util,
                         'ParseDieHookStatusFile',
                         return_value=cpvs)
        expected_rc = 1
        self.rc.SetDefaultCmdResult(returncode=expected_rc)

        result = test.BuildTargetUnitTest(self.build_target, self.chroot)

        self.assertFalse(result.success)
        self.assertEqual(expected_rc, result.return_code)
        self.assertCountEqual(cpvs, result.failed_cpvs)
Esempio n. 22
0
 def setUp(self):
     self.buildstore = FakeBuildStore()
     # Replace sudo_run, since we don't care about sudo.
     self.PatchObject(cros_build_lib, 'sudo_run', wraps=cros_build_lib.run)
     self.uploadartifact_mock = self.PatchObject(
         generic_stages.ArchivingStageMixin, 'UploadArtifact')
     # Prepare a fake chroot.
     self.fake_chroot = os.path.join(self.build_root,
                                     'chroot/build/amd64-host')
     self.fake_json_data = {}
     osutils.SafeMakedirs(self.fake_chroot)
     osutils.Touch(os.path.join(self.fake_chroot, 'file'))
     for package, v in self.fake_packages:
         cpv = package_info.SplitCPV('%s-%s' % (package, v))
         self.fake_json_data.setdefault(cpv.cp, []).append([v, {}])
    def DetermineAndroidVersion(self, package):
        """Determine the current Android version in buildroot now and return it.

    This uses the typical portage logic to determine which version of Android
    is active right now in the buildroot.

    Workspace version of cbuildbot_run.DetermineAndroidVersion().

    Args:
      package: String name of Android package to get version of.

    Returns:
      The Android build ID of the container for the boards.
    """
        cpv = package_info.SplitCPV(package)
        return cpv.version_no_rev
Esempio n. 24
0
def MarkStable(input_proto, output_proto, _config):
    """Uprev Android, if able.

  Uprev Android, verify that the newly uprevved package can be emerged, and
  return the new package info.

  See AndroidService documentation in api/proto/android.proto.

  Args:
    input_proto (MarkStableRequest): The input proto.
    output_proto (MarkStableResponse): The output proto.
    _config (api_config.ApiConfig): The call config.
  """
    chroot = controller_util.ParseChroot(input_proto.chroot)
    build_targets = controller_util.ParseBuildTargets(
        input_proto.build_targets)
    tracking_branch = input_proto.tracking_branch
    package_name = input_proto.package_name
    android_build_branch = input_proto.android_build_branch
    android_version = input_proto.android_version

    # Assume success.
    output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS
    # TODO(crbug/904939): This should move to service/android.py and the port
    # should be finished.
    try:
        android_atom_to_build = packages.uprev_android(
            tracking_branch=tracking_branch,
            android_package=package_name,
            android_build_branch=android_build_branch,
            chroot=chroot,
            build_targets=build_targets,
            android_version=android_version)
    except packages.AndroidIsPinnedUprevError as e:
        # If the uprev failed due to a pin, CI needs to unpin and retry.
        android_atom_to_build = e.new_android_atom
        output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED

    if android_atom_to_build:
        CPV = package_info.SplitCPV(android_atom_to_build)
        output_proto.android_atom.category = CPV.category
        output_proto.android_atom.package_name = CPV.package
        output_proto.android_atom.version = CPV.version
    else:
        output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT
Esempio n. 25
0
def GetPackageAPI(portage_root, package_cp):
    """Gets portage API handles for the given package.

  Args:
    portage_root: Root directory of portage tree. Eg '/' or '/build/lumpy'
    package_cp: A string similar to 'chromeos-base/autotest-tests'.

  Returns:
    Returns (package, vartree) tuple, where
      package is of type portage.dbapi.vartree.dblink
      vartree is of type portage.dbapi.vartree.vartree
  """
    if portage_root is None:
        # pylint: disable=no-member
        portage_root = portage.root
    # Ensure that portage_root ends with trailing slash.
    portage_root = os.path.join(portage_root, '')

    # Create a vartree object corresponding to portage_root.
    trees = portage.create_trees(portage_root, portage_root)
    vartree = trees[portage_root]['vartree']

    # List the matching installed packages in cpv format.
    matching_packages = vartree.dbapi.cp_list(package_cp)

    if not matching_packages:
        raise PortagePackageAPIError(
            'No matching package for %s in portage_root '
            '%s' % (package_cp, portage_root))

    if len(matching_packages) > 1:
        raise PortagePackageAPIError('Too many matching packages for %s in '
                                     'portage_root %s' %
                                     (package_cp, portage_root))

    # Convert string match to package dblink.
    package_cpv = matching_packages[0]
    package_split = package_info.SplitCPV(package_cpv)
    # pylint: disable=no-member
    package = portage.dblink(package_split.category,
                             package_split.pv,
                             settings=vartree.settings,
                             vartree=vartree)

    return package, vartree
  def testInstallToolchainError(self):
    """Test error handling from the libc install."""
    failed = ['cat/pkg', 'cat/pkg2']
    failed_cpvs = [package_info.SplitCPV(pkg, strict=False) for pkg in failed]
    result = cros_build_lib.CommandResult(returncode=1)
    error = toolchain.ToolchainInstallError('Error', result=result,
                                            tc_info=failed_cpvs)
    self.PatchObject(toolchain, 'InstallToolchain', side_effect=error)

    try:
      self.sysroot.UpdateToolchain('board')
    except sysroot_lib.ToolchainInstallError as e:
      self.assertTrue(e.failed_toolchain_info)
      self.assertEqual(failed_cpvs, e.failed_toolchain_info)
    except Exception as e:
      self.fail('Unexpected exception raised: %s' % type(e))
    else:
      self.fail('Expected an exception.')
Esempio n. 27
0
def _parse_summary_log_from_lines_iterator(log_lines, no_duplicates=False):
    cpv = None
    level = None
    phase = None

    # A mapping of package cpv -> log level -> ebuild phase -> messages
    # Ex: contents["app-editor/vim"]["ERROR"]["compile"] -> "something happened"
    contents = defaultdict(lambda: defaultdict(lambda: defaultdict(str)))

    for line in log_lines:
        # Skip over blank lines
        if not line.strip():
            continue

        # Update the state once we're in a log section for a particular package
        # If we encounter the same package twice that means the log has entries
        # from a previous attempt.
        header_match = SECTION_HEADER.match(line.strip())
        if header_match:
            cpv = package_info.SplitCPV(header_match.group('package'))
            if cpv in contents and no_duplicates:
                raise DuplicatePackageError()
            continue

        # Match the ebuild phase and log entry. If we don't have a package set yet,
        # then the log we're reading is malformed.
        entry_match = LOG_ENTRY.match(line.strip())
        if entry_match:
            if not cpv:
                raise MalformedLogError()
            phase = entry_match.group('phase')
            level = entry_match.group('level')
            continue

        # All other lines are then the actual messages printed by ebuilds. Append
        # them to their respective categories. If anything is unset by this point,
        # the log is again malformed.
        if not all((cpv, phase, level)):
            raise MalformedLogError()
        contents[cpv][level][phase] += line

    return SummaryLog(contents)
Esempio n. 28
0
def determine_kernel_version(build_target):
    """Returns a string containing the kernel version for this build target.

  Args:
    build_target (build_target_lib.BuildTarget): The build target.

  Returns:
    (str) The kernel versions, or None.
  """
    try:
        packages = portage_util.GetPackageDependencies(
            build_target.name, 'virtual/linux-sources')
    except cros_build_lib.RunCommandError as e:
        logging.warning('Unable to get package list for metadata: %s', e)
        return None
    for package in packages:
        if package.startswith('sys-kernel/chromeos-kernel-'):
            kernel_version = package_info.SplitCPV(package).version
            logging.info('Found active kernel version: %s', kernel_version)
            return kernel_version
    return None
Esempio n. 29
0
        def setUp(self):
            self.PatchObject(afdo, 'CanGenerateAFDOData', lambda _: True)
            chrome_version = package_info.SplitCPV(chrome_version_str)
            self.PatchObject(portage_util, 'PortageqBestVisible',
                             lambda *_, **_2: chrome_version)
            self.wait_for_data = self.PatchObject(afdo,
                                                  'WaitForAFDOPerfData',
                                                  autospec=True,
                                                  wraps=lambda *_: True)

            afdo_path = '/does/not/exist/afdo.prof'
            self.generate_afdo_data = self.PatchObject(
                afdo,
                'GenerateAFDOData',
                autospec=True,
                wraps=lambda *_: afdo_path)

            self.PatchObject(afdo_stages.AFDODataGenerateStage,
                             '_GetCurrentArch', lambda *_: 'some_arch')
            self.PatchObject(alerts, 'SendEmailLog')
            self._Prepare()
            self.buildstore = FakeBuildStore()
Esempio n. 30
0
    def testBuildTargetUnitTest(self):
        """Test BuildTargetUnitTest successful call."""
        pkgs = ['foo/bar', 'cat/pkg']
        packages = [package_info.SplitCPV(p, strict=False) for p in pkgs]
        input_msg = self._GetInput(board='board',
                                   result_path=self.tempdir,
                                   packages=packages)

        result = test_service.BuildTargetUnitTestResult(0, None)
        self.PatchObject(test_service,
                         'BuildTargetUnitTest',
                         return_value=result)

        tarball_result = os.path.join(input_msg.result_path, 'unit_tests.tar')
        self.PatchObject(test_service,
                         'BuildTargetUnitTestTarball',
                         return_value=tarball_result)

        response = self._GetOutput()
        test_controller.BuildTargetUnitTest(input_msg, response,
                                            self.api_config)
        self.assertEqual(response.tarball_path,
                         os.path.join(input_msg.result_path, 'unit_tests.tar'))