diff --git a/fusesoc/capi2/core.py b/fusesoc/capi2/core.py index 724fd2ee..ecc8d0ab 100644 --- a/fusesoc/capi2/core.py +++ b/fusesoc/capi2/core.py @@ -274,6 +274,7 @@ def get_files(self, flags): if (type(v) == bool and v == True) or (type(v) == str and len(v)) > 0 or (type(v) == list and len(v)) > 0 + or (type(v) == dict and len(v)) > 0 } _src_files.append(attributes) diff --git a/fusesoc/capi2/json_schema.py b/fusesoc/capi2/json_schema.py index 74ff03fe..abc746c2 100644 --- a/fusesoc/capi2/json_schema.py +++ b/fusesoc/capi2/json_schema.py @@ -228,6 +228,25 @@ "description": "Path to file", "type": "object", "properties": { + "define": { + "description": "Defines to be used for this file. These defines will be added to those specified in the target parameters section. If a define is specified both here and in the target parameter section, the value specified here will take precedence. The parameter default value can be set here with ``param=value``", + "type": "object", + "patternProperties": { + "^.+$": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "number" + }, + { + "type": "boolean" + }, + ] + } + } + }, "is_include_file": { "description": "Treats file as an include file when true", "type": "boolean" diff --git a/tests/capi2_cores/misc/fileattrs.core b/tests/capi2_cores/misc/fileattrs.core new file mode 100644 index 00000000..44624545 --- /dev/null +++ b/tests/capi2_cores/misc/fileattrs.core @@ -0,0 +1,12 @@ +CAPI=2: + +name : ::fileattrs:0 + +filesets: + defines: + files: + - hasdefines : {define : {key1 : value1, key2 : value2}} + - nodefines + +targets: + defines: {filesets : [defines]} diff --git a/tests/test_capi2.py b/tests/test_capi2.py index 0625dbd3..89ae458d 100644 --- a/tests/test_capi2.py +++ b/tests/test_capi2.py @@ -262,6 +262,18 @@ def test_capi2_get_files(): assert expected == result + core_file = os.path.join(tests_dir, "capi2_cores", "misc", "fileattrs.core") + core = Core(Core2Parser(), core_file) + flags = {"is_toplevel": True, "target": "defines"} + result = core.get_files(flags) + expected = [ + {"name": "hasdefines", "define": {"key1": "value1", "key2": "value2"}}, + { + "name": "nodefines", + }, + ] + assert expected == result + def test_capi2_type_check(): from fusesoc.capi2.coreparser import Core2Parser