Skip to content

Commit

Permalink
update(fildesh): with new boolean & array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
grencez committed Jul 7, 2024
1 parent c720229 commit c536e50
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 88 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Bzlmod for dependencies.
common --experimental_enable_bzlmod
common --registry=https://raw.githubusercontent.com/rendezqueue/rendezqueue_bazel_registry/trunk
common --registry=https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main

Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/test_bazel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]

name: ${{ matrix.platform }}
runs-on: ${{ matrix.platform }}

steps:
Expand All @@ -22,7 +23,7 @@ jobs:
- name: Bazel Setup
uses: jwlawson/actions-setup-bazel@v2
with:
bazel-version: 'latest'
bazel-version: latest

- name: Bazel Version
run: bazel --version
Expand Down Expand Up @@ -51,11 +52,28 @@ jobs:
!bazel-bin*/**/*.runfiles*
coverage:
test_with_old_bazel:
runs-on: ubuntu-latest
steps:
- name: Bazel Setup
uses: jwlawson/actions-setup-bazel@v2
with:
bazel-version: "5.4.1"
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
run: touch WORKSPACE
- name: Test
run: >
bazel test
--check_direct_dependencies=error
--experimental_enable_bzlmod
--ignore_dev_dependency
-- //...
strategy:
fail-fast: false
coverage:
runs-on: ubuntu-latest

steps:
- name: Cache Setup
Expand All @@ -68,7 +86,7 @@ jobs:
- name: Bazel Setup
uses: jwlawson/actions-setup-bazel@v2
with:
bazel-version: 'latest'
bazel-version: latest

- name: Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.2.0")
bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "fildesh", version = "0.1.9")
bazel_dep(name = "protobuf", version = "3.19.6")
bazel_dep(name = "rules_proto", version = "4.0.0")

git_override(
module_name = "fildesh",
remote = "https://github.com/grencez/fildesh.git",
commit="11ff65ed78103bc1b1caefb1deb8fa42110eea08",
commit = "e9421ebbb546cf38bf2051d02fdc38dcf71f8216",
remote = "https://github.com/fildesh/fildesh.git",
)
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ Since each field of that message is an S-expression itself, there's no ambiguity

**Array fields.**
Rather than holding just one value of a certain type, a repeated field holds an array of such values.
Conceptually, an array is a funny message with no field names, so we wrap the name of the "funny message" field with parentheses and use an empty S-expression `()` in place of each element's nonexistent field name.
For simplicity, the "nonexistent field name" part is omitted for repeated scalars.
Conceptually, an array is a funny message with no field names, so we put `(())` where the first field would be.
For message elements, we put an empty S-expression `()` where the name would be.
```lisp
; An array of integers.
((my_integers) 1 2 3)
(my_integers (()) 1 2 3)
; An array of strings.
((my_strings) "yo" "howdy" "sup")
(my_strings (()) "yo" "howdy" "sup")
; An array of messages.
((my_messages)
(my_messages (())
(() (i 5))
(())
(() (i 5) (f 5.5) (s "hello")))
()
(() (i 5) (f 5.5) (s "hello"))
)
```
Empty file removed WORKSPACE.bazel
Empty file.
16 changes: 13 additions & 3 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
load("//sxproto:defs.bzl", "sxproto_data")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//sxproto:defs.bzl", "sxproto_data")

package(default_visibility = [
"//test:__subpackages__",
])

proto_library(
name = "intro_proto",
testonly = True,
srcs = ["intro.proto"],
)

sxproto_data(
name = "intro_1_scalar",
testonly = True,
src = "intro_1_scalar.sxpb",
proto_deps = ["intro_proto"],
proto_message = "IntroMessage",
)

sxproto_data(
name = "intro_2_message",
testonly = True,
src = "intro_2_message.sxpb",
proto_deps = ["intro_proto"],
proto_message = "IntroMessage",
)

sxproto_data(
name = "intro_3_empty_message",
testonly = True,
src = "intro_3_empty_message.sxpb",
proto_deps = ["intro_proto"],
proto_message = "IntroMessage",
)

sxproto_data(
name = "intro_5_array",
testonly = True,
src = "intro_5_array.sxpb",
proto_deps = ["intro_proto"],
proto_message = "IntroMessage",
)


proto_library(
name = "grocery_proto",
testonly = True,
srcs = ["grocery.proto"],
)

sxproto_data(
name = "popcorn_data",
testonly = True,
src = "popcorn.sxpb",
proto_deps = ["grocery_proto"],
proto_message = "GroceryListItem",
)

sxproto_data(
name = "sauces_data",
testonly = True,
src = "sauces.sxpb",
out_textproto = "sauces_data.txtpb",
out_json = "sauces_data.json",
out_json_camelcase = "sauces_data_camelcase.json",
out_textproto = "sauces_data.txtpb",
proto_deps = ["grocery_proto"],
proto_message = "GroceryList",
)
Expand Down
11 changes: 6 additions & 5 deletions example/intro_5_array.sxpb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
; An array of integers.
((my_integers) 1 2 3)
(my_integers (()) 1 2 3)

; An array of strings.
((my_strings) "yo" "howdy" "sup")
(my_strings (()) "yo" "howdy" "sup")

