This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][NFC] Set LineEnding to LF in config files
ClosedPublic

Authored by owenpan on Jan 5 2023, 4:19 PM.

Details

Summary

To prevent \r\n line endings from getting into the source files.

I'd rather change the default to false for LLVM style though. What do you think?

Diff Detail

Event Timeline

owenpan created this revision.Jan 5 2023, 4:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 4:19 PM
owenpan requested review of this revision.Jan 5 2023, 4:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 4:19 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a comment.Jan 5 2023, 7:24 PM

The LLVM Coding Standard apparently doesn't mention line endings..? A quick grep does show a bunch of \r\n results, primarily in tests. I'd be in favor of forcing \n, but I think this is a wider matter..?

The LLVM Coding Standard apparently doesn't mention line endings..?

Line endings probably should never be specified in coding standards, but the default should match the majority, and in the case of LLVM style, it should be \n IMO.

A quick grep does show a bunch of \r\n results, primarily in tests.

It's possible that some/most of those \r\n get in by accident like in https://github.com/llvm/llvm-project/blob/617277e7cbdaea6881425c7a1a5b1cf4b1d4b507/clang/unittests/Format/FormatTest.cpp? And for tests, clang-format can be disabled like in D128706.

I think we should combine DeriveLineEnding and UseCRLF, with the default being LF for LLVM. If you all agree, I will abandon this patch and implement a new option and deprecate the current ones.

rymiel added a comment.Jan 6 2023, 7:34 PM

I think we should combine DeriveLineEnding and UseCRLF

Do you mean a single LineEnding options which is an enum with LF, CRLF and Derive, or similar?

I think we should combine DeriveLineEnding and UseCRLF

Do you mean a single LineEnding options which is an enum with LF, CRLF and Derive, or similar?

Yep.

MyDeveloperDay accepted this revision.Jan 9 2023, 1:36 AM

I kind of agree, it would be nice not to have to use dos2unix and it be set by default.

This revision is now accepted and ready to land.Jan 9 2023, 1:36 AM

Unfortunately, changing the default value of DeriveLineEnding to false would break too many unit tests.

owenpan added a comment.EditedJan 12 2023, 10:11 PM

I will change DeriveLineEnding: false to LineEnding: LF after D141654 lands.

owenpan retitled this revision from [clang-format][NFC] Set DeriveLineEnding to false in config files to [clang-format][NFC] Set LineEnding to DeriveLF in config files.Jan 22 2023, 2:30 AM
owenpan retitled this revision from [clang-format][NFC] Set LineEnding to DeriveLF in config files to [clang-format][NFC] Set LineEnding to LF in config files.Jan 22 2023, 2:41 AM
owenpan edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.

I guess we'll need to revert this until the buildbots are updated.

Why don't we fix the buildbot instead? Why does it use a pre-16 version to test 16 source?

sunho added a comment.Feb 6 2023, 3:29 PM

I think buildbot is "formatting" the patch using clang-format-15. The tests of clang-format would be done with latest code.

I think buildbot is "formatting" the patch using clang-format-15. The tests of clang-format would be done with latest code.

Can we just fix the buildbot so that it runs git-clang-format with --binary? Using clang-format-15 to format a patch to clang-format-16 source still looks wrong to me.

sunho added a comment.Feb 7 2023, 6:54 PM

Wouldn't that mean llvm contributors have to format their code using clang-format built from top-of-tree source code before submitting the patch? Technically that script is for checking if the code has been formatted correctly.

Wouldn't that mean llvm contributors have to format their code using clang-format built from top-of-tree source code before submitting the patch?

Only if the patch is to clang-format source.

sunho added a comment.Feb 7 2023, 8:33 PM

I think it makes more sense to use stable version of clang-format for that purpose but I'm not in a postion to decide as I don't work with format. Can you change the script to use latest clang-format for format codebase and revert this patch in the meantime? Currently, all patches that touch format part will see format verifiaction ci faliure with this patch.

I think it makes more sense to use stable version of clang-format for that purpose but I'm not in a postion to decide as I don't work with format. Can you change the script to use latest clang-format for format codebase and revert this patch in the meantime?

We don't want to change git-clang-format on a whim. If you think there is an issue, please file a bug report.

Currently, all patches that touch format part will see format verifiaction ci faliure with this patch.

That's not true. We've had several clang-format commits since this patch landed. We don't want to defeat the purpose (or delay the effect) of this patch and should let the premerge check fail if the patch to the current format source is not formatted by the latest clang-format.

This is the only buildbot reported to be impacted by this patch. Can we fix the bot instead? In addition to using --binary of git-clang-format as I suggested before, another way would be to format a patch to files outside the format directory?

Can we just fix the buildbot so that it runs git-clang-format with --binary? Using clang-format-15 to format a patch to clang-format-16 source still looks wrong to me.

The general principle is that developers of LLVM 16 should be able to use clang-format from the previous release (that is: one where we have prebuilt binaries available) to format patches in general.
It does not seem reasonable to me that we should need to build clang-format ourselves for the purpose of writing patches to LLVM.

Can we just fix the buildbot so that it runs git-clang-format with --binary? Using clang-format-15 to format a patch to clang-format-16 source still looks wrong to me.

The general principle is that developers of LLVM 16 should be able to use clang-format from the previous release (that is: one where we have prebuilt binaries available) to format patches in general.
It does not seem reasonable to me that we should need to build clang-format ourselves for the purpose of writing patches to LLVM.

Agreed, except for the clang-format source, which its .clang-format files are part of.