albertzl / google-styleguide

Automatically exported from code.google.com/p/google-styleguide
0 stars 0 forks source link

`--root` Parameter not working in Windows #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run `cpplint --root=include file.h`. The file.h is inside the directory 
`include\project`.

What is the expected output? What do you see instead?

Expected: cpplint performing its checks.
Instead:

    Traceback (most recent call last):
      File "C:\dev\cpplint\cpplint.py", line 4753, in <module>
        main()
      File "C:\dev\cpplint\cpplint.py", line 4746, in main
        ProcessFile(filename, _cpplint_state.verbose_level)
      File "C:\dev\cpplint\cpplint.py", line 4631, in ProcessFile
        extra_check_functions)
      File "C:\dev\cpplint\cpplint.py", line 4556, in ProcessFileData
        CheckForHeaderGuard(filename, lines, error)
      File "C:\dev\cpplint\cpplint.py", line 1409, in CheckForHeaderGuard
        cppvar = GetHeaderGuardCPPVariable(filename)
      File "C:\dev\cpplint\cpplint.py", line 1393, in GetHeaderGuardCPPVariable
        file_path_from_root = re.sub('^' + _root + os.sep, '', file_path_from_root)
      File "C:\dev\portable-python-2.7.5.1\App\lib\re.py", line 151, in sub
        return _compile(pattern, flags).sub(repl, string, count)
      File "C:\dev\portable-python-2.7.5.1\App\lib\re.py", line 242, in _compile
        raise error, v # invalid expression
    sre_constants.error: bogus escape (end of line)

What version of the product are you using? On what operating system?

Microsoft Windows 7 64 Bit [6.3.9600]
Python 2.7.5
cpplint.py from trunk

Please provide any additional information below.

By adding a backslash to the end of the --root value, the error doesn't occur, 
but the correct include guards aren't detected by cpplint.

Example: `cpplint --root=include\ file.h`

I expect the following output:

    file.h:8:  #ifndef header guard has wrong style, please use: PROJECT_FILE_H_  [build/header_guard] [5]
    ball.h:101:  #endif line should be "#endif  // PROJECT_FILE_H_"  [build/header_guard] [5]
    Done processing file.h
    Total errors found: 2

But instead, the following is generated:

    file.h:8:  #ifndef header guard has wrong style, please use: INCLUDE_PROJECT_FILE_H_  [build/header_guard] [5]
    ball.h:101:  #endif line should be "#endif  // INCLUDE_PROJECT_FILE_H_"  [build/header_guard] [5]
    Done processing file.h
    Total errors found: 2

Original issue reported on code.google.com by Florian....@gmail.com on 12 Mar 2014 at 5:09

GoogleCodeExporter commented 9 years ago
I had the same problem.
The error seems to be that all Windows-backslashes ("\") are replaced by 
unix-style forward slashes ("/") in the file paths. But then it is tried to 
erase the given root folder in the file headers with the os-specific-slash (for 
Windows the backslash).
Current codeline in cpplint.py (line 1393):
file_path_from_root = re.sub('^' + _root + os.sep, '', file_path_from_root)
where an example file_path_from_root is 'src/foo/bar.h'
This leads to the seen error.

Quick fix for me was to change the line to
file_path_from_root = re.sub('^' + _root + '/', '', file_path_from_root)

Original comment by christop...@gmail.com on 15 Jun 2014 at 12:53

GoogleCodeExporter commented 9 years ago
I also had the same issue. 

I fixed the issue by removing the os.sep totally from the line 

file_path_from_root = re.sub('^' + _root + os.sep, '', file_path_from_root)

and instead added the '/' to the --root definition.

Original comment by ksole...@gmail.com on 1 Oct 2014 at 6:46