-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump iwyu to 0.19 and dirty fix angle-bracket-curse
- Loading branch information
Showing
5 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Steps to Build IWYU 0.19 | ||
|
||
|
||
## Install LLVM/Clang 15.x | ||
|
||
1. Download LLVM/Clang 15.x distribution from https://github.com/llvm/llvm-project/releases | ||
|
||
2. Extract and rename it to /opt/llvm after downloading. | ||
|
||
E.g., | ||
|
||
``` | ||
sudo tar xJvf clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.gz -C /opt | ||
sudo mv /opt/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04 /opt/llvm | ||
``` | ||
|
||
## Download IWYU 0.19 | ||
|
||
IWYU 0.19 can be downloaded from https://github.com/include-what-you-use/include-what-you-use/releases/tag/0.19 | ||
|
||
## Build IWYU | ||
|
||
When IWYU tarball is extracted, cd into the directory, and run: | ||
|
||
``` | ||
# patch python shebang for our environment (we need python3, not python) | ||
sed -i 's,^#!/usr/bin/env python,#!/usr/bin/env python3,g' iwyu_tool.py | ||
sed -i 's,^#!/usr/bin/env python,#!/usr/bin/env python3,g' fix_includes.py | ||
patch -p1 < /path/to/angle_bracket_curse_dirty_fix.patch | ||
``` | ||
|
||
then build it with `build_iwyu.sh`. | ||
|
||
To work around [IWYU Issue #100](https://github.com/include-what-you-use/include-what-you-use/issues/100#issuecomment-111944224) | ||
|
||
We may need to run the following commands after the `make install` step in `build_iwyu.sh`. | ||
|
||
``` | ||
pushd /tmp/iwyu-0.19-linux-x86_64 | ||
mkdir -p lib/clang/15.0.6/include | ||
cp -r /opt/llvm/lib/clang/15.0.6/include/* \ | ||
lib/clang/15.0.6/include/ | ||
popd | ||
pushd /tmp | ||
tar czvf iwyu-0.19-linux-x86_64.tar.gz iwyu-0.19-linux-x86_64 | ||
``` | ||
|
||
## About angle-bracket-curse | ||
See [IWYU Issues on angle-bracket-curse](https://github.com/include-what-you-use/include-what-you-use/issues?q=angle+label%3Aangle-quote-curse) for details. | ||
We should remove `angle_bracket_curse_dirty_fix.patch` once upstream has this issue fixed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
diff --git a/iwyu_output.cc b/iwyu_output.cc | ||
index 3f364ac..40f4ed5 100644 | ||
--- a/iwyu_output.cc | ||
+++ b/iwyu_output.cc | ||
@@ -1986,16 +1986,24 @@ size_t PrintableDiffs(const string& filename, | ||
vector<OutputLine> output_lines; | ||
|
||
const set<string>& aqi = associated_quoted_includes; // short alias | ||
- | ||
// Sort all the output-lines: system headers before user headers | ||
// before forward-declares, etc. The easiest way to do this is to | ||
// just put them all in multimap whose key is a sort-order (multimap | ||
// because some headers might be listed twice in the source file.) | ||
multimap<LineSortKey, const OneIncludeOrForwardDeclareLine*> sorted_lines; | ||
+ | ||
+ set<std::string> existing_includes; | ||
+ set<std::string> to_add_includes; | ||
for (const OneIncludeOrForwardDeclareLine& line : lines) { | ||
const IwyuFileInfo* file_info = nullptr; | ||
- if (line.IsIncludeLine()) | ||
+ if (line.IsIncludeLine()) { | ||
file_info = preprocessor_info->FileInfoFor(line.included_file()); | ||
+ const std::string& unquoted_include = line.unquoted_include(); | ||
+ existing_includes.insert(unquoted_include); | ||
+ if (line.is_desired() && !line.is_present()) { | ||
+ to_add_includes.insert(unquoted_include); | ||
+ } | ||
+ } | ||
|
||
sorted_lines.insert(make_pair(GetSortKey(line, aqi, file_info), &line)); | ||
} | ||
@@ -2005,10 +2013,27 @@ size_t PrintableDiffs(const string& filename, | ||
bool no_adds_or_deletes = true; | ||
for (const auto& key_line : sorted_lines) { | ||
const OneIncludeOrForwardDeclareLine* line = key_line.second; | ||
- if ((line->is_desired() && !line->is_present()) || // add | ||
- (line->is_present() && !line->is_desired())) { // delete | ||
- no_adds_or_deletes = false; | ||
- break; | ||
+ if (line->is_desired() && !line->is_present()) { // add | ||
+ if (line->IsIncludeLine()) { | ||
+ if (!ContainsKey(existing_includes, line->unquoted_include())) { | ||
+ no_adds_or_deletes = false; | ||
+ break; | ||
+ } | ||
+ } else { | ||
+ no_adds_or_deletes = false; | ||
+ break; | ||
+ } | ||
+ } | ||
+ if (line->is_present() && !line->is_desired()) { // delete | ||
+ if (line->IsIncludeLine()) { | ||
+ if (!ContainsKey(to_add_includes, line->unquoted_include())) { | ||
+ no_adds_or_deletes = false; | ||
+ break; | ||
+ } | ||
+ } else { | ||
+ no_adds_or_deletes = false; | ||
+ break; | ||
+ } | ||
} | ||
} | ||
if (no_adds_or_deletes && !GlobalFlags().update_comments) { | ||
@@ -2025,6 +2050,9 @@ size_t PrintableDiffs(const string& filename, | ||
for (const auto& key_line : sorted_lines) { | ||
const OneIncludeOrForwardDeclareLine* line = key_line.second; | ||
if (line->is_desired() && !line->is_present()) { | ||
+ if (line->IsIncludeLine() && ContainsKey(existing_includes, line->unquoted_include())) { | ||
+ continue; | ||
+ } | ||
output_lines.push_back( | ||
PrintableIncludeOrForwardDeclareLine(*line, aqi)); | ||
++num_edits; | ||
@@ -2039,6 +2067,9 @@ size_t PrintableDiffs(const string& filename, | ||
for (const auto& key_line : sorted_lines) { | ||
const OneIncludeOrForwardDeclareLine* line = key_line.second; | ||
if (line->is_present() && !line->is_desired()) { | ||
+ if (line->IsIncludeLine() && ContainsKey(to_add_includes, line->unquoted_include())) { | ||
+ continue; | ||
+ } | ||
output_lines.push_back( | ||
PrintableIncludeOrForwardDeclareLine(*line, aqi)); | ||
output_lines.back().add_prefix("- "); | ||
diff --git a/iwyu_output.h b/iwyu_output.h | ||
index 43d2cc8..2b13b75 100644 | ||
--- a/iwyu_output.h | ||
+++ b/iwyu_output.h | ||
@@ -134,6 +134,12 @@ class OneIncludeOrForwardDeclareLine { | ||
return quoted_include_; | ||
} | ||
|
||
+ string unquoted_include() const { | ||
+ CHECK_(IsIncludeLine() && "Must call unquoted_include() on include lines"); | ||
+ CHECK_(!fwd_decl_ && "unquoted_include and fwd_decl are mutually exclusive"); | ||
+ return quoted_include_.substr(1, quoted_include_.size() - 2); | ||
+ } | ||
+ | ||
const clang::FileEntry* included_file() const { | ||
CHECK_(IsIncludeLine() && "Must call included_file() on include lines"); | ||
CHECK_(!fwd_decl_ && "included_file and fwd_decl are mutually exclusive"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" | ||
|
||
# Set BUILD_TYPE via Cmdline: | ||
# /build_me.sh RelWithDebInfo | ||
BUILD_TYPE="${1:-Release}" | ||
|
||
[[ -d "${TOP_DIR}/build" ]] || mkdir "${TOP_DIR}/build" | ||
rm -rf "${TOP_DIR}/build"/* | ||
|
||
pushd "${TOP_DIR}/build" >/dev/null | ||
|
||
ARCH="$(uname -m)" | ||
DEST_DIR="/tmp/iwyu-${VERSION}-linux-${ARCH}" | ||
export CC=/opt/llvm/bin/clang | ||
export CXX=/opt/llvm/bin/clang++ | ||
|
||
cmake -G "Unix Makefiles" .. \ | ||
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ | ||
-DCMAKE_PREFIX_PATH=/opt/llvm \ | ||
-DCMAKE_VERBOSE_MAKEFILE=ON \ | ||
-DCMAKE_INSTALL_PREFIX="${DEST_DIR}" | ||
|
||
make -j$(nproc) | ||
make install | ||
|
||
popd >/dev/null |