Merged from trunk 7253:7267
authorFabian Groffen <grobian@gentoo.org>
Sun, 15 Jul 2007 09:38:30 +0000 (09:38 -0000)
committerFabian Groffen <grobian@gentoo.org>
Sun, 15 Jul 2007 09:38:30 +0000 (09:38 -0000)
   +------------------------------------------------------------------------+
   | 7254     | For bug #185278, make the verbose flag display show         |
   | zmedico  | masked/forced flag status for binary packages too.          |
   |----------+-------------------------------------------------------------|
   | 7256     | Make the repo display work for overlays that don't define   |
   | zmedico  | repo_name (like it used to).                                |
   |----------+-------------------------------------------------------------|
   | 7257     | Always show PORTDIR with index 0 in the repo display.       |
   | zmedico  |                                                             |
   |----------+-------------------------------------------------------------|
   | 7258     | Encapsulate the repo display code in a class.               |
   | zmedico  |                                                             |
   |----------+-------------------------------------------------------------|
   | 7259     | Use sys.stdout instead of print to avoid an extra newline.  |
   | zmedico  |                                                             |
   |----------+-------------------------------------------------------------|
   | 7260     | Remove unused repo_name code.                               |
   | zmedico  |                                                             |
   |----------+-------------------------------------------------------------|
   | 7263     | When deciding if a package is slotted inside                |
   | zmedico  | create_world_atom(), check the vdb in case the package is   |
   |          | multislot.                                                  |
   |----------+-------------------------------------------------------------|
   | 7265     | Fix typo.                                                   |
   | zmedico  |                                                             |
   |----------+-------------------------------------------------------------|
   | 7267     | split up the debug/sources steps as proposed by swegener    |
   | SpankMan | and give the whole file a cleanup                           |
   +------------------------------------------------------------------------+

svn path=/main/branches/prefix/; revision=7268

bin/prepstrip
pym/emerge/__init__.py

index 68418b5f2d81c3425fb57e688bb2b9b3ba9c6be1..ca184f064ec7c4fb99937ea235fc518d726e1e2b 100755 (executable)
@@ -1,15 +1,17 @@
 #!@BASH@
 # Copyright 1999-2007 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Id$
+# $Id:$
 
 source "${PORTAGE_BIN_PATH:-${EPREFIX}/usr/lib/portage/bin}"/isolated-functions.sh
 
-unset NOSTRIP
-if hasq nostrip ${FEATURES} ${RESTRICT} || \
+banner=false
+SKIP_STRIP=false
+if hasq nostrip ${FEATURES} || \
    hasq strip ${RESTRICT}
 then
-       NOSTRIP=1
+       SKIP_STRIP=true
+       banner=true
        hasq installsources ${FEATURES} || exit 0
 fi
 
@@ -23,43 +25,44 @@ type -P -- ${OBJCOPY} > /dev/null || OBJCOPY=objcopy
 export SAFE_STRIP_FLAGS="--strip-unneeded"
 export PORTAGE_STRIP_FLAGS=${PORTAGE_STRIP_FLAGS-${SAFE_STRIP_FLAGS} -R .comment}
 
