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