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 / +182 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 1478-1483 Link Here
1478
			   "  " + pp.localoption("-p, --portage-tree") + "	  - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
1479
			   "  " + pp.localoption("-p, --portage-tree") + "	  - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
1479
			   "  " + pp.localoption("-o, --overlay-tree") + "	  - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n"
1480
			   "  " + pp.localoption("-o, --overlay-tree") + "	  - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n"
1480
1481
1482
class CmdDisplayGccInfo(Command):
1483
	"""Display info about compiler and flags used to compile a package."""
1484
	
1485
	def __init__(self):
1486
		self.default_opts = {
1487
			"allInstalledPackages": 0,
1488
			}
1489
1490
	def shortHelp(self):
1491
		return pp.localoption("<local-opts>") + " - display the gcc version used to compile a package"
1492
	
1493
	def longHelp(self):
1494
		return "Display th gcc version used to compile a particular a package\n" + \
1495
			   "\n" + \
1496
			   "Syntax:\n" + \
1497
			   "  " + pp.command("gcc") + pp.localoption(" <local-opts> ") + "\n" + \
1498
			   "  " + pp.command("gcc") + pp.pkgquery(" pkgspec") + "\n" + \
1499
			   pp.localoption("<local-opts>") + " is either of: \n" + \
1500
			   "  " + pp.localoption("-A, --all") + " - scan all installed packages\n"
1501
1502
	def parseArgs(self, args):
1503
1504
		query = ""
1505
		need_help = 0
1506
		opts = self.default_opts
1507
		skip = 0
1508
		
1509
		if len(args)==0:
1510
			need_help=1
1511
		
1512
		for i in xrange(len(args)):
1513
1514
			if skip:
1515
				skip -= 1
1516
				continue
1517
			x = args[i]
1518
			
1519
			if x in ["-h","--help"]:
1520
				need_help = 1
1521
				break
1522
			elif x in ["-A", "--all"]:
1523
				opts["allInstalledPackages"] = 1
1524
			#elif len(args)==0:
1525
				
1526
			else:
1527
				query = x
1528
1529
		if need_help:
1530
			print_info(0, self.longHelp())
1531
			sys.exit(-1)
1532
			
1533
		return (query, opts)
1534
1535
	def perform(self, args):
1536
		(query, opts)=self.parseArgs(args)
1537
		if opts["allInstalledPackages"]:
1538
			print_info(0,"[ Searching for gcc used for "+pp.pkgquery("all packages")+"... ]")
1539
			all=self._scanDb()
1540
			print_info(0,"  Last installed gcc slot:                         "+pp.number(all[0]))
1541
			print_info(0,"  Packages installed:                              "+pp.number(all[1]))
1542
			print_info(0,"  Packages compiled with a gcc of an old slot:     "+portage.output.yellow(all[3]))
1543
			if len(all[4])!=0:
1544
				print_info(0,string.rjust("[SLOT]",13)+string.rjust("[VERSION]",13))
1545
				for p in all[4]:
1546
					print_info(0,string.rjust("["+pp.number((p[0]))+"]",32)+string.rjust("["+pp.number((p[1]))+"]",32)+' '+pp.cpv(p[2]))
1547
			
1548
		else:
1549
			print_info(0,"[ Searching for packages matching "+pp.pkgquery(query+" ")+"... ]")
1550
			retval=self._getGccInfo(query)
1551
			for pkg in retval:
1552
				print_info(0,"")
1553
				print_info(0,pp.section("*")+" gcc version used for "+pp.cpv(pkg["CPV"]))
1554
				print_info(0,string.rjust("host: ",16)+pp.number(pkg["CHOST"]))
1555
				print_info(0,string.rjust("C compiler: ",16)+pp.number(pkg["CC"]))
1556
				print_info(0,string.rjust("C++ compiler: ",16)+pp.number(pkg["CXX"]))
1557
				print_info(0,string.rjust("version: ",16)+pp.number(pkg["COMPILER"]["VERSION"]))
1558
				print_info(0,string.rjust("slot: ",16)+pp.number(pkg["COMPILER"]["SLOT"]))
1559
				print_info(0,string.rjust("C flags: ",16)+pp.number(pkg["CFLAGS"]))
1560
				print_info(0,string.rjust("C++ flags: ",16)+pp.number(pkg["CXXFLAGS"]))
1561
1562
	def _gccInstalledSlots(self):
1563
		slots=[]
1564
		expr=re.compile("^gcc-[0-9]")
1565
		for n in os.listdir(portage.root+portage.VDB_PATH+os.sep+"sys-devel"):
1566
			if expr.match(n):
1567
				slots.append(n)
1568
		slots.sort()
1569
		for n in slots:
1570
			slots[slots.index(n)]=open(portage.root+portage.VDB_PATH+os.sep+"sys-devel"+os.sep+n+os.sep+"SLOT", "r").read()[:-1]
1571
		return slots
1572
1573
	def _getGccInfo(self,pkg):
1574
		pkg_split=gentoolkit.split_package_name(pkg)
1575
		if pkg_split[2]!="":     # if a specific version is given