-banner=1
+save_elf_sources() {
+       hasq installsources ${FEATURES} || return 0
+       type -P debugedit >/dev/null || return 0
 
-save_elf_debug() {
        local x=$1
-       local y="${ED}usr/lib/debug/${x:${#ED}}.debug"
-
-       if hasq installsources ${FEATURES} && [ -x "${EPREFIX}"/usr/bin/debugedit ] ; then
-               local sources_dir=/usr/src/debug/${CATEGORY}/${PF}
-               debugedit -b "${WORKDIR}" -d "${EPREFIX}/${sources_dir}" \
-                       -l "${T}"/debug.sources "${x}"
-               if [[ -s ${T}/debug.sources ]] ; then 
-                       [[ -d ${ED}${sources_dir} ]] || mkdir -p "${ED}${sources_dir}"
-                       grep -zv '/<built-in>$' "${T}"/debug.sources | \
-                               (cd "${WORKDIR}"; LANG=C sort -z -u | \
-                               rsync -rtL0 --files-from=- "${WORKDIR}/" "${ED}${sources_dir}/" )
-               fi
+       local sources_dir=${EPREFIX}/usr/src/debug/${CATEGORY}/${PF}
+       debugedit -b "${WORKDIR}" -d "${sources_dir}" \
+               -l "${T}"/debug.sources "${x}"
+       if [[ -s ${T}/debug.sources ]] ; then 
+               [[ -d ${D}${sources_dir} ]] || mkdir -p "${D}${sources_dir}"
+               grep -zv '/<built-in>$' "${T}"/debug.sources | \
+                       (cd "${WORKDIR}"; LANG=C sort -z -u | \
+                       rsync -rtL0 --files-from=- "${WORKDIR}/" "${D}${sources_dir}/" )
        fi
-
+}
+ 
+save_elf_debug() {
        hasq splitdebug ${FEATURES} || return 0
-       [[ -z "${NOSTRIP}" ]] || return 0
 
-       # dont save debug info twice.
-       [[ ${x:7} == ".debug" ]] && return 0
+       local x=$1
+       local y="${ED}usr/lib/debug/${x:${#ED}}.debug"
+
+       # dont save debug info twice
+       [[ ${x} == *".debug" ]] && return 0
 
        mkdir -p $(dirname "${y}")
        ${OBJCOPY} --only-keep-debug "${x}" "${y}"
        ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}"
-       [ -g "${x}" ] && chmod go-r "${y}"
-       [ -u "${x}" ] && chmod go-r "${y}"
+       [[ -g ${x} ]] && chmod go-r "${y}"
+       [[ -u ${x} ]] && chmod go-r "${y}"
        chmod a-x,o-w "${y}"
 }
 
 # The existance of the section .symtab tells us that a binary is stripped.
 # We want to log already stripped binaries, as this may be a QA violation.
 # They prevent us from getting the splitdebug data.
-f="$(scanelf -yqRBF '#k%F' -k '!.symtab' "$@")"
-if [[ -n "${f}" ]] ; then
+f=$(scanelf -yqRBF '#k%F' -k '!.symtab' "$@")
+if [[ -n ${f} ]] ; then
        vecho -e "\a\n"
        eqawarn "QA Notice: Pre-stripped files found:"
        eqawarn "${f}"
@@ -71,42 +74,53 @@ for x in \
        $(scanelf -yqRBF '#k%F' -k '.symtab' "$@") \
        $(find "$@" -type f -name '*.a')
 do
-       if [[ ${banner} -eq 1 ]] ; then
-               [[ -z ${NOSTRIP} ]] && vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}"
-               banner=0
+       if ! ${banner} ; then
+               vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}"
+               banner=true
        fi
 
        f=$(file "${x}") || continue
        [[ -z ${f} ]] && continue
 
-       # The noglob funk is to support STRIP_MASK="/*/booga" and to keep
-       #  the for loop from expanding the globs.
-       # The eval echo is to support STRIP_MASK="/*/{booga,bar}" sex.
-       set -o noglob
-       stripitbaby=1
-       for m in $(eval echo ${STRIP_MASK}) ; do
-               [[ ${x} == ${m} ]] && stripitbaby=0 && break
-       done
-       set +o noglob
+       if ! ${SKIP_STRIP} ; then
+               # The noglob funk is to support STRIP_MASK="/*/booga" and to keep
+               #  the for loop from expanding the globs.
+               # The eval echo is to support STRIP_MASK="/*/{booga,bar}" sex.
+               set -o noglob
+               strip_this=true
+               for m in $(eval echo ${STRIP_MASK}) ; do
+                       [[ ${x} == ${m} ]] && strip_this=false && break
+               done
+               set +o noglob
+       else
+               strip_this=false
+       fi
+
+       # only split debug info for final linked objects
+       # or kernel modules as debuginfo for intermediatary
+       # files (think crt*.o from gcc/glibc) is useless and
+       # actually causes problems.  install sources for all
+       # elf types though cause that stuff is good.
 
        if [[ ${f} == *"current ar archive"* ]] ; then
                vecho "   ${x:${#ED}}"
-               [[ -n ${NOSTRIP} ]] && continue
-               [[ ${stripitbaby} -eq 1 ]] && ${STRIP} -g "${x}"
-       elif [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* || ${f} == *"SB relocatable"* ]] ; then
+               if ${strip_this} ; then
+                       # hmm, can we split debug/sources for .a ?
+                       ${STRIP} -g "${x}"
+               fi
+       elif [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]] ; then
                vecho "   ${x:${#ED}}"
