Skip to content

[Bug]: base_parser.TargetFilePath not reverted when exiting an !include parse #394

@Javagedes

Description

@Javagedes

Contact Details

No response

Describe the Bug

Per section 2.2.5 of the DSC specification, when searching for an !include filepath, the first location to check is relative to the directory containing the currently parsed file.

edk2-pytool-library emulates this functionality by storing the currently parsed file in TargetFilePath so that if we need to find another include, we are looking in the correct relative directory. The bug, is that we do not revert TargetFilePath to the previous file when we are done parsing an included file. This means that searches for additional includes could fail as the relative directory we look for is incorrect.

Example

Folder layout we are parsing

src
└─ Platforms
  └─ PlatformPkg
    ├─ PlatformPkg.dsc
    └─ includes
      ├─ PCDs1.dsc.inc
      └─ PCDs2.dsc.inc   

Abbreviated DSC we are parsing

[PcdsFixedAtBuild]
gPlatformPkgTokenSpaceGuid.PcdSomethig
!include includes/PCDs1.dsc.inc
!include includes/PCDs2.dsc.inc

When we start parsing PlatformPkg.dsc, TargetFilePath is ~/src/Platforms/PlatformPkg/PlatformPkg.dsc.

When we start parsing the first include, the relative import is a success because the ~src/Platforms/PlatformPkg/ + includes/PCDs1.dsc.inc exists. We then update TargetFilePath to ~/src/Platforms/PlatformPkg/includes/PCDs1.dsc.inc.

When we start parsing the second include, we fail because TargetFilePath was not reverted back to ~/src/Platforms/PlatformPkg/PlatformPkg.dsc. Since it remains the same, we think the file path should be ~src/Platforms/PlatformPkg/includes/includes/PCDs2.dsc.inc, which is wrong.

Reproduction steps

Update your two dscs to use two relative path includes (not macro defined absolute paths or edk2 package path relative paths) and the parsing will fail.

!include relative/myfile1.dsc
!include relative/myfile2.dsc
!include relative/myfile3.dsc

Expected behavior

Parsing should correctly update TargetFilePath and relative includes should not fail.

What Python version are you using?

Python 3.9, Python 3.10, Python 3.11

Execution Environment

No response

Pip packages

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions