[libc++] Remove the ignore_format.txt file (#73135)

The ignore_format.txt file and the associated checks have been causing a
lot of confusion since we introduced them. Formatting becomes one of the
main hurdle for contributors (especially new contributors), and that is
not great.

The original goal of ignore_format.txt was to enforce clang-format only
in a subset of the files of the project. In practice, we have now
shifted to a model where we have a Github action that checks whether new
code surrounding edits is formatted. In that context, it probably
doesn't make sense to keep having a ignore list for formatting files.

After this patch, the clang-format job will enforce that all new code is
formatted properly, and that all edits to existing files are formatted
properly, regardless of which files the edits are in. This seems
reasonable and I believe will lead to much less confusion than our
current setup.

In the future, we could consider clang-formatting the whole code base
once and for all but this requires a bit of upfront technical work to
put in place a merge driver to help resolve merge conflicts across
formatting changes.
This commit is contained in:
Louis Dionne 2023-11-22 10:21:01 -10:00 committed by GitHub
parent a9c149df76
commit 6772c4f248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 7339 deletions

View File

@ -231,20 +231,6 @@ check-generated-output)
false
fi
echo "+++ Making sure libcxx/utils/data/ignore_format.txt was updated appropriately"
cp ${MONOREPO_ROOT}/libcxx/utils/data/ignore_format.txt ${BUILD_DIR}/before.txt
${MONOREPO_ROOT}/libcxx/utils/generate_ignore_format.sh
diff ${BUILD_DIR}/before.txt ${MONOREPO_ROOT}/libcxx/utils/data/ignore_format.txt | tee ${BUILD_DIR}/ignore_format.diff || true
if [ -s ${BUILD_DIR}/ignore_format.diff ]; then
echo "It looks like the list of not formatted files has changed."
echo "If a file is now properly formatted with clang-format, remove the file name from "
echo "libcxx/utils/data/ignore_format.txt. Otherwise you have to fix the"
echo "formatting of some of the changed files. The diff above represents the "
echo "changes that would be needed to ignore_format.txt to keep it representative "
echo "of which files are mis-formatted in the project."
false
fi
# Reject patches that introduce non-ASCII characters or hard tabs.
# Depends on LC_COLLATE set at the top of this script.
set -x

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
#!/bin/bash
# Generate a list of headers that aren't formatted yet
if [ -z "${CLANG_FORMAT}" ]; then
CLANG_FORMAT=clang-format
fi
rm libcxx/utils/data/ignore_format.txt
# This uses the same matches as the check-format CI step.
#
# Since it's hard to match empty extensions the following
# method is used, remove all files with an extension, then
# add the list of extensions that should be formatted.
for file in $(find libcxx -type f -not -name '*.*' -or \( \
-name "*.h" -or -name "*.hpp" -or \
-name "*.c" -or -name "*.cpp" -or \
-name "*.inc" -or -name "*.ipp" \
\) ); do
${CLANG_FORMAT} --Werror --dry-run ${file} >& /dev/null
if [ $? != 0 ]; then
echo ${file} >> libcxx/utils/data/ignore_format.txt
fi
done
# Force sorting not to depend on the system's locale.
LC_ALL=C sort libcxx/utils/data/ignore_format.txt -d -o libcxx/utils/data/ignore_format.txt

View File

@ -115,17 +115,6 @@ class ClangFormatHelper(FormatHelper):
def instructions(self) -> str:
return " ".join(self.cf_cmd)
@cached_property
def libcxx_excluded_files(self) -> list[str]:
with open("libcxx/utils/data/ignore_format.txt", "r") as ifd:
return [excl.strip() for excl in ifd.readlines()]
def should_be_excluded(self, path: str) -> bool:
if path in self.libcxx_excluded_files:
print(f"{self.name}: Excluding file {path}")
return True
return False
def should_include_extensionless_file(self, path: str) -> bool:
return path.startswith("libcxx/include")
@ -134,8 +123,7 @@ class ClangFormatHelper(FormatHelper):
for path in changed_files:
_, ext = os.path.splitext(path)
if ext in (".cpp", ".c", ".h", ".hpp", ".hxx", ".cxx", ".inc", ".cppm"):
if not self.should_be_excluded(path):
filtered_files.append(path)
filtered_files.append(path)
elif ext == "" and self.should_include_extensionless_file(path):
filtered_files.append(path)
return filtered_files