Skip to content

Commit b3d2037

Browse files
author
José Valim
committed
Fix mix iex
1 parent 486cb79 commit b3d2037

File tree

9 files changed

+96
-22
lines changed

9 files changed

+96
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* [CLI] `--debug-info` is now true by default
33
* [ExUnit] Make ExUnit exit happen in two steps allowing developers to add custom `at_exit` hooks
44
* [Macro] Improvements to `Macro.to_binary`
5+
* [Mix] Mix now prints information as they come when executing git commands and compiling projects
56
* [Kernel] Functions defined with `fn` can now handle many clauses
67
* [Kernel] Raise an error if clauses with different arities are defined in the same function
78
* [Kernel] `function` macro now accepts arguments in `M.f/a` format

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define APP_TEMPLATE
1515
$(1): lib/$(1)/ebin/Elixir-$(2).beam lib/$(1)/ebin/$(1).app
1616

1717
lib/$(1)/ebin/$(1).app:
18-
@ cd lib/$(1) && ../../bin/elixir ../../bin/mix compile.app
18+
@ cd lib/$(1) && ../../bin/mix compile.app
1919

2020
lib/$(1)/ebin/Elixir-$(2).beam: $(wildcard lib/$(1)/lib/*.ex) $(wildcard lib/$(1)/lib/*/*.ex) $(wildcard lib/$(1)/lib/*/*/*.ex)
2121
@ echo "==> $(1) (compile)"

bin/mix

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
#!/usr/bin/env elixir
2-
Mix.start
3-
Mix.CLI.run
1+
#!/bin/sh
2+
readlink_f () {
3+
cd "$(dirname "$1")" > /dev/null
4+
local filename="$(basename "$1")"
5+
if [ -h "$filename" ]; then
6+
readlink_f "$(readlink "$filename")"
7+
else
8+
echo "`pwd -P`/$filename"
9+
fi
10+
}
11+
12+
SELF=$(readlink_f "$0")
13+
SCRIPT_PATH=$(dirname "$SELF")
14+
ERL_OPTS=""
15+
16+
if [ "$1" == "iex" ]; then ERL_OPTS="-user Elixir-IEx-CLI -iex wait true"; fi
17+
exec "$SCRIPT_PATH"/elixir --erl "$ERL_OPTS" -e "Mix.start; Mix.CLI.run" -- "$@"

lib/elixir/lib/kernel.ex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,7 @@ defmodule Kernel do
14831483
differences:
14841484
14851485
1) Differently from records, exceptions are documented by default;
1486+
14861487
2) Exceptions **must** implement `message/1` as API that return a
14871488
binary as result;
14881489
@@ -1519,12 +1520,14 @@ defmodule Kernel do
15191520
case __CALLER__.in_guard? do
15201521
true ->
15211522
quote do
1522-
is_tuple(unquote(thing)) and :erlang.element(2, unquote(thing)) == :__exception__
1523+
is_tuple(unquote(thing)) and tuple_size(unquote(thing)) > 1 and
1524+
:erlang.element(2, unquote(thing)) == :__exception__
15231525
end
15241526
false ->
15251527
quote do
15261528
result = unquote(thing)
1527-
is_tuple(result) and :erlang.element(2, result) == :__exception__
1529+
is_tuple(result) and tuple_size(result) > 1 and
1530+
:erlang.element(2, result) == :__exception__
15281531
end
15291532
end
15301533
end
@@ -2727,7 +2730,7 @@ defmodule Kernel do
27272730
"""
27282731
@spec raise(binary | atom | tuple) :: no_return
27292732
def raise(msg) when is_binary(msg) do
2730-
:erlang.error RuntimeError.new(message: msg)
2733+
:erlang.error RuntimeError[message: msg]
27312734
end
27322735

27332736
def raise(exception) do
@@ -2744,14 +2747,23 @@ defmodule Kernel do
27442747
Any module defined via `defexception` automatically
27452748
defines `exception(args)` that returns a new instance
27462749
of the record and a `exception(args, current)` that
2747-
works as no-op.
2750+
updates the current exception.
2751+
2752+
Re-raising an exception will retrieve the previous
2753+
stacktrace so it keps the properties of the original
2754+
exception.
27482755
27492756
## Examples
27502757
27512758
raise ArgumentError, message: "Sample"
27522759
27532760
"""
27542761
@spec raise(tuple | atom, list) :: no_return
2762+
def raise(exception, args) when is_tuple(exception) and tuple_size(exception) > 1 and
2763+
:erlang.element(2, exception) == :__exception__ do
2764+
:erlang.raise(:error, exception.exception(args), :erlang.get_stacktrace)
2765+
end
2766+
27552767
def raise(exception, args) do
27562768
:erlang.error exception.exception(args)
27572769
end

