Add a --rebuilt-binaries[=n] option, causing automatic replacement of
authorZac Medico <zmedico@gentoo.org>
Thu, 18 Feb 2010 07:07:41 +0000 (07:07 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 18 Feb 2010 07:07:41 +0000 (07:07 -0000)
installed packages with binary packages that have been rebuilt. Rebuilds
are detected by comparison of BUILD_TIME package metadata. This option is
enabled automatically when using binary packages, so rebuilt binaries are
installed with a user's typical update command. This isn't possible with
the existing @rebuild-binaries package set since that only works with
--selective=n and therefore can't be used with a typical world update.
The package set framework should support this type of behavior sometime
in the future.

svn path=/main/trunk/; revision=15364

man/emerge.1
pym/_emerge/depgraph.py
pym/_emerge/help.py
pym/_emerge/main.py

index 47149061498b97c57b370ec8cda8486b36d72906..6c2727de8a1ead714c32b7f01fc8df2d6089cf90 100644 (file)
@@ -477,6 +477,13 @@ output from portage's displays.
 Redirect all build output to logs alone, and do not
 display it on stdout.
 .TP
+.BR "\-\-rebuilt\-binaries[=n]"
+Replace installed packages with binary packages that have
+been rebuilt. Rebuilds are detected by comparison of
+BUILD_TIME package metadata. This option is enabled
+automatically when using binary packages (see
+\fB\-\-usepkg\fR and \fB\-\-getbinpkg\fR).
+.TP
 .BR "\-\-reinstall changed\-use"
 Tells emerge to include installed packages where USE flags have
 changed since installation.  Unlike \fB\-\-newuse\fR, this option does
index 38a48d6fe1b5c0fdc769ea281f81c3acfdfa244c..ac6744a6b4c2b2d8e40ed71a2317fb44757c24fb 100644 (file)
@@ -2396,6 +2396,9 @@ class depgraph(object):
                atom_set = InternalPackageSet(initial_atoms=(atom,))
                existing_node = None
                myeb = None
+               usepkg = "--usepkg" in self._frozen_config.myopts
+               rebuilt_binaries = usepkg and \
+                       self._frozen_config.myopts.get('--rebuilt-binaries') != 'n'
                usepkgonly = "--usepkgonly" in self._frozen_config.myopts
                empty = "empty" in self._dynamic_config.myparams
                selective = "selective" in self._dynamic_config.myparams
@@ -2615,10 +2618,26 @@ class depgraph(object):
                                        if pkg.cp == cp]
                                break
 
+               if existing_node is not None and \
+                       existing_node in matched_packages:
+                       return existing_node, existing_node
+
                if len(matched_packages) > 1:
+                       if rebuilt_binaries:
+                               inst_pkg = None
+                               built_pkg = None
+                               for pkg in matched_packages:
+                                       if pkg.installed:
+                                               inst_pkg = pkg
+                                       elif pkg.built:
+                                               built_pkg = pkg
+                               if built_pkg is not None and inst_pkg is not None:
+                                       if built_pkg >= inst_pkg and \
+                                               built_pkg.metadata['BUILD_TIME'] != \
+                                               inst_pkg.metadata['BUILD_TIME']:
+                                               return built_pkg, built_pkg
+
                        if avoid_update:
-                               if existing_node is not None:
-                                       return existing_node, existing_node
                                for pkg in matched_packages:
                                        if pkg.installed:
                                                return pkg, existing_node
index 88b818cfb371e88bc3167110ab53be264b8bdb29..a30b6dadcbc2c0c46e2e5a9143a3188d30e5dd60 100644 (file)
@@ -506,6 +506,15 @@ def help(myopts, havecolor=1):
                for line in wrap(desc, desc_width):
                        print(desc_indent + line)
                print()
+               print("       "+green("--rebuilt-binaries[=n]"))
+               desc = "Replace installed packages with binary packages that have " + \
+                       "been rebuilt. Rebuilds are detected by comparison of " + \
+                       "BUILD_TIME package metadata. This option is enabled " + \
+                       "automatically when using binary packages (see " + \
+                       "--usepkg and --getbinpkg)."
+               for line in wrap(desc, desc_width):
+                       print(desc_indent + line)
+               print()
                print("       "+green("--reinstall ") + turquoise("changed-use"))
                print("              Tells emerge to include installed packages where USE flags have")
                print("              changed since installation.  Unlike --newuse, this option does")
index f96654eeabd88cc4fc14033eb3203ecea847be68..a92ae035136fc7680aef9040e7c516dce1a80396 100644 (file)
@@ -395,6 +395,7 @@ def insert_optional_args(args):
                '--getbinpkgonly'        : ('n',),
                '--jobs'       : valid_integers,
                '--keep-going'           : ('n',),
+               '--rebuilt-binaries'     : ('n',),
                '--root-deps'  : ('rdeps',),
                '--select'               : ('n',),
                '--selective'            : ('n',),
@@ -620,6 +621,13 @@ def parse_opts(tmpcmdline, silent=False):
                        "choices"  : ("True", "n")
                },
 
+               "--rebuilt-binaries": {
+                       "help"     : "replace installed packages with binary " + \
+                                    "packages that have been rebuilt",
+                       "type"     : "choice",
+                       "choices"  : ("True", "n")
+               },
+
                "--root": {
                 "help"   : "specify the target root filesystem for merging packages",
                 "action" : "store"
@@ -732,6 +740,10 @@ def parse_opts(tmpcmdline, silent=False):
        else:
                myoptions.keep_going = None
 
+       if myoptions.rebuilt_binaries in ("True",):
+               # The depgraph will enable this by default unless 'n' is specified.
+               myoptions.rebuilt_binaries = None
+
        if myoptions.root_deps == "True":
                myoptions.root_deps = True