Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 115203 | Differences between
and this patch

Collapse All | Expand All

(-)src/equery/equery.orig (-2 / +162 lines)
Lines 19-24 Link Here
19
import time
19
import time
20
import string
20
import string
21
import types
21
import types
22
import bz2
22
23
23
# portage (output module) and gentoolkit need special path modifications
24
# portage (output module) and gentoolkit need special path modifications
24
sys.path.insert(0, "/usr/lib/portage/pym")
25
sys.path.insert(0, "/usr/lib/portage/pym")
Lines 1574-1579 Link Here
1574
			   "  " + pp.localoption("-p, --portage-tree") + "	  - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
1575
			   "  " + pp.localoption("-p, --portage-tree") + "	  - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
1575
			   "  " + pp.localoption("-o, --overlay-tree") + "	  - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n"
1576
			   "  " + pp.localoption("-o, --overlay-tree") + "	  - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n"
1576
1577
1578
class CmdShowGccInfo(Command):
1579
	"""Show informations about compiler and flags used to compile a package."""
1580
	
1581
	__installedGccSlots = None
1582
1583
	def __init__(self):
1584
		self.default_opts = {
1585
			"allInstalledPackages": 0,
1586
			}
1587
		self.__installedGccSlots = []
1588
		expr = re.compile("^gcc-[0-9]")
1589
		for n in os.listdir(os.path.join(portage.root, portage.VDB_PATH, "sys-devel")):
1590
			if expr.match(n):
1591
				self.__installedGccSlots.append(n)
1592
		self.__installedGccSlots.sort()
1593
		for n in range(len(self.__installedGccSlots)):
1594
			self.__installedGccSlots[n] = open(os.path.join(portage.root, portage.VDB_PATH, "sys-devel", self.__installedGccSlots[n], "SLOT"), "r").read()
1595
			if self.__installedGccSlots[n][-1] == "\n":
1596
				self.__installedGccSlots[n] = self.__installedGccSlots[n][:-1]
1597
		self.__installedGccSlots.sort()
1598
1599
	def shortHelp(self):
1600
		return pp.localoption("<local-opts>") + " - display the gcc version used to compile a package"
1601
	
1602
	def longHelp(self):
1603
		return "Display the gcc version used to compile a package\n" + \
1604
			   "\n" + \
1605
			   "Syntax:\n" + \
1606
			   "  " + pp.command("gcc") + pp.localoption(" <local-opts> ") + "\n" + \
1607
			   "  " + pp.command("gcc") + pp.pkgquery(" pkgspec") + "\n" + \
1608
			   pp.localoption("<local-opts>") + " is either of: \n" + \
1609
			   "  " + pp.localoption("-A, --all") + " - scan all installed packages\n"
1610
1611
	def parseArgs(self, args):
1612
1613
		query = ""
1614
		need_help = 0
1615
		opts = self.default_opts
1616
		skip = 0
1617
		
1618
		if len(args) == 0:
1619
			need_help = 1
1620
		
1621
		for i in xrange(len(args)):
1622
1623
			if skip:
1624
				skip -= 1
1625
				continue
1626
			x = args[i]
1627
			
1628
			if x in ["-h","--help"]:
1629
				need_help = 1
1630
				break
1631
			elif x in ["-A", "--all"]:
1632
				opts["allInstalledPackages"] = 1
1633
			else:
1634
				query = x
1635
1636
		if need_help:
1637
			print_info(0, self.longHelp())
1638
			sys.exit(-1)
1639
			
1640
		return (query, opts)
1641
1642
	def perform(self, args):
1643
		(query, opts) = self.parseArgs(args)
1644
		if opts["allInstalledPackages"]:
1645
			# search for information about ALL installed packages
1646
			print_info(0, "[ Searching for gcc used for " + pp.pkgquery("all packages") + "... ]")
1647
			result = self.__scanVDB()
1648
			print_info(0, "  Last installed gcc slot:                         " + pp.number(self.__installedGccSlots[-1]) )
1649
			print_info(0, "  Packages installed:                              " + pp.number( str(result["NUM_COMPILED_WITH_LATEST_VERSION"] + len(result["COMPILED_WITH_OLD_VERSION"])) ) )
1650
			print_info(0, "  Packages compiled with a gcc of an old slot:     " + portage.output.yellow( str(len( result["COMPILED_WITH_OLD_VERSION"])) ) )
1651
			if len(result["COMPILED_WITH_OLD_VERSION"]) != 0:
1652
				print_info(0, string.rjust("[SLOT]", 13) + string.rjust("[VERSION]", 13))
1653
				for p in result["COMPILED_WITH_OLD_VERSION"]:
1654
					print_info(0,string.rjust("[" + pp.number(p[p.keys()[0]]["SLOT"]) +"]", 32) + string.rjust("[" + pp.number(p[p.keys()[0]]["VERSION"]) + "]", 32) + ' ' + pp.cpv(p.keys()[0]))
1655
		else:
1656
			# search for the given package and print the result
1657
			print_info(0, "[ Searching for packages matching " + pp.pkgquery(query + " ") + "... ]")
1658
			gccVersion = self.__getGccVersion(query)
1659
			for pkg in gccVersion:
1660
				print_info(0, "")
1661
				print_info(0, pp.section("*") + " gcc version used for " + pp.cpv(pkg))
1662
				sortedKeys = gccVersion[pkg].keys()[:]
1663
				sortedKeys.sort()
1664
				for k in sortedKeys:
1665
					print_info(0, string.rjust(k + " : ", 16) + pp.number(gccVersion[pkg][k]))
