Commit Graph

21 Commits

Author SHA1 Message Date
Kim Gräsman c685e46c4e Don't attempt to canonicalize '<stdin>'
This little beauty would cause an assertion failure in GetCanonicalName:

  printf "#include <stdio.h>" | include-what-you-use -c -x c -

Special-case '<stdin>' like we do with '<built-in>'.

Fixes issue #1105.
2022-09-10 10:49:16 +02:00
Andrea Bocci 53487d2097 Add explicit conversion from llvm::StringRef to std::string
llvm/llvm-project@777180a makes the llvm::StringRef conversion operator
to std::string explicit.
These changes add a call to the str() method to perform the conversion.

Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
2020-03-03 21:44:35 +01:00
Kim Grasman 4d2bbcc0d9 Remove ".." from normalized file paths
This fixes a case where IWYU would suggest include paths with ".." where
a simpler non-".." path would suffice. E.g.

  // a.h
  struct Symbol {};

  // foo/b.h
  #include "../a.h"

  // main.c
  #include "foo/b.h"

  Symbol s;

IWYU would suggest we should include "foo/../a.h" from main.c here. This
is correct, but inelegant.

After this patch, we'll suggest "a.h" directly. Unfortunately, this is
broken in the face of symlinks (example cut from bug report) --

  akuli@Akuli-Desktop:~$ ln -s /usr a
  akuli@Akuli-Desktop:~$ file a
  a: symbolic link to /usr
  akuli@Akuli-Desktop:~$ file lib
  lib: cannot open `lib' (No such file or directory)
  akuli@Akuli-Desktop:~$ file a/../lib
  a/../lib: directory
  akuli@Akuli-Desktop:~$

-- but I suspect this is more unusual than relative includes.

Fixes issue 690.
2019-07-17 20:33:58 +02:00
Kim Grasman 56dbfbe9ca Remove Google-specific handling of third-party
This is part of Google's original open-sourcing of IWYU.

They keep third-party libraries in a directory called, well,
'third-party', so there was lots of special casing for code in
that directory.

Remove that code, unit tests covering it and explicit mappings.

Keep one special case for allowing include cycles for files with
'internal/' in the name, to avoid breaking the include_cycle test
case. Not sure what to do about that longer term, but I didn't want to
remove the test case right now.
2019-03-10 21:45:20 +01:00
Kim Grasman 6e28b990ba Add .H as a known header extension
Both in IWYU and fix_includes.py.

Fix issue #452.
2017-07-15 19:46:51 +02:00
Kim Grasman aa2dd1bb8f Whitespace changes from clang-(tidy|format)
Presumably this makes formatting more consistent.
No functional change.

This is based on an original patch by Eugene Zelenko, thanks!
2016-08-15 22:04:47 +02:00
Kim Grasman d0be569fa4 Fix bug in source extension detection
Found by clang-tidy's excellent suspicious-missing-comma check.

Original patch by Eugene Zelenko, thanks!
2016-08-15 21:52:30 +02:00
Kim Grasman 5b61a55190 Fix #310: Replace Each with C++11 range for loops
The Each construct was nice, but it's outlived its usefulness, the range for
loops are both easier to read and write.

For iteration over maps, we consistently use 'auto' to avoid repeating the map
value type.
2016-07-11 07:19:51 +02:00
EugeneZelenko 137907952c Fix some Clang-tidy warnings
NULL/0 -> nullptr
C standard library include -> C++ counterparts
Use override keyword
Range for loops in selected places
Occasional use of auto
Remove unused usings
Remove unnecessary uses of c_str()
Closing comments for anonymous namespaces
2016-06-18 09:59:40 +02:00
Flamefire 23119ba66a Use absolute paths to build include names
This has been a long-standing issue with IWYU (see issues #5, #271 and
probably others) where ConvertToQuotedInclude generates absolute paths
if IWYU is invoked with the current directory different from the source
file path.

This patch moves most path building to use absolute paths and path of
the includer (rather than the cwd) to produce better results.
2016-06-08 08:23:26 +02:00
Flamefire 6cf6b76a43 Remove CanonicalizeFilePath and add NormalizeDirPath 2016-05-18 20:54:58 +02:00
Kim Grasman b8069259e7 Remove excess blank lines and wordsmith a comment 2015-11-23 20:55:41 +01:00
Kim Grasman 7c700e8ca5 Fix #210: Avoid mis-stripping of same path prefix
If two paths in the header search set shared the same prefix, IWYU would
sometimes pick the wrong one and produce an invalid quoted include. For
example:

Header search path: /a/foo, /a/foobar
File path: /a/foobar/header.h

This would yield "bar/header.h", as "/a/foo" was considered a basename of
the file path.

We fix this by ensuring all search path entries end with "/" up-front.

I didn't add a test for this, because an end-to-end test would be almost
nonsensical. Once we get the unit test suite up and running, I'd like to
add a test for this there instead.
2015-11-23 20:51:50 +01:00
Volodymyr Sapsai 0133e14917 Update to reflect changes in LLVM (issue #149).
"llvm/Support/system_error.h" was removed in LLVM r210803.  Replaced
llvm::error_code with std::error_code.
2014-06-13 16:36:34 +00:00
Kim Gräsman 5997b50ef7 Update #include to use new name of LLVM support header.
llvm/Support/PathV2.h was renamed to Path.h in LLVM r183801
2013-06-12 19:49:14 +00:00
Kim Gräsman 49b0d89ba0 Remove unused function GetCWD
- No longer necessary to define _POSIX_ for MSVC builds
- Remove some cruft from port.h
- Remove unused direct.h/unistd.h includes
- Clean up includes in iwyu_path_util.h
- No functionality change intended
- Tested on Win32/MSVC + Linux/GCC
2013-03-19 20:53:26 +00:00
Volodymyr Sapsai a55e849150 Reduce number of file extensions' locations (issue #82). Patch by Kim Gräsman.
Also support more extensions.
2012-12-30 20:14:14 +00:00
Volodymyr Sapsai f8fd069e44 Fixed file heading comments not matching the filename (issue #83). Patch by Ryan Pavlik.
Also made the length of the first line to be 80 characters where possible.
2012-11-25 22:09:37 +00:00
Volodymyr Sapsai 40999861b2 Enhanced search paths of mapping files. Patch by Kim Gräsman.
Search for mapping files:
- in the current working directory;
- in the directory where IWYU executable is located;
- in the directory where another discovered mapping file is located.
2012-11-25 21:26:06 +00:00
Volodymyr Sapsai 52c3ef5b22 Fixed build under MinGW (issue #71).
Don't use Visual Studio-specific linking by #pragma, replaced some
#ifdef _MSC_VER with #ifdef _WIN32. Patch by Chris Glover.
2012-07-15 08:54:54 +00:00
csilvers+iwyu fb4d252c40 Oops, forgot to submit these new files to SVN.
Revision created by MOE tool push_codebase.
MOE_MIGRATION=3895
2011-12-01 02:37:46 +00:00