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