]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/VerSection.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / VerSection.py
1 ## @file
2 # process Version section generation
3 #
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8
9 ##
10 # Import Modules
11 #
12 from __future__ import absolute_import
13 from .Ffs import SectionSuffix
14 import Common.LongFilePathOs as os
15 from .GenFdsGlobalVariable import GenFdsGlobalVariable
16 from CommonDataClass.FdfClass import VerSectionClassObject
17 from Common.LongFilePathSupport import OpenLongFilePath as open
18 from Common.DataType import SUP_MODULE_SEC
19
20 ## generate version section
21 #
22 #
23 class VerSection (VerSectionClassObject):
24
25 ## The constructor
26 #
27 # @param self The object pointer
28 #
29 def __init__(self):
30 VerSectionClassObject.__init__(self)
31
32 ## GenSection() method
33 #
34 # Generate version section
35 #
36 # @param self The object pointer
37 # @param OutputPath Where to place output file
38 # @param ModuleName Which module this section belongs to
39 # @param SecNum Index of section
40 # @param KeyStringList Filter for inputs of section generation
41 # @param FfsInf FfsInfStatement object that contains this section data
42 # @param Dict dictionary contains macro and its value
43 # @retval tuple (Generated file name, section alignment)
44 #
45 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):
46 #
47 # Prepare the parameter of GenSection
48 #
49 if FfsInf:
50 self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)
51 self.BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)
52 self.StringData = FfsInf.__ExtendMacro__(self.StringData)
53 self.FileName = FfsInf.__ExtendMacro__(self.FileName)
54
55 OutputFile = os.path.join(OutputPath,
56 ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get('VERSION'))
57 OutputFile = os.path.normpath(OutputFile)
58
59 # Get String Data
60 StringData = ''
61 if self.StringData:
62 StringData = self.StringData
63 elif self.FileName:
64 FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
65 FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
66 FileObj = open(FileNameStr, 'r')
67 StringData = FileObj.read()
68 StringData = '"' + StringData + '"'
69 FileObj.close()
70 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',
71 Ver=StringData, BuildNumber=self.BuildNum, IsMakefile=IsMakefile)
72 OutputFileList = []
73 OutputFileList.append(OutputFile)
74 return OutputFileList, self.Alignment