; An array of 3 messages.
((my_messages)
(my_messages (())
(() (i 5))
(())
(() (i 5) (f 5.5) (s "hello")))
()
(() (i 5) (f 5.5) (s "hello"))
)
14 changes: 8 additions & 6 deletions example/popcorn.sxpb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
(name "popcorn")
(name popcorn)
(amount 3)
(variety true)
(variety +true)
(expect_unit_cost 7.50)

; List of favorite kinds.
((favorites)
"cheddar" "caramel" "butter")
(favorites (())
cheddar caramel butter
)

; In case of no popcorn.
(alternative
(name "hot dog")
(amount 2))
(name "hot dog")
(amount 2)
)
12 changes: 7 additions & 5 deletions example/sauces.sxpb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
(budget 30)

((items)
(items (())
(()
(name "dip")
(amount 1)
(expect_cost 6.50)
((favorites) "hummus" "garlic"))
(favorites (()) "hummus" "garlic"))
(()
(name "hot sauce")
(amount 3)
(variety true)
(variety +true)
(expect_unit_cost 6.50)
((favorites)
(favorites (())
"yuzu" "kiss" "fire"
"bee" "sunshine")))
"bee" "sunshine")
)
)

; vim: ft=lisp lw=nil
4 changes: 1 addition & 3 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ cc_binary(

cc_binary(
name = "diffprotobuf",
srcs = [
"diffprotobuf.cc",
],
srcs = ["diffprotobuf.cc"],
deps = [":protobuf_transcode_lib"],
)
11 changes: 8 additions & 3 deletions src/binaryproto2sxproto_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ write_message_to_sxproto_ostream(
reflection->ListFields(message, &fields);

for (const FieldDescriptor* field : fields) {
out << '(';
out << '(' << field->name() << ' ';
if (field->is_repeated()) {
out << '(' << field->name() << ')';
out << "(())";
int n = reflection->FieldSize(message, field);

if (field->type() == FieldDescriptor::TYPE_MESSAGE) {
Expand All @@ -42,12 +42,14 @@ write_message_to_sxproto_ostream(
if (i > 0) {out << ' ';}
std::string s;
TextFormat::PrintFieldValueToString(message, field, i, &s);
if (field->type() == FieldDescriptor::TYPE_BOOL) {
out << '+';
}
out << s;
}
}
}
else {
out << field->name() << ' ';
if (field->type() == FieldDescriptor::TYPE_MESSAGE) {
const Message& submessage = reflection->GetMessage(message, field);
const bool good = write_message_to_sxproto_ostream(out, submessage);
Expand All @@ -56,6 +58,9 @@ write_message_to_sxproto_ostream(
else {
std::string s;
TextFormat::PrintFieldValueToString(message, field, -1, &s);
if (field->type() == FieldDescriptor::TYPE_BOOL) {
out << '+';
}
out << s;
}
}
Expand Down
30 changes: 15 additions & 15 deletions test/depend/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//sxproto:defs.bzl", "sxproto_data", "protobuf_equality_test")
load("//sxproto:defs.bzl", "protobuf_equality_test", "sxproto_data")

proto_library(
name = "shopping_proto",
testonly = True,
srcs = ["shopping.proto"],
deps = ["//example:grocery_proto"],
testonly = 1,
)

cc_proto_library(
name = "shopping_cc_proto",
testonly = True,
deps = [":shopping_proto"],
testonly = 1,
)

sxproto_data(
name = "shopping_data",
testonly = True,
src = "shopping.sxpb",
out_textproto = "shopping_data.txtpb",
proto_deps = [":shopping_proto"],
proto_message = "sxproto.test.depend.ShoppingList",
testonly = 1,
)

cc_test(
name = "shopping_expect_test",
size = "small",
srcs = ["shopping_expect_test.cc"],
deps = [":shopping_cc_proto"],
data = [":shopping_data"],
args = ["$(location :shopping_data)"],
size = "small",
data = [":shopping_data"],
deps = [":shopping_cc_proto"],
)

protobuf_equality_test(
name = "shopping_textproto_equality_test",
srcs = [
"shopping_data.txtpb",
"shopping_data",
"shopping_data.txtpb",
],
proto_deps = [":shopping_proto"],
proto_message = "sxproto.test.depend.ShoppingList",
)

proto_library(
name = "task_proto",
testonly = True,
srcs = ["task.proto"],
deps = [":shopping_proto"],
testonly = 1,
)

sxproto_data(
name = "task_data",
testonly = True,
src = "task.sxpb",
out_json = "task_data.json",
proto_deps = [":task_proto"],
proto_message = "sxproto.test.depend.TaskList",
testonly = 1,
)

cc_proto_library(
name = "task_cc_proto",
testonly = True,
deps = [":task_proto"],
testonly = 1,
)

cc_test(
name = "task_expect_test",
size = "small",
srcs = ["task_expect_test.cc"],
deps = [":task_cc_proto"],
data = [":task_data"],
args = ["$(location :task_data)"],
size = "small",
data = [":task_data"],
deps = [":task_cc_proto"],
)

protobuf_equality_test(
name = "task_json_equality_test",
srcs = [
"task_data.json",
"task_data",
"task_data.json",
],
proto_deps = [":task_proto"],
proto_message = "sxproto.test.depend.TaskList",
Expand Down
Loading

0 comments on commit c536e50

Please sign in to comment.