-               if [[ ${f} != *"SB relocatable"* ]] || [[ ${x} == *.ko ]] ; then
-                       # only split debug info for final linked objects
-                       # or kernel modules as debuginfo for intermediatary
-                       # files (think crt*.o from gcc/glibc) is useless and
-                       # actually causes problems
+               save_elf_sources "${x}"
+               if ${strip_this} ; then
                        save_elf_debug "${x}"
+                       ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}"
                fi
-               [[ -n ${NOSTRIP} ]] && continue
-               if [[ ${stripitbaby} -eq 1 ]] ; then
-                       [[ ${f} == *"SB relocatable"* ]] \
-                               && ${STRIP} ${SAFE_STRIP_FLAGS} "${x}" \
-                               || ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}"
+       elif [[ ${f} == *"SB relocatable"* ]] ; then
+               vecho "   ${x:${#D}}"
+               save_elf_sources "${x}"
+               if ${strip_this} ; then
+                       [[ ${x} == *.ko ]] && save_elf_debug "${x}"
+                       ${STRIP} ${SAFE_STRIP_FLAGS} "${x}"
                fi
        fi
 done
index 65c31f9369e06e146b3a552c9e5bfb4c6bc642d4..b64dbd66e30e13f0273fad33fc5ac20c7666c5ae 100644 (file)
@@ -687,7 +687,7 @@ class RootConfig(object):
                system_set = SystemSet(self.settings)
                self.sets["system"] = system_set
 
