rbs_protobuf 0.3.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +10 -6
- data/CHANGELOG.md +17 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +32 -19
- data/README.md +3 -0
- data/Rakefile +4 -2
- data/bin/protoc-gen-dumper +3 -1
- data/bin/steep +7 -5
- data/example/Steepfile +1 -0
- data/example/d.proto +6 -0
- data/exe/protoc-gen-rbs +4 -1
- data/lib/rbs_protobuf/name.rb +68 -0
- data/lib/rbs_protobuf/translator/base.rb +1 -1
- data/lib/rbs_protobuf/translator/protobuf_gem.rb +547 -268
- data/lib/rbs_protobuf/version.rb +1 -1
- data/lib/rbs_protobuf.rb +2 -1
- data/rbs_collection.lock.yaml +38 -52
- data/rbs_collection.yaml +1 -8
- data/sig/rbs_protobuf/name.rbs +45 -0
- data/sig/rbs_protobuf/translator/protobuf_gem.rbs +80 -11
- metadata +6 -4
- data/.protoc-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36689cc81f238ec33c07f1485ab4ff50f73fe365c1e84fcb925d34b0159859d3
|
4
|
+
data.tar.gz: a149120654ab2387721383d723bf3c54923385a66feff3a755ebce1056bf014c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2bc3a51198e70d9617edf6df9c40e9fbfbac8061d3b849d6cf2ec21b839bd379bea6bf94d5a63dc134af173c773338f7b937b53597906e1bb3e85dd6c965c3c
|
7
|
+
data.tar.gz: 349c294046f6c7665dad74a0461311bf4c7edb58d9c8f804bd70b6c6ed11442d295086a59b9990465d478195c87c96e54180237e8fdd1a73c202e48ffde73b60
|
data/.github/workflows/test.yml
CHANGED
@@ -12,12 +12,13 @@ jobs:
|
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
14
|
container_tag:
|
15
|
-
-
|
16
|
-
- 3.
|
17
|
-
- 3.
|
15
|
+
- 3.0-dev-focal
|
16
|
+
- 3.1-dev-jammy
|
17
|
+
- 3.2-dev-jammy
|
18
18
|
protoc_version:
|
19
|
-
- 3.18.2
|
20
|
-
- 3.19.4
|
19
|
+
- "3.18.2"
|
20
|
+
- "3.19.4"
|
21
|
+
- "24.0"
|
21
22
|
container:
|
22
23
|
image: rubylang/ruby:${{ matrix.container_tag }}
|
23
24
|
steps:
|
@@ -30,7 +31,10 @@ jobs:
|
|
30
31
|
unzip protoc-${{ matrix.protoc_version }}-linux-x86_64.zip
|
31
32
|
mv bin/protoc /usr/local/bin/protoc
|
32
33
|
protoc --version
|
33
|
-
- uses: actions/checkout@
|
34
|
+
- uses: actions/checkout@v3
|
35
|
+
- name: Set up git safe.directory
|
36
|
+
run: |
|
37
|
+
git config --global --add safe.directory /__w/rbs_protobuf/rbs_protobuf
|
34
38
|
- name: Run test
|
35
39
|
run: |
|
36
40
|
ruby -v
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.1.0 (2023-08-16)
|
4
|
+
|
5
|
+
* Support optional fields in proto3 ([\#32](https://github.com/square/rbs_protobuf/pull/32))
|
6
|
+
* Update Steep to 1.5 and RBS to 3.1 ([\#30](https://github.com/square/rbs_protobuf/pull/30))
|
7
|
+
|
8
|
+
## 1.0.0 (2022-04-25)
|
9
|
+
|
10
|
+
This is version 1.0.0. 🎉
|
11
|
+
|
12
|
+
It includes changes on `nil` handling on required fields. Passing `nil` to required fields is prohibited by default, but there is an option to allow it, define `$RBS_PROTOBUF_ACCEPT_NIL_ATTR_WRITER` env var.
|
13
|
+
|
14
|
+
* Stop accepting `nil` to required fields ([\#16](https://github.com/square/rbs_protobuf/pull/16))
|
15
|
+
* Add an option to let required fields accept `nil` ([\#27](https://github.com/square/rbs_protobuf/pull/27))
|
16
|
+
* Fix extension generator ([\#21](https://github.com/square/rbs_protobuf/pull/21))
|
17
|
+
* Use overload for field write types ([\#22](https://github.com/square/rbs_protobuf/pull/22))
|
18
|
+
* Generate helper types and use them ([\#24](https://github.com/square/rbs_protobuf/pull/24))
|
19
|
+
|
3
20
|
## 0.3.0 (2022-04-05)
|
4
21
|
|
5
22
|
* Put protobuf _options_ in RBS comment ([\#15](https://github.com/square/rbs_protobuf/pull/15))
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,59 +1,72 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbs_protobuf (
|
4
|
+
rbs_protobuf (1.1.0)
|
5
5
|
activesupport (>= 4.0)
|
6
6
|
rbs (>= 2.2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.0.
|
11
|
+
activesupport (7.0.7)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
15
15
|
tzinfo (~> 2.0)
|
16
16
|
ast (2.4.2)
|
17
|
-
concurrent-ruby (1.
|
17
|
+
concurrent-ruby (1.2.2)
|
18
|
+
csv (3.2.7)
|
18
19
|
ffi (1.15.5)
|
19
|
-
|
20
|
+
fileutils (1.7.1)
|
21
|
+
i18n (1.14.1)
|
20
22
|
concurrent-ruby (~> 1.0)
|
21
|
-
|
22
|
-
|
23
|
+
json (2.6.3)
|
24
|
+
language_server-protocol (3.17.0.3)
|
25
|
+
listen (3.8.0)
|
23
26
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
24
27
|
rb-inotify (~> 0.9, >= 0.9.10)
|
28
|
+
logger (1.5.3)
|
25
29
|
middleware (0.1.0)
|
26
|
-
minitest (5.
|
27
|
-
|
28
|
-
parser (3.1.1.0)
|
30
|
+
minitest (5.19.0)
|
31
|
+
parser (3.2.2.3)
|
29
32
|
ast (~> 2.4.1)
|
33
|
+
racc
|
30
34
|
protobuf (3.10.5)
|
31
35
|
activesupport (>= 3.2)
|
32
36
|
middleware
|
33
37
|
thor
|
34
38
|
thread_safe
|
39
|
+
racc (1.7.1)
|
35
40
|
rainbow (3.1.1)
|
36
41
|
rake (12.3.3)
|
37
|
-
rb-fsevent (0.11.
|
42
|
+
rb-fsevent (0.11.2)
|
38
43
|
rb-inotify (0.10.1)
|
39
44
|
ffi (~> 1.0)
|
40
|
-
rbs (
|
41
|
-
|
45
|
+
rbs (3.1.3)
|
46
|
+
securerandom (0.2.2)
|
47
|
+
steep (1.5.3)
|
42
48
|
activesupport (>= 5.1)
|
49
|
+
concurrent-ruby (>= 1.1.10)
|
50
|
+
csv (>= 3.0.9)
|
51
|
+
fileutils (>= 1.1.0)
|
52
|
+
json (>= 2.1.0)
|
43
53
|
language_server-protocol (>= 3.15, < 4.0)
|
44
54
|
listen (~> 3.0)
|
45
|
-
|
46
|
-
parser (>= 3.
|
55
|
+
logger (>= 1.3.0)
|
56
|
+
parser (>= 3.1)
|
47
57
|
rainbow (>= 2.2.2, < 4.0)
|
48
|
-
rbs (>=
|
58
|
+
rbs (>= 3.1.0)
|
59
|
+
securerandom (>= 0.1)
|
60
|
+
strscan (>= 1.0.0)
|
49
61
|
terminal-table (>= 2, < 4)
|
62
|
+
strscan (3.0.6)
|
50
63
|
terminal-table (3.0.2)
|
51
64
|
unicode-display_width (>= 1.1.1, < 3)
|
52
65
|
thor (1.2.1)
|
53
66
|
thread_safe (0.3.6)
|
54
|
-
tzinfo (2.0.
|
67
|
+
tzinfo (2.0.6)
|
55
68
|
concurrent-ruby (~> 1.0)
|
56
|
-
unicode-display_width (2.
|
69
|
+
unicode-display_width (2.4.2)
|
57
70
|
|
58
71
|
PLATFORMS
|
59
72
|
ruby
|
@@ -62,9 +75,9 @@ DEPENDENCIES
|
|
62
75
|
minitest (~> 5.0)
|
63
76
|
protobuf (~> 3.10)
|
64
77
|
rake (~> 12.0)
|
65
|
-
rbs
|
78
|
+
rbs (~> 3.1)
|
66
79
|
rbs_protobuf!
|
67
80
|
steep
|
68
81
|
|
69
82
|
BUNDLED WITH
|
70
|
-
2.
|
83
|
+
2.3.11
|
data/README.md
CHANGED
@@ -95,12 +95,15 @@ gems:
|
|
95
95
|
We assume that you don't type check the generated `.pb.rb` code.
|
96
96
|
If you want to type check them, you need the definition of `Google::Protobuf`, which can be generated from [`descriptor.proto`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto).
|
97
97
|
|
98
|
+
Note: `rbs_protobuf` generates RBS files assuming some types added in [this PR](https://github.com/ruby/gem_rbs_collection/pull/145). Make sure you are using one of the newer versions of `rbs_gem_collection` definitions.
|
99
|
+
|
98
100
|
### Options
|
99
101
|
|
100
102
|
* `RBS_PROTOBUF_BACKEND` specifies the Ruby code generator gem. Supported value is `protobuf`. (We will add `google-protobuf` for `google-protobuf` gem.)
|
101
103
|
* `PB_UPCASE_ENUMS` is for `protobuf` gem support. Specify the environment variable to make enum value constants upper case.
|
102
104
|
* `RBS_PROTOBUF_NO_NESTED_NAMESPACE` is to make the RBS declarations flat.
|
103
105
|
* `RBS_PROTOBUF_EXTENSION` specifies what to do for extensions.
|
106
|
+
* `RBS_PROTOBUF_ACCEPT_NIL_ATTR_WRITER` is to allow passing `nil` to required fields.
|
104
107
|
|
105
108
|
## Supported features
|
106
109
|
|
data/Rakefile
CHANGED
@@ -27,7 +27,8 @@ namespace :example do
|
|
27
27
|
"-I#{proto_path}",
|
28
28
|
"example/a.proto",
|
29
29
|
"example/b.proto",
|
30
|
-
"example/c.proto"
|
30
|
+
"example/c.proto",
|
31
|
+
"example/d.proto"
|
31
32
|
)
|
32
33
|
sh(
|
33
34
|
{ "RBS_PROTOBUF_BACKEND" => "protobuf", "RBS_PROTOBUF_EXTENSION" => "true" },
|
@@ -35,7 +36,8 @@ namespace :example do
|
|
35
36
|
"--rbs_out=example/protobuf-gem",
|
36
37
|
"-Iexample",
|
37
38
|
"example/a.proto",
|
38
|
-
"example/b.proto"
|
39
|
+
"example/b.proto",
|
40
|
+
"example/d.proto"
|
39
41
|
)
|
40
42
|
sh(
|
41
43
|
{ "RBS_PROTOBUF_BACKEND" => "protobuf", "RBS_PROTOBUF_EXTENSION" => "true", "RUBYOPT" => "-rbundler/setup -Iexample/protobuf-gem -rc.pb" },
|
data/bin/protoc-gen-dumper
CHANGED
@@ -7,5 +7,7 @@ require "rbs_protobuf"
|
|
7
7
|
input = STDIN.read()
|
8
8
|
File.write(ENV["PROTOC_DUMPER_OUT"] || "a.pb.out", input)
|
9
9
|
|
10
|
-
response = Google::Protobuf::Compiler::CodeGeneratorResponse.new
|
10
|
+
response = Google::Protobuf::Compiler::CodeGeneratorResponse.new(
|
11
|
+
:supported_features => ::Google::Protobuf::Compiler::CodeGeneratorResponse::Feature::FEATURE_PROTO3_OPTIONAL.to_i
|
12
|
+
)
|
11
13
|
print Google::Protobuf::Compiler::CodeGeneratorResponse.encode(response)
|
data/bin/steep
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
|
3
|
+
BINSTUB_DIR=$(cd $(dirname $0); pwd)
|
4
|
+
GEMFILE=$(readlink -f ${BINSTUB_DIR}/../Gemfile)
|
5
|
+
ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/..)
|
4
6
|
|
5
|
-
STEEP="bundle exec steep"
|
7
|
+
STEEP="bundle exec --gemfile=${GEMFILE} steep"
|
6
8
|
|
7
9
|
if type "rbenv" > /dev/null 2>&1; then
|
8
10
|
STEEP="rbenv exec ${STEEP}"
|
9
11
|
else
|
10
12
|
if type "rvm" > /dev/null 2>&1; then
|
11
|
-
STEEP="rvm ${
|
13
|
+
STEEP="rvm ${ROOT_DIR} do ${STEEP}"
|
12
14
|
fi
|
13
15
|
fi
|
14
16
|
|
15
|
-
exec $STEEP
|
17
|
+
exec $STEEP $@
|
data/example/Steepfile
CHANGED
data/example/d.proto
ADDED
data/exe/protoc-gen-rbs
CHANGED
@@ -30,11 +30,14 @@ translator = case backend
|
|
30
30
|
true
|
31
31
|
end
|
32
32
|
|
33
|
+
accept_nil_writer = ENV.key?("RBS_PROTOBUF_ACCEPT_NIL_ATTR_WRITER")
|
34
|
+
|
33
35
|
RBSProtobuf::Translator::ProtobufGem.new(
|
34
36
|
input,
|
35
37
|
upcase_enum: upcase_enum,
|
36
38
|
nested_namespace: !no_nested_namespace,
|
37
|
-
extension: extension
|
39
|
+
extension: extension,
|
40
|
+
accept_nil_writer: accept_nil_writer
|
38
41
|
)
|
39
42
|
when "google-protobuf"
|
40
43
|
raise NotImplementedError
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module RBSProtobuf
|
2
|
+
module Name
|
3
|
+
class Class
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
raise unless name.class?
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
|
11
|
+
def instance_type(*args)
|
12
|
+
RBS::Types::ClassInstance.new(name: name, args: args, location: nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
alias [] instance_type
|
16
|
+
|
17
|
+
def singleton_type
|
18
|
+
RBS::Types::ClassSingleton.new(name: name, location: nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
def instance_type?(t)
|
22
|
+
t.is_a?(RBS::Types::ClassInstance) && t.name == name
|
23
|
+
end
|
24
|
+
|
25
|
+
def singleton_type?(t)
|
26
|
+
t.is_a?(RBS::Types::ClassSingleton) && t.name == name
|
27
|
+
end
|
28
|
+
|
29
|
+
def super_class(*args)
|
30
|
+
RBS::AST::Declarations::Class::Super.new(name: name, args: args, location: nil)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Alias
|
35
|
+
attr_reader :name
|
36
|
+
|
37
|
+
def initialize(name)
|
38
|
+
raise unless name.alias?
|
39
|
+
@name = name
|
40
|
+
end
|
41
|
+
|
42
|
+
def [](*args)
|
43
|
+
RBS::Types::Alias.new(name: name, args: args, location: nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
def type?(t)
|
47
|
+
t.is_a?(RBS::Types::Alias) && t.name == name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Interface
|
52
|
+
attr_reader :name
|
53
|
+
|
54
|
+
def initialize(name)
|
55
|
+
raise unless name.interface?
|
56
|
+
@name = name
|
57
|
+
end
|
58
|
+
|
59
|
+
def [](*args)
|
60
|
+
RBS::Types::Interface.new(name: name, args: args, location: nil)
|
61
|
+
end
|
62
|
+
|
63
|
+
def type?(t)
|
64
|
+
t.is_a?(RBS::Types::Interface) && t.name == name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -14,7 +14,7 @@ module RBSProtobuf
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def response
|
17
|
-
@response ||= Google::Protobuf::Compiler::CodeGeneratorResponse.new
|
17
|
+
@response ||= Google::Protobuf::Compiler::CodeGeneratorResponse.new(:supported_features => ::Google::Protobuf::Compiler::CodeGeneratorResponse::Feature::FEATURE_PROTO3_OPTIONAL.to_i)
|
18
18
|
end
|
19
19
|
|
20
20
|
def generate_rbs!
|