]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/VerSection.py
BaseTools: Use absolute import in GenFds
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / VerSection.py
1 ## @file
2 # process Version section generation
3 #
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 from __future__ import absolute_import
19 from .Ffs import Ffs
20 from . import Section
21 import Common.LongFilePathOs as os
22 import subprocess
23 from .GenFdsGlobalVariable import GenFdsGlobalVariable
24 from CommonDataClass.FdfClass import VerSectionClassObject
25 from Common.LongFilePathSupport import OpenLongFilePath as open
26 from Common.DataType import SUP_MODULE_SEC
27
28 ## generate version section
29 #
30 #
31 class VerSection (VerSectionClassObject):
32
33 ## The constructor
34 #
35 # @param self The object pointer
36 #
37 def __init__(self):
38 VerSectionClassObject.__init__(self)
39
40 ## GenSection() method
41 #
42 # Generate version section
43 #
44 # @param self The object pointer
45 # @param OutputPath Where to place output file
46 # @param ModuleName Which module this section belongs to
47 # @param SecNum Index of section
48 # @param KeyStringList Filter for inputs of section generation
49 # @param FfsInf FfsInfStatement object that contains this section data
50 # @param Dict dictionary contains macro and its value
51 # @retval tuple (Generated file name, section alignment)
52 #
53 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):
54 #
55 # Prepare the parameter of GenSection
56 #
57 if FfsInf is not None:
58 self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)
59 self.BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)
60 self.StringData = FfsInf.__ExtendMacro__(self.StringData)
61 self.FileName = FfsInf.__ExtendMacro__(self.FileName)
62
63 OutputFile = os.path.join(OutputPath,
64 ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get('VERSION'))
65 OutputFile = os.path.normpath(OutputFile)
66
67 # Get String Data
68 StringData = ''
69 if self.StringData is not None:
70 StringData = self.StringData
71 elif self.FileName is not None:
72 FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
73 FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
74 FileObj = open(FileNameStr, 'r')
75 StringData = FileObj.read()
76 StringData = '"' + StringData + '"'
77 FileObj.close()
78 else:
79 StringData = ''
80 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',
81 Ver=StringData, BuildNumber=self.BuildNum, IsMakefile=IsMakefile)
82 OutputFileList = []
83 OutputFileList.append(OutputFile)
84 return OutputFileList, self.Alignment