1666
1667
	# search for gcc compiler version and C/C++ flags used to compile the package given as parameter
1668
	def __getGccVersion(self, pkg):
1669
		pkg_split = gentoolkit.split_package_name(pkg)
1670
		if pkg_split[2] != "":     # if a specific version is given
1671
			if pkg_split[0] != "":     # if the category of the package is given
1672
				if pkg_split[0][0] != "=":     # if the category is not preceded by an "="
1673
					found = gentoolkit.find_installed_packages("=" + pkg)     # add the "="
1674
				else:
1675
					found = gentoolkit.find_installed_packages(pkg)
1676
			else:     # the category is not given, so we check for the "=" on the package name
1677
				if pkg_split[1][0] != "=":     # if the name is not preceded by an "="
1678
					found = gentoolkit.find_installed_packages("=" + pkg)     # add the "="
1679
				else:
1680
					found = gentoolkit.find_installed_packages(pkg)
1681
		else:     # search for all version for the given package
1682
			found = gentoolkit.find_installed_packages(pkg)
1683
		# exit if no package has been found
1684
		if len(found) == 0:
1685
			print_error("Package not found")
1686
			sys.exit(1)
1687
		else:
1688
			retval = {}
1689
			# search for compiler infos about every selected package
1690
			for p in gentoolkit.sort_package_list(found):
1691
				basePath = os.path.join( portage.root, portage.VDB_PATH, p.get_category(), p.get_name() + '-' + p.get_version() )
1692
				# set the initial retval in case we can't find the compiler version used (probably this never happens...)
1693
				retval[p.get_cpv()] = { "VERSION" : portage.output.red("!!! ") + "unknown", "SLOT" : portage.output.red("!!! ") + "unknown" }
1694
				# match the line containing the PATH variable declaration
1695
				matchedString = re.search( "^PATH=\"?.*?\"?\n", bz2.BZ2File( os.path.join( basePath, "environment.bz2" )).read(), re.M ).group()[:]
1696
				# remove the \n character, if found
1697
				if matchedString[-1] == "\n":
1698
					matchedString = matchedString[:-1]
1699
				# match the compiler version in the string matched before
1700
				for x in matchedString.split(":"):
1701
					tmp = re.search("gcc-bin", x)
1702
					if tmp != None:
1703
						matchedString = tmp
1704
				# save the version
1705
				retval[p.get_cpv()]["VERSION"] = matchedString.string.split("gcc-bin")[1][1:]
1706
				tmp = retval[p.get_cpv()]["VERSION"].split(".")
1707
				# save the slot
1708
				retval[p.get_cpv()]["SLOT"] = tmp[0] + "." + tmp[1]
1709
				# save compiler flags, if stored in vdb
1710
				for f in [ "CHOST" , "CC", "CFLAGS", "CXX", "CXXFLAGS" ]:
1711
					if os.access( os.path.join( basePath, f ) , os.R_OK):
1712
						retval[p.get_cpv()][f] = open(os.path.join( basePath, f )).read()
1713
						if retval[p.get_cpv()][f][-1] == "\n":
1714
							retval[p.get_cpv()][f] = retval[p.get_cpv()][f][:-1]
1715
			return retval
1716
				
1717
	# scan vdb searching for gcc version about every installed package
1718
	def __scanVDB(self):
1719
		numCompiledWithLastVersion = 0
1720
		compiledWithAnOldVersion = []
1721
		categoriesList = os.listdir( os.path.join( portage.root, portage.VDB_PATH ) )
1722
		categoriesList.sort()
1723
		for category in categoriesList:
1724
			packagesList = os.listdir( os.path.join( portage.root, portage.VDB_PATH, category ) )
1725
			packagesList.sort()
1726
			for package in packagesList:
1727
				pkgGccVersion = self.__getGccVersion(os.path.join( category, package ))
1728
				if pkgGccVersion[os.path.join( category, package )]["SLOT"] == self.__installedGccSlots[-1]:
1729
					numCompiledWithLastVersion += 1
1730
				else:
1731
					compiledWithAnOldVersion.append(pkgGccVersion)
1732
		return { "NUM_COMPILED_WITH_LATEST_VERSION" : numCompiledWithLastVersion, "COMPILED_WITH_OLD_VERSION" : compiledWithAnOldVersion }
1733
1734
1577
#
1735
#
1578
# Command line tokens to commands mapping
1736
# Command line tokens to commands mapping
1579
#
1737
#
Lines 1591-1597 Link Here
1591
	"check" : CmdCheckIntegrity(),
1749
	"check" : CmdCheckIntegrity(),
1592
	"stats" : CmdDisplayStatistics(),
1750
	"stats" : CmdDisplayStatistics(),
1593
	"glsa" : CmdListGLSAs(),
1751
	"glsa" : CmdListGLSAs(),
1594
	"which": CmdWhich()
1752
	"which": CmdWhich(),
1753
	"gcc" : CmdShowGccInfo()
1595
	}
1754
	}
1596
1755
1597
# Short command line tokens
1756
# Short command line tokens
Lines 1609-1615 Link Here
1609
	"s" : "size",
1768
	"s" : "size",
1610
	"t" : "stats",
1769
	"t" : "stats",
1611
	"u" : "uses",
1770
	"u" : "uses",
1612
	"w" : "which"
1771
	"w" : "which",
1772
	"v" : "gcc"
1613
}
1773
}
1614
1774
1615
from gentoolkit import Config
1775
from gentoolkit import Config

Return to bug 115203