weixin_39822993 2020-11-30 11:25
浏览 0

ConvertToQuotedInclude needs to handle leading backslashes (for Win32)

Originally reported on Google Code with ID 54


ConvertToQuotedInclude tidies any stray leading directory separator after is has stripped
an include path:

      StripLeft(&path, "/");

to work on windows, it needs to do the following:

      StripLeft(&path, "/") || StripLeft(&path, "\\");

Without this a number of the tests are failing like so:


Unexpected summary diffs for tests/virtual_tpl_method.cc:
+++
@@ -1,8 +1,8 @@
 tests/virtual_tpl_method.cc should add these lines:
-#include "tests/indirect.h"
+#include "\tests/indirect.h"

 tests/virtual_tpl_method.cc should remove these lines:
 - #include "tests/direct.h"  // lines XX-XX

 The full include-list for tests/virtual_tpl_method.cc:
-#include "tests/indirect.h"  // for IndirectClass
+#include "\tests/indirect.h"  // for IndirectClass

---


I'm assuming this will no-op on Linux, but I could use an #ifdef _MSC_VER guard to
ensure this additional strip is only performed on Win32.

Reported by paul.holden on 2011-07-16 17:58:50

该提问来源于开源项目:include-what-you-use/include-what-you-use

  • 写回答

4条回答 默认 最新

  • weixin_39822993 2020-11-30 11:25
    关注
    
    A similar fix is needed to NormalizePath to fix tests/re_fwd_decl.cc on Windows:
    
    
    (.\tests/re_fwd_decl.h has correct #includes/fwd-decls)
    tests/re_fwd_decl.cc:20:1: warning: Indirect needs a declaration, but does not provide
    or directly #include one.
    
    tests/re_fwd_decl.cc should add these lines:
    class Indirect;
    
    tests/re_fwd_decl.cc should remove these lines:
    
    The full include-list for tests/re_fwd_decl.cc:
    #include "tests/re_fwd_decl.h"
    #include "tests/re_fwd_decl-d1.h"       // for Direct (ptr only), FullUse
    class Indirect;
    ---
    
    The fix is to strip any leading '.\':
    
    inline string NormalizeFilePath(const string& path) {
      string result = path;
      while (StripLeft(&result, "./")) {
      }
      while (StripLeft(&result, ".\\")) {
      }
      return result;
    }
    
    Again, I'm assuming this will no-op on Linux, but I can add a _MSC_VER guard if desired.
    

    Reported by paul.holden on 2011-07-17 10:34:29

    评论

报告相同问题?