Browse code

package builder: Simplify the paths calling into buildPackages()

We have 3 main options to build packages -
- build a single package
- build the packages listed in a json input file
- build all packages in the codebase

There is quite a bit of code duplication just among these 3 paths.
Simplify it by using a common routine called buildSpecifiedPackages().
Also reorder the arguments for these functions to be consistent, and
remove the now unnecessary buildAPackage().

While at it, remove the pkgBuildType argument from buildPackages(),
since the PackageManager already gets that parameter during
instantiation.

Change-Id: I3d09bb7a4df5a9568ea2adf6218492ec7dfc0c2d
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5964
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Srivatsa S. Bhat <srivatsab@vmware.com>

Srivatsa S. Bhat (VMware) authored on 2018/10/27 09:15:20
Showing 2 changed files
... ...
@@ -63,8 +63,7 @@ class PackageManager(object):
63 63
             #TODO: rebuild container only if anything in listToolChainPackages was built
64 64
             self._createBuildContainer()
65 65
 
66
-    def buildPackages(self, listPackages, buildThreads, pkgBuildType):
67
-        self.pkgBuildType = pkgBuildType
66
+    def buildPackages(self, listPackages, buildThreads):
68 67
         if constants.rpmCheck:
69 68
             constants.rpmCheck = False
70 69
             self.buildToolChainPackages(buildThreads)
... ...
@@ -179,13 +179,13 @@ def main():
179 179
             pkgManager = PackageManager()
180 180
             pkgManager.buildToolChainPackages(options.buildThreads)
181 181
         elif options.installPackage:
182
-            buildAPackage(package, options.buildThreads, options.pkgBuildType)
182
+            buildSpecifiedPackages([package], options.buildThreads, options.pkgBuildType)
183 183
         elif options.pkgJsonInput:
184
-            buildPackagesInJson(logger, options.buildThreads, pkgInfoJsonFile,
185
-                                     options.pkgJsonInput, options.pkgBuildType)
184
+            buildPackagesInJson(options.pkgJsonInput, options.buildThreads,
185
+                                options.pkgBuildType, pkgInfoJsonFile, logger)
186 186
         else:
187
-            buildPackagesForAllSpecs(logger, options.buildThreads, pkgInfoJsonFile,
188
-                                     options.pkgBuildType)
187
+            buildPackagesForAllSpecs(options.buildThreads, options.pkgBuildType,
188
+                                     pkgInfoJsonFile, logger)
189 189
     except Exception as e:
190 190
         logger.error("Caught an exception")
191 191
         logger.error(str(e))
... ...
@@ -195,41 +195,32 @@ def main():
195 195
     sys.exit(0)
196 196
 
197 197
 
198
-def buildAPackage(package, buildThreads, pkgBuildType):
199
-    listPackages = [package]
200
-    pkgManager = PackageManager(pkgBuildType=pkgBuildType)
198
+def buildSpecifiedPackages(listPackages, buildThreads, pkgBuildType, pkgInfoJsonFile=None, logger=None):
201 199
     if constants.rpmCheck:
202 200
         constants.setTestForceRPMS(copy.copy(listPackages))
203
-    pkgManager.buildPackages(listPackages, buildThreads, pkgBuildType)
201
+    pkgManager = PackageManager(pkgBuildType=pkgBuildType)
202
+    pkgManager.buildPackages(listPackages, buildThreads)
203
+
204
+    if pkgInfoJsonFile is not None:
205
+        # Generating package info file which is required by installer
206
+        if logger is not None:
207
+            logger.debug("Writing Package info to the file:" + pkgInfoJsonFile)
208
+        pkgInfo = PackageInfo()
209
+        pkgInfo.loadPackagesData()
210
+        pkgInfo.writePkgListToFile(pkgInfoJsonFile)
204 211
 
205
-def buildPackagesInJson(logger, buildThreads, pkgInfoJsonFile, pkgJsonInput, pkgBuildType):
212
+
213
+def buildPackagesInJson(pkgJsonInput, buildThreads, pkgBuildType, pkgInfoJsonFile, logger):
206 214
     listPackages = []
207 215
     with open(pkgJsonInput) as jsonData:
208 216
         pkg_list_json = json.load(jsonData)
209 217
         listPackages = pkg_list_json["packages"]
210
-    if constants.rpmCheck:
211
-        constants.setTestForceRPMS(copy.copy(listPackages))
212
-    pkgManager = PackageManager(pkgBuildType=pkgBuildType)
213
-    pkgManager.buildPackages(listPackages, buildThreads, pkgBuildType)
218
+    buildSpecifiedPackages(listPackages, buildThreads, pkgBuildType, pkgInfoJsonFile, logger)
214 219
 
215
-    # Generating package info file which is required by installer
216
-    logger.debug("Writing Package info to the file:" + pkgInfoJsonFile)
217
-    pkgInfo = PackageInfo()
218
-    pkgInfo.loadPackagesData()
219
-    pkgInfo.writePkgListToFile(pkgInfoJsonFile)
220 220
 
221
-def buildPackagesForAllSpecs(logger, buildThreads, pkgInfoJsonFile, pkgBuildType):
221
+def buildPackagesForAllSpecs(buildThreads, pkgBuildType, pkgInfoJsonFile, logger):
222 222
     listPackages = SPECS.getData().getListPackages()
223
-    if constants.rpmCheck:
224
-        constants.setTestForceRPMS(copy.copy(listPackages))
225
-    pkgManager = PackageManager(pkgBuildType=pkgBuildType)
226
-    pkgManager.buildPackages(listPackages, buildThreads, pkgBuildType)
227
-
228
-    # Generating package info file which is required by installer
229
-    logger.debug("Writing Package info to the file:" + pkgInfoJsonFile)
230
-    pkgInfo = PackageInfo()
231
-    pkgInfo.loadPackagesData()
232
-    pkgInfo.writePkgListToFile(pkgInfoJsonFile)
223
+    buildSpecifiedPackages(listPackages, buildThreads, pkgBuildType, pkgInfoJsonFile, logger)
233 224
 
234 225
 
235 226
 def get_packages_with_build_options(pkg_build_options_file):