-
Notifications
You must be signed in to change notification settings - Fork 385
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
Fix resource dir issue #1173
Fix resource dir issue #1173
Changes from all commits
fc0ab38
906f399
ea1a067
6ad66cd
fce793f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,19 @@ def replacer(matchobj): | |
return replacer | ||
|
||
|
||
def __get_compiler_resource_dir(context, analyzer_binary): | ||
resource_dir = '' | ||
if len(context.compiler_resource_dir) > 0: | ||
resource_dir = context.compiler_resource_dir | ||
# If not set then ask the binary for the resource dir. | ||
else: | ||
# Can be None if Clang is too old. | ||
resource_dir = host_check.get_resource_dir(analyzer_binary) | ||
if resource_dir is None: | ||
resource_dir = "" | ||
return resource_dir | ||
|
||
|
||
def __build_clangsa_config_handler(args, context): | ||
""" | ||
Build the config handler for clang static analyzer. | ||
|
@@ -275,7 +288,8 @@ def __build_clangsa_config_handler(args, context): | |
config_handler = config_handler_clangsa.ClangSAConfigHandler() | ||
config_handler.analyzer_plugins_dir = context.checker_plugin | ||
config_handler.analyzer_binary = context.analyzer_binaries.get(CLANG_SA) | ||
config_handler.compiler_resource_dir = context.compiler_resource_dir | ||
config_handler.compiler_resource_dir =\ | ||
__get_compiler_resource_dir(context, config_handler.analyzer_binary) | ||
|
||
if 'ctu_phases' in args: | ||
config_handler.ctu_dir = os.path.join(args.output_path, | ||
|
@@ -337,7 +351,24 @@ def __build_clang_tidy_config_handler(args, context): | |
|
||
config_handler = config_handler_clang_tidy.ClangTidyConfigHandler() | ||
config_handler.analyzer_binary = context.analyzer_binaries.get(CLANG_TIDY) | ||
config_handler.compiler_resource_dir = context.compiler_resource_dir | ||
|
||
# FIXME We cannot get the resource dir from the clang-tidy binary, | ||
# therefore now we get a clang binary which is a sibling of the clang-tidy. | ||
# TODO Support "clang-tidy -print-resource-dir" . | ||
check_env = analyzer_env.get_check_env(context.path_env_extra, | ||
context.ld_lib_path_extra) | ||
# Overwrite PATH to contain only the parent of the clang binary. | ||
if os.path.isabs(config_handler.analyzer_binary): | ||
check_env['PATH'] = os.path.dirname(config_handler.analyzer_binary) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a good idea to overwrite the PATH? What is the motivation behind this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just extend it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or in case the point is to always resolve to the absolute clang binary, maybe we could just set the binary instead of invoking the function that looks up the binary in the path? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to lookup It might be confusing to append to the path, because we may end up with /a/b/c/clang for /x/y/z/clang-tidy. This is true nevertheless in the relative case too, but that we cannot work around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we want tidy and clang from the same directory we should modify the lookup function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simply setting the binary will miss the binary e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't write over the effective PATH in the global env. We use a local variable and we overwrite the path in that local variable. |
||
clang_bin = analyzer_clangsa.ClangSA.resolve_missing_binary('clang', | ||
check_env) | ||
if os.path.isfile(clang_bin): | ||
config_handler.compiler_resource_dir =\ | ||
__get_compiler_resource_dir(context, clang_bin) | ||
else: | ||
config_handler.compiler_resource_dir =\ | ||
__get_compiler_resource_dir(context, | ||
config_handler.analyzer_binary) | ||
|
||
try: | ||
with open(args.tidy_args_cfg_file, 'rb') as tidy_cfg: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to move this logic to
__get_compiler_resource_dir
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a long run we plan to use a function which takes both the system includes and the resource dir as a parameter, so we could implement just in one place the madness around this header include order.