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

Format generated code only when clang-format is available #101

Merged
merged 3 commits into from
Dec 16, 2022

Conversation

mickel8
Copy link
Member

@mickel8 mickel8 commented Dec 14, 2022

We shouldn't require clang-format to be available on the system. Otherwise, everyone who compiles membrane package and doesn't have clang-format, will get a warning /usr/bin/sh: 1: clang-format: not found.

clang-format is required in tests so they should remain deterministic.

"#{out_base_path}.h #{out_base_path}.c #{out_base_path}.cpp"
)
# Format generated code only when clang-format is available
if Mix.shell().cmd("whereis clang-format") == 0 do
Copy link
Member

Choose a reason for hiding this comment

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

It seems whereis always returns 0 on Mac

iex(1)> System.cmd("whereis", ~w(dupa))
{"dupa:\n", 0}

test/unifex/integration_test.exs Show resolved Hide resolved
ExUnit.start()
# clang-format is required to format the generated code
# it won't match the reference files otherwise
case System.cmd("clang-format", ~w(--version)) do
Copy link
Member

@FelonEkonom FelonEkonom Dec 15, 2022

Choose a reason for hiding this comment

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

  1. System.cmd/2 raises %ErlangError{orginal: :enoent}, when it can't find a command
  2. Why do you use one time $ whereis clang-format and second time $ clang-format to check, if clang-format is available?
  3. Analogically, why do you use System.cmd/2 in one place, to execute command, but Mix.shell().cmd/1 in the another place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly speaking I don't know what is the difference between System.cmd and Mix.shell().cmd() except that Mix might not be available in the runtime. I moved everything to System


@spec clang_format_installed?() :: boolean()
def clang_format_installed?() do
if System.find_executable("clang-format"), do: true, else: false
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if System.find_executable("clang-format"), do: true, else: false
System.find_executable("clang-format") != nil

@mickel8 mickel8 merged commit a81cc99 into master Dec 16, 2022
@mickel8 mickel8 deleted the clang-format branch December 16, 2022 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants