How to let cscope use absolute path in cscope.out file?
Asked Answered
S

6

10

Everytime after load a cscope.out in Vim, I need to change Vim's "pwd" to the same directory as cscope.out file is under, which might be due to that cscope use relative path when generating tag file. So if there is a way to force cscope to use absolute path in its tag file - cscope.out, then it will be regardless of whether the pwd of your Vim session is the same as the directory that cscope.out file is under.

Shire answered 2/2, 2010 at 22:54 Comment(0)
D
16

You can ask vim to interpret the paths in cscope.out relative to the location of the cscope.out file by setting the cscoperelative option. From :help csre:

If 'cscoperelative' is set, then in absence of a prefix given to cscope (prefix is the argument of -P option of cscope), basename of cscope.out location (usually the project root directory) will be used as the prefix to construct an absolute path. The default is off. Note: This option is only effective when cscope (cscopeprg) is initialized without a prefix path (-P).

Examples

: set csre
: set nocsre

Denison answered 13/4, 2015 at 11:46 Comment(1)
This should really be the accepted answer as from a vim+cscope perspective is by far the easiest solution. Thank you for your answer!Recorder
W
12

When importing cscope.out, you can supply the prefix, i.e.

:cscope add /path/to/cscope.out /path/to/src/code

Then your searches will turn up like:

Cscope Tag: foobar
    #   line  filename / context / line
    1     21 /path/to/src/code/foobar_file.c
Winson answered 7/7, 2010 at 17:14 Comment(0)
D
4

The cscope tutorial has a very simple workaround for this problem:

11.Try setting the $CSCOPE_DB environment variable to point to a Cscope database you create, so you won't always need to launch Vim in the same directory as the database. This is particularly useful for projects where code is split into multiple subdirectories. Note: for this to work, you should build the database with absolute pathnames: cd to /, and do

find /my/project/dir -name '*.c' -o -name '*.h' > /foo/cscope.files

Then run Cscope in the same directory as the cscope.files file (or use 'cscope -i /foo/cscope.files'), then set and export the $CSCOPE_DB variable, pointing it to the cscope.out file that results):

cd /foo
cscope -b
CSCOPE_DB=/foo/cscope.out; export CSCOPE_DB   

(The last command above is for Bourne/Korn/Bash shells: I've forgotten how to export variables in csh-based shells, since I avoid them like the plague).

You should now be able to run 'vim -t foo' in any directory on your machine and have Vim jump right to the definition of 'foo'. I tend to write little shell scripts (that just define and export CSCOPE_DB) for all my different projects, which lets me switch between them with a simple 'source projectA' command.

Douro answered 5/1, 2012 at 22:17 Comment(0)
E
3

You can create your cscope.files using absolute paths to your files, here is my scripts to generate my cscope databases

#!/bin/sh

find $PWD -name '*.[ch]' -exec echo \"{}\" \; | sort -u > cscope.files
cscope -bvq

Then just vim cscope.files and maybe :cs add cscope.out, although my cscope plugin does that automatically. Then I search for the files I am interested in and jump to them with gf.

Ellswerth answered 5/2, 2013 at 10:14 Comment(1)
also, run export CSCOPE_DB=$(pwd)/cscope.out on the same dir that the script runsRoper
S
1

@Aaron H. is right.

For my configuration I used the cscope_maps.vim plugin and modified the following lines:

  40     " add any cscope database in current directory
  41     if filereadable("/usr/project/cscope.out")
  42         cs add /usr/project/cscope.out /usr/project
  43     " else add the database pointed to by environment variable 
  44     elseif $CSCOPE_DB != ""
  45         cs add $CSCOPE_DB
  46     endif

Where "/usr/project" is the location of the cscope.out file and the absolute path I want to use.

Shippy answered 14/12, 2010 at 6:7 Comment(0)
B
1

Note: since I am not senior enough to add comments yet: Aaron and Neha's answers were useful to me to learn more about the entire system, but the best and most direct answer to the question is currently in 3rd place and is Shayan's.

The asker was more asking about getting absolute pathnames by cscope, not working around it using (the very capable and powerful) vim.

Note2: There is another way to make a single change in vim and accomplish the same as what Neha did.

:set cscopeprg=cscope -P path_to_relative_base

I like Neha's better, but this way is closer to modifying cscope rather than vim settings, if this is what you want. And this is the only way that allows you to move the cscope db to anywhere.

Botnick answered 17/11, 2016 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.