Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyzer] Relative include paths to --sysroot #3259

Merged
merged 1 commit into from
May 6, 2021

Conversation

bruntib
Copy link
Contributor

@bruntib bruntib commented Apr 8, 2021

If a -I flag is followed by a path starting with "=" sign, it means that
it's relative to --sysroot. In CodeChecker we tend to convert all paths
to absolute, however, these should be skipped. For example:
-I =/usr/include/my_lib

@bruntib bruntib added CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands bugfix 🔨 analyzer 📈 Related to the analyze commands (analysis driver) labels Apr 8, 2021
@bruntib bruntib added this to the release 6.16.0 milestone Apr 8, 2021
@bruntib bruntib requested review from csordasmarton and zomen2 April 8, 2021 12:56
@@ -722,48 +722,48 @@ def __collect_transform_include_opts(flag_iterator, details):

m = COMPILE_OPTIONS_MERGED.match(flag_iterator.item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"matches" or any non one-character variable name please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a commonly used variable name (see the official documentation: https://docs.python.org/3/library/re.html) like the name f for file objects. So I think it is better to leave it as it but it's up to @bruntib.

Comment on lines 761 to 764
if together:
details['analyzer_options'].append(flag + param)
else:
details['analyzer_options'].extend([flag, param])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think to shorten the source code like this:

Suggested change
if together:
details['analyzer_options'].append(flag + param)
else:
details['analyzer_options'].extend([flag, param])
details['analyzer_options'].extend(
[f"{flag}{param}"] if together else [flag, param])

@@ -722,48 +722,48 @@ def __collect_transform_include_opts(flag_iterator, details):

m = COMPILE_OPTIONS_MERGED.match(flag_iterator.item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a commonly used variable name (see the official documentation: https://docs.python.org/3/library/re.html) like the name f for file objects. So I think it is better to leave it as it but it's up to @bruntib.

if m:
flag = m.group(0)
together = len(flag) != len(flag_iterator.item)
if not m:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change 😊

# --sysroot=/path/to/include as
# --sysroot /path/to/include
# which is a valid format too.
if param.startswith("="):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above in the if branch we check this on this way: param[0] != '='. Here we are using the startswith function. Can we use a common way to check this?

'-iquote', '-isysroot', '-isystem',
'-iwithprefix', '-iwithprefixbefore', '-sysroot',
'--sysroot']
if flag in flags_with_path and ('sysroot' in flag or param[0] != '='):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation mention the = only for the following options:

-I dir
-iquote dir
-isystem dir
-idirafter dir

See: https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html.

My question is that here we handle this not only for these options but for others as well like for iwithprefix or imultilib. What do you think, is it a problem or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not a problem, because the path can't start with = at these flags, because it wouldn't compile. However the paths at these flags shouldn't be converted to absolute, so I removed them from the list. Good point, thank you.

If a -I flag is followed by a path starting with "=" sign, it means that
it's relative to --sysroot. In CodeChecker we tend to convert all paths
to absolute, however, these should be skipped. For example:
-I =/usr/include/my_lib
Copy link
Contributor

@csordasmarton csordasmarton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@csordasmarton csordasmarton merged commit 46cca7e into Ericsson:master May 6, 2021
@bruntib bruntib deleted the include_path branch May 6, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 📈 Related to the analyze commands (analysis driver) bugfix 🔨 CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants