Add feature of MACRO support in FDF file.
[efi/basetools/.git] / Source / Python / GenFds / CompressSection.py
1 from Ffs import Ffs\r
2 import Section\r
3 import subprocess\r
4 import os\r
5 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
6 from CommonDataClass.FdfClassObject import CompressSectionClassObject\r
7 \r
8 class CompressSection (CompressSectionClassObject) :\r
9     CompTypeDict = {\r
10         'PI_STD'     : ' -c PI_STD ',\r
11         'NON_PI_STD' : ' -c NON_PI_STD '\r
12     }\r
13     \r
14     def __init__(self):\r
15         CompressSectionClassObject.__init__(self)\r
16         \r
17 \r
18     def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}):\r
19         #\r
20         # Generate all section\r
21         #\r
22         if FfsInf != None:\r
23             self.CompType = FfsInf.__ExtendMarco__(self.CompType)\r
24             self.Alignment = FfsInf.__ExtendMarco__(self.Alignment)\r
25             \r
26         SectFiles = ''\r
27         Index = 0\r
28         for Sect in self.SectionList:\r
29             Index = Index + 1\r
30             SecIndex = '%s.%d' %(SecNum, Index)\r
31             ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict)\r
32             if ReturnSectList != []:\r
33                 for file in ReturnSectList:\r
34                    SectFiles = SectFiles + \\r
35                                ' '       + \\r
36                                file\r
37                         \r
38 \r
39         OutputFile = OutputPath + \\r
40                      os.sep     + \\r
41                      ModuleName + \\r
42                      'SEC'      + \\r
43                      SecNum     + \\r
44                      Ffs.SectionSuffix['COMPRESS']\r
45         OutputFile = os.path.normpath(OutputFile)\r
46         \r
47         GenSectionCmd = 'GenSec -o '                                  + \\r
48                          OutputFile                                   + \\r
49                          ' -s '                                       + \\r
50                          Section.Section.SectionType['COMPRESS']      + \\r
51                          self.CompTypeDict[self.CompType]             + \\r
52                          SectFiles\r
53         #\r
54         # Call GenSection\r
55         #\r
56         GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
57         OutputFileList = []\r
58         OutputFileList.append(OutputFile)\r
59         return OutputFileList, self.Alignment\r
60 \r
61         \r