Browse code

Manually cherry pick commit 5fc28b16ccc803 5fc28b16ccc803dbb6169ec3eb12b7fd349e1c8e

Change-Id: I9b5f6b2d7725f9e59895b2c013776552ec590d42
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4550
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Xiaolin Li <xiaolinl@vmware.com>

Rui Gu authored on 2017/12/21 11:26:54
Showing 1 changed files
... ...
@@ -9,7 +9,7 @@ import traceback
9 9
 import shutil
10 10
 
11 11
 class ToolChainUtils(object):
12
-    
12
+
13 13
     def __init__(self,logName=None,logPath=None):
14 14
         if logName is None:
15 15
             logName = "Toolchain Utils"
... ...
@@ -59,7 +59,7 @@ class ToolChainUtils(object):
59 59
             if rpmFile is None:
60 60
                 self.logger.error("Cannot find filesystem rpm")
61 61
                 raise Exception("Cannot find filesystem rpm")
62
-        
62
+
63 63
         self.logger.debug("Installing filesystem rpms:" + package)
64 64
         if os.geteuid()==0:
65 65
             cmd=self.rpmCommand + " -i --nodeps --root "+chrootID+" --define '_dbpath /var/lib/rpm' "+ rpmFile
... ...
@@ -70,7 +70,7 @@ class ToolChainUtils(object):
70 70
         if retval != 0:
71 71
             self.logger.error("Installing filesystem rpm failed")
72 72
             raise Exception("RPM installation failed")
73
-        
73
+
74 74
         prepareChrootCmd=self.prepareBuildRootCmd+" "+chrootID
75 75
         logFile=constants.logPath+"/prepareBuildRoot.log"
76 76
         returnVal=cmdUtils.runCommandInShell(prepareChrootCmd,logFile)
... ...
@@ -112,11 +112,11 @@ class ToolChainUtils(object):
112 112
         if retval != 0:
113 113
             self.logger.error("Installing toolchain rpms failed")
114 114
             raise Exception("RPM installation failed")
115
-        
115
+
116 116
         self.logger.info("Installed default toolchain successfully on chroot:"+chrootID)
117 117
         if "openjdk" in packageName or "openjre" in packageName:
118 118
             self.installToolChainXRPMS(chrootID);
119
-    
119
+
120 120
     def installCoreToolChainPackages(self,chrootID):
121 121
         self.logger.info("Installing toolchain.....")
122 122
         cmdUtils = CommandUtils()
... ...
@@ -144,9 +144,9 @@ class ToolChainUtils(object):
144 144
         if retval != 0:
145 145
             self.logger.error("Installing toolchain rpms failed")
146 146
             raise Exception("RPM installation failed")
147
-            
148
-        self.logger.info("Installed core tool chain packages successfully on chroot:"+chrootID)    
149
-    
147
+
148
+        self.logger.info("Installed core tool chain packages successfully on chroot:"+chrootID)
149
+
150 150
     def findRPMFileInGivenLocation(self,package,rpmdirPath):
151 151
         cmdUtils = CommandUtils()
152 152
         listFoundRPMFiles = cmdUtils.findFile(package+"-*.rpm",rpmdirPath)
... ...
@@ -164,7 +164,7 @@ class ToolChainUtils(object):
164 164
         if len(listFilterRPMFiles) > 1 :
165 165
             self.logger.error("Found multiple rpm files for given package in rpm directory.Unable to determine the rpm file for package:"+package)
166 166
             return None
167
-    
167
+
168 168
     def buildCoreToolChainPackages(self, listBuildOptionPackages, pkgBuildOptionFile):
169 169
         self.logger.info("Building core tool chain packages.....")
170 170
         chrootID=None
... ...
@@ -197,7 +197,7 @@ class ToolChainUtils(object):
197 197
             # print stacktrace
198 198
             traceback.print_exc()
199 199
             raise e
200
-                
200
+
201 201
     def installToolChainRPMS(self,chrootID, packageName):
202 202
         cmdUtils = CommandUtils()
203 203
         self.prepareBuildRoot(chrootID)
... ...
@@ -206,7 +206,10 @@ class ToolChainUtils(object):
206 206
         packages = ""
207 207
         for package in constants.listToolChainRPMPkgsToBuild:
208 208
             pkgUtils=PackageUtils(self.logName,self.logPath)
209
-            rpmFile=pkgUtils.findRPMFileForGivenPackage(package)
209
+            rpmFile = None
210
+            if ((packageName not in constants.listToolChainRPMPkgsToBuild) or
211
+                    (constants.listToolChainRPMPkgsToBuild.index(packageName) > constants.listToolChainRPMPkgsToBuild.index(package))):
212
+                rpmFile=pkgUtils.findRPMFileForGivenPackage(package)
210 213
             if rpmFile is None:
211 214
                 rpmFile=self.findRPMFileInGivenLocation(package, constants.prevPublishRPMRepo)
212 215
                 if rpmFile is None:
... ...
@@ -228,18 +231,18 @@ class ToolChainUtils(object):
228 228
         if retval != 0:
229 229
             self.logger.error("Installing tool chain  failed")
230 230
             raise Exception("RPM installation failed")
231
-            
231
+
232 232
         self.logger.info("Successfully installed default Tool Chain RPMS in Chroot:"+chrootID)
233 233
         if "openjdk" in packageName or "openjre" in packageName:
234 234
             self.installToolChainXRPMS(chrootID);
235
-   
235
+
236 236
     def installToolChainXRPMS(self, chrootID):
237 237
         self.logger.info("Installing Tool Chain X package RPMS.......")
238 238
         rpmFiles = ""
239 239
         packages = ""
240 240
         for package in constants.listToolChainXRPMsToInstall:
241 241
             pkgUtils=PackageUtils(self.logName,self.logPath)
242
-	    print "DEBUG:" + package
242
+            print "DEBUG:" + package
243 243
             rpmFile=self.findRPMFileInGivenLocation(package, constants.prevPublishXRPMRepo)
244 244
             if rpmFile is None:
245 245
                 self.logger.error("Unable to find rpm "+ package +" in current and previous versions")
... ...
@@ -248,12 +251,12 @@ class ToolChainUtils(object):
248 248
             packages += " " + package
249 249
 
250 250
         self.logger.debug("Installing rpms:"+packages)
251
-	cmd=self.rpmCommand + " -i --nodeps --force --root "+chrootID+" --define \'_dbpath /var/lib/rpm\' "+ rpmFiles
252
-	print "Command Executed:" + cmd 
251
+        cmd=self.rpmCommand + " -i --nodeps --force --root "+chrootID+" --define \'_dbpath /var/lib/rpm\' "+ rpmFiles
252
+        print "Command Executed:" + cmd
253 253
         process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE)
254 254
         retval = process.wait()
255 255
         if retval != 0:
256 256
             self.logger.error("Installing tool chain  failed")
257 257
             raise Exception("RPM installation failed")
258 258
         self.logger.info("Successfully installed all Tool Chain X RPMS")
259
- 
259
+