ldgen: do not generate rules when no condition is true

Closes https://github.com/espressif/esp-idf/issues/3295
This commit is contained in:
Renz Christian Bagaporo 2019-04-14 19:34:27 +08:00
parent e1592c8c81
commit 2522268c20
3 changed files with 23 additions and 5 deletions

View file

@ -276,12 +276,14 @@ class Mapping(Fragment):
MAPPING_ALL_OBJECTS = "*"
def __init__(self):
Fragment.__init__(self)
self.entries = set()
def set_key_value(self, key, parse_results):
if key == "archive":
self.archive = parse_results[0]["archive"]
elif key == "entries":
self.entries = set()
for result in parse_results:
obj = None
symbol = None
@ -321,7 +323,7 @@ class Mapping(Fragment):
grammars = {
"archive": KeyGrammar(Fragment.ENTITY.setResultsName("archive"), 1, 1, True),
"entries": KeyGrammar(entry, 1, None, True)
"entries": KeyGrammar(entry, 0, None, True)
}
return grammars

View file

@ -617,8 +617,10 @@ entries:
* (noflash) # if condition is false, then no 'entries' key value
""")
with self.assertRaises(ParseFatalException):
FragmentFile(test_fragment, self.sdkconfig)
expected = set()
fragment_file = FragmentFile(test_fragment, self.sdkconfig)
self.assertEqual(expected, fragment_file.fragments[0].entries)
test_fragment = self.create_fragment_file(u"""
[mapping:test]

View file

@ -1108,6 +1108,20 @@ entries:
self.compare_rules(expected, actual)
def test_rule_generation_empty_entries(self):
normal = u"""
[mapping:test]
archive: lib.a
entries:
if PERFORMANCE_LEVEL >= 1: # is false, generate no special rules
obj.a (noflash)
"""
self.add_fragments(normal)
actual = self.model.generate_rules(self.sections_info)
expected = self.generate_default_rules() # only default rules
self.compare_rules(expected, actual)
def test_conditional_sections_1(self):
generation_with_condition = u"""
[sections:cond_text_data]