-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
mix.exs
219 lines (189 loc) · 5.82 KB
/
mix.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
defmodule Xandra.Mixfile do
use Mix.Project
@description "Fast, simple, and robust Cassandra driver for Elixir."
@repo_url "https://github.com/lexhide/xandra"
@version "0.19.1"
def project() do
[
app: :xandra,
version: @version,
elixir: "~> 1.15",
elixirc_paths: elixirc_paths(Mix.env()),
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
xref: [exclude: [Decimal]],
# Task aliases
aliases: aliases(),
# Dialyzer
dialyzer: [
flags: [:no_contracts, :no_improper_lists],
list_unused_filters: true,
plt_add_apps: [:ssl, :crypto, :mix, :ex_unit, :erts, :kernel, :stdlib],
plt_local_path: "plts",
plt_core_path: "plts"
],
# Testing
preferred_cli_env: [
"test.cassandra": :test,
"test.scylladb": :test,
"test.all": :test,
"test.all_with_html_coverage": :test,
"coveralls.html": :test
],
test_coverage: [tool: ExCoveralls],
# Hex
package: package(),
description: @description,
# Docs
name: "Xandra",
docs: [
main: "Xandra",
source_ref: "v#{@version}",
source_url: @repo_url,
extras: [
"pages/Data types comparison table.md",
"pages/Compatibility.md",
"pages/Telemetry events.md"
]
]
]
end
def application() do
[extra_applications: [:logger]]
end
defp elixirc_paths(:test), do: ["test/support"] ++ elixirc_paths(:dev)
defp elixirc_paths(_env), do: ["lib"]
defp package() do
[
maintainers: ["Andrea Leopardi"],
licenses: ["ISC"],
links: %{"GitHub" => @repo_url}
]
end
defp run_cassandra_tests(args, extra_env \\ []) do
case List.keyfind(extra_env, "CASSANDRA_NATIVE_PROTOCOL", 0) do
{_, protocol} -> print_header("Running Cassandra tests (native protocol #{protocol})")
_other -> print_header("Running Cassandra tests")
end
mix_cmd_with_status_check(
["test", "--exclude", "scylla_specific", ansi_option() | args],
[
{"CASSANDRA_PORT", "9052"},
{"CASSANDRA_WITH_AUTH_PORT", "9053"}
] ++ extra_env
)
end
defp run_scylladb_tests(args, extra_env \\ []) do
case List.keyfind(extra_env, "CASSANDRA_NATIVE_PROTOCOL", 0) do
{_, protocol} -> print_header("Running ScyllaDB tests (native protocol #{protocol})")
_other -> print_header("Running ScyllaDB tests")
end
mix_cmd_with_status_check(
[
"test",
"--exclude",
"cassandra_specific",
"--exclude",
"encryption",
"--include",
"scylla_specific",
ansi_option() | args
],
[
{"CASSANDRA_PORT", "9062"},
{"CASSANDRA_WITH_AUTH_PORT", "9063"}
] ++ extra_env
)
end
defp run_tests_with_protocols_and_coverage(coverage_task, args) do
for protocol <- ["", "v5", "v4", "v3"] do
run_cassandra_tests(
["--cover", "--export-coverage", "cassandra-#{protocol}" | args],
[{"CASSANDRA_NATIVE_PROTOCOL", protocol}]
)
end
for protocol <- ["", "v4", "v3"] do
run_scylladb_tests(
["--cover", "--export-coverage", "scylladb-#{protocol}" | args],
[{"CASSANDRA_NATIVE_PROTOCOL", protocol}]
)
end
Mix.Task.run(coverage_task, ["--exclude", "test", "--import-cover", "cover"])
end
defp aliases() do
[
test: "test --exclude scylla_specific",
"test.cassandra": &run_cassandra_tests/1,
"test.scylladb": &run_scylladb_tests/1,
"test.all": fn args ->
Mix.Task.run("test.cassandra", args)
Mix.Task.run("test.scylladb", args)
end,
"test.all_with_html_coverage": &run_tests_with_protocols_and_coverage("coveralls.html", &1),
"test.ci_with_coverage": &run_tests_with_protocols_and_coverage("coveralls.github", &1),
docs: [
"run pages/generate_telemetry_events_page.exs",
"docs"
]
]
end
defp deps() do
[
{:decimal, "~> 1.7 or ~> 2.0", optional: true},
{:nimble_options, "~> 1.0"},
{:telemetry, "~> 0.4.3 or ~> 1.0"},
# Dev and test dependencies
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.30", only: :dev},
{:excoveralls, "~> 0.18", only: :test},
{:mox, "~> 1.0", only: :test},
{:stream_data, "~> 1.0", only: [:dev, :test]},
{:nimble_lz4, "~> 0.1.3 or ~> 1.0", only: [:dev, :test]},
# This is a fix to avoid warnings on Elixir 1.17+, it overrides the toxiproxy_ex
# requirement.
{:tesla, ">= 1.11.2", only: :test, override: true},
{:toxiproxy_ex, "~> 2.0", only: :test}
]
end
defp mix_cmd_with_status_check(args, env) do
port =
Port.open({:spawn_executable, System.find_executable("mix")}, [
:binary,
:exit_status,
args: args,
env:
Enum.map(env, fn {key, val} ->
{String.to_charlist(key), String.to_charlist(val)}
end)
])
# We want a port so that we can shut down the port if we shut down the system.
receive_loop(port)
end
defp receive_loop(port) do
receive do
{^port, {:data, data}} ->
:ok = IO.write(data)
receive_loop(port)
{^port, {:exit_status, 0}} ->
:ok
{^port, {:exit_status, status}} ->
Mix.raise("Mix failed with exit status #{status}")
after
60_000 ->
Mix.raise("Timed out waiting for Mix to send back any data (after 60s)")
end
end
defp ansi_option do
if IO.ANSI.enabled?(), do: "--color", else: "--no-color"
end
defp print_header(header) do
Mix.shell().info([:cyan, :bright, header, :reset])
Mix.shell().info([
:cyan,
:bright,
String.duplicate("=", String.length(header)) <> "\n",
:reset
])
end
end