Browse code

Added separate target to generate yaml files for packages and also Added logic to take blacklist packages for yaml file generation

Change-Id: Icb36a44dbe4b68c1134d754dac3122b8512c7251
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/2942
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

dthaluru authored on 2017/06/15 04:54:13
Showing 3 changed files
... ...
@@ -70,7 +70,7 @@ IMGCONVERTER := $(TOOLS_BIN)/imgconverter
70 70
 
71 71
 .PHONY : all iso clean photon-build-machine photon-vagrant-build photon-vagrant-local cloud-image \
72 72
 check-tools check-docker check-bison check-g++ check-gawk check-createrepo check-kpartx check-vagrant check-packer check-packer-ovf-plugin check-sanity \
73
-clean-install clean-chroot build-updated-packages check
73
+clean-install clean-chroot build-updated-packages check generate-yaml-files
74 74
 
75 75
 THREADS?=1
76 76
 
... ...
@@ -533,6 +533,27 @@ check: packages
533 533
                               $(PHOTON_RPMCHECK_FLAGS) \
534 534
                               -l $(PHOTON_LOGS_DIR)
535 535
 
536
+generate-yaml-files: check $(PHOTON_STAGE) $(PHOTON_PACKAGES)
537
+	@echo "Generating yaml files for packages ..."
538
+	@cd $(PHOTON_PKG_BUILDER_DIR) && \
539
+        $(PHOTON_PACKAGE_BUILDER) -y \
540
+                              -b $(PHOTON_CHROOT_PATH) \
541
+                              -s $(PHOTON_SPECS_DIR) \
542
+                              -r $(PHOTON_RPMS_DIR) \
543
+                              -a $(PHOTON_SRPMS_DIR) \
544
+                              -x $(PHOTON_SRCS_DIR) \
545
+                              -p $(PHOTON_PUBLISH_RPMS_DIR) \
546
+                              -e $(PHOTON_PUBLISH_XRPMS_DIR) \
547
+                              -c $(PHOTON_PULLSOURCES_CONFIG) \
548
+                              -d $(PHOTON_DIST_TAG) \
549
+                              -n $(PHOTON_BUILD_NUMBER) \
550
+                              -v $(PHOTON_RELEASE_VERSION) \
551
+                              -g $(PHOTON_DATA_DIR)/pkg_build_options.json \
552
+                              $(PHOTON_RPMCHECK_OPTION) \
553
+                              -l $(PHOTON_LOGS_DIR) \
554
+                              -j $(PHOTON_STAGE) \
555
+                              -f $(PHOTON_PKG_BLACKLIST_FILE)
556
+
536 557
 $(TOOLS_BIN):
537 558
 	mkdir -p $(TOOLS_BIN)
538 559
 
... ...
@@ -65,3 +65,5 @@ PHOTON_BUILD_NUMBER=$(shell git rev-parse --short HEAD)
65 65
 PHOTON_RELEASE_MAJOR_ID=2.0
66 66
 PHOTON_RELEASE_MINOR_ID=
67 67
 PHOTON_RELEASE_VERSION=$(PHOTON_RELEASE_MAJOR_ID)$(PHOTON_RELEASE_MINOR_ID)
68
+
69
+PHOTON_PKG_BLACKLIST_FILE=""
... ...
@@ -39,6 +39,9 @@ def main():
39 39
     parser.add_argument("-g",  "--pkg-build-option-file",  dest="pkgBuildOptionFile",  default="../../common/data/pkg_build_options.json")
40 40
     parser.add_argument("-q",  "--rpmcheck-stop-on-error", dest="rpmCheckStopOnError",  default=False, action ="store_true")
41 41
 
42
+    parser.add_argument("-y",  "--generate-pkg-yaml-files",  dest="generatePkgYamlFiles",  default=False, action ="store_true")
43
+    parser.add_argument("-j",  "--pkg-yaml-dir-path",  dest="pkgYamlDirPath",  default="../../stage/")
44
+    parser.add_argument("-f",  "--pkg-blacklist-file",  dest="pkgBlacklistFile",  default=None)
42 45
     parser.add_argument("PackageName", nargs='?')
43 46
     options = parser.parse_args()
44 47
     cmdUtils=CommandUtils()
... ...
@@ -81,6 +84,11 @@ def main():
81 81
         logger.error("Given input RPMS Path is not a directory:"+options.inputRPMSPath)
82 82
         errorFlag = True
83 83
 
84
+    if options.generatePkgYamlFiles:
85
+        if options.pkgBlacklistFile is not None and options.pkgBlacklistFile != "" and not os.path.isfile(options.pkgBlacklistFile):
86
+            logger.error("Given package blacklist file is not valid:"+options.pkgBlacklistFile)
87
+            errorFlag = True
88
+
84 89
     if options.installPackage :
85 90
         if not options.PackageName:
86 91
             logger.error("Please provide package name")
... ...
@@ -103,6 +111,10 @@ def main():
103 103
     if not os.path.isdir(options.buildRootPath):
104 104
         cmdUtils.runCommandInShell("mkdir -p "+options.buildRootPath)
105 105
 
106
+    if options.generatePkgYamlFiles:
107
+        if not os.path.isdir(options.pkgYamlDirPath):
108
+            cmdUtils.runCommandInShell("mkdir -p "+options.pkgYamlDirPath)
109
+
106 110
     logger.info("Source Path :"+options.sourcePath)
107 111
     logger.info("Spec Path :" + options.specPath)
108 112
     logger.info("Rpm Path :" + options.rpmPath)
... ...
@@ -120,14 +132,10 @@ def main():
120 120
         constants.initialize(options)
121 121
         if package == "packages_list":
