rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.79k stars 314 forks source link

Exclude relative path #387

Closed MJAS1 closed 3 years ago

MJAS1 commented 3 years ago

Accroding to this and my own testing, it seems that I can use paths_to_exclude to only exclude absolute paths. If I remember correctly, I was able to use an earlier version of Bear with --exclude flag to exclude relative paths. Is there really no way to currently achieve the same thing? I am trying to setup a CI/CD step that will not work with absolute paths since it might not be known beforehand.

rizsotto commented 3 years ago

Hey @MJAS1 , thanks for the report.

Yes, you are right the 2.4 version had this code to fix the relative path for the include/exclude directory list.

def make_absolute(directory):
    # type: (str) -> str  
    """ Makes a path like object absolute (to the project root). """
    if os.path.isabs(directory):
        return directory
    else:
        return os.path.normpath(os.path.join(os.getcwd(), directory))

The current implementation using the include/exclude directories without this check. (source/citnames/source/Output.cc:44 the ContentFilter class needs to be changed for that.)

If I understand correctly, you would prefer to use the current directory as a base to the relative paths. Is this correct?

MJAS1 commented 3 years ago

Yes, you are correct. I was trying to use bear in a GitLab CI/CD pipeline step. The problem was that, as far as I know, there is no way to know beforehand the full absolute path as the pipeline is ran inside a Docker container that contains a folder named after the username of the person initiating the pipeline. Finally, I ended up going a different route but anyways I think it would be nice if you could use a relative path.

rizsotto commented 3 years ago

I think this is fixed now on latest master branch. Will be released as 3.0.13 soon.

@MJAS1 could you verify that it works for you?

MJAS1 commented 3 years ago

I just tested this and it seems to work. Thanks for the great work!