1576
			if pkg_split[0]!="":     # if the category of the package is given
1577
				if pkg_split[0][0]!="=":     # if the category is not preceded by an "="
1578
					found=gentoolkit.find_installed_packages("="+pkg)     # add the "="
1579
				else:
1580
					found=gentoolkit.find_installed_packages(pkg)
1581
			else:     # the category is not given, so we check for the "=" on the package name
1582
				if pkg_split[1][0]!="=":     # if the name is not preceded by an "="
1583
					found=gentoolkit.find_installed_packages("="+pkg)     # add the "="
1584
				else:
1585
					found=gentoolkit.find_installed_packages(pkg)
1586
		else:     # search for all version for the given package
1587
			found=gentoolkit.find_installed_packages(pkg)
1588
		if len(found)==0:
1589
			print_error("Package not found")
1590
			sys.exit(1)
1591
		else:
1592
			retval=[]
1593
			for i in gentoolkit.sort_package_list(found):
1594
				compiler={"VERSION":portage.output.red("!!! ")+"unknown", "SLOT":portage.output.red("!!! ")+"unknown"}
1595
				env=bz2.BZ2File(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"environment.bz2")
1596
				expr=re.compile("^PATH=")
1597
				for l in env.readlines():
1598
					if expr.match(l)!=None:
1599
						break
1600
				l=string.split(string.split(l, "=")[1], ":")
1601
				expr=re.compile(i.get_env_var("CHOST"))
1602
				for v in l:
1603
					m=expr.search(v)
1604
					if m!=None:
1605
						break
1606
				if m==None:
1607
					retval.append({"CPV":i.get_cpv(),"COMPILER":compiler})
1608
				else:
1609
					v=string.split(v, os.sep)
1610
					v=v[len(v)-1]
1611
					if v[-1]=='\n':
1612
						compiler["VERSION"]=v[:-1]
1613
					else:
1614
						compiler["VERSION"]=v
1615
					for s in self._gccInstalledSlots():
1616
						expr=re.compile(s)
1617
						if expr.match(v):
1618
							break
1619
					compiler["SLOT"]=s
1620
				f=open(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"CHOST")
1621
				chost=f.readline()[:-1]
1622
				f=open(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"CFLAGS")
1623
				cflags=f.readline()[:-1]
1624
				f=open(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"CXXFLAGS")
1625
				cxxflags=f.readline()[:-1]
1626
				f=open(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"CC")
1627
				cc=f.readline()[:-1]
1628
				f=open(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"CXX")
1629
				cxx=f.readline()[:-1]
1630
				retval.append({"CPV":i.get_cpv(),"COMPILER":compiler,"CHOST":chost,"CFLAGS":cflags,"CXXFLAGS":cxxflags,"CC":cc,"CXX":cxx})
1631
			return retval
1632
1633
	def _scanDb(self):
1634
		slots=self._gccInstalledSlots()
1635
		last_slot=slots[-1]
1636
		num_pkg=0
1637
		num_last=0
1638
		old=[]
1639
		l1=os.listdir(portage.root+portage.VDB_PATH)
1640
		l1.sort()
1641
		for i in l1:
1642
			l2=os.listdir(portage.root+portage.VDB_PATH+os.sep+i)
1643
			l2.sort()
1644
			for j in l2:
1645
				pkg=i+os.sep+j
1646
				pkg_gcc=self._getGccInfo(pkg)
1647
				num_pkg+=1
1648
				if pkg_gcc[0]["COMPILER"]["SLOT"]==last_slot:
1649
					num_last+=1
1650
				else:
1651
					old.append(pkg)
1652
		l=[]
1653
		for p in old:
1654
			v=self._getGccInfo(p)
1655
			l.append([v["COMPILER"]["SLOT"],v["COMPILER"]["VERSION"],p])
1656
		return [str(last_slot),str(num_pkg),str(num_last),str(num_pkg-num_last),l]
1657
1658
1481
#
1659
#
1482
# Command line tokens to commands mapping
1660
# Command line tokens to commands mapping
1483
#
1661
#
Lines 1495-1501 Link Here
1495
	"check" : CmdCheckIntegrity(),
1671
	"check" : CmdCheckIntegrity(),
1496
	"stats" : CmdDisplayStatistics(),
1672
	"stats" : CmdDisplayStatistics(),
1497
	"glsa" : CmdListGLSAs(),
1673
	"glsa" : CmdListGLSAs(),
1498
	"which": CmdWhich()
1674
	"which": CmdWhich(),
1675
	"gcc" : CmdDisplayGccInfo()
1499
	}
1676
	}
1500
1677
1501
# Short command line tokens
1678
# Short command line tokens
Lines 1513-1519 Link Here
1513
	"s" : "size",
1690
	"s" : "size",
1514
	"t" : "stats",
1691
	"t" : "stats",
1515
	"u" : "uses",
1692
	"u" : "uses",
1516
	"w" : "which"
1693
	"w" : "which",
1694
	"o" : "gcc"
1517
}
1695
}
1518
1696
1519
from gentoolkit import Config
1697
from gentoolkit import Config

Return to bug 115203