... | ... |
@@ -112,7 +112,7 @@ class ChrootUtils(object): |
112 | 112 |
self.logger.error("Unable to destroy chroot:"+ chrootID +".Unknown error.") |
113 | 113 |
return False |
114 | 114 |
cmdUtils=CommandUtils() |
115 |
- cmdUtils.run_command("rm -rf "+chrootID) |
|
115 |
+ cmdUtils.runCommandInShell("rm -rf "+chrootID) |
|
116 | 116 |
ChrootUtils.lockForTrackingChroots.acquire() |
117 | 117 |
ChrootUtils.lockForTrackingChroots.release() |
118 | 118 |
self.logger.info("Successfully destroyed chroot:"+chrootID) |
... | ... |
@@ -1,29 +1,21 @@ |
1 | 1 |
import subprocess |
2 | 2 |
import os |
3 |
-import re |
|
4 | 3 |
|
5 | 4 |
class CommandUtils(object): |
6 | 5 |
def __init__(self): |
7 |
- self.rpmbuild_binary = "rpmbuild" |
|
8 |
- self.rpmbuild_buildall_option = "-ba" |
|
9 |
- self.rpmbuild_nocheck_option = "--nocheck" |
|
10 |
- self.rpm_binary = "rpm" |
|
11 |
- self.install_rpm_package_options = "-Uvh" |
|
12 |
- self.nodeps_rpm_package_options = "--nodeps" |
|
13 |
- self.query_rpm_package_options = "-qa" |
|
14 |
- self.force_rpm_package_options = "--force" |
|
15 |
- self.find_command = "find" |
|
6 |
+ self.findBinary = "find" |
|
16 | 7 |
|
17 |
- |
|
18 |
- def find_file (self, filename, sourcePath): |
|
19 |
- process = subprocess.Popen([self.find_command, sourcePath, "-name", filename], stdout=subprocess.PIPE) |
|
8 |
+ def findFile (self, filename, sourcePath): |
|
9 |
+ process = subprocess.Popen([self.findBinary, sourcePath, "-name", filename], stdout=subprocess.PIPE) |
|
20 | 10 |
returnVal = process.wait() |
11 |
+ if returnVal != 0: |
|
12 |
+ return None |
|
21 | 13 |
result=process.communicate()[0] |
22 | 14 |
if result is None: |
23 | 15 |
return None |
24 | 16 |
return result.split() |
25 | 17 |
|
26 |
- def run_command(self,cmd,logfilePath=None,chrootCmd=None): |
|
18 |
+ def runCommandInShell(self,cmd,logfilePath=None,chrootCmd=None): |
|
27 | 19 |
if chrootCmd is not None: |
28 | 20 |
cmd = chrootCmd+" "+cmd |
29 | 21 |
if logfilePath is None: |
... | ... |
@@ -35,59 +27,16 @@ class CommandUtils(object): |
35 | 35 |
if retval==0: |
36 | 36 |
return True |
37 | 37 |
return False |
38 |
- |
|
39 |
- def find_installed_rpm_packages(self, chrootCmd=None): |
|
40 |
- cmd = self.rpm_binary+" "+self.query_rpm_package_options |
|
38 |
+ |
|
39 |
+ def runCommandInShell2(self,cmd,chrootCmd=None): |
|
41 | 40 |
if chrootCmd is not None: |
42 | 41 |
cmd = chrootCmd+" "+cmd |
43 |
- #process may hang if buffer is full |
|
44 | 42 |
process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE) |
45 | 43 |
retval = process.wait() |
44 |
+ if retval != 0: |
|
45 |
+ return None |
|
46 | 46 |
result = process.communicate()[0] |
47 |
+ if result is None: |
|
48 |
+ return None |
|
47 | 49 |
return result.split() |
48 | 50 |
|
49 |
- def installRPM(self, rpmfilepath,logfilePath, chrootCmd=None, withNodeps=False): |
|
50 |
- print "Installing RPM...",rpmfilepath |
|
51 |
- rpmInstallcmd=self.rpm_binary+" "+ self.install_rpm_package_options |
|
52 |
- |
|
53 |
- if withNodeps: |
|
54 |
- rpmInstallcmd+=" "+self.nodeps_rpm_package_options |
|
55 |
- |
|
56 |
- rpmInstallcmd+=" "+rpmfilepath |
|
57 |
- if chrootCmd is not None: |
|
58 |
- rpmInstallcmd= chrootCmd +" "+rpmInstallcmd |
|
59 |
- logfile=open(logfilePath,'w') |
|
60 |
- process = subprocess.Popen("%s" %rpmInstallcmd,shell=True,stdout=logfile,stderr=logfile) |
|
61 |
- retval = process.wait() |
|
62 |
- logfile.close() |
|
63 |
- if retval != 0: |
|
64 |
- return False |
|
65 |
- return True |
|
66 |
- |
|
67 |
- def buildRPM(self, specfilepath, logfilePath, chrootCmd=None): |
|
68 |
- print "Building RPM...",specfilepath |
|
69 |
- rpmBuildcmd= self.rpmbuild_binary+" "+self.rpmbuild_buildall_option+" "+self.rpmbuild_nocheck_option |
|
70 |
- rpmBuildcmd+=" "+specfilepath |
|
71 |
- if chrootCmd is not None: |
|
72 |
- rpmBuildcmd=chrootCmd +" "+rpmBuildcmd |
|
73 |
- |
|
74 |
- logfile=open(logfilePath,'w') |
|
75 |
- process = subprocess.Popen("%s" %rpmBuildcmd,shell=True,stdout=logfile,stderr=logfile) |
|
76 |
- retval = process.wait() |
|
77 |
- logfile.close() |
|
78 |
- if retval != 0: |
|
79 |
- print "Building rpm is failed" |
|
80 |
- return False, None |
|
81 |
- |
|
82 |
- #Extracting rpms created from log file |
|
83 |
- logfile=open(logfilePath,'r') |
|
84 |
- fileContents=logfile.readlines() |
|
85 |
- logfile.close() |
|
86 |
- listRpms=[] |
|
87 |
- for i in range(0,len(fileContents)): |
|
88 |
- if re.search("^Wrote:",fileContents[i]): |
|
89 |
- listcontents=fileContents[i].split() |
|
90 |
- if (len(listcontents) == 2) and listcontents[1].strip()[-4:] == ".rpm" and listcontents[1].find("/RPMS/") != -1: |
|
91 |
- listRpms.append(listcontents[1]) |
|
92 |
- |
|
93 |
- return True, listRpms |
|
94 | 51 |
\ No newline at end of file |
... | ... |
@@ -32,5 +32,5 @@ class MiscUtils(object): |
32 | 32 |
|
33 | 33 |
if __name__=="__main__": |
34 | 34 |
listInputFiles=["SpecParser.py","Logger.py"] |
35 |
- listOutputFiles=["Main.py"] |
|
35 |
+ listOutputFiles=["builder.py"] |
|
36 | 36 |
print MiscUtils.isOutdated(listInputFiles, listOutputFiles) |
37 | 37 |
\ No newline at end of file |
... | ... |
@@ -3,7 +3,15 @@ from constants import constants |
3 | 3 |
from sets import Set |
4 | 4 |
import copy |
5 | 5 |
|
6 |
- |
|
6 |
+ |
|
7 |
+ |
|
8 |
+def removeDuplicateEntriesInList(myList): |
|
9 |
+ myListCopy=[] |
|
10 |
+ for p in myList: |
|
11 |
+ if p not in myListCopy: |
|
12 |
+ myListCopy.append(p) |
|
13 |
+ return myListCopy |
|
14 |
+ |
|
7 | 15 |
class PackageBuildDataGenerator(object): |
8 | 16 |
|
9 | 17 |
cycleCount=0 |
... | ... |
@@ -24,154 +32,129 @@ class PackageBuildDataGenerator(object): |
24 | 24 |
self.__sortedBuildDependencyGraph={} |
25 | 25 |
|
26 | 26 |
def getPackageBuildData(self,listPackages): |
27 |
- if not self.__readDependencyGraphAndCyclesForGivenPackages(listPackages): |
|
28 |
- return False,None,None,None |
|
29 |
- |
|
30 |
- self.logger.info("sorted build order") |
|
31 |
- self.logger.info(self.__sortedBuildDependencyGraph) |
|
32 |
- #self.logger.info("Map cycles to package list") |
|
33 |
- #self.logger.info(self.__mapCyclesToPackageList) |
|
27 |
+ self.__readDependencyGraphAndCyclesForGivenPackages(listPackages) |
|
28 |
+ self.__getSortedBuildOrderListForGivenPackages(listPackages) |
|
29 |
+ return self.__mapCyclesToPackageList, self.__mapPackageToCycle, self.__sortedPackageList |
|
34 | 30 |
|
35 |
- if not self.__getSortedBuildOrderListForGivenPackages(listPackages): |
|
36 |
- return False,None,None,None |
|
31 |
+ #todo |
|
32 |
+ def findCompleteListOfPackagesRequiredToBuildGivenPackages(self,listPackages): |
|
33 |
+ return self.__buildDependencyGraph.keys() |
|
34 |
+ |
|
35 |
+ def createSortListForPkg(self,pkg): |
|
36 |
+ runTimeDepPkgList=self.__runTimeDependencyGraph[pkg] |
|
37 |
+ runTimeDepPkgList.append(pkg) |
|
38 |
+ sortListForPkg=[] |
|
37 | 39 |
|
38 |
- return True,self.__mapCyclesToPackageList,self.__mapPackageToCycle,self.__sortedPackageList |
|
40 |
+ for p in runTimeDepPkgList: |
|
41 |
+ basePkg=constants.specData.getSpecName(p) |
|
42 |
+ for bPkg in self.__sortedBuildDependencyGraph[basePkg]: |
|
43 |
+ if bPkg not in sortListForPkg: |
|
44 |
+ sortListForPkg.append(bPkg) |
|
39 | 45 |
|
46 |
+ return sortListForPkg |
|
47 |
+ |
|
48 |
+ def getCircularDependentPackages(self,pkg): |
|
49 |
+ circularDependentPackages=[] |
|
50 |
+ if self.__mapPackageToCycle.has_key(pkg): |
|
51 |
+ circularDependentPackages.extend(self.__mapCyclesToPackageList[self.__mapPackageToCycle[pkg]]) |
|
52 |
+ circularDependentPackages.remove(pkg) |
|
53 |
+ return circularDependentPackages |
|
54 |
+ |
|
40 | 55 |
def __getSortedBuildOrderListForGivenPackages(self,listPackages): |
41 |
- #should not include toolchain packages |
|
42 | 56 |
|
43 | 57 |
alreadyProcessedPackages=[] |
44 |
- sList=[] |
|
45 |
- listPackagesCopy=self.__buildDependencyGraph.keys()#listPackages[:] |
|
46 |
- sortedListIndex = 0 |
|
58 |
+ sortedList=[] |
|
59 |
+ completeListPackagesToBuild=self.findCompleteListOfPackagesRequiredToBuildGivenPackages(listPackages) |
|
60 |
+ packageIndexInSortedList = 0 |
|
61 |
+ prevSortListLen=0 |
|
47 | 62 |
|
48 |
- listPkgsRequiredToBuildToolchain=["linux-api-headers", "glibc","glibc-devel", "zlib","zlib-devel", "file", |
|
49 |
- "binutils","binutils-devel", "gmp","gmp-devel", "mpfr", "mpfr-devel", "mpc", |
|
50 |
- "libgcc","libgcc-devel","libstdc++","libstdc++-devel","libgomp","libgomp-devel","gcc", |
|
51 |
- "pkg-config", "ncurses", "bash", "bzip2", "sed","ncurses-devel","procps-ng","coreutils", "m4","grep", |
|
52 |
- "readline", "diffutils","gawk", "findutils", "gettext", "gzip","make", "patch", |
|
53 |
- "util-linux", "tar", "xz","libtool", "flex", "bison", |
|
54 |
- "readline-devel", "lua","lua-devel","popt","popt-devel","nspr","sqlite-autoconf","nss","nss-devel", |
|
55 |
- "bzip2-devel","elfutils-libelf","elfutils","elfutils-libelf-devel","elfutils-devel", |
|
56 |
- "expat","libffi","libpipeline", "gdbm","perl","texinfo","autoconf","automake", |
|
57 |
- "openssl","openssl-devel","python2","python2-libs","python2-devel","rpm", |
|
58 |
- "groff", "man-db", "man-pages","cpio"] |
|
59 |
- ''' |
|
60 |
- toolChainPackagesCount=0 |
|
61 |
- toolChainPackagelist=[] |
|
62 |
- for p in listPkgsRequiredToBuildToolchain: |
|
63 |
- basePkg=constants.specData.getSpecName(p) |
|
64 |
- if basePkg in listPackagesCopy: |
|
65 |
- listPackagesCopy.remove(basePkg) |
|
66 |
- toolChainPackagelist.append(basePkg) |
|
67 |
- toolChainPackagesCount = toolChainPackagesCount + 1 |
|
68 |
- ''' |
|
69 |
- sListLenBackUp=0 |
|
70 |
- while listPackagesCopy: |
|
71 |
- pkg = None |
|
72 |
- lenIndex=len(sList) |
|
73 |
- for i in range(lenIndex): |
|
74 |
- if sList[i] in alreadyProcessedPackages: |
|
63 |
+ while completeListPackagesToBuild: |
|
64 |
+ |
|
65 |
+ # find next package to process |
|
66 |
+ pkg=None |
|
67 |
+ index=-1 |
|
68 |
+ lenList=len(sortedList) |
|
69 |
+ for i in range(lenList): |
|
70 |
+ if sortedList[i] in alreadyProcessedPackages: |
|
75 | 71 |
continue |
76 |
- pkg = sList[i] |
|
77 |
- sortedListIndex = i |
|
72 |
+ pkg = sortedList[i] |
|
73 |
+ packageIndexInSortedList = i |
|
78 | 74 |
break |
79 |
- |
|
80 | 75 |
|
81 | 76 |
if pkg is None: |
82 |
- pkg = listPackagesCopy.pop() |
|
83 |
- sortedListIndex = len(sList) |
|
84 |
- |
|
85 |
- rbrList=[] |
|
86 |
- for p in self.__runTimeDependencyGraph[pkg]: |
|
87 |
- if p not in rbrList: |
|
88 |
- rbrList.append(p) |
|
89 |
- rbrList.append(pkg) |
|
90 |
- brList=[] |
|
91 |
- |
|
92 |
- for p in rbrList: |
|
93 |
- basePkg=constants.specData.getSpecName(p) |
|
94 |
- for bPkg in self.__sortedBuildDependencyGraph[basePkg]: |
|
95 |
- if bPkg not in brList: |
|
96 |
- brList.append(bPkg) |
|
97 |
- |
|
98 |
- #remove any cyclic packages in brList if they exists in sList |
|
99 |
- circularDependentPackages=[] |
|
100 |
- if self.__mapPackageToCycle.has_key(pkg): |
|
101 |
- circularDependentPackages.extend(self.__mapCyclesToPackageList[self.__mapPackageToCycle[pkg]]) |
|
102 |
- circularDependentPackages.remove(pkg) |
|
77 |
+ pkg = completeListPackagesToBuild.pop() |
|
78 |
+ packageIndexInSortedList = len(sortedList) |
|
79 |
+ |
|
80 |
+ #creating sort list for package |
|
81 |
+ sortListForPkg=self.createSortListForPkg(pkg) |
|
103 | 82 |
|
83 |
+ #remove any cyclic packages in sortListForPkg if they already exists in sortedList |
|
84 |
+ circularDependentPackages=self.getCircularDependentPackages(pkg) |
|
104 | 85 |
for p in circularDependentPackages: |
105 |
- if p in sList: |
|
106 |
- if p in brList: |
|
107 |
- brList.remove(p) |
|
86 |
+ if p in sortedList and p in sortListForPkg: |
|
87 |
+ sortListForPkg.remove(p) |
|
108 | 88 |
|
109 |
- index=sortedListIndex |
|
89 |
+ # insert sort list of package in global sorted list |
|
90 |
+ index=packageIndexInSortedList |
|
110 | 91 |
subList=[] |
111 |
- if sortedListIndex > 0: |
|
112 |
- subList=sList[:sortedListIndex] |
|
113 |
- for p in brList: |
|
92 |
+ if packageIndexInSortedList > 0: |
|
93 |
+ subList=sortedList[:packageIndexInSortedList] |
|
94 |
+ for p in sortListForPkg: |
|
114 | 95 |
if p not in subList: |
115 |
- sList.insert(index, p) |
|
96 |
+ sortedList.insert(index, p) |
|
116 | 97 |
index = index + 1 |
98 |
+ |
|
117 | 99 |
alreadyProcessedPackages.append(p) |
118 | 100 |
|
119 |
- if (len(sList)-sListLenBackUp) > 100 : |
|
120 |
- self.logger.info("Removing duplicates in sList") |
|
121 |
- sListCopy=[] |
|
122 |
- for p in sList: |
|
123 |
- if p not in sListCopy: |
|
124 |
- sListCopy.append(p) |
|
125 |
- sList = sListCopy |
|
101 |
+ # Remove duplicate entries in sorted list in intervals |
|
102 |
+ if (len(sortedList)-prevSortListLen) > 100 : |
|
103 |
+ self.logger.info("Removing duplicates in sortedList") |
|
104 |
+ sortedList = removeDuplicateEntriesInList(sortedList) |
|
126 | 105 |
else: |
127 |
- sListLenBackUp=len(sList) |
|
106 |
+ prevSortListLen=len(sortedList) |
|
128 | 107 |
|
129 |
- self.logger.info("Only final step remains....") |
|
130 |
- sListCopy=[] |
|
131 |
- for p in sList: |
|
132 |
- #if p in toolChainPackagelist: |
|
133 |
- # continue |
|
134 |
- if p not in sListCopy: |
|
135 |
- sListCopy.append(p) |
|
136 |
- sList = sListCopy |
|
108 |
+ self.logger.info("Removing duplicates in sorted list") |
|
109 |
+ sortedList = removeDuplicateEntriesInList(sortedList) |
|
137 | 110 |
|
111 |
+ self.logger.info("Sorted list:") |
|
112 |
+ self.logger.info(sortedList) |
|
113 |
+ self.__sortedPackageList=sortedList |
|
114 |
+ |
|
115 |
+ def __constructBuildAndRunTimeDependencyGraph(self,package): |
|
138 | 116 |
|
139 |
- self.logger.info("sorted list") |
|
140 |
- self.logger.info(sList) |
|
141 |
- self.__sortedPackageList=sList |
|
142 |
- return True |
|
117 |
+ basePackage=constants.specData.getSpecName(package) |
|
118 |
+ |
|
119 |
+ addBuildTimeGraph=True |
|
120 |
+ addRunTimeGraph=True |
|
121 |
+ if self.__buildDependencyGraph.has_key(basePackage): |
|
122 |
+ addBuildTimeGraph = False |
|
123 |
+ if self.__runTimeDependencyGraph.has_key(basePackage): |
|
124 |
+ addRunTimeGraph=False |
|
143 | 125 |
|
144 |
- def __constructBuildTimeDependencyGraph(self,package): |
|
145 |
- if self.__buildDependencyGraph.has_key(package): |
|
146 |
- return True |
|
147 |
- listDependentRpmPackages=constants.specData.getBuildRequiresForPackage(package) |
|
148 |
- listDependentPackages=[] |
|
149 |
- for rpmPkg in listDependentRpmPackages: |
|
150 |
- basePkg=constants.specData.getSpecName(rpmPkg) |
|
151 |
- if basePkg not in listDependentPackages: |
|
152 |
- listDependentPackages.append(basePkg) |
|
153 |
- |
|
154 |
- self.__buildDependencyGraph[package]=listDependentPackages |
|
155 |
- for basePkg in listDependentPackages: |
|
156 |
- self.__constructBuildTimeDependencyGraph(basePkg) |
|
157 |
- self.__constructRunTimeDependencyGraph(basePkg) |
|
158 |
- |
|
159 |
- def __constructRunTimeDependencyGraph(self,package): |
|
160 |
- if self.__runTimeDependencyGraph.has_key(package): |
|
161 |
- return True |
|
162 |
- listRpmPackages=constants.specData.getPackages(package) |
|
163 |
- for rpmPkg in listRpmPackages: |
|
164 |
- listDependentRpmPackages=constants.specData.getRequiresAllForPackage(rpmPkg) |
|
165 |
- self.__runTimeDependencyGraph[rpmPkg]=listDependentRpmPackages[:] |
|
166 |
- for rpmPkg in listRpmPackages: |
|
167 |
- for pkg in self.__runTimeDependencyGraph[rpmPkg]: |
|
168 |
- self.__constructRunTimeDependencyGraph(pkg) |
|
169 |
- self.__constructBuildTimeDependencyGraph(pkg) |
|
126 |
+ nextPackagesToConstructGraph=[] |
|
127 |
+ if addBuildTimeGraph: |
|
128 |
+ listDependentRpmPackages=constants.specData.getBuildRequiresForPackage(basePackage) |
|
129 |
+ listDependentPackages=[] |
|
130 |
+ for rpmPkg in listDependentRpmPackages: |
|
131 |
+ basePkg=constants.specData.getSpecName(rpmPkg) |
|
132 |
+ if basePkg not in listDependentPackages: |
|
133 |
+ listDependentPackages.append(basePkg) |
|
134 |
+ self.__buildDependencyGraph[basePackage]=listDependentPackages |
|
135 |
+ nextPackagesToConstructGraph.extend(listDependentPackages) |
|
136 |
+ |
|
137 |
+ if addRunTimeGraph: |
|
138 |
+ listRpmPackages=constants.specData.getPackages(basePackage) |
|
139 |
+ for rpmPkg in listRpmPackages: |
|
140 |
+ listDependentRpmPackages=constants.specData.getRequiresAllForPackage(rpmPkg) |
|
141 |
+ self.__runTimeDependencyGraph[rpmPkg]=listDependentRpmPackages[:] |
|
142 |
+ nextPackagesToConstructGraph.extend(listDependentRpmPackages) |
|
170 | 143 |
|
144 |
+ for pkg in nextPackagesToConstructGraph: |
|
145 |
+ self.__constructBuildAndRunTimeDependencyGraph(pkg) |
|
146 |
+ |
|
171 | 147 |
def __readDependencyGraphAndCyclesForGivenPackages(self,listPackages): |
172 | 148 |
for pkg in listPackages: |
173 |
- self.__constructBuildTimeDependencyGraph(pkg) |
|
174 |
- self.__constructRunTimeDependencyGraph(pkg) |
|
149 |
+ self.__constructBuildAndRunTimeDependencyGraph(pkg) |
|
175 | 150 |
|
176 | 151 |
packagesToBUild=self.__buildDependencyGraph.keys() |
177 | 152 |
for pkg in packagesToBUild: |
... | ... |
@@ -179,21 +162,20 @@ class PackageBuildDataGenerator(object): |
179 | 179 |
if len(circularDependentPackages) > 0 : |
180 | 180 |
self.logger.error("Found circular dependency") |
181 | 181 |
self.logger.error(circularDependentPackages) |
182 |
- return False |
|
182 |
+ raise Exception("Build Time Circular Dependency") |
|
183 | 183 |
self.__sortedBuildDependencyGraph[pkg]=sortedPackageList |
184 | 184 |
sortedPackageList,circularDependentPackages = self.topologicalSortPackages(self.__runTimeDependencyGraph) |
185 | 185 |
if len(circularDependentPackages) > 0 : |
186 | 186 |
self.__findCircularDependencies(circularDependentPackages) |
187 |
- return True |
|
188 | 187 |
|
189 |
- def topologicalSortPackages(self, dependentPackages1, package=None): |
|
188 |
+ def topologicalSortPackages(self, dependencyGraph, package=None): |
|
190 | 189 |
noDepPackages = Set() |
191 | 190 |
sortedPackageList = [] |
192 | 191 |
dependentOfPackage = dict() |
193 | 192 |
|
194 | 193 |
dependentPackages={} |
195 | 194 |
if package is None: |
196 |
- dependentPackages=copy.deepcopy(dependentPackages1) |
|
195 |
+ dependentPackages=copy.deepcopy(dependencyGraph) |
|
197 | 196 |
else: |
198 | 197 |
listDepPkgs= Set() |
199 | 198 |
listDepPkgs.add(package) |
... | ... |
@@ -201,9 +183,10 @@ class PackageBuildDataGenerator(object): |
201 | 201 |
pkg = listDepPkgs.pop() |
202 | 202 |
if dependentPackages.has_key(pkg): |
203 | 203 |
continue |
204 |
- dependentPackages[pkg]=dependentPackages1[pkg][:] |
|
205 |
- for depPkg in dependentPackages1[pkg]: |
|
204 |
+ dependentPackages[pkg]=dependencyGraph[pkg][:] |
|
205 |
+ for depPkg in dependencyGraph[pkg]: |
|
206 | 206 |
listDepPkgs.add(depPkg) |
207 |
+ |
|
207 | 208 |
#Find packages with no dependencies and generate dependentof_package edge list |
208 | 209 |
for pkg in dependentPackages: |
209 | 210 |
if len(dependentPackages[pkg]) == 0: |
... | ... |
@@ -226,28 +209,28 @@ class PackageBuildDataGenerator(object): |
226 | 226 |
if len(dependentPackages[childPkg])==0: |
227 | 227 |
noDepPackages.add(childPkg) |
228 | 228 |
|
229 |
- circularDependentGraph={} |
|
229 |
+ # creating circular dependency graph for given dependency graph |
|
230 |
+ circularDependencyGraph={} |
|
230 | 231 |
listCircularPkg = dependentPackages.keys() |
231 | 232 |
for pkg in listCircularPkg: |
232 | 233 |
if len(dependentPackages[pkg]) != 0: |
233 |
- circularDependentGraph[pkg]=dependentPackages[pkg] |
|
234 |
+ circularDependencyGraph[pkg]=dependentPackages[pkg] |
|
234 | 235 |
|
235 | 236 |
#return (non-circular dependent package in sorted order and circular dependent package list in a dependencyGraph) |
236 |
- return sortedPackageList,circularDependentGraph |
|
237 |
+ return sortedPackageList,circularDependencyGraph |
|
237 | 238 |
|
238 |
- def __findCircularDependencies(self,cyclicDependentGraph): |
|
239 |
- if len(cyclicDependentGraph) == 0: |
|
240 |
- return True |
|
241 |
- #step1: construct dependency map from dependency graph |
|
239 |
+ |
|
240 |
+ def __constructDependencyMap(self,cyclicDependencyGraph): |
|
241 |
+ self.logger.info("Constructing dependency map from circular dependency graph.....") |
|
242 | 242 |
constructDependencyMap={} |
243 |
- listNodes=cyclicDependentGraph.keys() |
|
243 |
+ listNodes=cyclicDependencyGraph.keys() |
|
244 | 244 |
for node in listNodes: |
245 | 245 |
tmpDepNodeList=[] |
246 | 246 |
tmpDepNodeList.append(node) |
247 | 247 |
depNodeList=[] |
248 | 248 |
while len(tmpDepNodeList)!=0: |
249 | 249 |
currentNode = tmpDepNodeList.pop() |
250 |
- addDepNodeList = cyclicDependentGraph[currentNode] |
|
250 |
+ addDepNodeList = cyclicDependencyGraph[currentNode] |
|
251 | 251 |
depNodeList.append(currentNode) |
252 | 252 |
for depNode in addDepNodeList: |
253 | 253 |
if depNode in depNodeList: |
... | ... |
@@ -259,8 +242,19 @@ class PackageBuildDataGenerator(object): |
259 | 259 |
constructDependencyMap[node]=depNodeList |
260 | 260 |
self.logger.info("Dependency Map:") |
261 | 261 |
self.logger.info(constructDependencyMap) |
262 |
+ return constructDependencyMap |
|
263 |
+ |
|
264 |
+ |
|
265 |
+ def __findCircularDependencies(self,cyclicDependencyGraph): |
|
266 |
+ if len(cyclicDependencyGraph) == 0: |
|
267 |
+ return |
|
268 |
+ #step1: construct dependency map from dependency graph |
|
269 |
+ constructDependencyMap=self.__constructDependencyMap(cyclicDependencyGraph) |
|
262 | 270 |
|
263 |
- #find cycles in dependency map |
|
271 |
+ #step2: find cycles in dependency map |
|
272 |
+ self.logger.info("Finding and adding cycles using constructed dependency map......") |
|
273 |
+ cycleCount=0 |
|
274 |
+ listNodes=cyclicDependencyGraph.keys() |
|
264 | 275 |
for node in listNodes: |
265 | 276 |
listDepPkg=constructDependencyMap[node] |
266 | 277 |
cycPkgs=[] |
... | ... |
@@ -277,9 +271,16 @@ class PackageBuildDataGenerator(object): |
277 | 277 |
for x in cycPkgs: |
278 | 278 |
self.__mapPackageToCycle[x]=cycleName |
279 | 279 |
self.__mapCyclesToPackageList[cycleName]=cycPkgs |
280 |
- self.logger.info("New Circular dependency found") |
|
281 |
- self.logger.info(cycPkgs) |
|
282 |
- return True |
|
280 |
+ self.logger.info("New circular dependency found:") |
|
281 |
+ self.logger.info(cycleName+" "+ ",".join(cycPkgs)) |
|
282 |
+ cycleCount = cycleCount + 1 |
|
283 |
+ |
|
284 |
+ if cycleCount > 0 : |
|
285 |
+ self.logger.info("Found "+str(cycleCount) + " cycles.") |
|
286 |
+ self.logger.info("Successfully added all detected circular dependencies to list.") |
|
287 |
+ else: |
|
288 |
+ self.logger.info("No circular dependencies found.") |
|
289 |
+ |
|
283 | 290 |
|
284 | 291 |
|
285 | 292 |
|
... | ... |
@@ -8,12 +8,6 @@ from constants import constants |
8 | 8 |
|
9 | 9 |
class PackageBuilder(object): |
10 | 10 |
|
11 |
- #logger=None |
|
12 |
- |
|
13 |
- #@staticmethod |
|
14 |
- #def setLog(logPath): |
|
15 |
- # PackageBuilder.logger=Logger.getLogger(logPath+"/PackageBuilder") |
|
16 |
- |
|
17 | 11 |
def __init__(self,mapPackageToCycles,listAvailableCyclicPackages,logName=None,logPath=None): |
18 | 12 |
if logName is None: |
19 | 13 |
logName = "PackageBuilder" |
... | ... |
@@ -22,22 +16,25 @@ class PackageBuilder(object): |
22 | 22 |
self.logName=logName |
23 | 23 |
self.logPath=logPath |
24 | 24 |
self.logger=Logger.getLogger(logName,logPath) |
25 |
- self.runInChrootCommand="./run-in-chroot.sh" |
|
26 | 25 |
self.mapPackageToCycles = mapPackageToCycles |
27 | 26 |
self.listAvailableCyclicPackages = listAvailableCyclicPackages |
28 | 27 |
self.listNodepsPackages = ["glibc","gmp","zlib","file","binutils","mpfr","mpc","gcc","ncurses","util-linux","groff","perl","texinfo","rpm","openssl","go"] |
29 | 28 |
|
30 | 29 |
#assumes tool chain is already built |
31 | 30 |
def prepareBuildRoot(self): |
32 |
- chrUtils = ChrootUtils(self.logName,self.logPath) |
|
33 |
- returnVal,chrootID = chrUtils.createChroot() |
|
34 |
- if not returnVal: |
|
35 |
- self.logger.error("Unable to build tool chain.") |
|
36 |
- chrUtils.destroyChroot(chrootID) |
|
37 |
- return False |
|
38 |
- tUtils=ToolChainUtils(self.logName,self.logPath) |
|
39 |
- returnVal = tUtils.installToolChain(chrootID) |
|
40 |
- return returnVal,chrootID |
|
31 |
+ chrootID=None |
|
32 |
+ try: |
|
33 |
+ chrUtils = ChrootUtils(self.logName,self.logPath) |
|
34 |
+ returnVal,chrootID = chrUtils.createChroot() |
|
35 |
+ if not returnVal: |
|
36 |
+ raise Exception("Unable to prepare build root") |
|
37 |
+ tUtils=ToolChainUtils(self.logName,self.logPath) |
|
38 |
+ tUtils.installToolChain(chrootID) |
|
39 |
+ except Exception as e: |
|
40 |
+ if chrootID is not None: |
|
41 |
+ chrUtils.destroyChroot(chrootID) |
|
42 |
+ raise e |
|
43 |
+ return chrootID |
|
41 | 44 |
|
42 | 45 |
def findPackageNameFromRPMFile(self,rpmfile): |
43 | 46 |
rpmfile=os.path.basename(rpmfile) |
... | ... |
@@ -53,8 +50,8 @@ class PackageBuilder(object): |
53 | 53 |
return packageName |
54 | 54 |
|
55 | 55 |
def findInstalledPackages(self,chrootID): |
56 |
- cmdUtils = CommandUtils() |
|
57 |
- listInstalledRPMs=cmdUtils.find_installed_rpm_packages(self.runInChrootCommand+" "+chrootID) |
|
56 |
+ pkgUtils = PackageUtils(self.logName,self.logPath) |
|
57 |
+ listInstalledRPMs=pkgUtils.findInstalledRPMPackages(chrootID) |
|
58 | 58 |
listInstalledPackages=[] |
59 | 59 |
for installedRPM in listInstalledRPMs: |
60 | 60 |
packageName=self.findPackageNameFromRPMFile(installedRPM) |
... | ... |
@@ -63,90 +60,74 @@ class PackageBuilder(object): |
63 | 63 |
return listInstalledPackages |
64 | 64 |
|
65 | 65 |
def buildPackageThreadAPI(self,package,outputMap, threadName): |
66 |
- returnVal=self.buildPackage(package) |
|
67 |
- outputMap[threadName]=returnVal |
|
66 |
+ try: |
|
67 |
+ self.buildPackage(package) |
|
68 |
+ outputMap[threadName]=True |
|
69 |
+ except Exception as e: |
|
70 |
+ self.logger.error(e) |
|
71 |
+ outputMap[threadName]=False |
|
68 | 72 |
|
69 | 73 |
def buildPackage(self,package): |
70 | 74 |
#should initialize a logger based on package name |
71 | 75 |
chrUtils = ChrootUtils(self.logName,self.logPath) |
72 |
- returnVal,chrootID = self.prepareBuildRoot() |
|
73 |
- if not returnVal: |
|
74 |
- return False |
|
75 |
- |
|
76 |
- destLogPath=constants.logPath+"/build-"+package |
|
77 |
- if not os.path.isdir(destLogPath): |
|
78 |
- cmdUtils = CommandUtils() |
|
79 |
- cmdUtils.run_command("mkdir -p "+destLogPath) |
|
80 |
- |
|
81 |
- listInstalledPackages=self.findInstalledPackages(chrootID) |
|
82 |
- self.logger.info("List of installed packages") |
|
83 |
- self.logger.info(listInstalledPackages) |
|
84 |
- returnVal,listDependentPackages=self.findBuildTimeRequiredPackages(package) |
|
85 |
- if not returnVal: |
|
86 |
- chrUtils.destroyChroot(chrootID) |
|
87 |
- self.logger.error ("Failed during building the package"+package) |
|
88 |
- return False |
|
89 |
- |
|
90 |
- if len(listDependentPackages) != 0: |
|
91 |
- self.logger.info("Installing the build time dependent packages......") |
|
92 |
- for pkg in listDependentPackages: |
|
93 |
- returnVal = self.installPackage(pkg,chrootID,destLogPath,listInstalledPackages) |
|
94 |
- if not returnVal: |
|
95 |
- self.logger.error("Failed while installing the build time dependent package"+pkg) |
|
96 |
- chrUtils.destroyChroot(chrootID) |
|
97 |
- return False |
|
98 |
- self.logger.info("Finished installing the build time dependent packages......") |
|
76 |
+ chrootID=None |
|
77 |
+ try: |
|
78 |
+ chrootID = self.prepareBuildRoot() |
|
79 |
+ destLogPath=constants.logPath+"/build-"+package |
|
80 |
+ if not os.path.isdir(destLogPath): |
|
81 |
+ cmdUtils = CommandUtils() |
|
82 |
+ cmdUtils.runCommandInShell("mkdir -p "+destLogPath) |
|
83 |
+ |
|
84 |
+ listInstalledPackages=self.findInstalledPackages(chrootID) |
|
85 |
+ self.logger.info("List of installed packages") |
|
86 |
+ self.logger.info(listInstalledPackages) |
|
87 |
+ listDependentPackages=self.findBuildTimeRequiredPackages(package) |
|
88 |
+ |
|
89 |
+ if len(listDependentPackages) != 0: |
|
90 |
+ self.logger.info("Installing the build time dependent packages......") |
|
91 |
+ for pkg in listDependentPackages: |
|
92 |
+ self.installPackage(pkg,chrootID,destLogPath,listInstalledPackages) |
|
93 |
+ self.logger.info("Finished installing the build time dependent packages......") |
|
99 | 94 |
|
100 |
- pkgUtils = PackageUtils(self.logName,self.logPath) |
|
101 |
- returnVal = pkgUtils.buildRPMSForGivenPackage(package,chrootID,destLogPath) |
|
102 |
- if not returnVal: |
|
103 |
- self.logger.error("Failed while building the package"+package) |
|
104 |
- chrUtils.destroyChroot(chrootID) |
|
105 |
- return False |
|
106 |
- self.logger.info("Successfully built the package:"+package) |
|
107 |
- chrUtils.destroyChroot(chrootID) |
|
108 |
- return True |
|
95 |
+ pkgUtils = PackageUtils(self.logName,self.logPath) |
|
96 |
+ pkgUtils.buildRPMSForGivenPackage(package,chrootID,destLogPath) |
|
97 |
+ self.logger.info("Successfully built the package:"+package) |
|
98 |
+ except Exception as e: |
|
99 |
+ self.logger.error("Failed while building package:"+package) |
|
100 |
+ raise e |
|
101 |
+ finally: |
|
102 |
+ if chrootID is not None: |
|
103 |
+ chrUtils.destroyChroot(chrootID) |
|
104 |
+ |
|
109 | 105 |
|
110 | 106 |
def findRunTimeRequiredRPMPackages(self,rpmPackage): |
111 | 107 |
listRequiredPackages=constants.specData.getRequiresForPackage(rpmPackage) |
112 |
- return True,listRequiredPackages |
|
108 |
+ return listRequiredPackages |
|
113 | 109 |
|
114 | 110 |
def findBuildTimeRequiredPackages(self,package): |
115 | 111 |
listRequiredPackages=constants.specData.getBuildRequiresForPackage(package) |
116 |
- return True,listRequiredPackages |
|
112 |
+ return listRequiredPackages |
|
117 | 113 |
|
118 | 114 |
def installPackage(self,package,chrootID,destLogPath,listInstalledPackages): |
119 |
- #if toolchain package called this method, preventing from installing again |
|
120 | 115 |
if package in listInstalledPackages: |
121 |
- return True |
|
122 |
- returnVal = self.installDependentRunTimePackages(package,chrootID,destLogPath,listInstalledPackages) |
|
123 |
- if not returnVal: |
|
124 |
- return False |
|
116 |
+ return |
|
117 |
+ self.installDependentRunTimePackages(package,chrootID,destLogPath,listInstalledPackages) |
|
125 | 118 |
pkgUtils = PackageUtils(self.logName,self.logPath) |
126 | 119 |
noDeps=False |
127 | 120 |
if self.mapPackageToCycles.has_key(package): |
128 | 121 |
noDeps = True |
129 | 122 |
if package in self.listNodepsPackages: |
130 | 123 |
noDeps=True |
131 |
- returnVal = pkgUtils.installRPM(package,chrootID,noDeps,destLogPath) |
|
132 |
- if not returnVal: |
|
133 |
- self.logger.error("Stop installing package"+package) |
|
134 |
- return False |
|
124 |
+ pkgUtils.installRPM(package,chrootID,noDeps,destLogPath) |
|
135 | 125 |
listInstalledPackages.append(package) |
136 | 126 |
self.logger.info("Installed the package:"+package) |
137 |
- return True |
|
138 | 127 |
|
139 | 128 |
def installDependentRunTimePackages(self,package,chrootID,destLogPath,listInstalledPackages): |
140 |
- returnVal,listRunTimeDependentPackages=self.findRunTimeRequiredRPMPackages(package) |
|
141 |
- if not returnVal: |
|
142 |
- return False |
|
129 |
+ listRunTimeDependentPackages=self.findRunTimeRequiredRPMPackages(package) |
|
143 | 130 |
if len(listRunTimeDependentPackages) != 0: |
144 | 131 |
for pkg in listRunTimeDependentPackages: |
145 | 132 |
if self.mapPackageToCycles.has_key(pkg) and pkg not in self.listAvailableCyclicPackages: |
146 | 133 |
continue |
147 | 134 |
if pkg in listInstalledPackages: |
148 | 135 |
continue |
149 |
- returnVal = self.installPackage(pkg,chrootID,destLogPath,listInstalledPackages) |
|
150 |
- if not returnVal: |
|
151 |
- return False |
|
152 |
- return True |
|
136 |
+ self.installPackage(pkg,chrootID,destLogPath,listInstalledPackages) |
... | ... |
@@ -6,6 +6,7 @@ import time |
6 | 6 |
from PackageBuilder import PackageBuilder |
7 | 7 |
import os |
8 | 8 |
from PackageUtils import PackageUtils |
9 |
+from ToolChainUtils import ToolChainUtils |
|
9 | 10 |
|
10 | 11 |
class PackageManager(object): |
11 | 12 |
|
... | ... |
@@ -28,10 +29,10 @@ class PackageManager(object): |
28 | 28 |
self.listPackagesToBuild=[] |
29 | 29 |
|
30 | 30 |
def readPackageBuildData(self, listPackages): |
31 |
- pkgBuildDataGen = PackageBuildDataGenerator(self.logName,self.logPath) |
|
32 |
- returnVal,self.mapCyclesToPackageList,self.mapPackageToCycle,self.sortedPackageList = pkgBuildDataGen.getPackageBuildData(listPackages) |
|
33 |
- |
|
34 |
- if not returnVal: |
|
31 |
+ try: |
|
32 |
+ pkgBuildDataGen = PackageBuildDataGenerator(self.logName,self.logPath) |
|
33 |
+ self.mapCyclesToPackageList,self.mapPackageToCycle,self.sortedPackageList = pkgBuildDataGen.getPackageBuildData(listPackages) |
|
34 |
+ except: |
|
35 | 35 |
self.logger.error("unable to get sorted list") |
36 | 36 |
return False |
37 | 37 |
|
... | ... |
@@ -162,6 +163,10 @@ class PackageManager(object): |
162 | 162 |
return returnVal |
163 | 163 |
|
164 | 164 |
def buildPackages (self, listPackages): |
165 |
+ |
|
166 |
+ tUtils=ToolChainUtils() |
|
167 |
+ tUtils.buildToolChain() |
|
168 |
+ |
|
165 | 169 |
returnVal=self.calculateParams(listPackages) |
166 | 170 |
if not returnVal: |
167 | 171 |
self.logger.error("Unable to set paramaters. Terminating the package manager.") |
... | ... |
@@ -3,6 +3,7 @@ from Logger import Logger |
3 | 3 |
import os |
4 | 4 |
import shutil |
5 | 5 |
from constants import constants |
6 |
+import re |
|
6 | 7 |
|
7 | 8 |
|
8 | 9 |
class PackageUtils(object): |
... | ... |
@@ -16,7 +17,15 @@ class PackageUtils(object): |
16 | 16 |
self.logPath=logPath |
17 | 17 |
self.logger=Logger.getLogger(logName,logPath) |
18 | 18 |
self.runInChrootCommand="./run-in-chroot.sh" |
19 |
+ self.rpmBinary = "rpm" |
|
20 |
+ self.installRPMPackageOptions = "-Uvh" |
|
21 |
+ self.nodepsRPMPackageOptions = "--nodeps" |
|
19 | 22 |
|
23 |
+ self.rpmbuildBinary = "rpmbuild" |
|
24 |
+ self.rpmbuildBuildallOption = "-ba" |
|
25 |
+ self.rpmbuildNocheckOption = "--nocheck" |
|
26 |
+ self.queryRpmPackageOptions = "-qa" |
|
27 |
+ self.forceRpmPackageOptions = "--force" |
|
20 | 28 |
|
21 | 29 |
def getRPMDestDir(self,rpmName,rpmDir): |
22 | 30 |
arch="" |
... | ... |
@@ -24,7 +33,6 @@ class PackageUtils(object): |
24 | 24 |
arch='x86_64' |
25 | 25 |
elif rpmName.find("noarch") != -1: |
26 | 26 |
arch="noarch" |
27 |
- #else: Todo throw an exeption |
|
28 | 27 |
rpmDestDir=rpmDir+"/"+arch |
29 | 28 |
return rpmDestDir |
30 | 29 |
|
... | ... |
@@ -33,52 +41,55 @@ class PackageUtils(object): |
33 | 33 |
rpmName=os.path.basename(rpmFile) |
34 | 34 |
rpmDestDir=self.getRPMDestDir(rpmName,destDir) |
35 | 35 |
if not os.path.isdir(rpmDestDir): |
36 |
- cmdUtils.run_command("mkdir -p "+rpmDestDir) |
|
36 |
+ cmdUtils.runCommandInShell("mkdir -p "+rpmDestDir) |
|
37 | 37 |
rpmDestPath=rpmDestDir+"/"+rpmName |
38 | 38 |
shutil.copyfile(rpmFile, rpmDestPath) |
39 | 39 |
return rpmDestPath |
40 | 40 |
|
41 | 41 |
def installRPM(self,package,chrootID,noDeps=False,destLogPath=None): |
42 |
+ self.logger.info("Installing rpm for package:"+package) |
|
43 |
+ self.logger.debug("No deps:"+str(noDeps)) |
|
44 |
+ |
|
42 | 45 |
rpmfile=self.findRPMFileForGivenPackage(package) |
43 | 46 |
if rpmfile is None: |
44 |
- self.logger.error("unexpected error") |
|
45 |
- self.logger.error("Stopping installing package:"+package) |
|
46 |
- return False |
|
47 |
+ self.logger.error("No rpm file found for package:"+package) |
|
48 |
+ raise Exception("Missing rpm file") |
|
47 | 49 |
|
48 | 50 |
rpmDestFile = self.copyRPM(rpmfile, chrootID+constants.topDirPath+"/RPMS") |
49 | 51 |
rpmFile=rpmDestFile.replace(chrootID,"") |
50 | 52 |
chrootCmd=self.runInChrootCommand+" "+chrootID |
51 | 53 |
logFile=chrootID+constants.topDirPath+"/LOGS"+"/"+package+".completed" |
52 |
- |
|
54 |
+ |
|
55 |
+ rpmInstallcmd=self.rpmBinary+" "+ self.installRPMPackageOptions |
|
56 |
+ if noDeps: |
|
57 |
+ rpmInstallcmd+=" "+self.nodepsRPMPackageOptions |
|
58 |
+ rpmInstallcmd+=" "+rpmFile |
|
59 |
+ |
|
53 | 60 |
cmdUtils = CommandUtils() |
54 |
- returnVal = cmdUtils.installRPM(rpmFile,logFile,chrootCmd,noDeps) |
|
61 |
+ returnVal = cmdUtils.runCommandInShell(rpmInstallcmd, logFile, chrootCmd) |
|
55 | 62 |
if destLogPath is not None: |
56 | 63 |
shutil.copy2(logFile, destLogPath) |
57 | 64 |
if not returnVal: |
58 |
- self.logger.error("Installing " + rpmFile+" rpm is failed") |
|
59 |
- return False |
|
60 |
- return True |
|
65 |
+ self.logger.error("Unable to install rpm:"+ rpmFile) |
|
66 |
+ raise Exception("RPM installation failed") |
|
61 | 67 |
|
62 | 68 |
def copySourcesTobuildroot(self,listSourceFiles,package,destDir): |
63 | 69 |
cmdUtils = CommandUtils() |
64 | 70 |
for source in listSourceFiles: |
65 |
- sourcePath = cmdUtils.find_file(source,constants.sourcePath) |
|
71 |
+ sourcePath = cmdUtils.findFile(source,constants.sourcePath) |
|
66 | 72 |
if sourcePath is None or len(sourcePath) == 0: |
67 |
- sourcePath = cmdUtils.find_file(source,constants.specPath) |
|
73 |
+ sourcePath = cmdUtils.findFile(source,constants.specPath) |
|
68 | 74 |
if sourcePath is None or len(sourcePath) == 0: |
69 | 75 |
self.logger.error("Missing source: "+source+". Cannot find sources for package: "+package) |
70 |
- self.logger.error("Stopping building toolchain") |
|
71 |
- return False |
|
76 |
+ raise Exception("Missing source") |
|
72 | 77 |
if len(sourcePath) > 1: |
73 |
- self.logger.error("Multiple sources found: Unable to determine one. ") |
|
74 |
- self.logger.error("Stopping building toolchain") |
|
75 |
- return False |
|
78 |
+ self.logger.error("Multiple sources found for source:"+source+"\n"+ ",".join(sourcePath) +"\nUnable to determine one.") |
|
79 |
+ raise Exception("Multiple sources found") |
|
76 | 80 |
self.logger.info("Source path :" + source + " Source filename: " + sourcePath[0]) |
77 |
- shutil.copyfile(sourcePath[0], destDir+source) |
|
81 |
+ shutil.copy2(sourcePath[0], destDir) |
|
78 | 82 |
|
79 | 83 |
def buildRPMSForGivenPackage(self,package, chrootID,destLogPath=None): |
80 |
- self.logger.info("Building package......"+package) |
|
81 |
- #self.adjust_gcc_specs(package) |
|
84 |
+ self.logger.info("Building rpm's for package:"+package) |
|
82 | 85 |
|
83 | 86 |
listSourcesFiles = constants.specData.getSources(package) |
84 | 87 |
listPatchFiles = constants.specData.getPatches(package) |
... | ... |
@@ -94,48 +105,66 @@ class PackageUtils(object): |
94 | 94 |
self.copySourcesTobuildroot(listSourcesFiles,package,chrootSourcePath) |
95 | 95 |
self.copySourcesTobuildroot(listPatchFiles,package,chrootSourcePath) |
96 | 96 |
|
97 |
- returnVal,listRPMFiles = self.buildRPM(chrootSpecPath+"/"+specName,chrootLogsFilePath, chrootCmd) |
|
97 |
+ listRPMFiles = self.buildRPM(chrootSpecPath+"/"+specName,chrootLogsFilePath, chrootCmd) |
|
98 | 98 |
if destLogPath is not None: |
99 | 99 |
shutil.copy2(chrootLogsFilePath, destLogPath) |
100 |
- |
|
101 |
- if not returnVal: |
|
102 |
- return False |
|
103 |
- |
|
100 |
+ |
|
104 | 101 |
for rpmFile in listRPMFiles: |
105 | 102 |
self.copyRPM(chrootID+"/"+rpmFile, constants.rpmPath) |
106 |
- return True |
|
107 | 103 |
|
108 | 104 |
def buildRPM(self,specFile,logFile,chrootCmd): |
105 |
+ |
|
106 |
+ rpmBuildcmd= self.rpmbuildBinary+" "+self.rpmbuildBuildallOption+" "+self.rpmbuildNocheckOption |
|
107 |
+ rpmBuildcmd+=" "+specFile |
|
108 |
+ |
|
109 | 109 |
cmdUtils = CommandUtils() |
110 |
- returnVal,listRPMFiles = cmdUtils.buildRPM(specFile,logFile,chrootCmd) |
|
110 |
+ returnVal = cmdUtils.runCommandInShell(rpmBuildcmd, logFile, chrootCmd) |
|
111 | 111 |
if not returnVal: |
112 | 112 |
self.logger.error("Building rpm is failed "+specFile) |
113 |
- return False,None |
|
114 |
- return True,listRPMFiles |
|
113 |
+ raise Exception("RPM Build failed") |
|
114 |
+ |
|
115 |
+ #Extracting rpms created from log file |
|
116 |
+ logfile=open(logFile,'r') |
|
117 |
+ fileContents=logfile.readlines() |
|
118 |
+ logfile.close() |
|
119 |
+ listRPMFiles=[] |
|
120 |
+ for i in range(0,len(fileContents)): |
|
121 |
+ if re.search("^Wrote:",fileContents[i]): |
|
122 |
+ listcontents=fileContents[i].split() |
|
123 |
+ if (len(listcontents) == 2) and listcontents[1].strip()[-4:] == ".rpm" and listcontents[1].find("/RPMS/") != -1: |
|
124 |
+ listRPMFiles.append(listcontents[1]) |
|
125 |
+ |
|
126 |
+ return listRPMFiles |
|
115 | 127 |
|
116 | 128 |
def findRPMFileForGivenPackage(self,package): |
117 | 129 |
cmdUtils = CommandUtils() |
118 | 130 |
version = constants.specData.getVersion(package) |
119 | 131 |
release = constants.specData.getRelease(package) |
120 |
- listFoundRPMFiles = cmdUtils.find_file(package+"-"+version+"-"+release+"*.rpm",constants.rpmPath) |
|
132 |
+ listFoundRPMFiles = cmdUtils.findFile(package+"-"+version+"-"+release+"*.rpm",constants.rpmPath) |
|
121 | 133 |
if len(listFoundRPMFiles) == 1 : |
122 | 134 |
return listFoundRPMFiles[0] |
123 | 135 |
if len(listFoundRPMFiles) == 0 : |
124 | 136 |
return None |
125 | 137 |
if len(listFoundRPMFiles) > 1 : |
126 |
- self.logger.error("Unable to determine the rpm file for package. Found multiple rpm files for given package in rpm directory") |
|
127 |
- return None |
|
128 |
- return None |
|
138 |
+ self.logger.error("Found multiple rpm files for given package in rpm directory.Unable to determine the rpm file for package:"+package) |
|
139 |
+ raise Exception("Multiple rpm files found") |
|
129 | 140 |
|
130 | 141 |
def findPackageNameFromRPMFile(self,rpmfile): |
131 | 142 |
rpmfile=os.path.basename(rpmfile) |
132 | 143 |
releaseindex=rpmfile.rfind("-") |
133 | 144 |
if releaseindex == -1: |
134 | 145 |
self.logger.error("Invalid rpm file:"+rpmfile) |
135 |
- return None |
|
146 |
+ raise Exception("Invalid RPM") |
|
136 | 147 |
versionindex=rpmfile[0:releaseindex].rfind("-") |
137 | 148 |
if versionindex == -1: |
138 | 149 |
self.logger.error("Invalid rpm file:"+rpmfile) |
139 |
- return None |
|
150 |
+ raise Exception("Invalid RPM") |
|
140 | 151 |
packageName=rpmfile[0:versionindex] |
141 | 152 |
return packageName |
153 |
+ |
|
154 |
+ def findInstalledRPMPackages(self, chrootID): |
|
155 |
+ cmd = self.rpmBinary+" "+self.queryRpmPackageOptions |
|
156 |
+ chrootCmd=self.runInChrootCommand+" "+chrootID |
|
157 |
+ cmdUtils=CommandUtils() |
|
158 |
+ result=cmdUtils.runCommandInShell2(cmd, chrootCmd) |
|
159 |
+ return result |
... | ... |
@@ -22,7 +22,6 @@ class ToolChainUtils(object): |
22 | 22 |
self.localegenConfig = "./locale-gen.conf" |
23 | 23 |
self.prepareBuildRootCmd="./prepare-build-root.sh" |
24 | 24 |
|
25 |
- |
|
26 | 25 |
self.listPkgsRequiredToBuildToolchain=["linux-api-headers", "glibc","glibc-devel", "zlib","zlib-devel", "file", |
27 | 26 |
"binutils","binutils-devel", "gmp","gmp-devel", "mpfr", "mpfr-devel", "mpc", |
28 | 27 |
"libgcc","libgcc-devel","libstdc++","libstdc++-devel","libgomp","libgomp-devel","gcc", |
... | ... |
@@ -45,83 +44,60 @@ class ToolChainUtils(object): |
45 | 45 |
"libpipeline", "gdbm","perl","texinfo","rpm", |
46 | 46 |
"autoconf","automake", "groff", "man-db", "man-pages","elfutils","cpio"] |
47 | 47 |
|
48 |
- |
|
49 |
- |
|
50 | 48 |
def prepareChroot(self,chrootID,toolsArchive=""): |
51 | 49 |
process = subprocess.Popen([self.prepareBuildRootCmd, chrootID, constants.specPath, constants.rpmPath, constants.toolsPath,toolsArchive]) |
52 | 50 |
returnVal = process.wait() |
53 | 51 |
if returnVal != 0: |
54 |
- self.logger.error("Unable to prepare chroot.") |
|
55 |
- return False |
|
52 |
+ self.logger.error("Prepare build root script failed.Unable to prepare chroot.") |
|
53 |
+ raise Exception("Prepare build root script failed") |
|
56 | 54 |
|
57 | 55 |
cmdUtils=CommandUtils() |
58 |
- cmdUtils.run_command("mkdir -p "+chrootID+constants.topDirPath+"/RPMS") |
|
59 |
- cmdUtils.run_command("mkdir -p "+chrootID+constants.topDirPath+"/RPMS/x86_64") |
|
60 |
- cmdUtils.run_command("mkdir -p "+chrootID+constants.topDirPath+"/RPMS/noarch") |
|
61 |
- cmdUtils.run_command("mkdir -p "+chrootID+constants.topDirPath+"/SOURCES") |
|
62 |
- cmdUtils.run_command("mkdir -p "+chrootID+constants.topDirPath+"/SPECS") |
|
56 |
+ cmdUtils.runCommandInShell("mkdir -p "+chrootID+constants.topDirPath+"/RPMS") |
|
57 |
+ cmdUtils.runCommandInShell("mkdir -p "+chrootID+constants.topDirPath+"/RPMS/x86_64") |
|
58 |
+ cmdUtils.runCommandInShell("mkdir -p "+chrootID+constants.topDirPath+"/RPMS/noarch") |
|
59 |
+ cmdUtils.runCommandInShell("mkdir -p "+chrootID+constants.topDirPath+"/SOURCES") |
|
60 |
+ cmdUtils.runCommandInShell("mkdir -p "+chrootID+constants.topDirPath+"/SPECS") |
|
63 | 61 |
self.logger.info("Successfully prepared chroot:"+chrootID) |
64 |
- return True |
|
65 | 62 |
|
66 | 63 |
def buildToolChain(self): |
64 |
+ self.logger.info("Building Tool Chain .....") |
|
65 |
+ chrootID=None |
|
67 | 66 |
chrUtils = ChrootUtils(self.logName,self.logPath) |
68 |
- returnVal,chrootID = chrUtils.createChroot() |
|
69 |
- if not returnVal: |
|
70 |
- self.logger.error("Unable to build tool chain.") |
|
71 |
- chrUtils.destroyChroot(chrootID) |
|
72 |
- return False |
|
73 |
- if not self.prepareChroot(chrootID): |
|
74 |
- self.logger.error("Unable to build tool chain.") |
|
75 |
- chrUtils.destroyChroot(chrootID) |
|
76 |
- return False |
|
77 |
- |
|
78 |
- pkgUtils=PackageUtils(self.logName,self.logPath) |
|
79 |
- for package in self.listPkgsRequiredToBuildToolchain: |
|
80 |
- rpmPkg=pkgUtils.findRPMFileForGivenPackage(package) |
|
81 |
- if rpmPkg is None: |
|
82 |
- #directly push them to golden repo, no test required |
|
83 |
- returnVal = pkgUtils.buildRPMSForGivenPackage(package, chrootID) |
|
84 |
- if not returnVal: |
|
85 |
- self.logger.error("Stop building toolchain") |
|
86 |
- chrUtils.destroyChroot(chrootID) |
|
87 |
- return False |
|
88 |
- returnVal = pkgUtils.installRPM(package, chrootID, True) |
|
67 |
+ try: |
|
68 |
+ returnVal,chrootID = chrUtils.createChroot() |
|
89 | 69 |
if not returnVal: |
90 |
- self.logger.error("Stop building toolchain") |
|
70 |
+ raise Exception("creating chroot failed") |
|
71 |
+ self.prepareChroot(chrootID) |
|
72 |
+ pkgUtils=PackageUtils(self.logName,self.logPath) |
|
73 |
+ for package in self.listPkgsRequiredToBuildToolchain: |
|
74 |
+ rpmPkg=pkgUtils.findRPMFileForGivenPackage(package) |
|
75 |
+ if rpmPkg is None: |
|
76 |
+ pkgUtils.buildRPMSForGivenPackage(package, chrootID) |
|
77 |
+ pkgUtils.installRPM(package, chrootID, True) |
|
78 |
+ if package == "glibc": |
|
79 |
+ self.adjustToolChain(chrootID) |
|
80 |
+ self.logger.info("Successfully built toolchain") |
|
81 |
+ except Exception as e: |
|
82 |
+ self.logger.error("Unable to build tool chain.") |
|
83 |
+ raise e |
|
84 |
+ finally: |
|
85 |
+ if chrootID is not None: |
|
91 | 86 |
chrUtils.destroyChroot(chrootID) |
92 |
- return False |
|
93 |
- if package == "glibc": |
|
94 |
- if not self.adjustToolChain(chrootID): |
|
95 |
- self.logger.error("Adjusting tool chain failed. Stop building toolchain") |
|
96 |
- chrUtils.destroyChroot(chrootID) |
|
97 |
- return False |
|
98 |
- self.logger.info("Successfully built toolchain") |
|
99 |
- chrUtils.destroyChroot(chrootID) |
|
100 | 87 |
|
101 | 88 |
#tool chain should be updated before calling this method |
102 | 89 |
def installToolChain(self,chrootID): |
103 |
- if not self.prepareChroot(chrootID,"minimal"): |
|
104 |
- self.logger.error("Unable to install tool chain.") |
|
105 |
- return False |
|
90 |
+ self.logger.info("Installing toolchain.....") |
|
91 |
+ self.prepareChroot(chrootID,"minimal") |
|
106 | 92 |
pkgUtils= PackageUtils(self.logName,self.logPath) |
107 | 93 |
for package in self.listPkgsToInstallToolChain: |
108 |
- returnVal = pkgUtils.installRPM(package, chrootID, True) |
|
109 |
- if not returnVal: |
|
110 |
- self.logger.error("Error while installing toolchain on chroot:"+chrootID) |
|
111 |
- return False |
|
94 |
+ pkgUtils.installRPM(package, chrootID, True) |
|
112 | 95 |
if package == "glibc": |
113 |
- if not self.adjustToolChain(chrootID): |
|
114 |
- self.logger.error("Adjusting tool chain failed. Stop building toolchain") |
|
115 |
- return False |
|
96 |
+ self.adjustToolChain(chrootID) |
|
116 | 97 |
cmdUtils=CommandUtils() |
117 |
- returnVal = cmdUtils.run_command("rm -rf "+ chrootID+"/tools") |
|
118 |
- if not returnVal: |
|
119 |
- self.logger.error("Error while removing toolchain tar from chroot:"+chrootID) |
|
120 |
- return False |
|
121 |
- returnVal = cmdUtils.run_command("rm "+ chrootID+"/"+constants.topDirPath+"/RPMS/x86_64/*") |
|
122 |
- returnVal = cmdUtils.run_command("rm "+ chrootID+"/"+constants.topDirPath+"/RPMS/noarch/*") |
|
98 |
+ cmdUtils.runCommandInShell("rm -rf "+ chrootID+"/tools") |
|
99 |
+ cmdUtils.runCommandInShell("rm "+ chrootID+"/"+constants.topDirPath+"/RPMS/x86_64/*") |
|
100 |
+ cmdUtils.runCommandInShell("rm "+ chrootID+"/"+constants.topDirPath+"/RPMS/noarch/*") |
|
123 | 101 |
self.logger.info("Installed tool chain successfully on chroot:"+chrootID) |
124 |
- return True |
|
125 | 102 |
|
126 | 103 |
def adjustToolChain(self,chrootID): |
127 | 104 |
shutil.copy2(self.adjustToolChainScript, chrootID+"/tmp") |
... | ... |
@@ -129,8 +105,11 @@ class ToolChainUtils(object): |
129 | 129 |
shutil.copy2(self.localegenConfig, chrootID+"/etc") |
130 | 130 |
cmdUtils=CommandUtils() |
131 | 131 |
logFile=constants.logPath+"/adjustToolChainScript.log" |
132 |
- returnVal = cmdUtils.run_command("/tmp/"+self.adjustToolChainScript,logFile, "./run-in-chroot.sh "+chrootID) |
|
133 |
- return returnVal |
|
132 |
+ returnVal = cmdUtils.runCommandInShell("/tmp/"+self.adjustToolChainScript,logFile, "./run-in-chroot.sh "+chrootID) |
|
133 |
+ if not returnVal: |
|
134 |
+ self.logger.error("Adjust tool chain script failed.") |
|
135 |
+ raise Exception("Adjust tool chain script failed") |
|
136 |
+ |
|
134 | 137 |
|
135 | 138 |
|
136 | 139 |
|
... | ... |
@@ -34,11 +34,11 @@ def main(): |
34 | 34 |
|
35 | 35 |
cmdUtils=CommandUtils() |
36 | 36 |
if not os.path.isdir(options.logPath): |
37 |
- cmdUtils.run_command("mkdir -p "+options.logPath) |
|
37 |
+ cmdUtils.runCommandInShell("mkdir -p "+options.logPath) |
|
38 | 38 |
|
39 | 39 |
if not os.path.isdir(options.rpmPath): |
40 |
- cmdUtils.run_command("mkdir -p "+options.rpmPath+"/x86_64") |
|
41 |
- cmdUtils.run_command("mkdir -p "+options.rpmPath+"/noarch") |
|
40 |
+ cmdUtils.runCommandInShell("mkdir -p "+options.rpmPath+"/x86_64") |
|
41 |
+ cmdUtils.runCommandInShell("mkdir -p "+options.rpmPath+"/noarch") |
|
42 | 42 |
|
43 | 43 |
logger=Logger.getLogger(options.logPath+"/Main") |
44 | 44 |
logger.info("Source Path :"+options.sourcePath) |