-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved inheritance centralized inheritance calls remove extra import fixed lint issues improved yaml_merge_2_fusesoc_merge()
- Loading branch information
Showing
4 changed files
with
162 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright FuseSoC contributors | ||
# Licensed under the 2-Clause BSD License, see LICENSE for details. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
|
||
import copy | ||
import re | ||
|
||
from fusesoc import utils | ||
|
||
|
||
class Inheritance: | ||
MERGE_OPERATOR = "<<__FUSESOC_MERGE_OVERLOAD__<<" | ||
|
||
def yaml_merge_2_fusesoc_merge(capi): | ||
""" | ||
Replace YAML merge key operator (<<) with FuseSoC merge operator | ||
""" | ||
yaml_merge_pattern = r'((?:\n|{|\{\s*(?:[^{}]*\{[^{}]*\})*[^{}]*\},)\s*)<<(?=\s*:)' | ||
while re.search(yaml_merge_pattern, capi): | ||
capi = re.sub(yaml_merge_pattern, r'\1' + Inheritance.MERGE_OPERATOR, capi) | ||
return capi | ||
|
||
def elaborate_inheritance(capi): | ||
if not isinstance(capi, dict): | ||
return capi | ||
|
||
for key, value in capi.items(): | ||
if isinstance(value, dict): | ||
capi[key] = Inheritance.elaborate_inheritance(copy.deepcopy(value)) | ||
|
||
parent = capi.pop(Inheritance.MERGE_OPERATOR, {}) | ||
if isinstance(parent, dict): | ||
capi = utils.merge_dict(parent, capi, concat_list_appends_only=True) | ||
else: | ||
raise SyntaxError("Invalid use of inheritance operator") | ||
|
||
return capi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
CAPI=2: | ||
# Copyright FuseSoC contributors | ||
# Licensed under the 2-Clause BSD License, see LICENSE for details. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
|
||
name: ::inheritance:0 | ||
filesets: | ||
fileset_a: | ||
files: | ||
- 1.txt | ||
- 2.txt | ||
- 3.txt | ||
fileset_b: | ||
files: | ||
- 4.txt | ||
- 5.txt | ||
- 6.txt | ||
fileset_c: | ||
files: | ||
- 7.txt | ||
- 8.txt | ||
- 9.txt | ||
|
||
targets: | ||
default: &default | ||
filesets: | ||
- fileset_a | ||
child: &child | ||
<<: *default | ||
filesets_append: | ||
- fileset_b | ||
grandchild: &grandchild | ||
<<: *child | ||
filesets_append: | ||
- fileset_c | ||
child2: &child2 | ||
<<: *default | ||
filesets: | ||
- fileset_b | ||
filesets_append: | ||
- fileset_c | ||
|
||
subfield: &subfield | ||
tools: | ||
verilator: | ||
mode: cc | ||
verilator_options: | ||
- --timing | ||
subfield_child: | ||
<<: *subfield | ||
tools: | ||
verilator: | ||
mode: lint-only | ||
|
||
merge_test1: {<<: *default} | ||
merge_test2<<: {tools: {2<<: {}}} | ||
<<merge_test3: {tools: {<<3: {}}} | ||
merge_test4: {tools: {t4: {t44: <<4, <<: *default}}, <<: *default} | ||
merge_test5: {<<__FUSESOC_MERGE_OVERLOAD__<<: *default} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters