-
Notifications
You must be signed in to change notification settings - Fork 0
Edk2 Metafile Parser
In one build process, the data of metadata files are stored in multiple tables which are implemented by python List. Those data are organized like a relational database. There is one table to record all metadata file basic information such as file name, file path, timestamp and etc. And there are multiple table to store dsc file content, inf file content and dec file content.
The MetaFileParser class has a member of MetaFileTable which is the table to store the metadata file content mentioned above. MetaFileParser parses the metadata file and insert each line content into MetaFileTable and provides a [] style access method to query data from MetaFileTable.
Fdf file parser is implemented as another style.
The parameters of DscParser initialization function are:
- FilePath: Path to dsc file
- FileType: MODEL_FILE_DSC which is evaluated to a number 1013
- Arch
- Table: a instance of MetaFileStorage class whose initialization parameters are:
- a instance of WorkspaceDatabase class.
- FilePath
- FileType
- Owner: For the root dsc file the value is -1, for the included dsc file, the value is the ID of the line of "!include" statement from its parent.
- From: For the root dsc file the value is -1, for the included dsc file, the value is the ID of the line of "!include" statement from its parent.
WorkspaceDatabase is for storing the all metadata files' basic information, such as file path, timestamp and etc.
The parsing process has two steps. One (StartParse) is to read the dsc file, replace the Macro, check format, and store its content into a DscParser instance internal list called _RawTable
. The other step (_PostProcess) is to read each line in _RawTable
and do further processing including Macro replacement, syntax checking, included file extending, directive evaluation, and store the result into another internal list _Table
The schema of _Table
and _RawTable
are the same.
ID REAL PRIMARY KEY,
Model INTEGER NOT NULL, // Section Name
Value1 TEXT NOT NULL,
Value2 TEXT,
Value3 TEXT,
Scope1 TEXT,
Scope2 TEXT,
Scope3 TEXT,
BelongsToItem REAL NOT NULL,
FromItem REAL NOT NULL,
StartLine INTEGER NOT NULL,
StartColumn INTEGER NOT NULL,
EndLine INTEGER NOT NULL,
EndColumn INTEGER NOT NULL,
Enabled INTEGER DEFAULT 0
Using [] style to query data of dsc file. The query condition can be Model, Scope1 and Scope2 which are map to the section header [Model.Scope1.Scope2], Scope1 and Scope2 are optional. The data from a query is a list. Each item in that list is a tuple of ( Value1, Value2, Value3, Scope1, Scope2, Scope3, record Id, Line Number). The meaning of each field depends on the parser of each section.
For example, to retrieve Module info from dsc, the user can do:
RecordList = DscParser[MODEL_PCD_DYNAMIC_EX_HII, 'IA32']
for Record in RecordList:
(TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, DefaultStoreName, Id, LineNum) = Record
...
The schema of Inf file MetaData Table:
ID REAL PRIMARY KEY,
Model INTEGER NOT NULL,
Value1 TEXT NOT NULL,
Value2 TEXT,
Value3 TEXT,
Scope1 TEXT,
Scope2 TEXT,
BelongsToItem REAL NOT NULL,
StartLine INTEGER NOT NULL,
StartColumn INTEGER NOT NULL,
EndLine INTEGER NOT NULL,
EndColumn INTEGER NOT NULL,
Enabled INTEGER DEFAULT 0
Inf file does not support !include and other instruction, so there is just one table inside inf parser object and there is no _PostProcess step.
The schema of Dec file MetaData Table:
ID REAL PRIMARY KEY,
Model INTEGER NOT NULL,
Value1 TEXT NOT NULL,
Value2 TEXT,
Value3 TEXT,
Scope1 TEXT,
Scope2 TEXT,
BelongsToItem REAL NOT NULL,
StartLine INTEGER NOT NULL,
StartColumn INTEGER NOT NULL,
EndLine INTEGER NOT NULL,
EndColumn INTEGER NOT NULL,
Enabled INTEGER DEFAULT 0
Inf file does not support !include and other instruction, so there is just one table inside inf parser object and there is no _PostProcess step.