Beispiel #1
0
def fix_conflict(config, depgraph):
    depgraph._slot_conflict_handler = slot_conflict_handler(depgraph)
    handler = depgraph._slot_conflict_handler
    for root, slot_atom, pkgs in handler.all_conflicts:
        print("%s" % (slot_atom,))
        for p in pkgs:
            parents = handler.all_parents.get(p)
            if not parents:
                continue
            collisions = {}
            for ppkg, atom in parents:
                if atom.soname:
                    continue
                for other_pkg in pkgs:
                    atom_without_use_set = \
                        InternalPackageSet(initial_atoms=(atom.without_use,))
                    if atom_without_use_set.findAtomForPackage(other_pkg,
                                                               modified_use=depgraph._pkg_use_enabled(other_pkg)):
                        continue
                    key = (atom.slot, atom.sub_slot, atom.slot_operator)
                    atoms = collisions.get(key, set())
                    atoms.add((ppkg, atom, other_pkg))
                    collisions[key] = atoms
                    print("collisions: %s" % collisions)
                    print("")
    return (config, False)
Beispiel #2
0
	def run(self, atoms, options={}, action=None):
		options = options.copy()
		options["--pretend"] = True
		if self.debug:
			options["--debug"] = True

		if action is None:
			if options.get("--depclean"):
				action = "depclean"
			elif options.get("--prune"):
				action = "prune"

		if "--usepkgonly" in options:
			options["--usepkg"] = True

		global_noiselimit = portage.util.noiselimit
		global_emergelog_disable = _emerge.emergelog._disable
		try:

			if not self.debug:
				portage.util.noiselimit = -2
			_emerge.emergelog._disable = True

			if action in ("depclean", "prune"):
				depclean_result = _calc_depclean(self.settings, self.trees, None,
					options, action, InternalPackageSet(initial_atoms=atoms, allow_wildcard=True), None)
				result = ResolverPlaygroundDepcleanResult(
					atoms,
					depclean_result.returncode,
					depclean_result.cleanlist,
					depclean_result.ordered,
					depclean_result.req_pkg_count,
					depclean_result.depgraph,
				)
			else:
				params = create_depgraph_params(options, action)
				success, depgraph, favorites = backtrack_depgraph(
					self.settings, self.trees, options, params, action, atoms, None)
				depgraph._show_merge_list()
				depgraph.display_problems()
				result = ResolverPlaygroundResult(atoms, success, depgraph, favorites)
		finally:
			portage.util.noiselimit = global_noiselimit
			_emerge.emergelog._disable = global_emergelog_disable

		return result
Beispiel #3
0
def format_unmatched_atom(pkg, atom, pkg_use_enabled):
	"""
	Returns two strings. The first string contains the
	'atom' with parts of the atom colored, which 'pkg'
	doesn't match. The second string has the same number
	of characters as the first one, but consists of only
	white space or ^. The ^ characters have the same position
	as the colored parts of the first string.
	"""
	# Things to check:
	#	1. Version
	#	2. cp
	#   3. slot/sub_slot
	#	4. repository
	#	5. USE

	highlight = set()

	def perform_coloring():
		atom_str = ""
		marker_str = ""
		for ii, x in enumerate(atom):
			if ii in highlight:
				atom_str += colorize("BAD", x)
				marker_str += "^"
			else:
				atom_str += x
				marker_str += " "
		return atom_str, marker_str

	if atom.cp != pkg.cp:
		# Highlight the cp part only.
		ii = atom.find(atom.cp)
		highlight.update(range(ii, ii + len(atom.cp)))
		return perform_coloring()

	version_atom = atom.without_repo.without_slot.without_use
	version_atom_set = InternalPackageSet(initial_atoms=(version_atom,))
	highlight_version = not bool(version_atom_set.findAtomForPackage(pkg,
		modified_use=pkg_use_enabled(pkg)))

	highlight_slot = False
	if (atom.slot and atom.slot != pkg.slot) or \
		(atom.sub_slot and atom.sub_slot != pkg.sub_slot):
		highlight_slot = True

	if highlight_version:
		op = atom.operator
		ver = None
		if atom.cp != atom.cpv:
			ver = cpv_getversion(atom.cpv)

		if op == "=*":
			op = "="
			ver += "*"

		if op is not None:
			highlight.update(range(len(op)))

		if ver is not None:
			start = atom.rfind(ver)
			end = start + len(ver)
			highlight.update(range(start, end))

	if highlight_slot:
		slot_str = ":" + atom.slot
		if atom.sub_slot:
			slot_str += "/" + atom.sub_slot
		if atom.slot_operator:
			slot_str += atom.slot_operator
		start = atom.find(slot_str)
		end = start + len(slot_str)
		highlight.update(range(start, end))

	highlight_use = set()
	if atom.use:
		use_atom = "%s[%s]" % (atom.cp, str(atom.use))
		use_atom_set = InternalPackageSet(initial_atoms=(use_atom,))
		if not use_atom_set.findAtomForPackage(pkg, \
			modified_use=pkg_use_enabled(pkg)):
			missing_iuse = pkg.iuse.get_missing_iuse(
				atom.unevaluated_atom.use.required)
			if missing_iuse:
				highlight_use = set(missing_iuse)
			else:
				#Use conditionals not met.
				violated_atom = atom.violated_conditionals(
					pkg_use_enabled(pkg), pkg.iuse.is_valid_flag)
				if violated_atom.use is not None:
					highlight_use = set(violated_atom.use.enabled.union(
						violated_atom.use.disabled))

	if highlight_use:
		ii = atom.find("[") + 1
		for token in atom.use.tokens:
			if token.lstrip("-!").rstrip("=?") in highlight_use:
				highlight.update(range(ii, ii + len(token)))
			ii += len(token) + 1

	return perform_coloring()
	def __init__(self, depgraph, mylist, favorites, verbosity):
		frozen_config = depgraph._frozen_config
		dynamic_config = depgraph._dynamic_config

		self.mylist = mylist
		self.favorites = InternalPackageSet(favorites, allow_repo=True)
		self.verbosity = verbosity

		if self.verbosity is None:
			self.verbosity = ("--quiet" in frozen_config.myopts and 1 or \
				"--verbose" in frozen_config.myopts and 3 or 2)

		self.oneshot = "--oneshot" in frozen_config.myopts or \
			"--onlydeps" in frozen_config.myopts
		self.columns = "--columns" in frozen_config.myopts
		self.tree_display = "--tree" in frozen_config.myopts
		self.alphabetical = "--alphabetical" in frozen_config.myopts
		self.quiet = "--quiet" in frozen_config.myopts
		self.all_flags = self.verbosity == 3 or self.quiet
		self.print_use_string = self.verbosity != 1 or "--verbose" in frozen_config.myopts
		self.changelog = "--changelog" in frozen_config.myopts
		self.edebug = frozen_config.edebug
		self.unordered_display = "--unordered-display" in frozen_config.myopts

		mywidth = 130
		if "COLUMNWIDTH" in frozen_config.settings:
			try:
				mywidth = int(frozen_config.settings["COLUMNWIDTH"])
			except ValueError as e:
				writemsg("!!! %s\n" % str(e), noiselevel=-1)
				writemsg("!!! Unable to parse COLUMNWIDTH='%s'\n" % \
					frozen_config.settings["COLUMNWIDTH"], noiselevel=-1)
				del e
		self.columnwidth = mywidth

		if "--quiet-repo-display" in frozen_config.myopts:
			self.repo_display = _RepoDisplay(frozen_config.roots)
		self.trees = frozen_config.trees
		self.pkgsettings = frozen_config.pkgsettings
		self.target_root = frozen_config.target_root
		self.running_root = frozen_config._running_root
		self.roots = frozen_config.roots

		# Create a set of selected packages for each root
		self.selected_sets = {}
		for root_name, root in self.roots.items():
			try:
				self.selected_sets[root_name] = InternalPackageSet(
					initial_atoms=root.setconfig.getSetAtoms("selected"))
			except PackageSetNotFound:
				# A nested set could not be resolved, so ignore nested sets.
				self.selected_sets[root_name] = root.sets["selected"]

		self.blocker_parents = dynamic_config._blocker_parents
		self.reinstall_nodes = dynamic_config._reinstall_nodes
		self.digraph = dynamic_config.digraph
		self.blocker_uninstalls = dynamic_config._blocker_uninstalls
		self.package_tracker = dynamic_config._package_tracker
		self.set_nodes = dynamic_config._set_nodes

		self.pkg_use_enabled = depgraph._pkg_use_enabled
		self.pkg = depgraph._pkg
Beispiel #5
0
 def __init__(self, atom=None, **kwargs):
     DependencyArg.__init__(self, **kwargs)
     self.atom = atom
     self.pset = InternalPackageSet(initial_atoms=(self.atom, ),
                                    allow_repo=True)