lib/iex/lib/iex.ex

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ defmodule IEx do
5656
list
5757
end
5858

59+
@doc """
60+
Releases waiting IEx.
61+
62+
When IEx is started with "-iex wait true",
63+
the console does not start until `IEx.release`
64+
is invoked.
65+
66+
It returns `:ok` if IEx is released, `:error`
67+
if the wait flag was not set.
68+
"""
69+
def release do
70+
case :application.get_env(:iex, :wait) do
71+
{ :ok, value } ->
72+
cond do
73+
is_pid(value) ->
74+
value <- { :iex_latch, :release }
75+
:ok
76+
value == true ->
77+
receive after: (200 -> release)
78+
value == false ->
79+
:error
80+
end
81+
:undefined ->
82+
# IEx wasn't even started yet
83+
:error
84+
end
85+
end
86+
5987
@doc """
6088
Registers options used on inspect.
6189
"""
@@ -67,10 +95,7 @@ defmodule IEx do
6795
Returns currently registered inspect options.
6896
"""
6997
def inspect_opts do
70-
case :application.get_env(:iex, :inspect_opts) do
71-
{ :ok, list } -> list
72-
:undefined -> [limit: 50]
73-
end
98+
:application.get_env(:iex, :inspect_opts)
7499
end
75100

76101
@doc """
@@ -114,9 +139,7 @@ defmodule IEx do
114139
if is_atom(remsh), do: remsh, else: binary_to_atom(remsh)
115140
end
116141

117-
function = fn ->
118-
start config
119-
end
142+
function = fn -> start(config) end
120143

121144
args =
122145
if remote do
@@ -150,6 +173,8 @@ defmodule IEx do
150173
Process.flag(:trap_exit, true)
151174

152175
preload()
176+
wait_until_release()
177+
153178
set_expand_fun()
154179
run_after_spawn()
155180
IEx.Loop.start(config)
@@ -158,8 +183,20 @@ defmodule IEx do
158183

159184
## Boot Helpers
160185

161-
def boot_config(opts) do
162-
scope = :elixir.scope_for_eval(
186+
defp wait_until_release do
187+
{ :ok, wait } = :application.get_env(:iex, :wait)
188+
189+
if wait do
190+
:application.set_env(:iex, :wait, self())
191+
192+
receive do
193+
{ :iex_latch, :release } -> :ok
194+
end
195+
end
196+
end
197+
198+
defp boot_config(opts) do
199+
scope = :elixir.scope_for_eval(
163200
file: "iex",
164201
delegate_locals_to: IEx.Helpers
165202
)

lib/iex/mix.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ defmodule IEx.Mixfile do
66
end
77

88
def application do
9-
[env: [after_spawn: []]]
9+
[env: [
10+
after_spawn: [],
11+
inspect_opts: [limit: 50],
12+
wait: false,
13+
]]
1014
end
1115
end

lib/mix/lib/mix/tasks/iex.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ defmodule Mix.Tasks.Iex do
1111
"""
1212
def run(_) do
1313
Mix.Task.run Mix.project[:prepare_task]
14-
IEx.run
15-
:timer.sleep(:infinity)
14+
case IEx.release do
15+
:ok ->
16+
:timer.sleep(:infinity)
17+
:error ->
18+
raise Mix.Error, message: "could not start IEx. Due to booting constraints, " <>
19+
"IEx needs to be started on its own, like `mix iex` and it cannot be mixed " <>
20+
"with other tasks as in `mix do compile, iex`"
21+
end
1622
end
1723
end

lib/mix/test/mix/cli_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Mix.CLITest do
55

66
test "env" do
77
in_fixture "custom_mixfile", fn ->
8-
env = System.cmd %b(MIX_ENV=prod #{elixir_executable} #{mix_executable} run "IO.puts Mix.env")
8+
env = System.cmd %b(MIX_ENV=prod #{mix_executable} run "IO.puts Mix.env")
99
assert env =~ %r"prod"
1010
end
1111
end

lib/mix/test/test_helper.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule MixTest.Case do
6666
end
6767

6868
def mix(args) do
69-
System.cmd "#{elixir_executable} #{mix_executable} #{args}"
69+
System.cmd "#{mix_executable} #{args}"
7070
end
7171

7272
def mix_executable do

0 commit comments

Comments
 (0)