예제 #1
0
 def testSplitEbuildPath(self):
     """Test if we can split an ebuild path into its components."""
     ebuild_path = 'chromeos-base/platform2/platform2-9999.ebuild'
     components = ['chromeos-base', 'platform2', 'platform2-9999']
     for path in (ebuild_path, './' + ebuild_path,
                  'foo.bar/' + ebuild_path):
         self.assertEquals(components, portage_util.SplitEbuildPath(path))
예제 #2
0
def SplitPVPath(path):
    """Utility function to run both SplitEbuildPath and SplitPV.

  Args:
    path: Ebuild path to run those functions on.

  Returns:
    The output of SplitPV.
  """
    return package_info.SplitPV(portage_util.SplitEbuildPath(path)[2])
예제 #3
0
def ListWorkonPackagesInfo(sysroot):
    """Find the specified workon packages for the specified board.

  Args:
    sysroot: sysroot_lib.Sysroot object.

  Returns:
    A list of WorkonPackageInfo objects for unique packages being worked on.
  """
    # Import portage late so that this script can be imported outside the chroot.
    # pylint: disable=F0401
    import portage.const
    packages = ListWorkonPackages(sysroot)
    if not packages:
        return []
    results = {}

    if sysroot.path == '/':
        overlays = portage_util.FindOverlays(constants.BOTH_OVERLAYS, None)
    else:
        overlays = sysroot.GetStandardField('PORTDIR_OVERLAY').splitlines()

    vdb_path = os.path.join(sysroot.path, portage.const.VDB_PATH)

    for overlay in overlays:
        for filename, projects, srcpaths in portage_util.GetWorkonProjectMap(
                overlay, packages):
            # chromeos-base/power_manager/power_manager-9999
            # cp = chromeos-base/power_manager
            # cpv = chromeos-base/power_manager-9999
            category, pn, p = portage_util.SplitEbuildPath(filename)
            cp = '%s/%s' % (category, pn)
            cpv = '%s/%s' % (category, p)

            # Get the time the package finished building. TODO(build): Teach Portage
            # to store the time the package started building and use that here.
            pkg_mtime_file = os.path.join(vdb_path, cpv, 'BUILD_TIME')
            try:
                pkg_mtime = int(osutils.ReadFile(pkg_mtime_file))
            except EnvironmentError as ex:
                if ex.errno != errno.ENOENT:
                    raise
                pkg_mtime = 0

            # Get the modificaton time of the ebuild in the overlay.
            src_ebuild_mtime = os.lstat(os.path.join(overlay,
                                                     filename)).st_mtime

            # Write info into the results dictionary, overwriting any previous
            # values. This ensures that overlays override appropriately.
            results[cp] = WorkonPackageInfo(cp, pkg_mtime, projects, srcpaths,
                                            src_ebuild_mtime)

    return results.values()
예제 #4
0
def MaskNewerPackages(overlay, ebuilds):
    """Mask ebuild versions newer than the ones passed in.

  This creates a new mask file called chromepin which masks ebuilds newer than
  the ones passed in. To undo the masking, just delete that file. The
  mask file is added with git.

  Args:
    overlay: The overlay that will hold the mask file.
    ebuilds: List of ebuilds to set up masks for.
  """
    content = '# Pin chrome by masking more recent versions.\n'
    for ebuild in ebuilds:
        parts = portage_util.SplitEbuildPath(ebuild)
        content += '>%s\n' % os.path.join(parts[0], parts[2])
    mask_file = os.path.join(overlay, MASK_FILE)
    osutils.WriteFile(mask_file, content)
    git.AddPath(mask_file)
예제 #5
0
def GetAffectedPackagesForOverlayChange(change, manifest, overlays):
    """Get the set of packages affected by the overlay |change|.

  Args:
    change: The GerritPatch instance that modifies an overlay.
    manifest: A ManifestCheckout instance representing our build directory.
    overlays: List of overlay paths.

  Returns:
    The set of packages affected by the specified |change|. E.g.
    {'chromeos-base/chromite-0.0.1-r1258'}. If the change affects
    something other than packages, return None.
  """
    checkout = change.GetCheckout(manifest, strict=False)
    if checkout:
        git_repo = checkout.GetPath(absolute=True)

    packages = set()
    for path in change.GetDiffStatus(git_repo):
        # Determine if path is in a package directory by walking up
        # directories and see if there is an ebuild in the directory.
        start_path = os.path.join(git_repo, path)
        ebuild_path = osutils.FindInPathParents('*.ebuild',
                                                start_path,
                                                test_func=glob.glob,
                                                end_path=git_repo)
        if ebuild_path:
            # Convert git_repo/../*.ebuild to the real ebuild path.
            ebuild_path = glob.glob(ebuild_path)[0]
            # Double check that the ebuild is two-levels deep in an overlay
            # directory.
            if os.path.sep.join(ebuild_path.split(
                    os.path.sep)[:-3]) in overlays:
                category, pkg_name, _ = portage_util.SplitEbuildPath(
                    ebuild_path)
                packages.add('%s/%s' % (category, pkg_name))
                continue

        # If |change| affects anything other than packages, return None.
        return None

    return packages