Beispiel #6
0
    def _prepare_conflict_msg_and_check_for_specificity(self):
        """
		Print all slot conflicts in a human readable way.
		"""
        _pkg_use_enabled = self.depgraph._pkg_use_enabled
        msg = self.conflict_msg
        indent = "  "
        msg.append("\n!!! Multiple package instances within a single " + \
         "package slot have been pulled\n")
        msg.append("!!! into the dependency graph, resulting" + \
         " in a slot conflict:\n\n")

        for (slot_atom, root), pkgs \
         in self.slot_collision_info.items():
            msg.append(str(slot_atom))
            if root != '/':
                msg.append(" for %s" % (root, ))
            msg.append("\n\n")

            for pkg in pkgs:
                msg.append(indent)
                msg.append(str(pkg))
                parent_atoms = self.all_parents.get(pkg)
                if parent_atoms:
                    #Create a list of collision reasons and map them to sets
                    #of atoms.
                    #Possible reasons:
                    #	("version", "ge") for operator >=, >
                    #	("version", "eq") for operator =, ~
                    #	("version", "le") for operator <=, <
                    #	("use", "<some use flag>") for unmet use conditionals
                    collision_reasons = {}
                    num_all_specific_atoms = 0

                    for ppkg, atom in parent_atoms:
                        atom_set = InternalPackageSet(initial_atoms=(atom, ))
                        atom_without_use_set = InternalPackageSet(
                            initial_atoms=(atom.without_use, ))

                        for other_pkg in pkgs:
                            if other_pkg == pkg:
                                continue

                            if not atom_without_use_set.findAtomForPackage(other_pkg, \
                             modified_use=_pkg_use_enabled(other_pkg)):
                                #The version range does not match.
                                sub_type = None
                                if atom.operator in (">=", ">"):
                                    sub_type = "ge"
                                elif atom.operator in ("=", "~"):
                                    sub_type = "eq"
                                elif atom.operator in ("<=", "<"):
                                    sub_type = "le"

                                atoms = collision_reasons.get(
                                    ("version", sub_type), set())
                                atoms.add((ppkg, atom, other_pkg))
                                num_all_specific_atoms += 1
                                collision_reasons[("version",
                                                   sub_type)] = atoms
                            elif not atom_set.findAtomForPackage(other_pkg, \
                             modified_use=_pkg_use_enabled(other_pkg)):
                                #Use conditionals not met.
                                violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
                                 other_pkg.iuse.is_valid_flag)
                                for flag in violated_atom.use.enabled.union(
                                        violated_atom.use.disabled):
                                    atoms = collision_reasons.get(
                                        ("use", flag), set())
                                    atoms.add((ppkg, atom, other_pkg))
                                    collision_reasons[("use", flag)] = atoms
                                num_all_specific_atoms += 1

                    msg.append(" pulled in by\n")

                    selected_for_display = set()

                    for (type, sub_type), parents in collision_reasons.items():
                        #From each (type, sub_type) pair select at least one atom.
                        #Try to select as few atoms as possible

                        if type == "version":
                            #Find the atom with version that is as far away as possible.
                            best_matches = {}
                            for ppkg, atom, other_pkg in parents:
                                if atom.cp in best_matches:
                                    cmp = vercmp( \
                                     cpv_getversion(atom.cpv), \
                                     cpv_getversion(best_matches[atom.cp][1].cpv))

                                    if (sub_type == "ge" and  cmp > 0) \
                                     or (sub_type == "le" and cmp < 0) \
                                     or (sub_type == "eq" and cmp > 0):
                                        best_matches[atom.cp] = (ppkg, atom)
                                else:
                                    best_matches[atom.cp] = (ppkg, atom)
                            selected_for_display.update(best_matches.values())
                        elif type == "use":
                            #Prefer atoms with unconditional use deps over, because it's
                            #not possible to change them on the parent, which means there
                            #are fewer possible solutions.
                            use = sub_type
                            hard_matches = set()
                            conditional_matches = set()
                            for ppkg, atom, other_pkg in parents:
                                parent_use = None
                                if isinstance(ppkg, Package):
                                    parent_use = _pkg_use_enabled(ppkg)
                                violated_atom = atom.unevaluated_atom.violated_conditionals( \
                                 _pkg_use_enabled(other_pkg), other_pkg.iuse.is_valid_flag,
                                 parent_use=parent_use)
                                if use in violated_atom.use.enabled.union(
                                        violated_atom.use.disabled):
                                    hard_matches.add((ppkg, atom))
                                else:
                                    conditional_matches.add((ppkg, atom))

                            if hard_matches:
                                matches = hard_matches
                            else:
                                matches = conditional_matches

                            if not selected_for_display.intersection(matches):
                                selected_for_display.add(matches.pop())

                    def highlight_violations(atom, version, use=[]):
                        """Colorize parts of an atom"""
                        atom_str = str(atom)
                        if version:
                            op = atom.operator
                            ver = cpv_getversion(atom.cpv)
                            slot = atom.slot
                            atom_str = atom_str.replace(
                                op, colorize("BAD", op), 1)

                            start = atom_str.rfind(ver)
                            end = start + len(ver)
                            atom_str = atom_str[:start] + \
                             colorize("BAD", ver) + \
                             atom_str[end+1:]
                            if slot:
                                atom_str = atom_str.replace(
                                    ":" + slot, colorize("BAD", ":" + slot))

                        if use and atom.use.tokens:
                            use_part_start = atom_str.find("[")
                            use_part_end = atom_str.find("]")

                            new_tokens = []
                            for token in atom.use.tokens:
                                if token.lstrip("-!").rstrip("=?") in use:
                                    new_tokens.append(colorize("BAD", token))
                                else:
                                    new_tokens.append(token)

                            atom_str = atom_str[:use_part_start] \
                             + "[%s]" % (",".join(new_tokens),) + \
                             atom_str[use_part_end+1:]

                        return atom_str

                    for parent_atom in selected_for_display:
                        parent, atom = parent_atom
                        msg.append(2 * indent)
                        if isinstance(parent, (PackageArg, AtomArg)):
                            # For PackageArg and AtomArg types, it's
                            # redundant to display the atom attribute.
                            msg.append(str(parent))
                        else:
                            # Display the specific atom from SetArg or
                            # Package types.
                            version_violated = False
                            use = []
                            for type, sub_type in collision_reasons:
                                if type == "version":
                                    for x in collision_reasons[(type,
                                                                sub_type)]:
                                        if ppkg == x[0] and atom == x[1]:
                                            version_violated = True
                                elif type == "use":
                                    use.append(sub_type)

                            atom_str = highlight_violations(
                                atom.unevaluated_atom, version_violated, use)

                            if version_violated:
                                self.is_a_version_conflict = True

                            msg.append("%s required by %s" %
                                       (atom_str, parent))
                        msg.append("\n")

                    if not selected_for_display:
                        msg.append(2 * indent)
                        msg.append(
                            "(no parents that aren't satisfied by other packages in this slot)\n"
                        )
                        self.conflict_is_unspecific = True

                    omitted_parents = num_all_specific_atoms - len(
                        selected_for_display)
                    if omitted_parents:
                        msg.append(2 * indent)
                        if len(selected_for_display) > 1:
                            msg.append(
                                "(and %d more with the same problems)\n" %
                                omitted_parents)
                        else:
                            msg.append(
                                "(and %d more with the same problem)\n" %
                                omitted_parents)
                else:
                    msg.append(" (no parents)\n")
                msg.append("\n")
        msg.append("\n")