122 122
             buildPackagesList(options.buildRootPath+"/../packages_list.csv")
123
-        elif package == "sources_list":
124
-            if not os.path.isdir("../../stage/yaml_sources"):
125
-                cmdUtils.runCommandInShell("mkdir -p ../../stage/yaml_sources")
126
-            buildSourcesList('../../stage/yaml_sources',logger)
127
-        elif package == "srpms_list":
128
-            if not os.path.isdir("../../stage/yaml_srpms"):
129
-                cmdUtils.runCommandInShell("mkdir -p ../../stage/yaml_srpms")
130
-            buildSRPMList(options.sourceRpmPath,"../../stage/yaml_srpms",logger)
123
+        elif options.generatePkgYamlFiles:
124
+            blackListPkgs = readBlackListPackages(options.pkgBlacklistFile)
125
+            buildSourcesList(options.pkgYamlDirPath, blackListPkgs, logger)
126
+            buildSRPMList(options.sourceRpmPath, options.pkgYamlDirPath, blackListPkgs, logger)
131 127
         elif options.toolChainStage == "stage1":
132 128
             pkgManager = PackageManager()
133 129
             pkgManager.buildToolChain()
... ...
@@ -168,14 +176,28 @@ def buildPackagesList(csvFilename):
168 168
         csvFile.write(name+","+version+","+license+","+url+","+sources+","+patches+"\n")
169 169
     csvFile.close()
170 170
 
171
-def buildSourcesList(yamlDir, logger, singleFile=True):
172
-    strUtils = StringUtils()
171
+def readBlackListPackages(pkgBlackListFile):
172
+    blackListPkgs = []
173
+    if pkgBlackListFile is not None and pkgBlackListFile != "":
174
+        with open(pkgBlackListFile) as jsonFile:
175
+            config = json.load(jsonFile)
176
+            if 'packages' in config:
177
+                blackListPkgs = config['packages']
178
+    return blackListPkgs
179
+
180
+def buildSourcesList(yamlDir, blackListPkgs, logger, singleFile=True):
181
+    cmdUtils = CommandUtils()
182
+    yamlSourceDir = os.path.join(yamlDir, "yaml_sources")
183
+    if not os.path.isdir(yamlSourceDir):
184
+        cmdUtils.runCommandInShell("mkdir -p "+yamlSourceDir)
173 185
     if singleFile:
174
-        yamlFile = open(yamlDir+"/sources_list.yaml", "w")
186
+        yamlFile = open(yamlSourceDir+"/sources_list.yaml", "w")
175 187
     listPackages =  constants.specData.getListPackages()
176 188
     listPackages.sort()
177 189
     import PullSources
178 190
     for package in listPackages:
191
+        if package in blackListPkgs:
192
+            continue
179 193
         ossname = package
180 194
         ossversion = constants.specData.getVersion(package)
181 195
         modified = False
... ...
@@ -195,7 +217,7 @@ def buildSourcesList(yamlDir, logger, singleFile=True):
195 195
                 PullSources.get(sourceName, sha1, yamlDir, constants.pullsourcesConfig, logger)
196 196
 
197 197
         if not singleFile:
198
-            yamlFile = open(yamlDir+"/"+ossname+"-"+ossversion+".yaml", "w")
198
+            yamlFile = open(yamlSourceDir+"/"+ossname+"-"+ossversion+".yaml", "w")
199 199
         yamlFile.write("vmwsource:"+ossname+":"+ossversion+":\n")
200 200
         yamlFile.write("  repository: VMWsource\n")
201 201
         yamlFile.write("  name: '"+ossname+"'\n")
... ...
@@ -214,14 +236,18 @@ def buildSourcesList(yamlDir, logger, singleFile=True):
214 214
         yamlFile.close()
215 215
     logger.info("Generated source yaml files for all packages")
216 216
 
217
-def buildSRPMList(srpmPath, yamlDir, logger, singleFile=True):
218
-    strUtils = StringUtils()
217
+def buildSRPMList(srpmPath, yamlDir, blackListPkgs, logger, singleFile=True):
218
+    cmdUtils = CommandUtils()
219
+    yamlSrpmDir = os.path.join(yamlDir, "yaml_srpms")
220
+    if not os.path.isdir(yamlSrpmDir):
221
+        cmdUtils.runCommandInShell("mkdir -p "+yamlSrpmDir)
219 222
     if singleFile:
220
-        yamlFile = open(yamlDir+"/srpm_list.yaml", "w")
223
+        yamlFile = open(yamlSrpmDir+"/srpm_list.yaml", "w")
221 224
     listPackages =  constants.specData.getListPackages()
222 225
     listPackages.sort()
223
-    cmdUtils = CommandUtils()
224 226
     for package in listPackages:
227
+        if package in blackListPkgs:
228
+            continue
225 229
         ossname = package
226 230
         ossversion = constants.specData.getVersion(package)
227 231
         ossrelease = constants.specData.getRelease(package)
... ...
@@ -239,7 +265,7 @@ def buildSRPMList(srpmPath, yamlDir, logger, singleFile=True):
239 239
              logger.error("SRPM file is not found:" +ossname)
240 240
 
241 241
         if not singleFile:
242
-            yamlFile = open(yamlDir+"/"+ossname+"-"+ossversion+"-"+ossrelease+".yaml", "w")
242
+            yamlFile = open(yamlSrpmDir+"/"+ossname+"-"+ossversion+"-"+ossrelease+".yaml", "w")
243 243
 
244 244
         yamlFile.write("baseos:"+ossname+":"+ossversion+"-"+ossrelease+":\n")
245 245
         yamlFile.write("  repository: BaseOS\n")