Sarcasm / compdb

The compilation database Swiss army knife
MIT License
292 stars 23 forks source link

Get relative path error when doing out-of-source build (build dir on another drive) #16

Closed ifree closed 5 years ago

ifree commented 5 years ago

Hi, I found a issue when build CMake project using vs2017, the build root is ${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name} which may different from current source directory. This will cause utils::get_friendly_path fail, may need additional check against this case.

Sarcasm commented 5 years ago

Do you have a traceback by any chance?

ifree commented 5 years ago

Sorry for the late response, Env: Win10, Python 2.7.15 (64 bit) Command: compdb -p . list

run from build dir

C:\Users\_me_\CMakeBuilds\_random_id\build>c:\Python27\Scripts\compdb.exe -p x64-Release list
Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "c:\Python27\Scripts\compdb.exe\__main__.py", line 9, in <module>
  File "c:\python27\lib\site-packages\compdb\cli.py", line 291, in main
    command.execute(config, args.args)
  File "c:\python27\lib\site-packages\compdb\cli.py", line 89, in execute
    included_by_database = builder.build(database)
  File "c:\python27\lib\site-packages\compdb\includedb.py", line 272, in build
    pp.preprocess(compile_command)
  File "c:\python27\lib\site-packages\compdb\includedb.py", line 81, in preprocess
    compdb.utils.get_friendly_path(includer), quote,
  File "c:\python27\lib\site-packages\compdb\utils.py", line 73, in get_friendly_path
    rel_path = os.path.relpath(full_path)
  File "c:\python27\lib\ntpath.py", line 529, in relpath
    % (path_prefix, start_prefix))
ValueError: path is on drive D:, start on drive C:

run from source dir

No error

Sarcasm commented 5 years ago

Thanks, I attempted a fix.