diff --git a/edk2toollib/uefi/edk2/parsers/base_parser.py b/edk2toollib/uefi/edk2/parsers/base_parser.py index 45199c65..ac792b8f 100644 --- a/edk2toollib/uefi/edk2/parsers/base_parser.py +++ b/edk2toollib/uefi/edk2/parsers/base_parser.py @@ -546,12 +546,14 @@ def _TokenizeConditional(cls: "BaseParser", text: str) -> str: mode = 0 tokens = [] for character in text: - if character == '"' and len(token) == 0: + if character == '"' and len(token) == 0 and mode != QUOTE_MODE: mode = QUOTE_MODE elif character == '"' and mode == QUOTE_MODE: if len(token) > 0: tokens.append(f'"{token}"') token = "" + else: + tokens.append('""') mode = TEXT_MODE elif character == "$" and len(token) == 0: token += character diff --git a/tests.unit/parsers/test_dsc_parser.py b/tests.unit/parsers/test_dsc_parser.py index 226c3b8d..b367bb2a 100644 --- a/tests.unit/parsers/test_dsc_parser.py +++ b/tests.unit/parsers/test_dsc_parser.py @@ -10,6 +10,7 @@ import unittest import tempfile import os +import textwrap from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser from edk2toollib.uefi.edk2.path_utilities import Edk2Path @@ -155,3 +156,37 @@ def test_dsc_include_relative_path(self): self.assertEqual(parser.LocalVars["INCLUDED"], "TRUE") # make sure we got the defines finally: os.chdir(cwd) + + def test_dsc_define_statements(self): + """This test some dsc define statements""" + SAMPLE_DSC_FILE1 = textwrap.dedent("""\ + [Defines] + PLATFORM_NAME = SomePlatformPkg + PLATFORM_GUID = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/$(PLATFORM_NAME) + + DEFINE FLAG1 = + + !if FLAG1 != "" + FLAG2 = "hi" + !endif + + !if $(FLAG2) == "hi" + [Components.IA32] + FakePath/FakePath2/FakeInf.inf + !endif + """) + workspace = tempfile.mkdtemp() + + file1_name = "file1.dsc" + file1_path = os.path.join(workspace, file1_name) + TestDscParserIncludes.write_to_file(file1_path, SAMPLE_DSC_FILE1) + try: + parser = DscParser() + parser.SetEdk2Path(Edk2Path(workspace, [])) + parser.ParseFile(file1_path) + finally: + os.remove(file1_path) + assert any("FakePath/FakePath2/FakeInf.inf" in value for value in parser.Components)