-
Notifications
You must be signed in to change notification settings - Fork 238
Jamulus.pro: Run clang-format on build #1741
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
Conversation
I have tested and it does not work at the moment (when using the windows/deploy_windows.ps1 script). Here the result: clang-format not in PATH: clang-format in PATH: In both occassions, no harm on the build itself that completed without issue. The reason for failing when clang-format is in the path, is because of the powershell script is executing the step from the "build" folder it creates. Here a part of the clang-format command being executed: This generates the message: no such file or directory (for each file) Hope this helps. |
|
I'm not sure I understand the benefit of this. Reformatting code with clang-format is not for a compiler's benefit; if it makes any difference to compilation, then that is a bug in clang-format. Reformatting code is for the benefit of people reading and editing the code. So it makes sense for clang-format to be run on code to be committed, but not as an intermediate step in building. Am I missing something? |
|
I guess the idea was that a contributor would at some point make a local build and then 'silently' get pretty code. |
Right, the idea is to make it simple for contributors to submit properly formatted code. Visual Studio will probably handle .clang-format integration, other editors (vim? emacs?) may not. This PR is supposed to make it simpler in general. |
|
It should never make code changes. |
|
So in that case there needs to be a If I clone or checkout a tree and then do a compilation, I wouldn't normally expect it to make any kind of changes to checked-out files, resulting in |
In Visual Studio you just need to have the "C/C++" Extension installed while |
|
There is also the point that if every source file was unnecessarily rewritten to a formatted version of itself (even if identical), that will defeat the normal use of modification timestamps by Disclaimer: I haven't yet studied the proposed changes, but am just talking generally, apologies if I have made a wrong assumption about how it will work. |
|
What version of Lots of the same error, one for each file. |
The workflow runs with version 10. I'm using 11 and it doesn't cause any errors/changes either. Maybe those experiences (and the one by @dcorson-ticino-com in the other PR) may make us review the decision of not running the formatting in PRs itself... Hrm. |
I'm still uncomfortable with the idea of Github modifying stuff I have pushed to it, requiring me to pull back again. I feel it should either accept what I have given it, or reject it and expect me to fix it and resubmit. |
Version 10 is required as it introduced some of the options we use (like |
|
Does anyone have an idea, which IDEs are mainly used? |
|
I've only ever used Qt Creator for work on Qt code. Or |
Jamulus.pro
Outdated
| # This must come before addition of opus sources: | ||
| clang_format.commands = 'clang-format -i $$SOURCES $$HEADERS || echo "clang-format-based source code formatting failed. Please ensure that clang-format is installed and available in your PATH variable."' | ||
| QMAKE_EXTRA_TARGETS += clang_format | ||
| PRE_TARGETDEPS += clang_format |
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.
I would remove the PRE_TARGETDEPS line. Removing it would allow the Makefile to offer the ability to do make clang_format to easily update the format of files, but would not make it a dependency of $(TARGET) to force it do be done on every compilation.
For example, my RPi does have clang-format, but it is only version 7 and not compatible with the Jamulus .clang-format. I do a lot of development and compilation on it, and having clang_format as a dependency would be incredibly annoying.
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.
Thanks. I've removed the automatical build dep. As the whole block becomes optional then, there's no reason to reduce the make clang_format addition to dev builds.
|
What's the status here?
At the moment, I type |
84c0262 to
742920d
Compare
This simplifies submission of properly formatted code for users with no editor/IDE integration of clang-format (jamulussoftware#1702).
742920d to
8571728
Compare
|
I've updated the source list file generation to be what it should be: A list of all .cpp and .h files, excluding Qt-auto-generated files and bundled libraries in libs/ and windows/nsProcess. It would be nice to see if this works properly on Mac and Windows as well. |
|
@hoffie , I have downloaded your branch on my windows machine and do not see errors during the build process and the generated executable works fine. However I am not sure what to expect from the change made now. As I went into one of the files (main.cpp) and made modifications which would fail the format check (verified with the clang-format --dry-run option to check if the formatting errors would be detected and they were). However after running the build again, the file remains unchanged. If this is the correct behaviour, then I don't understand what the benefit is of this. I might be wrong....or might just not understand what is supposed to be happening. |
|
@henkdegroot Thanks for confirming that the build works. As you assumed, the expectation is no longer that the build auto-fixes things. Instead, the scope is reduced to providing |
|
Thinking some more... As the scope of the PR has changed, changing title and PR content would not make sense regarding the existing comment history. I'm therefore closing this and have opened #2258 instead. |
This ensures that clang-format is run on all source files before building (#1702).
If clang-format is not available, a warning is output and the build continues.
clang-format is also invoked on non-release builds only as that is what PRs will usually be based on.
@passing @pljones Would that be a useful integration? Can someone test on Windows how it would behave there (does it work when clang-format is available, does it continue properly if it isn't)?.
Just seeing a disadvantage right now:
$$SOURCEdoes not include the platform-specific directories for the non-current platform (i.e. I'm on Linux and it won't containmac/, etc.). :(I guess we could do something
find-based, but that would be hard to get right and nice in a cross-platform way, I think?