Beispiel #7
0
	def findInstalledBlockers(self, new_pkg, acquire_lock=0):
		blocker_cache = BlockerCache(self._vartree.root, self._vartree.dbapi)
		dep_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
		settings = self._vartree.settings
		stale_cache = set(blocker_cache)
		fake_vartree = self._get_fake_vartree(acquire_lock=acquire_lock)
		dep_check_trees = self._dep_check_trees
		vardb = fake_vartree.dbapi
		installed_pkgs = list(vardb)

		for inst_pkg in installed_pkgs:
			stale_cache.discard(inst_pkg.cpv)
			cached_blockers = blocker_cache.get(inst_pkg.cpv)
			if cached_blockers is not None and \
				cached_blockers.counter != long(inst_pkg.metadata["COUNTER"]):
				cached_blockers = None
			if cached_blockers is not None:
				blocker_atoms = cached_blockers.atoms
			else:
				# Use aux_get() to trigger FakeVartree global
				# updates on *DEPEND when appropriate.
				depstr = " ".join(vardb.aux_get(inst_pkg.cpv, dep_keys))
				success, atoms = portage.dep_check(depstr,
					vardb, settings, myuse=inst_pkg.use.enabled,
					trees=dep_check_trees, myroot=inst_pkg.root)
				if not success:
					pkg_location = os.path.join(inst_pkg.root,
						portage.VDB_PATH, inst_pkg.category, inst_pkg.pf)
					portage.writemsg("!!! %s/*DEPEND: %s\n" % \
						(pkg_location, atoms), noiselevel=-1)
					continue

				blocker_atoms = [atom for atom in atoms \
					if atom.startswith("!")]
				blocker_atoms.sort()
				counter = long(inst_pkg.metadata["COUNTER"])
				blocker_cache[inst_pkg.cpv] = \
					blocker_cache.BlockerData(counter, blocker_atoms)
		for cpv in stale_cache:
			del blocker_cache[cpv]
		blocker_cache.flush()

		blocker_parents = digraph()
		blocker_atoms = []
		for pkg in installed_pkgs:
			for blocker_atom in blocker_cache[pkg.cpv].atoms:
				blocker_atom = blocker_atom.lstrip("!")
				blocker_atoms.append(blocker_atom)
				blocker_parents.add(blocker_atom, pkg)

		blocker_atoms = InternalPackageSet(initial_atoms=blocker_atoms)
		blocking_pkgs = set()
		for atom in blocker_atoms.iterAtomsForPackage(new_pkg):
			blocking_pkgs.update(blocker_parents.parent_nodes(atom))

		# Check for blockers in the other direction.
		depstr = " ".join(new_pkg.metadata[k] for k in dep_keys)
		success, atoms = portage.dep_check(depstr,
			vardb, settings, myuse=new_pkg.use.enabled,
			trees=dep_check_trees, myroot=new_pkg.root)
		if not success:
			# We should never get this far with invalid deps.
			show_invalid_depstring_notice(new_pkg, depstr, atoms)
			assert False

		blocker_atoms = [atom.lstrip("!") for atom in atoms \
			if atom[:1] == "!"]
		if blocker_atoms:
			blocker_atoms = InternalPackageSet(initial_atoms=blocker_atoms)
			for inst_pkg in installed_pkgs:
				try:
					next(blocker_atoms.iterAtomsForPackage(inst_pkg))
				except (portage.exception.InvalidDependString, StopIteration):
					continue
				blocking_pkgs.add(inst_pkg)

		return blocking_pkgs
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for (slot_atom, root), pkgs \
			in self.slot_collision_info.items():
			msg.append(str(slot_atom))
			if root != '/':
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append(str(pkg))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						atom_set = InternalPackageSet(initial_atoms=(atom,))
						atom_without_use_set = InternalPackageSet(initial_atoms=(atom.without_use,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								#The version range does not match.
								sub_type = None
								if atom.operator in (">=", ">"):
									sub_type = "ge"
								elif atom.operator in ("=", "~"):
									sub_type = "eq"
								elif atom.operator in ("<=", "<"):
									sub_type = "le"

								atoms = collision_reasons.get(("version", sub_type), set())
								atoms.add((ppkg, atom, other_pkg))
								num_all_specific_atoms += 1
								collision_reasons[("version", sub_type)] = atoms
							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								#Use conditionals not met.
								violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
									other_pkg.iuse.is_valid_flag)
								for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
									atoms = collision_reasons.get(("use", flag), set())
									atoms.add((ppkg, atom, other_pkg))
									collision_reasons[("use", flag)] = atoms
								num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
							selected_for_display.update(best_matches.values())
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							hard_matches = set()
							conditional_matches = set()
							for ppkg, atom, other_pkg in parents:
								parent_use = None
								if isinstance(ppkg, Package):
									parent_use = _pkg_use_enabled(ppkg)
								violated_atom = atom.unevaluated_atom.violated_conditionals( \
									_pkg_use_enabled(other_pkg), other_pkg.iuse.is_valid_flag,
									parent_use=parent_use)
								if use in violated_atom.use.enabled.union(violated_atom.use.disabled):
									hard_matches.add((ppkg, atom))
								else:
									conditional_matches.add((ppkg, atom))

							if hard_matches:
								matches = hard_matches
							else:
								matches = conditional_matches
							
							if not selected_for_display.intersection(matches):
								selected_for_display.add(matches.pop())

					def highlight_violations(atom, version, use=[]):
						"""Colorize parts of an atom"""
						atom_str = str(atom)
						if version:
							op = atom.operator
							ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							atom_str = atom_str.replace(op, colorize("BAD", op), 1)
							
							start = atom_str.rfind(ver)
							end = start + len(ver)
							atom_str = atom_str[:start] + \
								colorize("BAD", ver) + \
								atom_str[end+1:]
							if slot:
								atom_str = atom_str.replace(":" + slot, colorize("BAD", ":" + slot))
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
								else:
									new_tokens.append(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str

					for parent_atom in selected_for_display:
						parent, atom = parent_atom
						msg.append(2*indent)
						if isinstance(parent,
							(PackageArg, AtomArg)):
							# For PackageArg and AtomArg types, it's
							# redundant to display the atom attribute.
							msg.append(str(parent))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							use = []
							for type, sub_type in collision_reasons:
								if type == "version":
									for x in collision_reasons[(type, sub_type)]:
										if ppkg == x[0] and atom == x[1]:
											version_violated = True
								elif type == "use":
									use.append(sub_type)

							atom_str = highlight_violations(atom.unevaluated_atom, version_violated, use)

							if version_violated:
								self.is_a_version_conflict = True

							msg.append("%s required by %s" % (atom_str, parent))
						msg.append("\n")
					
					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")
		msg.append("\n")
Beispiel #9
0
	def _check_solution(self, config, all_involved_flags, all_conflict_atoms_by_slotatom):
		"""
		Given a configuartion and all involved flags, all possible settings for the involved
		flags are checked if they solve the slot conflict.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled

		if self.debug:
			#The code is a bit verbose, because the states might not
			#be a string, but a _value_helper.
			msg = "Solution candidate: "
			msg += "["
			first = True
			for involved_flags in all_involved_flags:
				if first:
					first = False
				else:
					msg += ", "
				msg += "{"
				inner_first = True
				for flag, state in involved_flags.items():
					if inner_first:
						inner_first = False
					else:
						msg += ", "
					msg += flag + ": %s" % (state,)
				msg += "}"
			msg += "]\n"
			writemsg(msg, noiselevel=-1)
		
		required_changes = {}
		for id, pkg in enumerate(config):
			if not pkg.installed:
				#We can't change the USE of installed packages.
				for flag in all_involved_flags[id]:
					if not pkg.iuse.is_valid_flag(flag):
						continue
					state = all_involved_flags[id][flag]
					self._force_flag_for_package(required_changes, pkg, flag, state)

			#Go through all (parent, atom) pairs for the current slot conflict.
			for ppkg, atom in all_conflict_atoms_by_slotatom[id]:
				use = atom.unevaluated_atom.use
				if not use:
					#No need to force something for an atom without USE conditionals.
					#These atoms are already satisfied.
					continue
				for flag in all_involved_flags[id]:
					state = all_involved_flags[id][flag]
					
					if flag not in use.required or not use.conditional:
						continue
					if flag in use.conditional.enabled:
						#[flag?]
						if state == "enabled":
							#no need to change anything, the atom won't
							#force -flag on pkg
							pass
						elif state == "disabled":
							#if flag is enabled we get [flag] -> it must be disabled
							self._force_flag_for_package(required_changes, ppkg, flag, "disabled")
					elif flag in use.conditional.disabled:
						#[!flag?]
						if state == "enabled":
							#if flag is enabled we get [-flag] -> it must be disabled
							self._force_flag_for_package(required_changes, ppkg, flag, "disabled")
						elif state == "disabled":
							#no need to change anything, the atom won't
							#force +flag on pkg
							pass
					elif flag in use.conditional.equal:
						#[flag=]
						if state == "enabled":
							#if flag is disabled we get [-flag] -> it must be enabled
							self._force_flag_for_package(required_changes, ppkg, flag, "enabled")
						elif state == "disabled":
							#if flag is enabled we get [flag] -> it must be disabled
							self._force_flag_for_package(required_changes, ppkg, flag, "disabled")
					elif flag in use.conditional.not_equal:
						#[!flag=]
						if state == "enabled":
							#if flag is enabled we get [-flag] -> it must be disabled
							self._force_flag_for_package(required_changes, ppkg, flag, "disabled")
						elif state == "disabled":
							#if flag is disabled we get [flag] -> it must be enabled
							self._force_flag_for_package(required_changes, ppkg, flag, "enabled")

		is_valid_solution = True
		for pkg in required_changes:
			for state in required_changes[pkg].values():
				if not state in ("enabled", "disabled"):
					is_valid_solution = False
		
		if not is_valid_solution:
			return None

		#Check if all atoms are satisfied after the changes are applied.
		for id, pkg in enumerate(config):
			new_use = _pkg_use_enabled(pkg)
			if pkg in required_changes:
				old_use = pkg.use.enabled
				new_use = set(new_use)
				for flag, state in required_changes[pkg].items():
					if state == "enabled":
						new_use.add(flag)
					elif state == "disabled":
						new_use.discard(flag)
				if not new_use.symmetric_difference(old_use):
					#avoid copying the package in findAtomForPackage if possible
					new_use = old_use

			for ppkg, atom in all_conflict_atoms_by_slotatom[id]:
				if not hasattr(ppkg, "use"):
					#It's a SetArg or something like that.
					continue
				ppkg_new_use = set(_pkg_use_enabled(ppkg))
				if ppkg in required_changes:
					for flag, state in required_changes[ppkg].items():
						if state == "enabled":
							ppkg_new_use.add(flag)
						elif state == "disabled":
							ppkg_new_use.discard(flag)

				new_atom = atom.unevaluated_atom.evaluate_conditionals(ppkg_new_use)
				i = InternalPackageSet(initial_atoms=(new_atom,))
				if not i.findAtomForPackage(pkg, new_use):
					#We managed to create a new problem with our changes.
					is_valid_solution = False
					if self.debug:
						writemsg(("new conflict introduced: %s"
							" does not match %s from %s\n") %
							(pkg, new_atom, ppkg), noiselevel=-1)
					break

			if not is_valid_solution:
				break

		#Make sure the changes don't violate REQUIRED_USE
		for pkg in required_changes:
			required_use = pkg._metadata.get("REQUIRED_USE")
			if not required_use:
				continue

			use = set(_pkg_use_enabled(pkg))
			for flag, state in required_changes[pkg].items():
				if state == "enabled":
					use.add(flag)
				else:
					use.discard(flag)

			if not check_required_use(required_use, use, pkg.iuse.is_valid_flag):
				is_valid_solution = False
				break

		if is_valid_solution and required_changes:
			return required_changes
		else:
			return None
Beispiel #10
0
def fix_conflict(depgraph):
    # non-supported problems
    dynamic_config = depgraph._dynamic_config
    if not have_conflict(dynamic_config):
        print("skip: no conflict")
        return []

    if dynamic_config._missing_args:
        print("skip: missing args")
        return []
    if dynamic_config._pprovided_args:
        print("skip: pprovided args")
        return []
    if dynamic_config._masked_license_updates:
        print("skip: masked license")
        return []
    if dynamic_config._masked_installed:
        print("skip: masked installed")
        return []
    # if dynamic_config._needed_unstable_keywords:
    #    print("skip: needed unstable: %s" % dynamic_config._needed_unstable_keywords)
    #    return []
    if dynamic_config._needed_p_mask_changes:
        print("skip: needed package mask")
        return []
    if dynamic_config._needed_use_config_changes.items():
        print("skip: needed use config changes")
        return []
    if dynamic_config._needed_license_changes.items():
        print("skip: needed license change")
        return []
    if dynamic_config._unsatisfied_deps_for_display:
        res = []
        for pargs, kwargs in dynamic_config._unsatisfied_deps_for_display:
            print("%s %s" % (pargs, kwargs))
            if "myparent" in kwargs and kwargs["myparent"].operation == "nomerge":
                ppkg = kwargs["myparent"]
                res.append(ppkg.cp)
        return res

    if dynamic_config._unsatisfied_blockers_for_display is not None:
        newpkg = set()
        blockers = dynamic_config._unsatisfied_blockers_for_display
        for blocker in blockers:
            for pkg in chain(dynamic_config._blocked_pkgs.child_nodes(blocker),
                             dynamic_config._blocker_parents.parent_nodes(blocker)):
                parent_atoms = dynamic_config._parent_atoms.get(pkg)
                if not parent_atoms:
                    continue
                for parent, atom in parent_atoms:
                    if not isinstance(parent, Package):
                        continue
                    if parent.operation != "merge":
                        print("reinstall %s for %s" % (parent, atom))
                        newpkg.add(parent)
        if newpkg:
            return [p.cp for p in newpkg]

    _pkg_use_enabled = depgraph._pkg_use_enabled
    depgraph._slot_conflict_handler = slot_conflict_handler(depgraph)
    handler = depgraph._slot_conflict_handler
    newpkg = set()
    print(handler.all_conflicts)
    for _, _, pkgs in handler.all_conflicts:
        for pkg in pkgs[1:]:
            parents = handler.all_parents.get(pkg)
            if not parents:
                continue
            for ppkg, atom in parents:
                if not isinstance(ppkg, Package):
                    continue
                if atom.soname:
                    continue
                for other_pkg in pkgs:
                    if pkg == other_pkg:
                        continue
                    atom_without_use_set = InternalPackageSet(
                        initial_atoms=(atom.without_use,))
                    atom_without_use_and_slot_set = InternalPackageSet(
                        initial_atoms=(atom.without_use.without_slot,))
                    if atom_without_use_and_slot_set.findAtomForPackage(
                            other_pkg, modified_use=_pkg_use_enabled(other_pkg)) and \
                        atom_without_use_set.findAtomForPackage(
                            other_pkg, modified_use=_pkg_use_enabled(other_pkg)):
                        continue
                    if ppkg.operation != "merge":
                        print("reinstall %s for %s" % (ppkg, pkg))
                        newpkg.add(ppkg)
    if newpkg:
        return [p.cp for p in newpkg]
        # return ["--reinstall-atoms=" + " ".join([pkg.cp for pkg in newpkg])]
    return []
Beispiel #11
0
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		usepkgonly = "--usepkgonly" in self.myopts
		need_rebuild = {}
		verboseconflicts = "--verbose-conflicts" in self.myopts
		any_omitted_parents = False
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for root, slot_atom, pkgs in self.all_conflicts:
			msg.append("%s" % (slot_atom,))
			if root != self.depgraph._frozen_config._running_root.root:
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append("%s" % (pkg,))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						if not atom.soname:
							atom_set = InternalPackageSet(
								initial_atoms=(atom,))
							atom_without_use_set = InternalPackageSet(
								initial_atoms=(atom.without_use,))
							atom_without_use_and_slot_set = \
								InternalPackageSet(initial_atoms=(
								atom.without_use.without_slot,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if atom.soname:
								# The soname does not match.
								key = ("soname", atom)
								atoms = collision_reasons.get(key, set())
								atoms.add((ppkg, atom, other_pkg))
								num_all_specific_atoms += 1
								collision_reasons[key] = atoms
							elif not atom_without_use_and_slot_set.findAtomForPackage(other_pkg,
								modified_use=_pkg_use_enabled(other_pkg)):
								if atom.operator is not None:
									# The version range does not match.
									sub_type = None
									if atom.operator in (">=", ">"):
										sub_type = "ge"
									elif atom.operator in ("=", "~"):
										sub_type = "eq"
									elif atom.operator in ("<=", "<"):
										sub_type = "le"

									key = ("version", sub_type)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
									# The slot and/or sub_slot does not match.
									key = ("slot", (atom.slot, atom.sub_slot, atom.slot_operator))
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									for flag in missing_iuse:
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
								else:
									#Use conditionals not met.
									violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
										other_pkg.iuse.is_valid_flag)
									if violated_atom.use is None:
										# Something like bug #453400 caused the
										# above findAtomForPackage call to
										# return None unexpectedly.
										msg = ("\n\n!!! BUG: Detected "
											"USE dep match inconsistency:\n"
											"\tppkg: %s\n"
											"\tviolated_atom: %s\n"
											"\tatom: %s unevaluated: %s\n"
											"\tother_pkg: %s IUSE: %s USE: %s\n" %
											(ppkg,
											violated_atom,
											atom,
											atom.unevaluated_atom,
											other_pkg,
											sorted(other_pkg.iuse.all),
											sorted(_pkg_use_enabled(other_pkg))))
										writemsg(msg, noiselevel=-2)
										raise AssertionError(
											'BUG: USE dep match inconsistency')
									for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
							elif isinstance(ppkg, AtomArg) and other_pkg.installed:
								parent_atoms = collision_reasons.get(("AtomArg", None), set())
								parent_atoms.add((ppkg, atom))
								collision_reasons[("AtomArg", None)] = parent_atoms
								num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()
					unconditional_use_deps = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
								if verboseconflicts:
									selected_for_display.add((ppkg, atom))
							if not verboseconflicts:
								selected_for_display.update(
										best_matches.values())
						elif type in ("soname", "slot"):
							# Check for packages that might need to
							# be rebuilt, but cannot be rebuilt for
							# some reason.
							for ppkg, atom, other_pkg in parents:
								if not (isinstance(ppkg, Package) and ppkg.installed):
									continue
								if not (atom.soname or atom.slot_operator_built):
									continue
								if self.depgraph._frozen_config.excluded_pkgs.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --exclude argument'
								elif self.depgraph._frozen_config.useoldpkg_atoms.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --useoldpkg-atoms argument'
								elif usepkgonly:
									# This case is tricky, so keep quiet in order to avoid false-positives.
									pass
								elif not self.depgraph._equiv_ebuild_visible(ppkg):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'ebuild is masked or unavailable'

							for ppkg, atom, other_pkg in parents:
								selected_for_display.add((ppkg, atom))
								if not verboseconflicts:
									break
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							for ppkg, atom, other_pkg in parents:
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									unconditional_use_deps.add((ppkg, atom))
								else:
									parent_use = None
									if isinstance(ppkg, Package):
										parent_use = _pkg_use_enabled(ppkg)
									violated_atom = atom.unevaluated_atom.violated_conditionals(
										_pkg_use_enabled(other_pkg),
										other_pkg.iuse.is_valid_flag,
										parent_use=parent_use)
									# It's possible for autounmask to change
									# parent_use such that the unevaluated form
									# of the atom now matches, even though the
									# earlier evaluated form (from before
									# autounmask changed parent_use) does not.
									# In this case (see bug #374423), it's
									# expected that violated_atom.use is None.
									# Since the atom now matches, we don't want
									# to display it in the slot conflict
									# message, so we simply ignore it and rely
									# on the autounmask display to communicate
									# the necessary USE change to the user.
									if violated_atom.use is None:
										continue
									if use in violated_atom.use.enabled or \
										use in violated_atom.use.disabled:
										unconditional_use_deps.add((ppkg, atom))
								# When USE flags are removed, it can be
								# essential to see all broken reverse
								# dependencies here, so don't omit any.
								# If the list is long, people can simply
								# use a pager.
								selected_for_display.add((ppkg, atom))
						elif type == "AtomArg":
							for ppkg, atom in parents:
								selected_for_display.add((ppkg, atom))

					def highlight_violations(atom, version, use, slot_violated):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						colored_idx = set()
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							if op == "=*":
								op = "="
								ver += "*"

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							# Compute color_idx before adding the color codes
							# as these change the indices of the letters.
							if op is not None:
								colored_idx.update(range(len(op)))

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								colored_idx.update(range(start, end))

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))


							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]

							if slot_str:
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)

						elif slot_violated:
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							# Compute start index in non-colored atom.
							ii = str(atom).find("[") +  1
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
									colored_idx.update(range(ii, ii + len(token)))
								else:
									new_tokens.append(token)
								ii += 1 + len(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str, colored_idx

					# Show unconditional use deps first, since those
					# are more problematic than the conditional kind.
					ordered_list = list(unconditional_use_deps)
					if len(selected_for_display) > len(unconditional_use_deps):
						for parent_atom in selected_for_display:
							if parent_atom not in unconditional_use_deps:
								ordered_list.append(parent_atom)
					for parent_atom in ordered_list:
						parent, atom = parent_atom
						if atom.soname:
							msg.append("%s required by %s\n" %
								(atom, parent))
						elif isinstance(parent, PackageArg):
							# For PackageArg it's
							# redundant to display the atom attribute.
							msg.append("%s\n" % (parent,))
						elif isinstance(parent, AtomArg):
							msg.append(2*indent)
							msg.append("%s (Argument)\n" % (atom,))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							slot_violated = False
							use = []
							for (type, sub_type), parents in collision_reasons.items():
								for x in parents:
									if parent == x[0] and atom == x[1]:
										if type == "version":
											version_violated = True
										elif type == "slot":
											slot_violated = True
										elif type == "use":
											use.append(sub_type)
										break

							atom_str, colored_idx = highlight_violations(atom.unevaluated_atom,
								version_violated, use, slot_violated)

							if version_violated or slot_violated:
								self.is_a_version_conflict = True

							cur_line = "%s required by %s\n" % (atom_str, parent)
							marker_line = ""
							for ii in range(len(cur_line)):
								if ii in colored_idx:
									marker_line += "^"
								else:
									marker_line += " "
							marker_line += "\n"
							msg.append(2*indent)
							msg.append(cur_line)
							msg.append(2*indent)
							msg.append(marker_line)

					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						any_omitted_parents = True
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")

		if any_omitted_parents:
			msg.append(colorize("INFORM",
				"NOTE: Use the '--verbose-conflicts'"
				" option to display parents omitted above"))
			msg.append("\n")

		if need_rebuild:
			msg.append("\n!!! The slot conflict(s) shown above involve package(s) which may need to\n")
			msg.append("!!! be rebuilt in order to solve the conflict(s). However, the following\n")
			msg.append("!!! package(s) cannot be rebuilt for the reason(s) shown:\n\n")
			for ppkg, reason in need_rebuild.items():
				msg.append("%s%s: %s\n" % (indent, ppkg, reason))
			msg.append("\n")

		msg.append("\n")
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		usepkgonly = "--usepkgonly" in self.myopts
		need_rebuild = {}
		verboseconflicts = "--verbose-conflicts" in self.myopts
		any_omitted_parents = False
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for root, slot_atom, pkgs in self.all_conflicts:
			msg.append("%s" % (slot_atom,))
			if root != self.depgraph._frozen_config._running_root.root:
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append("%s %s" % (pkg, pkg_use_display(pkg,
					self.depgraph._frozen_config.myopts,
					modified_use=self.depgraph._pkg_use_enabled(pkg))))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						if not atom.soname:
							atom_set = InternalPackageSet(
								initial_atoms=(atom,))
							atom_without_use_set = InternalPackageSet(
								initial_atoms=(atom.without_use,))
							atom_without_use_and_slot_set = \
								InternalPackageSet(initial_atoms=(
								atom.without_use.without_slot,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if atom.soname:
								# The soname does not match.
								key = ("soname", atom)
								atoms = collision_reasons.get(key, set())
								atoms.add((ppkg, atom, other_pkg))
								num_all_specific_atoms += 1
								collision_reasons[key] = atoms
							elif not atom_without_use_and_slot_set.findAtomForPackage(other_pkg,
								modified_use=_pkg_use_enabled(other_pkg)):
								if atom.operator is not None:
									# The version range does not match.
									sub_type = None
									if atom.operator in (">=", ">"):
										sub_type = "ge"
									elif atom.operator in ("=", "~"):
										sub_type = "eq"
									elif atom.operator in ("<=", "<"):
										sub_type = "le"

									key = ("version", sub_type)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
									# The slot and/or sub_slot does not match.
									key = ("slot", (atom.slot, atom.sub_slot, atom.slot_operator))
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									for flag in missing_iuse:
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
								else:
									#Use conditionals not met.
									violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
										other_pkg.iuse.is_valid_flag)
									if violated_atom.use is None:
										# Something like bug #453400 caused the
										# above findAtomForPackage call to
										# return None unexpectedly.
										msg = ("\n\n!!! BUG: Detected "
											"USE dep match inconsistency:\n"
											"\tppkg: %s\n"
											"\tviolated_atom: %s\n"
											"\tatom: %s unevaluated: %s\n"
											"\tother_pkg: %s IUSE: %s USE: %s\n" %
											(ppkg,
											violated_atom,
											atom,
											atom.unevaluated_atom,
											other_pkg,
											sorted(other_pkg.iuse.all),
											sorted(_pkg_use_enabled(other_pkg))))
										writemsg(msg, noiselevel=-2)
										raise AssertionError(
											'BUG: USE dep match inconsistency')
									for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
							elif isinstance(ppkg, AtomArg) and other_pkg.installed:
								parent_atoms = collision_reasons.get(("AtomArg", None), set())
								parent_atoms.add((ppkg, atom))
								collision_reasons[("AtomArg", None)] = parent_atoms
								num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()
					unconditional_use_deps = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
								if verboseconflicts:
									selected_for_display.add((ppkg, atom))
							if not verboseconflicts:
								selected_for_display.update(
										best_matches.values())
						elif type in ("soname", "slot"):
							# Check for packages that might need to
							# be rebuilt, but cannot be rebuilt for
							# some reason.
							for ppkg, atom, other_pkg in parents:
								if not (isinstance(ppkg, Package) and ppkg.installed):
									continue
								if not (atom.soname or atom.slot_operator_built):
									continue
								if self.depgraph._frozen_config.excluded_pkgs.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --exclude argument'
								elif self.depgraph._frozen_config.useoldpkg_atoms.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --useoldpkg-atoms argument'
								elif usepkgonly:
									# This case is tricky, so keep quiet in order to avoid false-positives.
									pass
								elif not self.depgraph._equiv_ebuild_visible(ppkg):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'ebuild is masked or unavailable'

							for ppkg, atom, other_pkg in parents:
								selected_for_display.add((ppkg, atom))
								if not verboseconflicts:
									break
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							for ppkg, atom, other_pkg in parents:
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									unconditional_use_deps.add((ppkg, atom))
								else:
									parent_use = None
									if isinstance(ppkg, Package):
										parent_use = _pkg_use_enabled(ppkg)
									violated_atom = atom.unevaluated_atom.violated_conditionals(
										_pkg_use_enabled(other_pkg),
										other_pkg.iuse.is_valid_flag,
										parent_use=parent_use)
									# It's possible for autounmask to change
									# parent_use such that the unevaluated form
									# of the atom now matches, even though the
									# earlier evaluated form (from before
									# autounmask changed parent_use) does not.
									# In this case (see bug #374423), it's
									# expected that violated_atom.use is None.
									# Since the atom now matches, we don't want
									# to display it in the slot conflict
									# message, so we simply ignore it and rely
									# on the autounmask display to communicate
									# the necessary USE change to the user.
									if violated_atom.use is None:
										continue
									if use in violated_atom.use.enabled or \
										use in violated_atom.use.disabled:
										unconditional_use_deps.add((ppkg, atom))
								# When USE flags are removed, it can be
								# essential to see all broken reverse
								# dependencies here, so don't omit any.
								# If the list is long, people can simply
								# use a pager.
								selected_for_display.add((ppkg, atom))
						elif type == "AtomArg":
							for ppkg, atom in parents:
								selected_for_display.add((ppkg, atom))

					def highlight_violations(atom, version, use, slot_violated):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						colored_idx = set()
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							if op == "=*":
								op = "="
								ver += "*"

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							# Compute color_idx before adding the color codes
							# as these change the indices of the letters.
							if op is not None:
								colored_idx.update(range(len(op)))

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								colored_idx.update(range(start, end))

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))


							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]

							if slot_str:
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)

						elif slot_violated:
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							# Compute start index in non-colored atom.
							ii = str(atom).find("[") +  1
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
									colored_idx.update(range(ii, ii + len(token)))
								else:
									new_tokens.append(token)
								ii += 1 + len(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str, colored_idx

					# Show unconditional use deps first, since those
					# are more problematic than the conditional kind.
					ordered_list = list(unconditional_use_deps)
					if len(selected_for_display) > len(unconditional_use_deps):
						for parent_atom in selected_for_display:
							if parent_atom not in unconditional_use_deps:
								ordered_list.append(parent_atom)
					for parent_atom in ordered_list:
						parent, atom = parent_atom
						if isinstance(parent, Package):
							use_display = pkg_use_display(parent,
								self.depgraph._frozen_config.myopts,
								modified_use=self.depgraph._pkg_use_enabled(parent))
						else:
							use_display = ""
						if atom.soname:
							msg.append("%s required by %s %s\n" %
								(atom, parent, use_display))
						elif isinstance(parent, PackageArg):
							# For PackageArg it's
							# redundant to display the atom attribute.
							msg.append("%s\n" % (parent,))
						elif isinstance(parent, AtomArg):
							msg.append(2*indent)
							msg.append("%s (Argument)\n" % (atom,))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							slot_violated = False
							use = []
							for (type, sub_type), parents in collision_reasons.items():
								for x in parents:
									if parent == x[0] and atom == x[1]:
										if type == "version":
											version_violated = True
										elif type == "slot":
											slot_violated = True
										elif type == "use":
											use.append(sub_type)
										break

							atom_str, colored_idx = highlight_violations(atom.unevaluated_atom,
								version_violated, use, slot_violated)

							if version_violated or slot_violated:
								self.is_a_version_conflict = True

							cur_line = "%s required by %s %s\n" % (atom_str, parent, use_display)
							marker_line = ""
							for ii in range(len(cur_line)):
								if ii in colored_idx:
									marker_line += "^"
								else:
									marker_line += " "
							marker_line += "\n"
							msg.append(2*indent)
							msg.append(cur_line)
							msg.append(2*indent)
							msg.append(marker_line)

					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						any_omitted_parents = True
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")

		if any_omitted_parents:
			msg.append(colorize("INFORM",
				"NOTE: Use the '--verbose-conflicts'"
				" option to display parents omitted above"))
			msg.append("\n")

		if need_rebuild:
			msg.append("\n!!! The slot conflict(s) shown above involve package(s) which may need to\n")
			msg.append("!!! be rebuilt in order to solve the conflict(s). However, the following\n")
			msg.append("!!! package(s) cannot be rebuilt for the reason(s) shown:\n\n")
			for ppkg, reason in need_rebuild.items():
				msg.append("%s%s: %s\n" % (indent, ppkg, reason))
			msg.append("\n")

		msg.append("\n")
	def testInternalPackageSet(self):
		i1_atoms = set(("dev-libs/A", ">=dev-libs/A-1", "dev-libs/B"))
		i2_atoms = set(("dev-libs/A", "dev-libs/*", "dev-libs/C"))

		i1 = InternalPackageSet(initial_atoms=i1_atoms)
		i2 = InternalPackageSet(initial_atoms=i2_atoms, allow_wildcard=True)
		self.assertRaises(InvalidAtom, InternalPackageSet, initial_atoms=i2_atoms)

		self.assertEqual(i1.getAtoms(), i1_atoms)
		self.assertEqual(i2.getAtoms(), i2_atoms)

		new_atom = Atom("*/*", allow_wildcard=True)
		self.assertRaises(InvalidAtom, i1.add, new_atom)
		i2.add(new_atom)

		i2_atoms.add(new_atom)

		self.assertEqual(i1.getAtoms(), i1_atoms)
		self.assertEqual(i2.getAtoms(), i2_atoms)

		removed_atom = Atom("dev-libs/A")

		i1.remove(removed_atom)
		i2.remove(removed_atom)

		i1_atoms.remove(removed_atom)
		i2_atoms.remove(removed_atom)

		self.assertEqual(i1.getAtoms(), i1_atoms)
		self.assertEqual(i2.getAtoms(), i2_atoms)

		update_atoms = [Atom("dev-libs/C"), Atom("dev-*/C", allow_wildcard=True)]

		self.assertRaises(InvalidAtom, i1.update, update_atoms)
		i2.update(update_atoms)

		i2_atoms.update(update_atoms)

		self.assertEqual(i1.getAtoms(), i1_atoms)
		self.assertEqual(i2.getAtoms(), i2_atoms)

		replace_atoms = [Atom("dev-libs/D"), Atom("*-libs/C", allow_wildcard=True)]

		self.assertRaises(InvalidAtom, i1.replace, replace_atoms)
		i2.replace(replace_atoms)

		i2_atoms = set(replace_atoms)

		self.assertEqual(i2.getAtoms(), i2_atoms)
Beispiel #14
0
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		verboseconflicts = "--verbose-conflicts" in self.myopts
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for (slot_atom, root), pkgs \
			in self.slot_collision_info.items():
			msg.append("%s" % (slot_atom,))
			if root != self.depgraph._frozen_config._running_root.root:
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append("%s" % (pkg,))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						atom_set = InternalPackageSet(initial_atoms=(atom,))
						atom_without_use_set = InternalPackageSet(initial_atoms=(atom.without_use,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								if atom.operator is not None:
									# The version range does not match.
									sub_type = None
									if atom.operator in (">=", ">"):
										sub_type = "ge"
									elif atom.operator in ("=", "~"):
										sub_type = "eq"
									elif atom.operator in ("<=", "<"):
										sub_type = "le"

									key = ("version", sub_type)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms
								else:
									# The sub_slot does not match.
									key = ("sub-slot", atom.sub_slot)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									for flag in missing_iuse:
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
								else:
									#Use conditionals not met.
									violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
										other_pkg.iuse.is_valid_flag)
									if violated_atom.use is None:
										# Something like bug #453400 caused the
										# above findAtomForPackage call to
										# return None unexpectedly.
										msg = ("\n\n!!! BUG: Detected "
											"USE dep match inconsistency:\n"
											"\tppkg: %s\n"
											"\tviolated_atom: %s\n"
											"\tatom: %s unevaluated: %s\n"
											"\tother_pkg: %s IUSE: %s USE: %s\n" %
											(ppkg,
											violated_atom,
											atom,
											atom.unevaluated_atom,
											other_pkg,
											sorted(other_pkg.iuse.all),
											sorted(_pkg_use_enabled(other_pkg))))
										writemsg(msg, noiselevel=-2)
										raise AssertionError(
											'BUG: USE dep match inconsistency')
									for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()
					unconditional_use_deps = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
								if verboseconflicts:
									selected_for_display.add((ppkg, atom))
							if not verboseconflicts:
								selected_for_display.update(
										best_matches.values())
						elif type == "sub-slot":
							for ppkg, atom, other_pkg in parents:
								selected_for_display.add((ppkg, atom))
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							for ppkg, atom, other_pkg in parents:
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									unconditional_use_deps.add((ppkg, atom))
								else:
									parent_use = None
									if isinstance(ppkg, Package):
										parent_use = _pkg_use_enabled(ppkg)
									violated_atom = atom.unevaluated_atom.violated_conditionals(
										_pkg_use_enabled(other_pkg),
										other_pkg.iuse.is_valid_flag,
										parent_use=parent_use)
									# It's possible for autounmask to change
									# parent_use such that the unevaluated form
									# of the atom now matches, even though the
									# earlier evaluated form (from before
									# autounmask changed parent_use) does not.
									# In this case (see bug #374423), it's
									# expected that violated_atom.use is None.
									# Since the atom now matches, we don't want
									# to display it in the slot conflict
									# message, so we simply ignore it and rely
									# on the autounmask display to communicate
									# the necessary USE change to the user.
									if violated_atom.use is None:
										continue
									if use in violated_atom.use.enabled or \
										use in violated_atom.use.disabled:
										unconditional_use_deps.add((ppkg, atom))
								# When USE flags are removed, it can be
								# essential to see all broken reverse
								# dependencies here, so don't omit any.
								# If the list is long, people can simply
								# use a pager.
								selected_for_display.add((ppkg, atom))

					def highlight_violations(atom, version, use=[]):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot

							if op == "=*":
								op = "="
								ver += "*"

							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]
							if slot:
								atom_str = atom_str.replace(":" + slot, colorize("BAD", ":" + slot))
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
								else:
									new_tokens.append(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str

					# Show unconditional use deps first, since those
					# are more problematic than the conditional kind.
					ordered_list = list(unconditional_use_deps)
					if len(selected_for_display) > len(unconditional_use_deps):
						for parent_atom in selected_for_display:
							if parent_atom not in unconditional_use_deps:
								ordered_list.append(parent_atom)
					for parent_atom in ordered_list:
						parent, atom = parent_atom
						msg.append(2*indent)
						if isinstance(parent,
							(PackageArg, AtomArg)):
							# For PackageArg and AtomArg types, it's
							# redundant to display the atom attribute.
							msg.append("%s" % (parent,))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							sub_slot_violated = False
							use = []
							for (type, sub_type), parents in collision_reasons.items():
								for x in parents:
									if parent == x[0] and atom == x[1]:
										if type == "version":
											version_violated = True
										elif type == "sub-slot":
											sub_slot_violated = True
										elif type == "use":
											use.append(sub_type)
										break

							atom_str = highlight_violations(atom.unevaluated_atom, version_violated, use)

							if version_violated or sub_slot_violated:
								self.is_a_version_conflict = True

							msg.append("%s required by %s" % (atom_str, parent))
						msg.append("\n")
					
					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")
		msg.append("\n")
Beispiel #15
0
    def findInstalledBlockers(self, new_pkg, acquire_lock=0):
        blocker_cache = BlockerCache(self._vartree.root, self._vartree.dbapi)
        dep_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
        settings = self._vartree.settings
        stale_cache = set(blocker_cache)
        fake_vartree = self._get_fake_vartree(acquire_lock=acquire_lock)
        dep_check_trees = self._dep_check_trees
        vardb = fake_vartree.dbapi
        installed_pkgs = list(vardb)

        for inst_pkg in installed_pkgs:
            stale_cache.discard(inst_pkg.cpv)
            cached_blockers = blocker_cache.get(inst_pkg.cpv)
            if cached_blockers is not None and \
             cached_blockers.counter != long(inst_pkg.metadata["COUNTER"]):
                cached_blockers = None
            if cached_blockers is not None:
                blocker_atoms = cached_blockers.atoms
            else:
                # Use aux_get() to trigger FakeVartree global
                # updates on *DEPEND when appropriate.
                depstr = " ".join(vardb.aux_get(inst_pkg.cpv, dep_keys))
                success, atoms = portage.dep_check(depstr,
                                                   vardb,
                                                   settings,
                                                   myuse=inst_pkg.use.enabled,
                                                   trees=dep_check_trees,
                                                   myroot=inst_pkg.root)
                if not success:
                    pkg_location = os.path.join(inst_pkg.root,
                                                portage.VDB_PATH,
                                                inst_pkg.category, inst_pkg.pf)
                    portage.writemsg("!!! %s/*DEPEND: %s\n" % \
                     (pkg_location, atoms), noiselevel=-1)
                    continue

                blocker_atoms = [atom for atom in atoms \
                 if atom.startswith("!")]
                blocker_atoms.sort()
                counter = long(inst_pkg.metadata["COUNTER"])
                blocker_cache[inst_pkg.cpv] = \
                 blocker_cache.BlockerData(counter, blocker_atoms)
        for cpv in stale_cache:
            del blocker_cache[cpv]
        blocker_cache.flush()

        blocker_parents = digraph()
        blocker_atoms = []
        for pkg in installed_pkgs:
            for blocker_atom in blocker_cache[pkg.cpv].atoms:
                blocker_atom = blocker_atom.lstrip("!")
                blocker_atoms.append(blocker_atom)
                blocker_parents.add(blocker_atom, pkg)

        blocker_atoms = InternalPackageSet(initial_atoms=blocker_atoms)
        blocking_pkgs = set()
        for atom in blocker_atoms.iterAtomsForPackage(new_pkg):
            blocking_pkgs.update(blocker_parents.parent_nodes(atom))

        # Check for blockers in the other direction.
        depstr = " ".join(new_pkg.metadata[k] for k in dep_keys)
        success, atoms = portage.dep_check(depstr,
                                           vardb,
                                           settings,
                                           myuse=new_pkg.use.enabled,
                                           trees=dep_check_trees,
                                           myroot=new_pkg.root)
        if not success:
            # We should never get this far with invalid deps.
            show_invalid_depstring_notice(new_pkg, depstr, atoms)
            assert False

        blocker_atoms = [atom.lstrip("!") for atom in atoms \
         if atom[:1] == "!"]
        if blocker_atoms:
            blocker_atoms = InternalPackageSet(initial_atoms=blocker_atoms)
            for inst_pkg in installed_pkgs:
                try:
                    next(blocker_atoms.iterAtomsForPackage(inst_pkg))
                except (portage.exception.InvalidDependString, StopIteration):
                    continue
                blocking_pkgs.add(inst_pkg)

        return blocking_pkgs
Beispiel #16
0
	def _check_configuration(self, config, all_conflict_atoms_by_slotatom, conflict_nodes):
		"""
		Given a configuartion, required use changes are computed and checked to
		make sure that no new conflict is introduced. Returns a solution or None.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		#An installed package can only be part of a valid configuration if it has no
		#pending use changed. Otherwise the ebuild will be pulled in again.
		for pkg in config:
			if not pkg.installed:
				continue

			for (atom, root), pkgs \
				in self.slot_collision_info.items():
				if pkg not in pkgs:
					continue
				for other_pkg in pkgs:
					if other_pkg == pkg:
						continue
					if pkg.iuse.all.symmetric_difference(other_pkg.iuse.all) \
						or _pkg_use_enabled(pkg).symmetric_difference(_pkg_use_enabled(other_pkg)):
						if self.debug:
							writemsg(("%s has pending USE changes. "
								"Rejecting configuration.\n") % (pkg,),
								noiselevel=-1)
						return False

		#A list of dicts. Keeps one dict per slot conflict. [ { flag1: "enabled" }, { flag2: "disabled" } ]
		all_involved_flags = []

		#Go through all slot conflicts
		for id, pkg in enumerate(config):
			involved_flags = {}
			for ppkg, atom in all_conflict_atoms_by_slotatom[id]:
				if ppkg in conflict_nodes and not ppkg in config:
					#The parent is part of a slot conflict itself and is
					#not part of the current config.
					continue

				i = InternalPackageSet(initial_atoms=(atom,))
				if i.findAtomForPackage(pkg, modified_use=_pkg_use_enabled(pkg)):
					continue

				i = InternalPackageSet(initial_atoms=(atom.without_use,))
				if not i.findAtomForPackage(pkg, modified_use=_pkg_use_enabled(pkg)):
					#Version range does not match.
					if self.debug:
						writemsg(("%s does not satify all version "
							"requirements. Rejecting configuration.\n") %
							(pkg,), noiselevel=-1)
					return False

				if not pkg.iuse.is_valid_flag(atom.unevaluated_atom.use.required):
					#Missing IUSE.
					#FIXME: This needs to support use dep defaults.
					if self.debug:
						writemsg(("%s misses needed flags from IUSE."
							" Rejecting configuration.\n") % (pkg,),
							noiselevel=-1)
					return False

				if not isinstance(ppkg, Package) or ppkg.installed:
					#We cannot assume that it's possible to reinstall the package. Do not
					#check if some of its atom has use.conditional
					violated_atom = atom.violated_conditionals(_pkg_use_enabled(pkg), \
						pkg.iuse.is_valid_flag)
				else:
					violated_atom = atom.unevaluated_atom.violated_conditionals(_pkg_use_enabled(pkg), \
						pkg.iuse.is_valid_flag, parent_use=_pkg_use_enabled(ppkg))
					if violated_atom.use is None:
						# It's possible for autounmask to change
						# parent_use such that the unevaluated form
						# of the atom now matches, even though the
						# earlier evaluated form (from before
						# autounmask changed parent_use) does not.
						# In this case (see bug #374423), it's
						# expected that violated_atom.use is None.
						continue

				if pkg.installed and (violated_atom.use.enabled or violated_atom.use.disabled):
					#We can't change USE of an installed package (only of an ebuild, but that is already
					#part of the conflict, isn't it?
					if self.debug:
						writemsg(("%s: installed package would need USE"
							" changes. Rejecting configuration.\n") % (pkg,),
							noiselevel=-1)
					return False

				#Compute the required USE changes. A flag can be forced to "enabled" or "disabled",
				#it can be in the conditional state "cond" that allows both values or in the
				#"contradiction" state, which means that some atoms insist on differnt values
				#for this flag and those kill this configuration.
				for flag in violated_atom.use.required:
					state = involved_flags.get(flag, "")
					
					if flag in violated_atom.use.enabled:
						if state in ("", "cond", "enabled"):
							state = "enabled"
						else:
							state = "contradiction"
					elif flag in violated_atom.use.disabled:
						if state in ("", "cond", "disabled"):
							state = "disabled"
						else:
							state = "contradiction"
					else:
						if state == "":
							state = "cond"

					involved_flags[flag] = state

			if pkg.installed:
				#We don't change the installed pkg's USE. Force all involved flags
				#to the same value as the installed package has it.
				for flag in involved_flags:
					if involved_flags[flag] == "enabled":
						if not flag in _pkg_use_enabled(pkg):
							involved_flags[flag] = "contradiction"
					elif involved_flags[flag] == "disabled":
						if flag in _pkg_use_enabled(pkg):
							involved_flags[flag] = "contradiction"
					elif involved_flags[flag] == "cond":
						if flag in _pkg_use_enabled(pkg):
							involved_flags[flag] = "enabled"
						else:
							involved_flags[flag] = "disabled"

			for flag, state in involved_flags.items():
				if state == "contradiction":
					if self.debug:
						writemsg("Contradicting requirements found for flag " + \
							flag + ". Rejecting configuration.\n", noiselevel=-1)
					return False

			all_involved_flags.append(involved_flags)

		if self.debug:
			writemsg("All involved flags:\n", noiselevel=-1)
			for id, involved_flags in enumerate(all_involved_flags):
				writemsg("   %s\n" % (config[id],), noiselevel=-1)
				for flag, state in involved_flags.items():
					writemsg("     " + flag + ": " + state + "\n", noiselevel=-1)

		solutions = []
		sol_gen = _solution_candidate_generator(all_involved_flags)
		checked = 0
		while True:
			candidate = sol_gen.get_candidate()
			if not candidate:
				break
			solution = self._check_solution(config, candidate, all_conflict_atoms_by_slotatom)
			checked += 1
			if solution:
				solutions.append(solution)

			if checked >= self._check_configuration_max:
				# TODO: Implement early elimination for candidates that would
				# change forced or masked flags, and don't count them here.
				if self.debug:
					writemsg("\nAborting _check_configuration due to "
						"excessive number of candidates.\n", noiselevel=-1)
				break

		if self.debug:
			if not solutions:
				writemsg("No viable solutions. Rejecting configuration.\n", noiselevel=-1)
		return solutions
Beispiel #17
0
def format_unmatched_atom(pkg, atom, pkg_use_enabled):
    """
	Returns two strings. The first string contains the
	'atom' with parts of the atom colored, which 'pkg'
	doesn't match. The second string has the same number
	of characters as the first one, but consists of only
	white space or ^. The ^ characters have the same position
	as the colored parts of the first string.
	"""
    # Things to check:
    #	1. Version
    #	2. cp
    #   3. slot/sub_slot
    #	4. repository
    #	5. USE

    if atom.soname:
        return "%s" % (atom, ), ""

    highlight = set()

    def perform_coloring():
        atom_str = ""
        marker_str = ""
        for ii, x in enumerate(atom):
            if ii in highlight:
                atom_str += colorize("BAD", x)
                marker_str += "^"
            else:
                atom_str += x
                marker_str += " "
        return atom_str, marker_str

    if atom.cp != pkg.cp:
        # Highlight the cp part only.
        ii = atom.find(atom.cp)
        highlight.update(range(ii, ii + len(atom.cp)))
        return perform_coloring()

    version_atom = atom.without_repo.without_slot.without_use
    version_atom_set = InternalPackageSet(initial_atoms=(version_atom, ))
    highlight_version = not bool(
        version_atom_set.findAtomForPackage(pkg,
                                            modified_use=pkg_use_enabled(pkg)))

    highlight_slot = False
    if (atom.slot and atom.slot != pkg.slot) or \
     (atom.sub_slot and atom.sub_slot != pkg.sub_slot):
        highlight_slot = True

    if highlight_version:
        op = atom.operator
        ver = None
        if atom.cp != atom.cpv:
            ver = cpv_getversion(atom.cpv)

        if op == "=*":
            op = "="
            ver += "*"

        if op is not None:
            highlight.update(range(len(op)))

        if ver is not None:
            start = atom.rfind(ver)
            end = start + len(ver)
            highlight.update(range(start, end))

    if highlight_slot:
        slot_str = ":" + atom.slot
        if atom.sub_slot:
            slot_str += "/" + atom.sub_slot
        if atom.slot_operator:
            slot_str += atom.slot_operator
        start = atom.find(slot_str)
        end = start + len(slot_str)
        highlight.update(range(start, end))

    highlight_use = set()
    if atom.use:
        use_atom = "%s[%s]" % (atom.cp, str(atom.use))
        use_atom_set = InternalPackageSet(initial_atoms=(use_atom, ))
        if not use_atom_set.findAtomForPackage(pkg, \
         modified_use=pkg_use_enabled(pkg)):
            missing_iuse = pkg.iuse.get_missing_iuse(
                atom.unevaluated_atom.use.required)
            if missing_iuse:
                highlight_use = set(missing_iuse)
            else:
                #Use conditionals not met.
                violated_atom = atom.violated_conditionals(
                    pkg_use_enabled(pkg), pkg.iuse.is_valid_flag)
                if violated_atom.use is not None:
                    highlight_use = set(
                        violated_atom.use.enabled.union(
                            violated_atom.use.disabled))

    if highlight_use:
        ii = atom.find("[") + 1
        for token in atom.use.tokens:
            if token.lstrip("-!").rstrip("=?") in highlight_use:
                highlight.update(range(ii, ii + len(token)))
            ii += len(token) + 1

    return perform_coloring()
Beispiel #18
0
    def __init__(self, repo_settings, myreporoot, config_root, options,
                 vcs_settings, mydir, env):
        '''Class __init__'''
        self.repo_settings = repo_settings
        self.config_root = config_root
        self.options = options
        self.vcs_settings = vcs_settings
        self.env = env

        # Repoman sets it's own ACCEPT_KEYWORDS and we don't want it to
        # behave incrementally.
        self.repoman_incrementals = tuple(x for x in portage.const.INCREMENTALS
                                          if x != 'ACCEPT_KEYWORDS')

        self.categories = []
        for path in self.repo_settings.repo_config.eclass_db.porttrees:
            self.categories.extend(
                portage.util.grabfile(
                    os.path.join(path, 'profiles', 'categories')))
        self.repo_settings.repoman_settings.categories = frozenset(
            portage.util.stack_lists([self.categories], incremental=1))
        self.categories = self.repo_settings.repoman_settings.categories

        self.portdb = repo_settings.portdb
        self.portdb.settings = self.repo_settings.repoman_settings

        digest_only = self.options.mode != 'manifest-check' \
         and self.options.digest == 'y'
        self.generate_manifest = digest_only or self.options.mode in \
         ("manifest", 'commit', 'fix')

        # We really only need to cache the metadata that's necessary for visibility
        # filtering. Anything else can be discarded to reduce memory consumption.
        if not self.generate_manifest:
            # Don't do this when generating manifests, since that uses
            # additional keys if spawn_nofetch is called (RESTRICT and
            # DEFINED_PHASES).
            self.portdb._aux_cache_keys.clear()
            self.portdb._aux_cache_keys.update(
                ["EAPI", "IUSE", "KEYWORDS", "repository", "SLOT"])

        self.reposplit = myreporoot.split(os.path.sep)
        self.repolevel = len(self.reposplit)

        if self.options.mode == 'commit':
            repochecks.commit_check(self.repolevel, self.reposplit)
            repochecks.conflict_check(self.vcs_settings, self.options)

        # Make startdir relative to the canonical repodir, so that we can pass
        # it to digestgen and it won't have to be canonicalized again.
        if self.repolevel == 1:
            startdir = self.repo_settings.repodir
        else:
            startdir = normalize_path(mydir)
            startdir = os.path.join(
                self.repo_settings.repodir,
                *startdir.split(os.sep)[-2 - self.repolevel + 3:])

        # get lists of valid keywords, licenses, and use
        new_data = repo_metadata(self.portdb,
                                 self.repo_settings.repoman_settings)
        kwlist, liclist, uselist, profile_list, \
         global_pmaskdict, liclist_deprecated = new_data
        self.repo_metadata = {
            'kwlist':
            kwlist,
            'liclist':
            liclist,
            'uselist':
            uselist,
            'profile_list':
            profile_list,
            'pmaskdict':
            global_pmaskdict,
            'lic_deprecated':
            liclist_deprecated,
            'package.deprecated':
            InternalPackageSet(
                initial_atoms=portage.util.stack_lists([
                    portage.util.grabfile_package(os.path.join(
                        path, 'profiles', 'package.deprecated'),
                                                  recursive=True)
                    for path in self.portdb.porttrees
                ],
                                                       incremental=True))
        }

        self.repo_settings.repoman_settings['PORTAGE_ARCHLIST'] = ' '.join(
            sorted(kwlist))
        self.repo_settings.repoman_settings.backup_changes('PORTAGE_ARCHLIST')

        profiles = setup_profile(profile_list)

        check_profiles(profiles,
                       self.repo_settings.repoman_settings.archlist())

        scanlist = scan(self.repolevel, self.reposplit, startdir,
                        self.categories, self.repo_settings)

        self.dev_keywords = dev_profile_keywords(profiles)

        self.qatracker = self.vcs_settings.qatracker

        if self.options.echangelog is None and self.repo_settings.repo_config.update_changelog:
            self.options.echangelog = 'y'

        if self.vcs_settings.vcs is None:
            self.options.echangelog = 'n'

        # Initialize the ModuleConfig class here
        # TODO Add layout.conf masters repository.yml config to the list to load/stack
        self.moduleconfig = ModuleConfig(
            self.repo_settings.masters_list,
            self.repo_settings.repoman_settings.valid_versions,
            repository_modules=self.options.experimental_repository_modules ==
            'y')

        checks = {}
        # The --echangelog option causes automatic ChangeLog generation,
        # which invalidates changelog.ebuildadded and changelog.missing
        # checks.
        # Note: Some don't use ChangeLogs in distributed SCMs.
        # It will be generated on server side from scm log,
        # before package moves to the rsync server.
        # This is needed because they try to avoid merge collisions.
        # Gentoo's Council decided to always use the ChangeLog file.
        # TODO: shouldn't this just be switched on the repo, iso the VCS?
        is_echangelog_enabled = self.options.echangelog in ('y', 'force')
        self.vcs_settings.vcs_is_cvs_or_svn = self.vcs_settings.vcs in ('cvs',
                                                                        'svn')
        checks[
            'changelog'] = not is_echangelog_enabled and self.vcs_settings.vcs_is_cvs_or_svn

        if self.options.mode == "manifest" or self.options.quiet:
            pass
        elif self.options.pretend:
            print(green("\nRepoMan does a once-over of the neighborhood..."))
        else:
            print(green("\nRepoMan scours the neighborhood..."))

        self.changed = self.vcs_settings.changes
        # bypass unneeded VCS operations if not needed
        if (self.options.if_modified == "y"
                or self.options.mode not in ("manifest", "manifest-check")):
            self.changed.scan()

        self.have = {
            'pmasked': False,
            'dev_keywords': False,
        }

        # NOTE: match-all caches are not shared due to potential
        # differences between profiles in _get_implicit_iuse.
        self.caches = {
            'arch': {},
            'arch_xmatch': {},
            'shared_xmatch': {
                "cp-list": {}
            },
        }

        self.include_arches = None
        if self.options.include_arches:
            self.include_arches = set()
            self.include_arches.update(
                *[x.split() for x in self.options.include_arches])
        self.include_profiles = None
        if self.options.include_profiles:
            self.include_profiles = set()
            self.include_profiles.update(
                *[x.split() for x in self.options.include_profiles])

        # Disable the "self.modules['Ebuild'].notadded" check when not in commit mode and
        # running `svn status` in every package dir will be too expensive.
        checks['ebuild_notadded'] = not \
         (self.vcs_settings.vcs == "svn" and self.repolevel < 3 and self.options.mode != "commit")

        self.effective_scanlist = scanlist
        if self.options.if_modified == "y":
            self.effective_scanlist = sorted(
                vcs_files_to_cps(
                    chain(self.changed.changed, self.changed.new,
                          self.changed.removed), self.repo_settings.repodir,
                    self.repolevel, self.reposplit, self.categories))

        # Create our kwargs dict here to initialize the plugins with
        self.kwargs = {
            "repo_settings": self.repo_settings,
            "portdb": self.portdb,
            "qatracker": self.qatracker,
            "vcs_settings": self.vcs_settings,
            "options": self.options,
            "metadata_xsd": get_metadata_xsd(self.repo_settings),
            "uselist": uselist,
            "checks": checks,
            "repo_metadata": self.repo_metadata,
            "profiles": profiles,
            "include_arches": self.include_arches,
            "include_profiles": self.include_profiles,
            "caches": self.caches,
            "repoman_incrementals": self.repoman_incrementals,
            "env": self.env,
            "have": self.have,
            "dev_keywords": self.dev_keywords,
            "linechecks": self.moduleconfig.linechecks,
        }
        # initialize the plugin checks here
        self.modules = {}
        self._ext_futures = {}
        self.pkg_level_futures = None
    def testInternalPackageSet(self):
        i1_atoms = set(("dev-libs/A", ">=dev-libs/A-1", "dev-libs/B"))
        i2_atoms = set(("dev-libs/A", "dev-libs/*", "dev-libs/C"))

        i1 = InternalPackageSet(initial_atoms=i1_atoms)
        i2 = InternalPackageSet(initial_atoms=i2_atoms, allow_wildcard=True)
        self.assertRaises(InvalidAtom,
                          InternalPackageSet,
                          initial_atoms=i2_atoms)

        self.assertEqual(i1.getAtoms(), i1_atoms)
        self.assertEqual(i2.getAtoms(), i2_atoms)

        new_atom = Atom("*/*", allow_wildcard=True)
        self.assertRaises(InvalidAtom, i1.add, new_atom)
        i2.add(new_atom)

        i2_atoms.add(new_atom)

        self.assertEqual(i1.getAtoms(), i1_atoms)
        self.assertEqual(i2.getAtoms(), i2_atoms)

        removed_atom = Atom("dev-libs/A")

        i1.remove(removed_atom)
        i2.remove(removed_atom)

        i1_atoms.remove(removed_atom)
        i2_atoms.remove(removed_atom)

        self.assertEqual(i1.getAtoms(), i1_atoms)
        self.assertEqual(i2.getAtoms(), i2_atoms)

        update_atoms = [
            Atom("dev-libs/C"),
            Atom("dev-*/C", allow_wildcard=True)
        ]

        self.assertRaises(InvalidAtom, i1.update, update_atoms)
        i2.update(update_atoms)

        i2_atoms.update(update_atoms)

        self.assertEqual(i1.getAtoms(), i1_atoms)
        self.assertEqual(i2.getAtoms(), i2_atoms)

        replace_atoms = [
            Atom("dev-libs/D"),
            Atom("*-libs/C", allow_wildcard=True)
        ]

        self.assertRaises(InvalidAtom, i1.replace, replace_atoms)
        i2.replace(replace_atoms)

        i2_atoms = set(replace_atoms)

        self.assertEqual(i2.getAtoms(), i2_atoms)