Skip to content

Commit d440a3f

Browse files
authored
Fix old TODO's related to minimum elixir version (#418)
* chore: fix todos related to minimum elixir version * Update Readme to point to newest version in hex * Code.fetch_docs/1 cannot handle bytecode directly
1 parent 6004d6b commit d440a3f

File tree

5 files changed

+13
-40
lines changed

5 files changed

+13
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The package can be installed by adding `:protobuf` to your list of dependencies
2222
```elixir
2323
def deps do
2424
[
25-
{:protobuf, "~> 0.14.1"}
25+
{:protobuf, "~> 0.15.0"}
2626
]
2727
end
2828
```

lib/protobuf/extension.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ defmodule Protobuf.Extension do
3535
3636
"""
3737

38-
import Bitwise, only: [<<<: 2]
39-
40-
# TODO: replace bitshift with Integer.pow/2 when we depend on Elixir 1.12+.
4138
# 2^29, see https://developers.google.com/protocol-buffers/docs/proto#extensions
42-
@max 1 <<< 29
39+
@max Integer.pow(2, 29)
4340

4441
@doc """
4542
Returns the maximum extension number.

lib/protobuf/wire/varint.ex

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,32 @@ defmodule Protobuf.Wire.Varint do
4949
@max_bits 64
5050
@mask64 bsl(1, @max_bits) - 1
5151

52-
# generated: true is required here to silence compilation warnings in Elixir
53-
# 1.10 and 1.11. OK to remove once we support only 1.12+
5452
@varints [
5553
{
5654
quote(do: <<0::1, value::7>>),
5755
quote(do: value)
5856
},
5957
{
6058
quote(do: <<1::1, x0::7, 0::1, x1::7>>),
61-
quote(generated: true, do: x0 + bsl(x1, 7))
59+
quote(do: x0 + bsl(x1, 7))
6260
},
6361
{
6462
quote(do: <<1::1, x0::7, 1::1, x1::7, 0::1, x2::7>>),
65-
quote(generated: true, do: x0 + bsl(x1, 7) + bsl(x2, 14))
63+
quote(do: x0 + bsl(x1, 7) + bsl(x2, 14))
6664
},
6765
{
6866
quote(do: <<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 0::1, x3::7>>),
69-
quote(generated: true, do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21))
67+
quote(do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21))
7068
},
7169
{
7270
quote(do: <<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 0::1, x4::7>>),
73-
quote(generated: true, do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21) + bsl(x4, 28))
71+
quote(do: x0 + bsl(x1, 7) + bsl(x2, 14) + bsl(x3, 21) + bsl(x4, 28))
7472
},
7573
{
7674
quote do
7775
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 0::1, x5::7>>
7876
end,
79-
quote(generated: true) do
77+
quote do
8078
x0 +
8179
bsl(x1, 7) +
8280
bsl(x2, 14) +
@@ -90,7 +88,7 @@ defmodule Protobuf.Wire.Varint do
9088
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 0::1,
9189
x6::7>>
9290
end,
93-
quote(generated: true) do
91+
quote do
9492
x0 +
9593
bsl(x1, 7) +
9694
bsl(x2, 14) +
@@ -105,7 +103,7 @@ defmodule Protobuf.Wire.Varint do
105103
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 1::1,
106104
x6::7, 0::1, x7::7>>
107105
end,
108-
quote(generated: true) do
106+
quote do
109107
x0 +
110108
bsl(x1, 7) +
111109
bsl(x2, 14) +
@@ -121,7 +119,7 @@ defmodule Protobuf.Wire.Varint do
121119
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 1::1,
122120
x6::7, 1::1, x7::7, 0::1, x8::7>>
123121
end,
124-
quote(generated: true) do
122+
quote do
125123
x0 +
126124
bsl(x1, 7) +
127125
bsl(x2, 14) +
@@ -138,7 +136,7 @@ defmodule Protobuf.Wire.Varint do
138136
<<1::1, x0::7, 1::1, x1::7, 1::1, x2::7, 1::1, x3::7, 1::1, x4::7, 1::1, x5::7, 1::1,
139137
x6::7, 1::1, x7::7, 1::1, x8::7, 0::1, x9::7>>
140138
end,
141-
quote(generated: true) do
139+
quote do
142140
v =
143141
x0 +
144142
bsl(x1, 7) +

test/protobuf/protoc/cli_integration_test.exs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
defmodule Protobuf.Protoc.CLIIntegrationTest do
22
use ExUnit.Case, async: true
33

4-
# TODO: Remove when we depend on Elixir 1.11+.
5-
import Protobuf.TestHelpers, only: [tmp_dir: 1, fetch_docs_from_bytecode: 1], warn: false
6-
74
alias Protobuf.TestHelpers
85

9-
if Version.match?(System.version(), ">= 1.11.0") do
10-
@moduletag :tmp_dir
11-
else
12-
setup :tmp_dir
13-
end
6+
@moduletag :tmp_dir
147

158
describe "with simple user.proto file" do
169
setup %{tmp_dir: tmp_dir} do
@@ -108,7 +101,7 @@ defmodule Protobuf.Protoc.CLIIntegrationTest do
108101
path
109102
|> Code.compile_file()
110103
|> Enum.map(fn {mod, bytecode} ->
111-
{mod, fetch_docs_from_bytecode(bytecode)}
104+
{mod, TestHelpers.fetch_docs_from_bytecode(bytecode)}
112105
end)
113106

114107
on_exit(fn ->

test/test_helper.exs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ defmodule Protobuf.TestHelpers do
1313
end)
1414
end
1515

16-
# TODO: Remove when we depend on Elixir 1.11+.
17-
def tmp_dir(context) do
18-
dir_name =
19-
"#{inspect(context[:case])}#{context[:describe]}#{context[:test]}"
20-
|> String.downcase()
21-
|> String.replace(["-", " ", ".", "_"], "_")
22-
23-
tmp_dir_name = Path.join(System.tmp_dir!(), dir_name)
24-
25-
File.rm_rf!(tmp_dir_name)
26-
File.mkdir_p!(tmp_dir_name)
27-
28-
Map.put(context, :tmp_dir, tmp_dir_name)
29-
end
30-
3116
def read_generated_file(relative_path) do
3217
[__DIR__, "../generated", relative_path]
3318
|> Path.join()

0 commit comments

Comments
 (0)