From 2b82a60585f09e3461178e7da24ef6d51674977e Mon Sep 17 00:00:00 2001 From: Olof Kindgren Date: Mon, 4 Nov 2024 21:30:53 +0100 Subject: [PATCH] WIP: Add file-specific defines --- fusesoc/capi2/core.py | 1 + fusesoc/capi2/json_schema.py | 19 +++++++++++++++++++ tests/capi2_cores/misc/files.core | 6 ++++++ tests/test_capi2.py | 4 ++++ 4 files changed, 30 insertions(+) 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/files.core b/tests/capi2_cores/misc/files.core index dc51bfa0..0c621206 100644 --- a/tests/capi2_cores/misc/files.core +++ b/tests/capi2_cores/misc/files.core @@ -5,6 +5,11 @@ CAPI=2: name: ::copytocore:0 filesets: + defines: + files: + - hasdefines : {define : {key1 : value1, key2 : value2}} + - nodefines + logical_name: files: - vlogfile : {logical_name : overridden_logical_name} @@ -47,6 +52,7 @@ scripts: targets: default: filesets: [ + defines, logical_name, copyfiles, miscfiles, diff --git a/tests/test_capi2.py b/tests/test_capi2.py index 0625dbd3..e9b35bdc 100644 --- a/tests/test_capi2.py +++ b/tests/test_capi2.py @@ -222,6 +222,10 @@ def test_capi2_get_files(): core = Core(Core2Parser(), core_file) expected = [ + {"name": "hasdefines", "define": {"key1": "value1", "key2": "value2"}}, + { + "name": "nodefines", + }, { "file_type": "vhdlSource", "logical_name": "overridden_logical_name",