Skip to content

Dsc parser

dsc_parser

Code to help parse DSC files.

DscParser

Object representing a parsed DSC file with a capability to parse.

Attributes:

Name Type Description
SixMods list

list of X64 Modules (the line in the file)

SixModsEnhanced list

Better parsed (in a dict) list of X64 Modules

ThreeMods list

list of IA32 Modules (the line in the file)

ThreeModsEnhanced list

Better parsed (in a dict) list of IA32 Modules

OtherMods list

list of other Mods that are not IA32, X64 specific

Libs list

list of Libs (the line in the file)

LibsEnhanced list

Better parsed (in a dict) list of Libs

ScopedLibraryDict dict

key (library class) value (list of instances)

LibraryClassToInstanceDict dict

Key (Library class) Value (Instance)

Pcds list

List of Pcds

Note

ScopedLibraryDict can have multiple library instances for the same scope because the INF can also filter the module types it supports. For example, two library instances could be in the scope of "common", but one filters to only PEI (MyLib| PEI_CORE) and the other filters to PEIM (MyLib| PEIM).

__init__

__init__() -> HashFileParser

Init an empty Parser.

ReplacePcds

ReplacePcds(line: str) -> str

Attempts to replace a token if it is a PCD token.

ParseInfPathLib

ParseInfPathLib(line: str) -> str

Parses a line with an INF path Lib.

ParseInfPathMod

ParseInfPathMod(line: str) -> str

Parses a line with an INF path.

__ProcessMore

__ProcessMore(
    lines: list, file_name: Optional[str] = None
) -> None

Runs after ProcessDefines and does a full parsing of the DSC.

Everything is resolved to a final state

__ProcessDefines

__ProcessDefines(lines: list) -> None

Goes through a file once to look for [Define] sections.

Only Sections, DEFINE, X = Y, and !includes are resolved This resolves all the defines since they can be anywhere in a file. Ideally this should be run until we reach stable state but this parser is not accurate and is more of an approximation of what the real parser does.

SetNoFailMode

SetNoFailMode(enabled: bool = True) -> None

The parser won't throw exceptions when this is turned on.

WARNING: This can result in some weird behavior

ResetParserState

ResetParserState() -> None

Resets the parser.

ParseFile

ParseFile(filepath: str) -> None

Parses the DSC file at the provided path.

GetMods

GetMods() -> list

Returns a list with all Mods.

GetModsEnhanced

GetModsEnhanced() -> list

Returns a list with all ModsEnhanced.

GetLibs

GetLibs() -> list

Returns a list with all Libs.

GetLibsEnhanced

GetLibsEnhanced() -> list

Returns a list with all LibsEnhanced.

GetAllDscPaths

GetAllDscPaths() -> set

Returns a list with all the paths that this DSC uses (the base file and any includes).

They are not all guaranteed to be DSC files

RegisterPcds

RegisterPcds(line: str) -> None

Reads the line and registers any PCDs found.