-
Notifications
You must be signed in to change notification settings - Fork 187
/
mix.exs
174 lines (141 loc) · 4.54 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
defmodule Hex.MixProject do
use Mix.Project
@version "2.1.2-dev"
def project do
[
app: :hex,
version: @version,
elixir: "~> 1.6",
aliases: aliases(),
preferred_cli_env: ["deps.get": :test],
config_path: config_path(),
compilers: [:leex] ++ Mix.compilers(),
deps: deps(Mix.env()),
elixirc_options: elixirc_options(Mix.env()),
elixirc_paths: elixirc_paths(Mix.env())
]
end
def application do
[
extra_applications: [:ssl, :inets, :logger],
mod: {Hex.Application, []}
]
end
defp deps(:test) do
[
{:bypass, "~> 1.0.0"},
{:cowboy, "~> 2.7.0"},
{:mime, "~> 1.0"},
{:plug, "~> 1.9.0"},
{:plug_cowboy, "~> 2.1.0"},
{:plug_crypto, "~> 1.1.2"}
]
end
defp deps(_) do
[]
end
defp elixirc_options(:prod), do: [debug_info: false]
defp elixirc_options(_), do: []
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp config_path() do
if Version.compare(System.version(), "1.11.0") in [:eq, :gt] do
"config/config.exs"
else
"config/mix_config.exs"
end
end
defp aliases do
[
"compile.elixir": [&unload_hex/1, "compile.elixir"],
run: [&unload_hex/1, "run"],
install: ["archive.build -o hex.ez", "archive.install hex.ez --force"],
certdata: [&certdata/1]
]
end
defp unload_hex(_) do
update_cached_deps(__MODULE__)
Application.stop(:hex)
Application.unload(:hex)
paths = Path.wildcard(Path.join(archives_path(), "hex*"))
Enum.each(paths, fn archive ->
ebin = archive_ebin(archive)
Code.delete_path(ebin)
{:ok, files} = ebin |> :unicode.characters_to_list() |> :erl_prim_loader.list_dir()
Enum.each(files, fn file ->
file = List.to_string(file)
size = byte_size(file) - byte_size(".beam")
case file do
<<name::binary-size(size), ".beam">> ->
module = String.to_atom(name)
:code.delete(module)
:code.purge(module)
_ ->
:ok
end
end)
end)
end
defp update_cached_deps(module) do
cond do
Version.compare(System.version(), "1.7.0") == :lt ->
if cached_deps = Mix.ProjectStack.read_cache({:cached_deps, Mix.env(), module}) do
cached_deps = Enum.map(cached_deps, &change_scm/1)
Mix.ProjectStack.write_cache({:cached_deps, Mix.env(), module}, cached_deps)
end
Version.compare(System.version(), "1.10.0") == :lt ->
case Mix.ProjectStack.read_cache({:cached_deps, module}) do
nil ->
:ok
{env_target, cached_deps} ->
cached_deps = Enum.map(cached_deps, &change_scm/1)
Mix.ProjectStack.write_cache({:cached_deps, module}, {env_target, cached_deps})
end
true ->
case Mix.State.read_cache({:cached_deps, module}) do
nil ->
:ok
{env_target, cached_deps} ->
cached_deps = Enum.map(cached_deps, &change_scm/1)
Mix.State.write_cache({:cached_deps, module}, {env_target, cached_deps})
end
end
end
defp change_scm(%Mix.Dep{deps: deps} = dep) do
%Mix.Dep{dep | scm: Hex.FakeSCM, deps: Enum.map(deps, &change_scm/1)}
end
@mk_ca_bundle_url "https://raw.githubusercontent.com/bagder/curl/master/scripts/mk-ca-bundle.pl"
@mk_ca_bundle_cmd "mk-ca-bundle.pl"
@ca_bundle "ca-bundle.crt"
@ca_bundle_target Path.join("lib/hex/http", @ca_bundle)
defp certdata(_) do
cmd("wget", [@mk_ca_bundle_url])
File.chmod!(@mk_ca_bundle_cmd, 0o755)
cmd(Path.expand(@mk_ca_bundle_cmd), ["-u"])
File.cp!(@ca_bundle, @ca_bundle_target)
File.rm!(@ca_bundle)
File.rm!(@mk_ca_bundle_cmd)
end
defp cmd(cmd, args) do
{_, result} = System.cmd(cmd, args, into: IO.stream(:stdio, :line), stderr_to_stdout: true)
if result != 0 do
raise "Non-zero result (#{result}) from: #{cmd} #{Enum.map_join(args, " ", &inspect/1)}"
end
end
cond do
function_exported?(Mix, :path_for, 1) ->
defp archives_path(), do: Mix.path_for(:archives)
function_exported?(Mix.Local, :path_for, 1) ->
defp archives_path(), do: Mix.Local.path_for(:archive)
true ->
defp archives_path(), do: Mix.Local.archives_path()
end
if function_exported?(Mix.Local, :archive_ebin, 1) do
defp archive_ebin(archive), do: Mix.Local.archive_ebin(archive)
else
defp archive_ebin(archive), do: Mix.Archive.ebin(archive)
end
end
defmodule Hex.FakeSCM do
def fetchable?, do: true
end