-
Notifications
You must be signed in to change notification settings - Fork 0
/
mix.exs
149 lines (124 loc) · 4.26 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
defmodule Hex.MixProject do
use Mix.Project
@version "0.17.2-dev"
{:ok, system_version} = Version.parse(System.version)
@elixir_version {system_version.major, system_version.minor, system_version.patch}
def project do
[
app: :hex,
version: @version,
elixir: "~> 1.0",
aliases: aliases(),
lockfile: lockfile(@elixir_version),
deps: deps(@elixir_version),
elixirc_options: elixirc_options(Mix.env),
elixirc_paths: elixirc_paths(Mix.env),
xref: xref()
]
end
def application do
[
applications: applications(Mix.env),
mod: {Hex, []}
]
end
defp applications(:prod), do: [:ssl, :inets]
defp applications(_), do: [:ssl, :inets, :logger]
# We use different versions of plug because older plug version produces
# warnings on elixir >=1.3.0 and newer plug versions do not work on elixir <1.2.3
defp lockfile(elixir_version) when elixir_version >= {1, 2, 3}, do: "mix-new.lock"
defp lockfile(_), do: "mix-old.lock"
# Can't use hex dependencies because the elixir compiler loads dependencies
# and calls the dependency SCM. This would cause us to crash if the SCM was
# Hex because we have to unload Hex before compiling it.
defp deps(elixir_version) when elixir_version >= {1, 2, 3} do
[{:plug, github: "elixir-lang/plug", tag: "v1.2.0", only: :test, override: true}] ++
deps()
end
defp deps(_) do
[{:plug, github: "elixir-lang/plug", tag: "v1.1.6", only: :test, override: true}] ++
deps()
end
defp deps do
[
{:bypass, github: "PSPDFKit-labs/bypass", only: :test},
{:mime, github: "elixir-lang/mime", tag: "v1.0.1", only: :test, override: true},
{:cowboy, github: "ninenines/cowboy", tag: "1.0.4", only: :test, override: true, manager: :rebar3},
{:cowlib, github: "ninenines/cowlib", tag: "1.0.2", only: :test, override: true, manager: :rebar3},
{:ranch, github: "ninenines/ranch", tag: "1.2.1", only: :test, override: true, manager: :rebar3}
]
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 xref do
[
exclude: [
{Mix.Local, :archives_path, 0},
{Mix.Local, :path_for, 1}
]
]
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
Application.stop(: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
@mk_ca_bundle_url "https://raw.githubusercontent.com/bagder/curl/master/lib/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
defp archives_path do
if function_exported?(Mix.Local, :path_for, 1) do
Mix.Local.path_for(:archive)
else
Mix.Local.archives_path()
end
end
defp archive_ebin(archive) do
if function_exported?(Mix.Local, :archive_ebin, 1) do
Mix.Local.archive_ebin(archive)
else
Mix.Archive.ebin(archive)
end
end
end