From 9424f3d28e7a2c19e2f7e93145c175fd44aa84ea Mon Sep 17 00:00:00 2001 From: Alexey Makhalov Date: Sat, 25 Feb 2023 01:37:43 -0800 Subject: [PATCH] package-builder/SpecParser: parse includes Support for source files parsing included as %include %{SOURCE2} for example. Added SOURCEX to the definitions list. Change-Id: I77156866d57e1cb619e0add5790f43333cb8af69 Signed-off-by: Alexey Makhalov Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/19824 Tested-by: gerrit-photon Reviewed-by: Shreenidhi Shedi --- support/package-builder/SpecParser.py | 32 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/support/package-builder/SpecParser.py b/support/package-builder/SpecParser.py index 71dd948dc5..613a569fdf 100644 --- a/support/package-builder/SpecParser.py +++ b/support/package-builder/SpecParser.py @@ -1,4 +1,5 @@ # pylint: disable=invalid-name,missing-docstring +import os import re from StringUtils import StringUtils from SpecStructures import dependentPackageData, Package, SpecObject @@ -31,12 +32,12 @@ def __init__(self, specfile, arch): self.macro_pattern = re.compile(r'%{(\S+?)\}') self.specfile = specfile - self._parseSpecFile() - - def _parseSpecFile(self): self.packages["default"] = Package(self.arch) - currentPkg = "default" - with open(self.specfile) as specFile: + self.currentPkg = "default" + self._parseSpecFile(self.specfile) + + def _parseSpecFile(self, file): + with open(file) as specFile: lines = specFile.readlines() totalLines = len(lines) i = 0 @@ -77,7 +78,7 @@ def _parseSpecFile(self): if line.startswith('%package'): pkg = Package(self.arch, defaultpkg) pkg.name = packageName - currentPkg = packageName + self.currentPkg = packageName self.packages[pkg.name] = pkg else: if defaultpkg.name == packageName: @@ -88,21 +89,27 @@ def _parseSpecFile(self): continue self.packages[packageName].updatePackageMacro(macro) elif self._isPackageHeaders(line): - self._readPackageHeaders(line, self.packages[currentPkg]) + self._readPackageHeaders(line, self.packages[self.currentPkg]) elif self._isGlobalSecurityHardening(line): self._readSecurityHardening(line) elif self._isChecksum(line): - self._readChecksum(line, self.packages[currentPkg]) + self._readChecksum(line, self.packages[self.currentPkg]) elif self._isExtraBuildRequires(line): - self._readExtraBuildRequires(line, self.packages[currentPkg]) + self._readExtraBuildRequires(line, self.packages[self.currentPkg]) elif self._isBuildRequiresNative(line): - self._readBuildRequiresNative(line, self.packages[currentPkg]) + self._readBuildRequiresNative(line, self.packages[self.currentPkg]) elif self._isDefinition(line): self._readDefinition(line) elif self._isConditionalCheckMacro(line): self.conditionalCheckMacroEnabled = True elif self.conditionalCheckMacroEnabled and self._isConditionalMacroEnd(line): self.conditionalCheckMacroEnabled = False + elif self._isInclude(line): + include = line.split() + if len(include) == 2: + includeFile = os.path.join(os.path.dirname(file), self._replaceMacros(include[1])) + # recursive parsing + self._parseSpecFile(includeFile) else: self.specAdditionalContent += line + "\n" i = i + 1 @@ -389,6 +396,8 @@ def _readPackageHeaders(self, line, pkg): return True if 'source' in headerName: pkg.sources.append(headerContent) + sourceNum = headerName[6:] + self.defs[f"SOURCE{sourceNum}"] = headerContent return True if 'patch' in headerName: pkg.patches.append(headerContent) @@ -514,6 +523,9 @@ def _isConditionalMacroStart(self, line): def _isConditionalMacroEnd(self, line): return line.strip() == "%endif" + def _isInclude(self, line): + return line.startswith("%include") + ######################################################################## # SpecObject generating functions ########################################################################