-
Notifications
You must be signed in to change notification settings - Fork 248
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
- Loading branch information
Showing
4 changed files
with
147 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,36 @@ | ||
# 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 | ||
""" | ||
return re.sub(r"<<(?!<)", Inheritance.MERGE_OPERATOR, 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,53 @@ | ||
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 |
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