Skip to content
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

Use escript directly to run ex_doc #8490

Conversation

chiroptical
Copy link
Contributor

@chiroptical chiroptical commented May 18, 2024

Closes #8378

Relying on #! /usr/bin/env escript to run ex_doc doesn't really work well in nixpkgs builds. We actually know the location of escript already so we can just use $ERL_TOP/escript to run ex_doc and we no longer have to rely on /usr/bin/env at all.

One issue arises though, you can't run a bash script with escript (i.e. make/ex_doc_wrapper) however we can run an equivalent erlang escript!

Let me know what you think!

Copy link
Contributor

github-actions bot commented May 18, 2024

CT Test Results

    3 files    143 suites   49m 17s ⏱️
1 588 tests 1 538 ✅ 50 💤 0 ❌
2 327 runs  2 252 ✅ 75 💤 0 ❌

Results for commit cf52f5f.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@@ -7330,7 +7330,7 @@ fi
done

if test -z "$EX_DOC"; then
EX_DOC="$ERL_TOP/make/ex_doc_wrapper"
EX_DOC="$ERL_TOP/make/ex_doc_wrapper.erl"
Copy link
Contributor Author

@chiroptical chiroptical May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I am unsure what the convention is for writing escript files. When I open an erl file inside this source directory I still get all my LSP niceties so I just used .erl

ExDocExe ->
Cmd = lists:append(["exec ", ExDocExe, " "], lists:join(" ", Args)),
io:format("Running ~s~n", [Cmd]),
os:cmd(Cmd)
Copy link
Contributor Author

@chiroptical chiroptical May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the same

  Out = os:cmd(Cmd),
  io:format("~s", [Out])

here, but I got a weird error when running ex_doc so I didn't worry about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has to do with the output being colorized

Comment on lines +42 to +47
{error, _Description} ->
io:format("Unable to get line?~n"),
{error, try_again};
eof ->
io:format("Got end of file?~n"),
{error, try_again};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure what {error, _} would arise from but it seems safe to try again and let them Ctrl-C

I guess eof is just an empty line so we should try again.

Input ->
case string:casefold(string:trim(Input)) of
"y" -> {ok, download};
"n" -> {error, do_not_download};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they explicitly ask to not download ex_doc we just quit out

case string:casefold(string:trim(Input)) of
"y" -> {ok, download};
"n" -> {error, do_not_download};
_ -> {error, try_again}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The didn't respond with y, Y, N or n so we try again.

Comment on lines +23 to +24
% Passing in --option "hello world" leads to ["--option", "hello world"]
% Re-wrap the latter in quotes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens in one spot as far as I can tell.

end.

quote_arguments(String) ->
case string:find(String, " ") of
Copy link
Contributor Author

@chiroptical chiroptical May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches Erlang System Documentation and pads it to "Erlang System Documentation" so the os:cmd doesn't fail.

make/ex_doc_wrapper.erl Outdated Show resolved Hide resolved
@rickard-green rickard-green added the team:VM Assigned to OTP team VM label May 20, 2024
@jhogberg jhogberg requested a review from bjorng May 20, 2024 10:10
@garazdawi garazdawi assigned garazdawi and unassigned bjorng May 30, 2024
@garazdawi
Copy link
Contributor

Hello!

I think that it would be better to do it the other way around, that is always use the bash wrapper and in that call escript. One reason is that we want the output from ex_doc to end up in the console so that we can view warnings and error messages.

To do that I would create an ex_doc_wrapper.in file and then use configure to insert the correct @EXEEXT@ for escript.

@chiroptical
Copy link
Contributor Author

Hello!

I think that it would be better to do it the other way around, that is always use the bash wrapper and in that call escript. One reason is that we want the output from ex_doc to end up in the console so that we can view warnings and error messages.

To do that I would create an ex_doc_wrapper.in file and then use configure to insert the correct @EXEEXT@ for escript.

Totally fair! I believe I can do this, but it is going to take me a bit of time. Trying to wrap up other OSS work. I appreciate your review!

@garazdawi
Copy link
Contributor

No worries, we are in no hurry. I will close this PR, looking forward to your new one :)

@garazdawi garazdawi closed this Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use built escript to execute ex_doc instead of one in PATH
4 participants