Skip to content

Commit b935cb0

Browse files
committed
Transitioned the in-memory board definitions representation from json dicts to protocol buffer messages. Next will do the same for fpgas and programmers.
1 parent 36422e2 commit b935cb0

24 files changed

Lines changed: 476 additions & 225 deletions

apio/commands/apio_api.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
usb_util,
2626
serial_util,
2727
util,
28+
proto_util,
2829
apio_platforms,
2930
env_options,
3031
)
@@ -387,7 +388,9 @@ def _get_project_cli(
387388
"id": pr.board_id,
388389
"is-custom": apio_ctx.definitions.is_custom_board(pr.board_id),
389390
}
390-
board_dict["definition"] = pr.board_info
391+
board_dict["definition"] = proto_util.proto_to_json_dict(
392+
pr.board_definition
393+
)
391394
section_dict["board"] = board_dict
392395

393396
fpga_dict = {
@@ -466,15 +469,15 @@ def _get_boards_cli(
466469

467470
# -- Generate the boards section.
468471
section = {}
469-
for board_id, board_info in apio_ctx.definitions.boards.items():
472+
for board_id, board_definition in apio_ctx.definitions.boards.items():
470473
# -- The board output dict.
471474
board_dict = {}
472475

473476
# -- Add board description
474-
board_dict["description"] = board_info.get("description", None)
477+
board_dict["description"] = board_definition.description
475478

476479
# -- Add board's fpga information.
477-
fpga_id = board_info.get("fpga-id", None)
480+
fpga_id = board_definition.fpga_id
478481
fpga_info = apio_ctx.definitions.fpgas.get(fpga_id, {})
479482
assert "id" not in fpga_info
480483
fpga_dict = {"id": fpga_id}
@@ -483,7 +486,7 @@ def _get_boards_cli(
483486

484487
# -- Add board's programmer information.
485488
programmer_dict = {}
486-
programmer_id = board_info.get("programmer", {}).get("id", None)
489+
programmer_id = board_definition.programmer.id
487490
programmer_dict["id"] = programmer_id
488491
board_dict["programmer"] = programmer_dict
489492

@@ -944,8 +947,8 @@ def _scan_devices_cli(
944947
section = []
945948
for device in usb_devices:
946949
dev = {}
947-
dev["vid"] = device.vendor_id
948-
dev["pid"] = device.product_id
950+
dev["vid"] = device.vid
951+
dev["pid"] = device.pid
949952
dev["bus"] = device.bus
950953
dev["device"] = device.device
951954
dev["manufacturer"] = device.manufacturer
@@ -967,8 +970,8 @@ def _scan_devices_cli(
967970
dev = {}
968971
dev["port"] = device.port
969972
dev["port-name"] = device.port_name
970-
dev["vendor-id"] = device.vendor_id
971-
dev["product-id"] = device.product_id
973+
dev["vendor-id"] = device.vid
974+
dev["product-id"] = device.pid
972975
dev["manufacturer"] = device.manufacturer
973976
dev["product"] = device.product
974977
dev["serial-number"] = device.serial_number

apio/commands/apio_boards.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ def _collect_board_entries(apio_ctx) -> List[Entry]:
5858

5959
# -- Collect the boards info into a list of entires, one per board.
6060
result: List[Entry] = []
61-
for board, board_info in apio_ctx.definitions.boards.items():
62-
fpga_id = board_info.get("fpga-id", "")
61+
for board, board_definition in apio_ctx.definitions.boards.items():
62+
fpga_id = board_definition.fpga_id
6363
fpga_info = apio_ctx.definitions.fpgas.get(fpga_id, {})
6464

6565
examples_count = " " + str(examples_counts.get(board, ""))
66-
board_description = board_info.get("description", "")
66+
board_description = board_definition.description
6767
fpga_arch = fpga_info.get("arch", "")
6868
fpga_size = fpga_info.get("size", "")
6969
fpga_part_num = fpga_info.get("part-num", "")
70-
programmer_id = board_info.get("programmer", {}).get("id", "")
70+
programmer_id = board_definition.programmer.id
7171

7272
result.append(
7373
Entry(

apio/commands/apio_devices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _list_usb_devices(apio_ctx: ApioContext) -> None:
5757
# -- Add a raw per device
5858
for device in devices:
5959
values = []
60-
values.append(f"{device.vendor_id}:{device.product_id}")
60+
values.append(f"{device.vid}:{device.pid}")
6161
values.append(f"{device.bus}:{device.device}")
6262
values.append(device.manufacturer)
6363
values.append(device.product)
@@ -141,7 +141,7 @@ def _list_serial_devices(apio_ctx: ApioContext) -> None:
141141
for device in devices:
142142
values = []
143143
values.append(device.port)
144-
values.append(f"{device.vendor_id}:{device.product_id}")
144+
values.append(f"{device.vid}:{device.pid}")
145145
values.append(device.manufacturer)
146146
values.append(device.product)
147147
values.append(device.serial_number)

apio/commands/apio_fpgas.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ def _collect_fpgas_entries(apio_ctx: ApioContext) -> List[Entry]:
4949

5050
# -- Collect a sparse dict with fpga ids to board count.
5151
boards_counts: Dict[str, int] = {}
52-
for board_info in apio_ctx.definitions.boards.values():
53-
fpga_id = board_info.get("fpga-id", None)
54-
if fpga_id:
55-
old_count = boards_counts.get(fpga_id, 0)
56-
boards_counts[fpga_id] = old_count + 1
52+
for board_definition in apio_ctx.definitions.boards.values():
53+
fpga_id = board_definition.fpga_id
54+
old_count = boards_counts.get(fpga_id, 0)
55+
boards_counts[fpga_id] = old_count + 1
5756

5857
# -- Collect all entries.
5958
result: List[Entry] = []

apio/common/proto/apio-common.proto

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
// 'invoke update-protos' to propagate them to the python stubs.
66
// Otherwise they do not take affect.
77

8-
// Online proto formatter at https://formatter.org/protobuf-formatter
9-
10-
// NOTE: Since we use the the serialized proto data within a single invocation
11-
// of apio, protocol buffers text mode and binary mode backward compatibility
12-
// considerations do not apply.
13-
148
// Using proto2 for features such as 'has' and 'required'.
159
syntax = "proto2";
1610

apio/common/proto/apio-definitions.proto

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
// 'invoke update-protos' to propagate them to the python stubs.
66
// Otherwise they do not take affect.
77

8-
// Online proto formatter at https://formatter.org/protobuf-formatter
9-
10-
// NOTE: Since we use the the serialized proto data within a single invocation
11-
// of apio, protocol buffers text mode and binary mode backward compatibility
12-
// considerations do not apply.
13-
148
// Using proto2 for features such as 'has' and 'required'.
159
syntax = "proto2";
1610

@@ -28,8 +22,8 @@ message BoardProgrammerSection {
2822

2923
// The board's USB info.
3024
message BoardUsbSection {
31-
required string vid = 1;
32-
required string pid = 2;
25+
optional string vid = 1;
26+
optional string pid = 2;
3327
optional string product_regex = 3 [json_name = "product-regex"];
3428
}
3529

apio/common/proto/apio-scons.proto

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44
// 'invoke update-protos' to propagate them to the python stubs.
55
// Otherwise they do not take affect.
66

7-
// Online proto formatter at https://formatter.org/protobuf-formatter
8-
9-
// NOTE: Since we use the the serialized proto data within a single invocation
10-
// of apio, protocol buffers text mode and binary mode backward compatibility
11-
// considerations do not apply.
12-
137
// Using proto2 for features such as 'has' and 'required'.
148
syntax = "proto2";
159

16-
1710
package apio.common.proto;
1811

1912
import "apio/common/proto/apio-common.proto";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Protocol buffers definitions used by apio tests only. The are not
2+
// used by Apio runtime.
3+
//
4+
// IMPORTANT: After making changes in this file, run the repo task
5+
// 'invoke update-protos' to propagate them to the python stubs.
6+
// Otherwise they do not take affect.
7+
8+
// Using proto2 for features such as 'has' and 'required'.
9+
syntax = "proto2";
10+
11+
package apio.common.proto;
12+
13+
14+
message MessageA {
15+
required string field_a1 = 1 [json_name = "field-a1"];
16+
optional string field_a2 = 2 [json_name = "field-a2"];
17+
}
18+
19+
message MessageB {
20+
required MessageA field_b1 = 1 [json_name = "field-b1"];
21+
optional MessageA field_b2 = 2 [json_name = "field-b2"];
22+
}

apio/common/proto/apio_definitions_pb2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from apio.common.proto import apio_common_pb2 as apio_dot_common_dot_proto_dot_apio__common__pb2
2828

2929

30-
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(apio/common/proto/apio-definitions.proto\x12\x11\x61pio.common.proto\x1a#apio/common/proto/apio-common.proto\"D\n\x16\x42oardProgrammerSection\x12\n\n\x02id\x18\x01 \x02(\t\x12\x1e\n\nextra_args\x18\x02 \x01(\tR\nextra-args\"Q\n\x0f\x42oardUsbSection\x12\x0b\n\x03vid\x18\x01 \x02(\t\x12\x0b\n\x03pid\x18\x02 \x02(\t\x12$\n\rproduct_regex\x18\x03 \x01(\tR\rproduct-regex\"6\n\x14\x42oardTinyprogSection\x12\x1e\n\nname_regex\x18\x01 \x02(\tR\nname-regex\"\xeb\x01\n\x0f\x42oardDefinition\x12\x13\n\x0b\x64\x65scription\x18\x01 \x02(\t\x12\x18\n\x07\x66pga_id\x18\x02 \x02(\tR\x07\x66pga-id\x12=\n\nprogrammer\x18\x03 \x02(\x0b\x32).apio.common.proto.BoardProgrammerSection\x12/\n\x03usb\x18\x04 \x01(\x0b\x32\".apio.common.proto.BoardUsbSection\x12\x39\n\x08tinyprog\x18\x05 \x01(\x0b\x32\'.apio.common.proto.BoardTinyprogSection\"0\n\x0f\x46pgaIce40Params\x12\x0c\n\x04type\x18\x01 \x02(\t\x12\x0f\n\x07package\x18\x02 \x02(\t\">\n\x0e\x46pgaEcp5Params\x12\x0c\n\x04type\x18\x01 \x02(\t\x12\x0f\n\x07package\x18\x02 \x02(\t\x12\r\n\x05speed\x18\x03 \x02(\t\"\x83\x01\n\x0f\x46pgaGowinParams\x12\"\n\x0cyosys_family\x18\x01 \x02(\tR\x0cyosys-family\x12&\n\x0enextpnr_family\x18\x02 \x02(\tR\x0enextpnr-family\x12$\n\rpacker_device\x18\x03 \x02(\tR\rpacker-device\"b\n\x10\x46pgaXilinxParams\x12\x0e\n\x06\x66\x61mily\x18\x01 \x02(\t\x12\x1e\n\nyosys_arch\x18\x02 \x02(\tR\nyosys-arch\x12\x0f\n\x07package\x18\x03 \x02(\t\x12\r\n\x05speed\x18\x04 \x02(\t\"\x9c\x03\n\x0e\x46pgaDefinition\x12\x1a\n\x08part_num\x18\x01 \x02(\tR\x08part-num\x12)\n\x04\x61rch\x18\x02 \x02(\x0e\x32\x1b.apio.common.proto.ApioArch\x12\x0c\n\x04size\x18\x03 \x02(\t\x12H\n\x0cice40_params\x18\n \x01(\x0b\x32\".apio.common.proto.FpgaIce40ParamsH\x00R\x0cice40-params\x12\x45\n\x0b\x65\x63p5_params\x18\x0b \x01(\x0b\x32!.apio.common.proto.FpgaEcp5ParamsH\x00R\x0b\x65\x63p5-params\x12H\n\x0cgowin_params\x18\x0c \x01(\x0b\x32\".apio.common.proto.FpgaGowinParamsH\x00R\x0cgowin-params\x12K\n\rxilinx_params\x18\r \x01(\x0b\x32#.apio.common.proto.FpgaXilinxParamsH\x00R\rxilinx-paramsB\r\n\x0b\x61rch_params\"5\n\x14ProgrammerDefinition\x12\x0f\n\x07\x63ommand\x18\x01 \x02(\t\x12\x0c\n\x04\x61rgs\x18\x02 \x02(\t')
30+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(apio/common/proto/apio-definitions.proto\x12\x11\x61pio.common.proto\x1a#apio/common/proto/apio-common.proto\"D\n\x16\x42oardProgrammerSection\x12\n\n\x02id\x18\x01 \x02(\t\x12\x1e\n\nextra_args\x18\x02 \x01(\tR\nextra-args\"Q\n\x0f\x42oardUsbSection\x12\x0b\n\x03vid\x18\x01 \x01(\t\x12\x0b\n\x03pid\x18\x02 \x01(\t\x12$\n\rproduct_regex\x18\x03 \x01(\tR\rproduct-regex\"6\n\x14\x42oardTinyprogSection\x12\x1e\n\nname_regex\x18\x01 \x02(\tR\nname-regex\"\xeb\x01\n\x0f\x42oardDefinition\x12\x13\n\x0b\x64\x65scription\x18\x01 \x02(\t\x12\x18\n\x07\x66pga_id\x18\x02 \x02(\tR\x07\x66pga-id\x12=\n\nprogrammer\x18\x03 \x02(\x0b\x32).apio.common.proto.BoardProgrammerSection\x12/\n\x03usb\x18\x04 \x01(\x0b\x32\".apio.common.proto.BoardUsbSection\x12\x39\n\x08tinyprog\x18\x05 \x01(\x0b\x32\'.apio.common.proto.BoardTinyprogSection\"0\n\x0f\x46pgaIce40Params\x12\x0c\n\x04type\x18\x01 \x02(\t\x12\x0f\n\x07package\x18\x02 \x02(\t\">\n\x0e\x46pgaEcp5Params\x12\x0c\n\x04type\x18\x01 \x02(\t\x12\x0f\n\x07package\x18\x02 \x02(\t\x12\r\n\x05speed\x18\x03 \x02(\t\"\x83\x01\n\x0f\x46pgaGowinParams\x12\"\n\x0cyosys_family\x18\x01 \x02(\tR\x0cyosys-family\x12&\n\x0enextpnr_family\x18\x02 \x02(\tR\x0enextpnr-family\x12$\n\rpacker_device\x18\x03 \x02(\tR\rpacker-device\"b\n\x10\x46pgaXilinxParams\x12\x0e\n\x06\x66\x61mily\x18\x01 \x02(\t\x12\x1e\n\nyosys_arch\x18\x02 \x02(\tR\nyosys-arch\x12\x0f\n\x07package\x18\x03 \x02(\t\x12\r\n\x05speed\x18\x04 \x02(\t\"\x9c\x03\n\x0e\x46pgaDefinition\x12\x1a\n\x08part_num\x18\x01 \x02(\tR\x08part-num\x12)\n\x04\x61rch\x18\x02 \x02(\x0e\x32\x1b.apio.common.proto.ApioArch\x12\x0c\n\x04size\x18\x03 \x02(\t\x12H\n\x0cice40_params\x18\n \x01(\x0b\x32\".apio.common.proto.FpgaIce40ParamsH\x00R\x0cice40-params\x12\x45\n\x0b\x65\x63p5_params\x18\x0b \x01(\x0b\x32!.apio.common.proto.FpgaEcp5ParamsH\x00R\x0b\x65\x63p5-params\x12H\n\x0cgowin_params\x18\x0c \x01(\x0b\x32\".apio.common.proto.FpgaGowinParamsH\x00R\x0cgowin-params\x12K\n\rxilinx_params\x18\r \x01(\x0b\x32#.apio.common.proto.FpgaXilinxParamsH\x00R\rxilinx-paramsB\r\n\x0b\x61rch_params\"5\n\x14ProgrammerDefinition\x12\x0f\n\x07\x63ommand\x18\x01 \x02(\t\x12\x0c\n\x04\x61rgs\x18\x02 \x02(\t')
3131

3232
_globals = globals()
3333
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# pylint: disable=all
2+
3+
# -*- coding: utf-8 -*-
4+
# Generated by the protocol buffer compiler. DO NOT EDIT!
5+
# NO CHECKED-IN PROTOBUF GENCODE
6+
# source: apio/common/proto/apio-testing.proto
7+
# Protobuf Python Version: 6.31.1
8+
"""Generated protocol buffer code."""
9+
from google.protobuf import descriptor as _descriptor
10+
from google.protobuf import descriptor_pool as _descriptor_pool
11+
from google.protobuf import runtime_version as _runtime_version
12+
from google.protobuf import symbol_database as _symbol_database
13+
from google.protobuf.internal import builder as _builder
14+
_runtime_version.ValidateProtobufRuntimeVersion(
15+
_runtime_version.Domain.PUBLIC,
16+
6,
17+
31,
18+
1,
19+
'',
20+
'apio/common/proto/apio-testing.proto'
21+
)
22+
# @@protoc_insertion_point(imports)
23+
24+
_sym_db = _symbol_database.Default()
25+
26+
27+
28+
29+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$apio/common/proto/apio-testing.proto\x12\x11\x61pio.common.proto\"B\n\x08MessageA\x12\x1a\n\x08\x66ield_a1\x18\x01 \x02(\tR\x08\x66ield-a1\x12\x1a\n\x08\x66ield_a2\x18\x02 \x01(\tR\x08\x66ield-a2\"|\n\x08MessageB\x12\x37\n\x08\x66ield_b1\x18\x01 \x02(\x0b\x32\x1b.apio.common.proto.MessageAR\x08\x66ield-b1\x12\x37\n\x08\x66ield_b2\x18\x02 \x01(\x0b\x32\x1b.apio.common.proto.MessageAR\x08\x66ield-b2')
30+
31+
_globals = globals()
32+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
33+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'apio.common.proto.apio_testing_pb2', _globals)
34+
if not _descriptor._USE_C_DESCRIPTORS:
35+
DESCRIPTOR._loaded_options = None
36+
_globals['_MESSAGEA']._serialized_start=59
37+
_globals['_MESSAGEA']._serialized_end=125
38+
_globals['_MESSAGEB']._serialized_start=127
39+
_globals['_MESSAGEB']._serialized_end=251
40+
# @@protoc_insertion_point(module_scope)

0 commit comments

Comments
 (0)