]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/CompressSection.py
BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / CompressSection.py
1 ## @file
2 # process compress 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 Ffs import Ffs
19 import Section
20 import subprocess
21 import Common.LongFilePathOs as os
22 from GenFdsGlobalVariable import GenFdsGlobalVariable
23 from CommonDataClass.FdfClass import CompressSectionClassObject
24 from Common.DataType import *
25
26 ## generate compress section
27 #
28 #
29 class CompressSection (CompressSectionClassObject) :
30
31 ## compress types: PI standard and non PI standard
32 CompTypeDict = {
33 'PI_STD' : 'PI_STD',
34 'PI_NONE' : 'PI_NONE'
35 }
36
37 ## The constructor
38 #
39 # @param self The object pointer
40 #
41 def __init__(self):
42 CompressSectionClassObject.__init__(self)
43
44 ## GenSection() method
45 #
46 # Generate compressed section
47 #
48 # @param self The object pointer
49 # @param OutputPath Where to place output file
50 # @param ModuleName Which module this section belongs to
51 # @param SecNum Index of section
52 # @param KeyStringList Filter for inputs of section generation
53 # @param FfsInf FfsInfStatement object that contains this section data
54 # @param Dict dictionary contains macro and its value
55 # @retval tuple (Generated file name, section alignment)
56 #
57 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
58
59 if FfsInf is not None:
60 self.CompType = FfsInf.__ExtendMacro__(self.CompType)
61 self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)
62
63 SectFiles = tuple()
64 SectAlign = []
65 Index = 0
66 MaxAlign = None
67 for Sect in self.SectionList:
68 Index = Index + 1
69 SecIndex = '%s.%d' %(SecNum, Index)
70 ReturnSectList, AlignValue = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=IsMakefile)
71 if AlignValue is not None:
72 if MaxAlign is None:
73 MaxAlign = AlignValue
74 if GenFdsGlobalVariable.GetAlignment (AlignValue) > GenFdsGlobalVariable.GetAlignment (MaxAlign):
75 MaxAlign = AlignValue
76 if ReturnSectList != []:
77 if AlignValue is None:
78 AlignValue = "1"
79 for FileData in ReturnSectList:
80 SectFiles += (FileData,)
81 SectAlign.append(AlignValue)
82
83 OutputFile = OutputPath + \
84 os.sep + \
85 ModuleName + \
86 SUP_MODULE_SEC + \
87 SecNum + \
88 Ffs.SectionSuffix['COMPRESS']
89 OutputFile = os.path.normpath(OutputFile)
90 DummyFile = OutputFile + '.dummy'
91 GenFdsGlobalVariable.GenerateSection(DummyFile, SectFiles, InputAlign=SectAlign, IsMakefile=IsMakefile)
92
93 GenFdsGlobalVariable.GenerateSection(OutputFile, [DummyFile], Section.Section.SectionType['COMPRESS'],
94 CompressionType=self.CompTypeDict[self.CompType], IsMakefile=IsMakefile)
95 OutputFileList = []
96 OutputFileList.append(OutputFile)
97 return OutputFileList, self.Alignment
98
99