-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix escript archive layout and support priv #13730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e10b13e
a2f9878
fc14fe5
9997a47
088e8d6
afdcc98
0443bea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,17 @@ defmodule Mix.Tasks.EscriptTest do | |
end | ||
end | ||
|
||
defmodule EscriptWithPrivs do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is fine to leave this as is, but I think these tests could be written without defining modules. We have a way of pushing updated configuration when we do We should probably refactor this whole test case to use said style, so it could be done later anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes!! |
||
def project do | ||
[ | ||
app: :escript_test_with_priv, | ||
version: "0.0.1", | ||
escript: [main_module: EscriptTest, include_priv_for: [:escript_test_with_priv, :ok]], | ||
deps: [{:ok, path: fixture_path("deps_status/deps/ok")}] | ||
] | ||
end | ||
end | ||
|
||
test "generate escript" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
|
@@ -104,6 +115,13 @@ defmodule Mix.Tasks.EscriptTest do | |
assert_received {:mix_shell, :info, ["Generated escript escript_test with MIX_ENV=dev"]} | ||
assert System.cmd("escript", ["escript_test"]) == {"TEST\n", 0} | ||
assert count_abstract_code("escript_test") == 0 | ||
|
||
# Each app has a distinct, valid path | ||
assert System.cmd("escript", ["escript_test", "--app-paths"]) == {"{true, true, true}\n", 0} | ||
|
||
# Does not include priv by default | ||
assert System.cmd("escript", ["escript_test", "--list-priv", "escript_test"]) == | ||
{":error\n", 0} | ||
end) | ||
end | ||
|
||
|
@@ -229,6 +247,10 @@ defmodule Mix.Tasks.EscriptTest do | |
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", ["escript_test_with_deps"]) == {"TEST\n", 0} | ||
|
||
# Does not include priv for deps by default | ||
assert System.cmd("escript", ["escript_test_with_deps", "--list-priv", "ok"]) == | ||
{":error\n", 0} | ||
end) | ||
after | ||
purge([Ok.MixProject]) | ||
|
@@ -280,6 +302,26 @@ defmodule Mix.Tasks.EscriptTest do | |
end) | ||
end | ||
|
||
test "generate escript with priv" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptWithPrivs) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript escript_test_with_priv with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", [ | ||
"escript_test_with_priv", | ||
"--list-priv", | ||
"escript_test_with_priv" | ||
]) == {~s/{:ok, [~c"hello"]}\n/, 0} | ||
|
||
assert System.cmd("escript", ["escript_test_with_priv", "--list-priv", "ok"]) == | ||
{~s/{:ok, [~c"sample"]}\n/, 0} | ||
end) | ||
end | ||
|
||
test "escript install and uninstall" do | ||
File.rm_rf!(tmp_path(".mix/escripts")) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also be more strict and say that they should not rely on the exact archive layout, instead they should do something like this:
(Ideally they would use
:erl_prim_loader
, but using it with escript is apparently deprecated, because it will change in the future)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR the deprecation note for escript +
:erl_prim_loader
was added in erlang/otp#8091.