-def create_world_atom(pkg_key, metadata, args_set, sets, portdb):
+def create_world_atom(pkg_key, metadata, args_set, root_config):
        """Create a new atom for the world file if one does not exist.  If the
        argument atom is precise enough to identify a specific slot then a slot
        atom will be returned. Atoms that are in the system set may also be stored
@@ -697,9 +697,19 @@ def create_world_atom(pkg_key, metadata, args_set, sets, portdb):
        arg_atom = args_set.findAtomForPackage(pkg_key, metadata)
        cp = portage.dep_getkey(arg_atom)
        new_world_atom = cp
+       sets = root_config.sets
+       portdb = root_config.trees["porttree"].dbapi
+       vardb = root_config.trees["vartree"].dbapi
        available_slots = set(portdb.aux_get(cpv, ["SLOT"])[0] \
                for cpv in portdb.match(cp))
-       slotted = len(available_slots) > 1 or "0" not in available_slots
+       slotted = len(available_slots) > 1 or \
+               (len(available_slots) == 1 and "0" not in available_slots)
+       if not slotted:
+               # check the vdb in case this is multislot
+               available_slots = set(vardb.aux_get(cpv, ["SLOT"])[0] \
+                       for cpv in vardb.match(cp))
+               slotted = len(available_slots) > 1 or \
+                       (len(available_slots) == 1 and "0" not in available_slots)
        if slotted and arg_atom != cp:
                # If the user gave a specific atom, store it as a
                # slot atom in the world file.
@@ -2652,41 +2662,7 @@ class depgraph(object):
                                        ret = '%s="%s" ' % (name, ret)
                                return ret
 
-               # Get repo data for verbose repo display.
-               repo_paths = set()
-               for root_config in self.roots.itervalues():
-                       portdir = root_config.settings.get("PORTDIR")
-                       if portdir:
-                               repo_paths.add(portdir)
-                       overlays = root_config.settings.get("PORTDIR_OVERLAY")
-                       if overlays:
-                               repo_paths.update(overlays.split())
-               repo_paths = list(repo_paths)
-               repo_paths.sort()
-               repo_paths_real = [ os.path.realpath(repo_path) \
-                       for repo_path in repo_paths ]
-               # Track which ones are show so the list can be pruned to save space.
-               shown_repos = {}
-               def repo_str(portdb, repo_name):
-                       repo_path_real = portdb.getRepositoryPath(repo_name)
-                       real_index = -1
-                       if repo_path_real:
-                               try:
-                                       real_index = repo_paths_real.index(repo_path_real)
-                               except ValueError:
-                                       pass
-                       if real_index == -1:
-                               s = "?"
-                               repo_str.unknown_repo = True
-                       else:
-                               repo_path = repo_paths[real_index]
-                               index = shown_repos.get(repo_path)
-                               if index is None:
-                                       index = len(shown_repos)
-                                       shown_repos[repo_path] = index
-                               s = str(index)
-                       return s
-               repo_str.unknown_repo = False
+               repo_display = RepoDisplay(self.roots)
 
                tree_nodes = []
                display_list = []
@@ -2815,7 +2791,6 @@ class depgraph(object):
                        else:
                                pkg_status = x[3]
                                pkg_merge = ordered and pkg_status != "nomerge"
-                               binary_package = pkg_type != "ebuild"
                                if pkg_node in self._slot_collision_nodes or \
                                        (pkg_status == "nomerge" and pkg_type != "installed"):
                                        # The metadata isn't cached due to a slot collision or
@@ -2831,14 +2806,10 @@ class depgraph(object):
                                        ebuild_path = portdb.findname(pkg_key)
                                        if not ebuild_path: # shouldn't happen
                                                raise portage.exception.PackageNotFound(pkg_key)
-                                       repo_path = os.path.sep.join(
-                                               ebuild_path.split(os.path.sep)[:-3])
-                                       for repo_name in portdb.getRepositories():
-                                               if portdb.getRepositoryPath(repo_name) == repo_path:
-                                                       repo_name = repo_name
-                                                       break
-                                               else:
-                                                       repo_name = None
+                                       repo_path_real = os.path.dirname(os.path.dirname(
+                                               os.path.dirname(ebuild_path)))
+                               else:
+                                       repo_path_real = portdb.getRepositoryPath(repo_name)
                                if pkg_key not in self.useFlags[myroot]:
                                        """If this is a --resume then the USE flags need to be
                                        fetched from the appropriate locations here."""
@@ -2921,9 +2892,8 @@ class depgraph(object):
                                                mydbapi.aux_get(pkg_key, ["IUSE"])[0].split()))
 
                                        forced_flags = set()
-                                       if not binary_package:
-                                               forced_flags.update(pkgsettings.useforce)
-                                               forced_flags.update(pkgsettings.usemask)
+                                       forced_flags.update(pkgsettings.useforce)
+                                       forced_flags.update(pkgsettings.usemask)
 
                                        cur_iuse = portage.unique_array(cur_iuse)
                                        cur_iuse.sort()
@@ -3053,10 +3023,15 @@ class depgraph(object):
                                        # now use the data to generate output
                                        repoadd = None
                                        if pkg_status == "nomerge" or not has_previous:
-                                               repoadd = repo_str(portdb, repo_name)
+                                               repoadd = repo_display.repoStr(repo_path_real)
                                        else:
-                                               repoadd = "%s=>%s" % (repo_str(portdb, repo_name_prev),
-                                                       repo_str(portdb, repo_name))
+                                               repo_path_prev = None
+                                               if repo_name_prev:
+                                                       repo_path_prev = portdb.getRepositoryPath(
+                                                               repo_name_prev)
+                                               repoadd = "%s=>%s" % (
+                                                       repo_display.repoStr(repo_path_prev),
+                                                       repo_display.repoStr(repo_path_real))
                                        if repoadd:
                                                verboseadd += teal("[%s]" % repoadd)
 
@@ -3101,7 +3076,7 @@ class depgraph(object):
                                                favorites_set.findAtomForPackage(pkg_key, metadata):
                                                # Maybe it will be added to world now.
                                                if create_world_atom(pkg_key, metadata,
-                                                       favorites_set, root_config.sets, portdb):
+                                                       favorites_set, root_config):
                                                        pkg_world = True
                                except portage.exception.InvalidDependString:
                                        # This is reported elsewhere if relevant.
@@ -3196,16 +3171,7 @@ class depgraph(object):
                if verbosity == 3:
                        print
                        print counters
-                       if shown_repos or repo_str.unknown_repo:
-                               print "Portage tree and overlays:"
-                       show_repo_paths = list(shown_repos)
-                       for repo_path, repo_index in shown_repos.iteritems():
-                               show_repo_paths[repo_index] = repo_path
-                       if show_repo_paths:
-                               for index, repo_path in enumerate(show_repo_paths):
-                                       print " "+teal("["+str(index)+"]"),repo_path
-                       if repo_str.unknown_repo:
-                               print " "+teal("[?]"), "indicates that the source repository could not be determined"
+                       sys.stdout.write(str(repo_display))
 
                if "--changelog" in self.myopts:
                        print
@@ -3325,7 +3291,7 @@ class depgraph(object):
                                self.mydbapi[root].aux_get(pkg_key, self._mydbapi_keys)))
                        try:
                                myfavkey = create_world_atom(pkg_key, metadata,
-                                       args_set, root_config.sets, portdb)
+                                       args_set, root_config)
                                if myfavkey:
                                        if myfavkey in added_favorites:
                                                continue
@@ -3373,6 +3339,65 @@ class depgraph(object):
                                fakedb[myroot].aux_update(pkg_key, {"USE":pkgsettings["USE"]})
                        self.spinner.update()
 
+class RepoDisplay(object):
+       def __init__(self, roots):
+               self._shown_repos = {}
+               self._unknown_repo = False
+               repo_paths = set()
+               for root_config in roots.itervalues():
+                       portdir = root_config.settings.get("PORTDIR")
+                       if portdir:
+                               repo_paths.add(portdir)
+                       overlays = root_config.settings.get("PORTDIR_OVERLAY")
+                       if overlays:
+                               repo_paths.update(overlays.split())
+               repo_paths = list(repo_paths)
+               self._repo_paths = repo_paths
+               self._repo_paths_real = [ os.path.realpath(repo_path) \
+                       for repo_path in repo_paths ]
+
+               # pre-allocate index for PORTDIR so that it always has index 0.
+               for root_config in roots.itervalues():
+                       portdb = root_config.trees["porttree"].dbapi
+                       portdir = portdb.porttree_root
+                       if portdir:
+                               self.repoStr(portdir)
+
+       def repoStr(self, repo_path_real):
+               real_index = -1
+               if repo_path_real:
+                       real_index = self._repo_paths_real.index(repo_path_real)
+               if real_index == -1:
+                       s = "?"
+                       self._unknown_repo = True
+               else:
+                       shown_repos = self._shown_repos
+                       repo_paths = self._repo_paths
+                       repo_path = repo_paths[real_index]
+                       index = shown_repos.get(repo_path)
+                       if index is None:
+                               index = len(shown_repos)
+                               shown_repos[repo_path] = index
+                       s = str(index)
+               return s
+
+       def __str__(self):
+               output = []
+               shown_repos = self._shown_repos
+               unknown_repo = self._unknown_repo
+               if shown_repos or self._unknown_repo:
+                       output.append("Portage tree and overlays:\n")
+               show_repo_paths = list(shown_repos)
+               for repo_path, repo_index in shown_repos.iteritems():
+                       show_repo_paths[repo_index] = repo_path
+               if show_repo_paths:
+                       for index, repo_path in enumerate(show_repo_paths):
+                               output.append(" "+teal("["+str(index)+"]")+" %s\n" % repo_path)
+               if unknown_repo:
+                       output.append(" "+teal("[?]") + \
+                               " indicates that the source repository could not be determined\n")
+               return "".join(output)
+
 class PackageCounters(object):
 
        def __init__(self):
@@ -3511,9 +3536,10 @@ class MergeTask(object):
                                del x, mytype, myroot, mycpv, mystatus, quiet_config
                        del shown_verifying_msg, quiet_settings
 
-               system_set = SystemSet(self.settings)
+               root_config = RootConfig(self.trees[self.target_root])
+               system_set = root_config.sets["system"]
                args_set = AtomSet(favorites)
-               world_set = WorldSet(self.settings)
+               world_set = root_config.sets["world"]
                if "--resume" not in self.myopts:
                        mymergelist = mylist
                        mtimedb["resume"]["mergelist"]=mymergelist[:]
@@ -3805,8 +3831,7 @@ class MergeTask(object):
                                        world_set.lock()
                                        world_set.load()
                                        myfavkey = create_world_atom(pkg_key, metadata,
-                                               args_set, {"world":world_set, "system":system_set},
-                                               portdb)
+                                               args_set, root_config)
                                        if myfavkey:
                                                world_set.add(myfavkey)
                                                print ">>> Recording",myfavkey,"in \"world\" favorites file..."