opencos-eda 0.3.9__py3-none-any.whl → 0.3.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opencos/commands/deps_help.py +89 -120
- opencos/commands/export.py +7 -2
- opencos/commands/multi.py +3 -3
- opencos/commands/sim.py +14 -16
- opencos/commands/synth.py +1 -2
- opencos/commands/upload.py +192 -4
- opencos/commands/waves.py +8 -8
- opencos/deps/deps_commands.py +6 -6
- opencos/deps/deps_file.py +82 -79
- opencos/deps/deps_processor.py +129 -50
- opencos/docs/Architecture.md +45 -0
- opencos/docs/ConnectingApps.md +29 -0
- opencos/docs/DEPS.md +199 -0
- opencos/docs/Debug.md +77 -0
- opencos/docs/DirectoryStructure.md +22 -0
- opencos/docs/Installation.md +117 -0
- opencos/docs/OcVivadoTcl.md +63 -0
- opencos/docs/OpenQuestions.md +7 -0
- opencos/docs/README.md +13 -0
- opencos/docs/RtlCodingStyle.md +54 -0
- opencos/docs/eda.md +147 -0
- opencos/docs/oc_cli.md +135 -0
- opencos/eda.py +175 -41
- opencos/eda_base.py +180 -50
- opencos/eda_config.py +62 -16
- opencos/eda_config_defaults.yml +21 -4
- opencos/eda_deps_bash_completion.bash +37 -15
- opencos/files.py +26 -1
- opencos/tools/cocotb.py +5 -5
- opencos/tools/invio.py +2 -2
- opencos/tools/invio_yosys.py +2 -1
- opencos/tools/iverilog.py +3 -3
- opencos/tools/quartus.py +113 -115
- opencos/tools/questa_common.py +3 -4
- opencos/tools/riviera.py +3 -3
- opencos/tools/slang.py +11 -7
- opencos/tools/slang_yosys.py +1 -0
- opencos/tools/surelog.py +4 -3
- opencos/tools/verilator.py +5 -4
- opencos/tools/vivado.py +307 -176
- opencos/tools/yosys.py +4 -4
- opencos/util.py +6 -3
- opencos/utils/dict_helpers.py +31 -0
- opencos/utils/markup_helpers.py +2 -2
- opencos/utils/str_helpers.py +7 -0
- opencos/utils/subprocess_helpers.py +3 -3
- opencos/utils/vscode_helper.py +2 -2
- opencos/utils/vsim_helper.py +58 -22
- {opencos_eda-0.3.9.dist-info → opencos_eda-0.3.11.dist-info}/METADATA +1 -1
- opencos_eda-0.3.11.dist-info/RECORD +94 -0
- {opencos_eda-0.3.9.dist-info → opencos_eda-0.3.11.dist-info}/entry_points.txt +1 -0
- opencos/tests/__init__.py +0 -0
- opencos/tests/custom_config.yml +0 -13
- opencos/tests/deps_files/command_order/DEPS.yml +0 -44
- opencos/tests/deps_files/error_msgs/DEPS.yml +0 -55
- opencos/tests/deps_files/iverilog_test/DEPS.yml +0 -4
- opencos/tests/deps_files/no_deps_here/DEPS.yml +0 -0
- opencos/tests/deps_files/non_sv_reqs/DEPS.yml +0 -50
- opencos/tests/deps_files/tags_with_tools/DEPS.yml +0 -54
- opencos/tests/deps_files/test_err_fatal/DEPS.yml +0 -4
- opencos/tests/helpers.py +0 -354
- opencos/tests/test_build.py +0 -12
- opencos/tests/test_deps_helpers.py +0 -207
- opencos/tests/test_deps_schema.py +0 -30
- opencos/tests/test_eda.py +0 -921
- opencos/tests/test_eda_elab.py +0 -110
- opencos/tests/test_eda_synth.py +0 -150
- opencos/tests/test_oc_cli.py +0 -25
- opencos/tests/test_tools.py +0 -404
- opencos_eda-0.3.9.dist-info/RECORD +0 -99
- {opencos_eda-0.3.9.dist-info → opencos_eda-0.3.11.dist-info}/WHEEL +0 -0
- {opencos_eda-0.3.9.dist-info → opencos_eda-0.3.11.dist-info}/licenses/LICENSE +0 -0
- {opencos_eda-0.3.9.dist-info → opencos_eda-0.3.11.dist-info}/licenses/LICENSE.spdx +0 -0
- {opencos_eda-0.3.9.dist-info → opencos_eda-0.3.11.dist-info}/top_level.txt +0 -0
opencos/commands/deps_help.py
CHANGED
|
@@ -10,32 +10,96 @@ it is generally run as simply
|
|
|
10
10
|
uses no tools and will print a help text regarding DEPS markup files to stdout.
|
|
11
11
|
'''
|
|
12
12
|
|
|
13
|
+
# pylint: disable=line-too-long
|
|
13
14
|
|
|
14
15
|
import os
|
|
16
|
+
import re
|
|
15
17
|
|
|
16
18
|
from opencos.eda_base import Command
|
|
17
19
|
from opencos import util
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
from opencos.util import Colors
|
|
21
|
+
|
|
22
|
+
def get_deps_md_file() -> str:
|
|
23
|
+
'''Tries to get docs/DEPS.md from our pypackage dist'''
|
|
24
|
+
opencos_dir, _ = os.path.split(util.__file__)
|
|
25
|
+
|
|
26
|
+
# Try to get it from site-packages dir, which should have docs/ alongside
|
|
27
|
+
# commands/ and tools/
|
|
28
|
+
filename = os.path.join(opencos_dir, 'docs', 'DEPS.md')
|
|
29
|
+
if os.path.isfile(filename):
|
|
30
|
+
return filename
|
|
31
|
+
|
|
32
|
+
# If you're running directly from the git checkout dir, you won't be getting
|
|
33
|
+
# this dist, so it's not in opencos/docs, it will simply be in ./docs
|
|
34
|
+
filename = os.path.join(opencos_dir, '..', 'docs', 'DEPS.md')
|
|
35
|
+
if os.path.isfile(filename):
|
|
36
|
+
return filename
|
|
37
|
+
return ''
|
|
38
|
+
|
|
39
|
+
def get_deps_md_contents() -> str:
|
|
40
|
+
'''Tries to get the docs/DEPS.md file and returns the str contents
|
|
41
|
+
|
|
42
|
+
This also performs some limited colorization of markdown and YAML
|
|
43
|
+
(assuming util was not disabled with --no-color)
|
|
44
|
+
'''
|
|
45
|
+
filename = get_deps_md_file()
|
|
46
|
+
if not filename:
|
|
47
|
+
return ''
|
|
48
|
+
|
|
49
|
+
def make_byellow(match):
|
|
50
|
+
'''Used by re.sub to wrap the match with bold yellow and return to normal yellow'''
|
|
51
|
+
return f'{Colors.byellow}{match.group(0)}{Colors.normal}{Colors.yellow}'
|
|
52
|
+
|
|
53
|
+
lines = []
|
|
54
|
+
with open(filename, encoding='utf-8') as f:
|
|
55
|
+
for line in f.readlines():
|
|
56
|
+
|
|
57
|
+
if line.startswith('# '):
|
|
58
|
+
# colors for markdown headings
|
|
59
|
+
line = f'{Colors.bgreen}{line}{Colors.normal}{Colors.yellow}'
|
|
60
|
+
elif line.startswith('## '):
|
|
61
|
+
# colors for markdown headings
|
|
62
|
+
line = f'{Colors.bcyan}{line}{Colors.normal}{Colors.yellow}'
|
|
63
|
+
|
|
64
|
+
elif '#' in line:
|
|
65
|
+
# colors for comments
|
|
66
|
+
line = line.replace('#', f'{Colors.normal}{Colors.cyan}#') + Colors.yellow
|
|
67
|
+
|
|
68
|
+
# colors for starting a line with:
|
|
69
|
+
# key: value
|
|
70
|
+
# - key : value
|
|
71
|
+
# try to make "key:" or "- key:" as bold:
|
|
72
|
+
line = re.sub(
|
|
73
|
+
r'^( *\-? ?[^ ]+):', make_byellow, line
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
lines.append(line)
|
|
77
|
+
|
|
78
|
+
return ''.join(lines)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
BASIC_DEPS_HELP = f'''
|
|
82
|
+
{Colors.yellow}
|
|
83
|
+
Note: you can run with one of: {Colors.cyan}--verbose, --help, --debug{Colors.yellow} to show full
|
|
84
|
+
schema supported, or {Colors.cyan}--no-color{Colors.yellow} to avoid printing this text with colors.
|
|
85
|
+
|
|
86
|
+
{Colors.green}--------------------------------------------------------------------{Colors.yellow}
|
|
87
|
+
|
|
88
|
+
What is a {Colors.byellow}DEPS.yml{Colors.normal}{Colors.yellow} file and why does `eda` use this?
|
|
89
|
+
- {Colors.byellow}DEPS.yml{Colors.normal}{Colors.yellow} is a fancy filelist.
|
|
26
90
|
- Used to organize a project into "targets", a tool can run on a "target".
|
|
27
91
|
- Allows for more than just source files attached to a "target".
|
|
28
92
|
-- incdirs, defines, and args can be applied to a "target".
|
|
29
93
|
|
|
30
|
-
--------------------------------------------------------------------
|
|
94
|
+
{Colors.green}--------------------------------------------------------------------{Colors.yellow}
|
|
31
95
|
|
|
32
96
|
Hello World example:
|
|
33
97
|
|
|
34
|
-
The following example is a DEPS.yml file example for a SystemVerilog simulation of
|
|
35
|
-
hello_world_tb.sv. DEPS.yml is, in short, a fancy filelist. We use them in the `eda`
|
|
98
|
+
The following example is a {Colors.byellow}DEPS.yml{Colors.normal}{Colors.yellow} file example for a SystemVerilog simulation of
|
|
99
|
+
hello_world_tb.sv. {Colors.byellow}DEPS.yml{Colors.normal}{Colors.yellow} is, in short, a fancy filelist. We use them in the `eda`
|
|
36
100
|
app to organize projects.
|
|
37
101
|
|
|
38
|
-
--- DEPS.yml: ---
|
|
102
|
+
--- {Colors.byellow}DEPS.yml{Colors.normal}{Colors.yellow}: ---
|
|
39
103
|
|
|
40
104
|
hello-world: # <-- this is a named target that will be run
|
|
41
105
|
|
|
@@ -64,20 +128,20 @@ endmodule : hello_world_tb
|
|
|
64
128
|
|
|
65
129
|
|
|
66
130
|
hello-world:
|
|
67
|
-
The target name in the DEPS.yml we named is hello-world. That is a valid target
|
|
131
|
+
The target name in the {Colors.byellow}DEPS.yml{Colors.normal}{Colors.yellow} we named is hello-world. That is a valid target
|
|
68
132
|
that `eda` can use. Such as:
|
|
69
133
|
|
|
70
134
|
eda sim --tool=verilator hello-world
|
|
71
135
|
|
|
72
136
|
|
|
73
|
-
--------------------------------------------------------------------
|
|
137
|
+
{Colors.green}--------------------------------------------------------------------{Colors.yellow}
|
|
74
138
|
|
|
75
139
|
Beyond Hello World example:
|
|
76
140
|
|
|
77
141
|
The following example is a DEPS.yml file for a more complex module simulation.
|
|
78
142
|
It has two files in ./DEPS.yml and ./lib/DEPS.yml.
|
|
79
143
|
|
|
80
|
-
--- ./DEPS.yml: ---
|
|
144
|
+
--- {Colors.byellow}./DEPS.yml{Colors.normal}{Colors.yellow}: ---
|
|
81
145
|
|
|
82
146
|
my_fifo: # <-- this is a design
|
|
83
147
|
incdirs: . lib # <-- 'incdirs' define the paths searched to find `include files
|
|
@@ -102,7 +166,7 @@ my_fifo_stress_test: # <-- this is another TEST
|
|
|
102
166
|
deps:
|
|
103
167
|
- my_fifo_test # aside from the define, this is same as "my_fifo_test"
|
|
104
168
|
|
|
105
|
-
--- lib/DEPS.yml: ---
|
|
169
|
+
--- {Colors.byellow}lib/DEPS.yml{Colors.normal}{Colors.yellow}: ---
|
|
106
170
|
|
|
107
171
|
lib_pkg: # <-- this is a package required by bin_to_gray below
|
|
108
172
|
deps:
|
|
@@ -115,113 +179,16 @@ bin_to_gray: # <-- this is the target that was required by .
|
|
|
115
179
|
# to be read before the code that uses them
|
|
116
180
|
- bin_to_gray.sv # an SV module pulled in directly
|
|
117
181
|
|
|
118
|
-
--------------------------------------------------------------------
|
|
182
|
+
{Colors.green}--------------------------------------------------------------------{Colors.yellow}
|
|
119
183
|
'''
|
|
120
184
|
|
|
121
185
|
|
|
122
|
-
FULL_DEPS_HELP = '''
|
|
123
|
-
|
|
124
|
-
--------------------------------------------------------------------
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
DEFAULTS: # <table> defaults applied to ALL targets in this file, local targets ** override ** the defaults.
|
|
130
|
-
|
|
131
|
-
METADATA: # <table> unstructured data, any UPPERCASE first level key is not considered a target.
|
|
132
|
-
|
|
133
|
-
target-spec:
|
|
134
|
-
|
|
135
|
-
args: # <array or | separated str>
|
|
136
|
-
- --waves
|
|
137
|
-
- --sim_plusargs="+info=500"
|
|
138
|
-
|
|
139
|
-
defines: # <table>
|
|
140
|
-
SOME_DEFINE: value
|
|
141
|
-
SOME_DEFINE_NO_VALUE: # we just leave this blank, or use nil (yaml's None)
|
|
142
|
-
|
|
143
|
-
incdirs: # <array>
|
|
144
|
-
- some/relative/path
|
|
145
|
-
|
|
146
|
-
top: # <string>
|
|
147
|
-
|
|
148
|
-
deps: # <array or | space separated string>
|
|
149
|
-
- some_relative_target # <string> aka, a target
|
|
150
|
-
- some_file.sv # <string> aka, a file
|
|
151
|
-
- sv@some_file.txt # <string> aka, ext@file where we'd like a file not ending in .sv to be
|
|
152
|
-
# treated as a .sv file for tools.
|
|
153
|
-
# Supported for sv@, v@, vhdl@, cpp@
|
|
154
|
-
- commands: # <table> with key 'commands' for a <array>: support for built-in commands
|
|
155
|
-
# Note this cannot be confused for other targets or files.
|
|
156
|
-
- shell: # <string>
|
|
157
|
-
var-subst-args: # <bool> default false. If true, substitute vars in commands, such as {fpga}
|
|
158
|
-
# substituted from eda arg --fpga=SomeFpga, such that {fpga} becomes SomeFpga
|
|
159
|
-
var-subst-os-env: #<bool> default false. If true, substitute vars in commands using os.environ vars,
|
|
160
|
-
# such as {FPGA} could get substituted by env value for $FPGA
|
|
161
|
-
tee: # <string> optional filename, otherwise shell commands write to {target-spec}__shell_0.log
|
|
162
|
-
run-from-work-dir: #<bool> default true. If false, runs from the directory of this DEPS file.
|
|
163
|
-
filepath-subst-target-dir: #<bool> default true. If false, disables shell file path
|
|
164
|
-
substituion on this target's directory (this DEPS file dir).
|
|
165
|
-
dirpath-subst-target-dir: #<bool> default false. If true, enables shell directory path
|
|
166
|
-
substituion on this target's directory (this DEPS file dir).
|
|
167
|
-
- shell: echo "Hello World!"
|
|
168
|
-
- work-dir-add-sources: # <array or | space separated string>, this is how to add generated files
|
|
169
|
-
# to compile order list.
|
|
170
|
-
- peakrdl: # <string> ## peakrdl command to generate CSRs
|
|
171
|
-
|
|
172
|
-
reqs: # <array or | space separated string>
|
|
173
|
-
- some_file.mem # <string> aka, a non-source file required for this target.
|
|
174
|
-
# This file is checked for existence prior to invoking the tool involved, for example,
|
|
175
|
-
# in a simulation this would be done prior to a compile step.
|
|
176
|
-
|
|
177
|
-
multi:
|
|
178
|
-
ignore-this-target: # <array of tables> eda commands to be ignored in `eda multi <command>` for this target only
|
|
179
|
-
# this is checked in the matching multi targets list, and is not inherited through dependencies.
|
|
180
|
-
- commands: synth # space separated strings
|
|
181
|
-
tools: vivado # space separated strings
|
|
182
|
-
|
|
183
|
-
- commands: sim # omit tools, ignores 'sim' commands for all tools, for this target only, when this target
|
|
184
|
-
# is in the target list called by `eda multi`.
|
|
185
|
-
|
|
186
|
-
- tools: vivado # omit commands, ignores all commands if tool is vivado, for this target only, when this target
|
|
187
|
-
# is in the target list called by `eda multi`.
|
|
188
|
-
|
|
189
|
-
args: # <array> additional args added to all multi commands of this target.
|
|
190
|
-
# Note that all args are POSIX with dashes, --sim-plusargs=value, etc.
|
|
191
|
-
|
|
192
|
-
<eda-command>: # key is one of sim, flist, build, synth, etc.
|
|
193
|
-
# can be used instead of 'tags' to support different args or deps.
|
|
194
|
-
disable-tools: # Note: not implemented yet.
|
|
195
|
-
only-tools: # Note: not implemented yet.
|
|
196
|
-
args: # <array or | space separated string>
|
|
197
|
-
deps: # <array or | space separated string> # Note: not implemented yet
|
|
198
|
-
defines: ## <table>
|
|
199
|
-
incdirs: ## <array>
|
|
200
|
-
|
|
201
|
-
tags: # <table> this is the currently support tags features in a target.
|
|
202
|
-
<tag-name>: # <string> key for table, can be anything, name is not used.
|
|
203
|
-
with-tools: <array or | space separated string>
|
|
204
|
-
# If using one of these tools, apply these values.
|
|
205
|
-
# entries can be in the form: vivado, or vivado:2024.1
|
|
206
|
-
with-commands: <array or | space separated string>
|
|
207
|
-
# apply if this was the `eda` command, such as: sim
|
|
208
|
-
with-args: # <table> (optional) arg key/value pairs to match for this tag.
|
|
209
|
-
# this would be an alternative to running eda with --tags=value
|
|
210
|
-
# The existence of an argument with correct value would enable a tag.
|
|
211
|
-
# And example would be:
|
|
212
|
-
# with-args:
|
|
213
|
-
# waves: true
|
|
214
|
-
args: <array or | space separated string> # args to be applied if this target is used, with a matching
|
|
215
|
-
# tool in 'with-tools'.
|
|
216
|
-
deps: <array or | space separated string, applied with tag>
|
|
217
|
-
defines: <table, applied with tag>
|
|
218
|
-
incdirs: <array, applied with tag>
|
|
219
|
-
replace-config-tools: <table> # spec matching eda_config_defaults.yml::tools.<tool> (replace merge strategy)
|
|
220
|
-
additive-config-tools: <table> # spec matching eda_config_defaults.yml::tools.<tool> (additive merge strategy)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
'''
|
|
186
|
+
FULL_DEPS_HELP = f'''
|
|
187
|
+
|
|
188
|
+
{Colors.green}--------------------------------------------------------------------{Colors.yellow}
|
|
189
|
+
|
|
190
|
+
''' + get_deps_md_contents()
|
|
191
|
+
|
|
225
192
|
|
|
226
193
|
|
|
227
194
|
class CommandDepsHelp:
|
|
@@ -256,4 +223,6 @@ class CommandDepsHelp:
|
|
|
256
223
|
'''
|
|
257
224
|
Command.help(self, tokens=tokens, no_targets=True)
|
|
258
225
|
print()
|
|
226
|
+
print(BASIC_DEPS_HELP)
|
|
227
|
+
print()
|
|
259
228
|
print(FULL_DEPS_HELP)
|
opencos/commands/export.py
CHANGED
|
@@ -58,9 +58,14 @@ class CommandExport(CommandDesign):
|
|
|
58
58
|
|
|
59
59
|
def do_it(self) -> None:
|
|
60
60
|
|
|
61
|
-
# decide output dir name
|
|
61
|
+
# decide output dir name, note this does not follow the work-dir naming of
|
|
62
|
+
# eda.work/{target}.{command}
|
|
62
63
|
if not self.args['output']:
|
|
63
|
-
|
|
64
|
+
if self.target:
|
|
65
|
+
name = f'{self.target}.export'
|
|
66
|
+
else:
|
|
67
|
+
name = self.args.get('top', '') + '.export'
|
|
68
|
+
self.args['output'] = os.path.join('.', 'eda.export', name)
|
|
64
69
|
out_dir = self.args['output']
|
|
65
70
|
|
|
66
71
|
if not self.target:
|
opencos/commands/multi.py
CHANGED
|
@@ -6,14 +6,14 @@ These are not intended to be overriden by child classes. They do not inherit Too
|
|
|
6
6
|
import argparse
|
|
7
7
|
import glob
|
|
8
8
|
import os
|
|
9
|
-
import shutil
|
|
10
9
|
from pathlib import Path
|
|
11
10
|
|
|
12
11
|
from opencos import util, eda_base, eda_config, export_helper, \
|
|
13
12
|
eda_tool_helper
|
|
14
|
-
from opencos.eda_base import CommandParallel, get_eda_exec
|
|
15
13
|
from opencos.deps.deps_file import get_deps_markup_file, deps_markup_safe_load, \
|
|
16
14
|
deps_data_get_all_targets, deps_list_target_sanitize
|
|
15
|
+
from opencos.eda_base import CommandParallel, get_eda_exec
|
|
16
|
+
from opencos.files import safe_shutil_which
|
|
17
17
|
from opencos.utils.str_helpers import fnmatch_or_re, dep_str2list
|
|
18
18
|
|
|
19
19
|
class CommandMulti(CommandParallel):
|
|
@@ -425,7 +425,7 @@ class CommandMulti(CommandParallel):
|
|
|
425
425
|
'''
|
|
426
426
|
eda_path = get_eda_exec('multi')
|
|
427
427
|
command = self.single_command
|
|
428
|
-
timeout =
|
|
428
|
+
timeout = safe_shutil_which('timeout')
|
|
429
429
|
|
|
430
430
|
# Built-in support for running > 1 tool.
|
|
431
431
|
all_multi_tools = self.multi_which_tools(command)
|
opencos/commands/sim.py
CHANGED
|
@@ -300,7 +300,6 @@ class CommandSim(CommandDesign): # pylint: disable=too-many-public-methods
|
|
|
300
300
|
tool = self.args.get('tool', None)
|
|
301
301
|
# Certain args are allow-listed here
|
|
302
302
|
deps_file_args = []
|
|
303
|
-
print(f'SUPER DREW DEBUG: {self.get_command_line_args()=}')
|
|
304
303
|
for a in self.get_command_line_args():
|
|
305
304
|
if any(a.startswith(x) for x in [
|
|
306
305
|
'--compile-args',
|
|
@@ -371,7 +370,8 @@ class CommandSim(CommandDesign): # pylint: disable=too-many-public-methods
|
|
|
371
370
|
def check_logs_for_errors( # pylint: disable=dangerous-default-value,too-many-locals,too-many-branches
|
|
372
371
|
self,
|
|
373
372
|
sim_retcode: int = 0,
|
|
374
|
-
filename: str = '',
|
|
373
|
+
filename: str = '',
|
|
374
|
+
file_contents_str: str = '',
|
|
375
375
|
bad_strings: list = [], must_strings: list = [],
|
|
376
376
|
warning_strings: list = [],
|
|
377
377
|
use_bad_strings: bool = True, use_must_strings: bool = True
|
|
@@ -405,32 +405,30 @@ class CommandSim(CommandDesign): # pylint: disable=too-many-public-methods
|
|
|
405
405
|
lines = []
|
|
406
406
|
|
|
407
407
|
log_fpath = ''
|
|
408
|
-
if os.path.
|
|
408
|
+
if os.path.isfile(filename):
|
|
409
409
|
log_fpath = filename
|
|
410
410
|
|
|
411
411
|
if file_contents_str:
|
|
412
412
|
lines = file_contents_str.split('\n')
|
|
413
413
|
log_fname = log_fpath + '(STDOUT)'
|
|
414
414
|
util.debug(f'Checking log for errors: {log_fpath=} but checking from STDOUT string...')
|
|
415
|
-
elif
|
|
415
|
+
elif log_fpath:
|
|
416
416
|
log_fname = log_fpath
|
|
417
|
-
util.
|
|
418
|
-
if not os.path.exists(log_fname):
|
|
419
|
-
self.error(f'sim.check_logs_for_errors: log {log_fpath} does not exist, cannot',
|
|
420
|
-
'check it for errors or passing strings')
|
|
421
|
-
return
|
|
417
|
+
util.info(f'Checking log filename: {log_fpath}')
|
|
422
418
|
with open(log_fpath, 'r', encoding='utf-8') as f:
|
|
423
419
|
lines = f.read().splitlines()
|
|
424
420
|
else:
|
|
425
|
-
|
|
426
|
-
|
|
421
|
+
log_fname = filename
|
|
422
|
+
self.error(f'sim.check_logs_for_errors: {log_fname=} is not a file or does not exist,',
|
|
423
|
+
'and no file_contents_str exists to check')
|
|
427
424
|
|
|
428
425
|
self.update_tool_warn_err_counts_from_log_lines(
|
|
429
426
|
log_lines=lines, bad_strings=_bad_strings, warning_strings=_warning_strings
|
|
430
427
|
)
|
|
431
428
|
|
|
432
|
-
|
|
433
|
-
|
|
429
|
+
func = getattr(self, 'report_tool_warn_error_counts', None)
|
|
430
|
+
if func and isinstance(self, Tool) and callable(func):
|
|
431
|
+
self.report_tool_warn_error_counts() # pylint: disable=no-member
|
|
434
432
|
|
|
435
433
|
if sim_retcode > 0:
|
|
436
434
|
# We have to update artifacts first, have the caller set the error.
|
|
@@ -447,14 +445,14 @@ class CommandSim(CommandDesign): # pylint: disable=too-many-public-methods
|
|
|
447
445
|
hit_must_string_dict[k] = True
|
|
448
446
|
if any(bad_str in line for bad_str in _bad_strings):
|
|
449
447
|
self.error(
|
|
450
|
-
f"log {log_fname}:{lineno} contains one of {_bad_strings
|
|
448
|
+
f"log {log_fname}:{lineno} contains one of: {_bad_strings}",
|
|
451
449
|
error_code=status_constants.EDA_SIM_LOG_HAS_BAD_STRING
|
|
452
450
|
)
|
|
453
451
|
|
|
454
452
|
if any(x is None for x in hit_must_string_dict.values()):
|
|
455
453
|
self.error(
|
|
456
|
-
f"Didn't get all passing patterns in log {log_fname}: {_must_strings
|
|
457
|
-
f" {hit_must_string_dict
|
|
454
|
+
f"Didn't get all passing patterns in log {log_fname}: {_must_strings},",
|
|
455
|
+
f" {hit_must_string_dict}",
|
|
458
456
|
error_code=status_constants.EDA_SIM_LOG_MISSING_MUST_STRING
|
|
459
457
|
)
|
|
460
458
|
|
opencos/commands/synth.py
CHANGED
|
@@ -67,9 +67,8 @@ class CommandSynth(CommandDesign):
|
|
|
67
67
|
if self.stop_process_tokens_before_do_it():
|
|
68
68
|
return unparsed
|
|
69
69
|
|
|
70
|
-
# add defines for this job type
|
|
71
70
|
if self.args['top']:
|
|
72
|
-
# create our work dir
|
|
71
|
+
# create our work dir (from self.args['top'])
|
|
73
72
|
self.create_work_dir()
|
|
74
73
|
self.run_dep_commands()
|
|
75
74
|
self.do_it()
|
opencos/commands/upload.py
CHANGED
|
@@ -4,20 +4,73 @@ Intended to be overriden by Tool based classes (such as CommandUploadVivado, etc
|
|
|
4
4
|
'''
|
|
5
5
|
|
|
6
6
|
import os
|
|
7
|
+
import re
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from pathlib import Path
|
|
7
10
|
|
|
8
11
|
from opencos.eda_base import Command, Tool
|
|
12
|
+
from opencos.util import Colors, debug, info, warning, safe_emoji, import_class_from_string
|
|
13
|
+
|
|
9
14
|
|
|
10
15
|
class CommandUpload(Command):
|
|
11
|
-
'''Base class command handler for: eda upload ...
|
|
16
|
+
'''Base class command handler for: eda upload ...
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
If a --tool arg is not specified, this is the default handler for 'eda upload'
|
|
19
|
+
and will attempt to choose a derived class based on the bit files found
|
|
20
|
+
'''
|
|
14
21
|
|
|
15
22
|
command_name = 'upload'
|
|
16
23
|
|
|
24
|
+
# SUPPORTED_TOOLS is used
|
|
25
|
+
SUPPORTED_TOOLS = {
|
|
26
|
+
'vivado': ['.bit'],
|
|
27
|
+
'quartus': ['.sof'],
|
|
28
|
+
}
|
|
29
|
+
BIT_EXT_TO_TOOL = {}
|
|
30
|
+
|
|
31
|
+
# Child classes can set SUPPORTED_BIT_EXT = ['.bit', ..] because they
|
|
32
|
+
# should only represent one tool
|
|
33
|
+
SUPPORTED_BIT_EXT = [item for value in SUPPORTED_TOOLS.values() for item in value]
|
|
34
|
+
|
|
35
|
+
|
|
17
36
|
def __init__(self, config: dict):
|
|
18
37
|
Command.__init__(self, config=config)
|
|
19
38
|
self.unparsed_args = []
|
|
20
39
|
|
|
40
|
+
self.args.update({
|
|
41
|
+
'bitfile': "",
|
|
42
|
+
'list-bitfiles': False,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
self.str_ext = '/'.join(self.SUPPORTED_BIT_EXT).replace('.', '').upper()
|
|
46
|
+
|
|
47
|
+
help_upload_tools = '|'.join(self.config.get('auto_tools_found', []))
|
|
48
|
+
if not help_upload_tools:
|
|
49
|
+
help_upload_tools = 'TOOL'
|
|
50
|
+
|
|
51
|
+
self.args_help.update({
|
|
52
|
+
'bitfile': (
|
|
53
|
+
f'Tool specific {self.str_ext} files to upload (auto-detected if not specified)'
|
|
54
|
+
' If you would like see full help for a given tool, use:'
|
|
55
|
+
f' {Colors.yellow}eda upload --help'
|
|
56
|
+
f' {Colors.byellow}--tool={help_upload_tools}{Colors.green}'
|
|
57
|
+
),
|
|
58
|
+
'list-bitfiles': (
|
|
59
|
+
f'List available {self.str_ext} files.'
|
|
60
|
+
' If you would like see full help for a given tool, use:'
|
|
61
|
+
f' {Colors.yellow}eda upload --help'
|
|
62
|
+
f' {Colors.byellow}--tool={help_upload_tools}{Colors.green}'
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
self.bitfiles = []
|
|
67
|
+
|
|
68
|
+
if not getattr(self, '_TOOL', ''):
|
|
69
|
+
for tool, bit_exts in self.SUPPORTED_TOOLS.items():
|
|
70
|
+
for ext in bit_exts:
|
|
71
|
+
self.BIT_EXT_TO_TOOL[ext] = tool
|
|
72
|
+
|
|
73
|
+
|
|
21
74
|
def process_tokens(
|
|
22
75
|
self, tokens: list, process_all: bool = True, pwd: str = os.getcwd()
|
|
23
76
|
) -> list:
|
|
@@ -25,9 +78,144 @@ class CommandUpload(Command):
|
|
|
25
78
|
self.unparsed_args = Command.process_tokens(
|
|
26
79
|
self, tokens=tokens, process_all=False, pwd=pwd
|
|
27
80
|
)
|
|
81
|
+
|
|
28
82
|
if self.stop_process_tokens_before_do_it():
|
|
29
83
|
return []
|
|
30
84
|
|
|
31
|
-
self.
|
|
32
|
-
|
|
85
|
+
self.bitfiles = self.get_list_bitfiles(display=True)
|
|
86
|
+
|
|
87
|
+
# If someone called --list-bitfiles, stop now.
|
|
88
|
+
if self.args['list-bitfiles']:
|
|
89
|
+
if not self.bitfiles:
|
|
90
|
+
self.error('No bitfiles found')
|
|
91
|
+
return []
|
|
92
|
+
|
|
93
|
+
sco = self._get_child_handling_class()
|
|
94
|
+
|
|
95
|
+
if sco is None or not isinstance(sco, Tool):
|
|
96
|
+
self.error('Could not find a suitable tool to process bitfiles')
|
|
97
|
+
return []
|
|
98
|
+
|
|
99
|
+
sco.unparsed_args = Command.process_tokens(
|
|
100
|
+
sco, tokens=tokens, process_all=False, pwd=pwd
|
|
101
|
+
)
|
|
102
|
+
sco.bitfiles = self.bitfiles
|
|
103
|
+
sco.create_work_dir()
|
|
104
|
+
sco.do_it()
|
|
33
105
|
return []
|
|
106
|
+
|
|
107
|
+
def get_targets_or_files_from_unparsed_args(self) -> (list, list):
|
|
108
|
+
'''Returns (list of targets, list of files) from unparsed args or --bitfile'''
|
|
109
|
+
|
|
110
|
+
targets = []
|
|
111
|
+
files = []
|
|
112
|
+
for f in self.unparsed_args + [self.args['bitfile']]:
|
|
113
|
+
if not f:
|
|
114
|
+
continue
|
|
115
|
+
if os.path.isfile(f):
|
|
116
|
+
files.append(f)
|
|
117
|
+
elif not f.startswith('-'):
|
|
118
|
+
# avoid a arg
|
|
119
|
+
targets.append(f)
|
|
120
|
+
return targets, files
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def get_list_bitfiles(self, display: bool = True) -> list:
|
|
124
|
+
'''Returns a list of bit files (ending with self.SUPPORTED_BIT_EXT)'''
|
|
125
|
+
|
|
126
|
+
bitfiles: list[Path] = []
|
|
127
|
+
|
|
128
|
+
targets, files = self.get_targets_or_files_from_unparsed_args()
|
|
129
|
+
targets.extend(files)
|
|
130
|
+
|
|
131
|
+
debug(f"Looking for bitfiles in {os.path.abspath('.')=}")
|
|
132
|
+
for root, _, files in os.walk("."):
|
|
133
|
+
for f in files:
|
|
134
|
+
if any(f.endswith(x) for x in self.SUPPORTED_BIT_EXT):
|
|
135
|
+
fullpath = os.path.abspath(Path(root) / f)
|
|
136
|
+
if os.path.isfile(fullpath) and fullpath not in bitfiles:
|
|
137
|
+
bitfiles.append(fullpath)
|
|
138
|
+
|
|
139
|
+
matched: list[Path] = []
|
|
140
|
+
for cand in bitfiles:
|
|
141
|
+
debug(f"Looking for {cand=} in {targets=}")
|
|
142
|
+
passing = all(re.search(t, str(cand)) for t in targets)
|
|
143
|
+
if passing:
|
|
144
|
+
matched.append(cand)
|
|
145
|
+
mod_time_string = datetime.fromtimestamp(
|
|
146
|
+
os.path.getmtime(cand)).strftime('%Y-%m-%d %H:%M:%S')
|
|
147
|
+
tool_guess = getattr(self, '_TOOL', '')
|
|
148
|
+
if not tool_guess:
|
|
149
|
+
ext = os.path.splitext(cand)[1]
|
|
150
|
+
tool_guess = self.BIT_EXT_TO_TOOL.get(ext, '')
|
|
151
|
+
if tool_guess:
|
|
152
|
+
tool_guess = f'({tool_guess})'
|
|
153
|
+
if display:
|
|
154
|
+
info(
|
|
155
|
+
f"{safe_emoji('⏩ ')}Found matching bitfile {tool_guess}:",
|
|
156
|
+
f"{Colors.cyan}{mod_time_string}{Colors.normal} :",
|
|
157
|
+
f"{Colors.byellow}{cand}"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
if display and not matched:
|
|
161
|
+
if self.args['list-bitfiles']:
|
|
162
|
+
warning(f'{safe_emoji("❕ ")}--list-bitfiles: no {self.str_ext} found that matched',
|
|
163
|
+
f'{targets}')
|
|
164
|
+
else:
|
|
165
|
+
warning(f'{safe_emoji("❕ ")} Searched for bitfiles with {self.str_ext}: none found',
|
|
166
|
+
f'that matched {targets}')
|
|
167
|
+
|
|
168
|
+
return matched
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _get_child_handling_class(self) -> object:
|
|
174
|
+
'''Returns a class handle of a child to process this, which should be a Tool class
|
|
175
|
+
|
|
176
|
+
if no appropriate child is found, returns self.
|
|
177
|
+
'''
|
|
178
|
+
|
|
179
|
+
if isinstance(self, Tool):
|
|
180
|
+
# We're already a tool handling class.
|
|
181
|
+
return self
|
|
182
|
+
|
|
183
|
+
tools_found = set()
|
|
184
|
+
for bitfile in self.bitfiles:
|
|
185
|
+
ext = os.path.splitext(bitfile)[1]
|
|
186
|
+
tool_guess = self.BIT_EXT_TO_TOOL.get(ext, '')
|
|
187
|
+
if tool_guess:
|
|
188
|
+
tools_found.add(tool_guess)
|
|
189
|
+
else:
|
|
190
|
+
warning(f'For bitfile {bitfile} no tool found for it')
|
|
191
|
+
return self
|
|
192
|
+
|
|
193
|
+
if not tools_found:
|
|
194
|
+
# Probably not an error?
|
|
195
|
+
warning(f'No tools found to process bitfiles: {self.bitfiles}')
|
|
196
|
+
return self
|
|
197
|
+
|
|
198
|
+
if len(tools_found) > 1:
|
|
199
|
+
warning(f'More than one tool found ({tools_found}) to to process bitfiles:',
|
|
200
|
+
f'{self.bitfiles}')
|
|
201
|
+
return self
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
tool = tools_found.pop() # only item in set
|
|
205
|
+
# Do we have a handler for this in our config?
|
|
206
|
+
if tool in self.config.get('tools_loaded', []):
|
|
207
|
+
auto_tools_order = self.config.get('auto_tools_order', [{}])[0]
|
|
208
|
+
if tool in auto_tools_order:
|
|
209
|
+
cls_str = auto_tools_order[tool].get('handlers', {}).get(self.command_name, None)
|
|
210
|
+
if cls_str:
|
|
211
|
+
cls = import_class_from_string(cls_str)
|
|
212
|
+
if issubclass(cls, Command):
|
|
213
|
+
info(f'For found bitfiles, can use tool={tool} and handler {cls}')
|
|
214
|
+
sco = cls(config=self.config)
|
|
215
|
+
return sco
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
warning(f'No handler found for tool={tool} to process bitfiles: {self.bitfiles}')
|
|
219
|
+
debug(f'config -- tools_loaded: {self.config["tools_loaded"]}')
|
|
220
|
+
debug(f'config -- auto_tools_order for tool: {self.config["auto_tools_order"][0][tool]}')
|
|
221
|
+
return self
|