Skip to content

ALE can't locate compile_commands.json with absolute paths in c_build_dir_names #5087

@abudden

Description

@abudden

Information

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Nov 6 2023 13:20:20)
MS-Windows 64-bit GUI/console version with OLE support
Included patches 1-2092

Operating System: Windows 11

What went wrong

ale#c#FindCompileCommands failed to find compile_commands.json despite the location being provided in c_build_dir_names.

Reproducing the bug

My build set-up puts compile_commands.json in a path that is typically BUILD_CMAKE\platform where platform varies depending on the microcontroller in use for that specific project. To get ALE to find it, I added this to after/ftplugin/c.vim:

let cmake_build = []
for path in glob(g:repository_root .. '/BUILD*', v:false, v:true)
	if isdirectory(path)
		let cmake_build += [path]
	endif
endfor
for path in glob(g:repository_root .. '/BUILD*/*', v:false, v:true)
	if isdirectory(path)
		let cmake_build += [path]
	endif
endfor

let g:ale_c_build_dir_names = cmake_build

(where g:repository_root is the root of the VCS repository)

That results in:

echo g:ale_c_build_dir_names
> ['c:\path\to\repo\BUILD_CMAKE', 'c:\path\to\repo\BUILD_CMAKE\L031']

With those absolute paths, ALE cannot find the compile_commands.json. I think it is because, on this line of c.vim, it is appending the build dir to another path (so probably ending up with something like c:\path\to\repo\c:\path\to\repo\BUILD_CMAKE\L031).

I've implemented a work-around for now by changing:

let cmake_build += [path]

to:

let cmake_build += [fnamemodify(path, ":~:.")]

That fixes the issue and results in:

echo g:ale_c_build_dir_names
['BUILD_CMAKE', 'BUILD_CMAKE\L031']

However, it would be nice if ALE could cope with absolute paths - it took me a long time to figure out why it wasn't working with gcc, especially since cppcheck does work with the absolute path.

:ALEInfo

Current Filetype: cpp
Available Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder']
Linter Aliases:
'cc' -> ['gcc', 'clang', 'g++', 'clang++']
Enabled Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder']
Ignored Linters: []
Suggested Fixers:
'astyle' - Fix C/C++ with astyle.
'clang-format' - Fix C, C++, C#, CUDA, Java, JavaScript, JSON, ObjectiveC and Protobuf files with clang-format.
'clangtidy' - Fix C/C++ and ObjectiveC files with clang-tidy.
'remove_trailing_lines' - Remove all blank lines at the end of a file.
'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
'uncrustify' - Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.

Linter Variables:
" Press Space to read :help for a setting
let g:ale_cpp_cc_executable = ''
let g:ale_cpp_cc_header_exts = ['h', 'hpp']
let g:ale_cpp_cc_options = '-std=c++14 -Wall'
let g:ale_cpp_cc_use_header_lang_flag = -1
let g:ale_cpp_ccls_executable = 'ccls'
let g:ale_cpp_ccls_init_options = {}
let g:ale_cpp_clangcheck_executable = 'clang-check'
let g:ale_cpp_clangcheck_options = ''
let g:ale_cpp_clangd_executable = 'clangd'
let g:ale_cpp_clangd_options = ''
let g:ale_cpp_clangtidy_checks = []
let g:ale_cpp_clangtidy_executable = 'clang-tidy'
let g:ale_cpp_clangtidy_extra_options = ''
let g:ale_cpp_clangtidy_options = ''
let g:ale_cpp_clazy_checks = ['level1']
let g:ale_cpp_clazy_executable = 'clazy-standalone'
let g:ale_cpp_clazy_options = ''
let g:ale_cpp_cppcheck_executable = 'C:\Program Files\Cppcheck Premium\cppcheck.exe'
let g:ale_cpp_cppcheck_options = '--enable=style --premium=misra-c++-2023 --premium=misra-c-2025:all'
let g:ale_cpp_cpplint_executable = 'cpplint'
let g:ale_cpp_cpplint_options = ''
let g:ale_cpp_cquery_cache_directory = 'c:\cygwin\home\al.cache\cquery'
let g:ale_cpp_cquery_executable = 'cquery'
let g:ale_cpp_flawfinder_executable = 'flawfinder'
let g:ale_cpp_flawfinder_minlevel = 1
let g:ale_cpp_flawfinder_options = ''

Global Variables:
" Press Space to read :help for a setting
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:false
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = v:false
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 'auto'
let g:ale_echo_cursor = v:true
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%linter% says %s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = v:false
let g:ale_fixers = {}
let g:ale_history_enabled = v:true
let g:ale_info_default_mode = 'preview'
let g:ale_history_log_output = v:true
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = v:true
let g:ale_lint_on_filetype_changed = v:true
let g:ale_lint_on_insert_leave = v:true
let g:ale_lint_on_save = v:true
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = v:false
let g:ale_linters_ignore = {}
let g:ale_list_vertical = v:false
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%linter% says %s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = v:false
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = v:true
let g:ale_set_highlights = v:true
let g:ale_set_loclist = v:true
let g:ale_set_quickfix = v:false
let g:ale_set_signs = v:true
let g:ale_sign_column_always = v:false
let g:ale_sign_error = 'E'
let g:ale_sign_info = 'I'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = 'E'
let g:ale_sign_style_warning = 'W'
let g:ale_sign_warning = 'W'
let g:ale_sign_highlight_linenrs = v:false
let g:ale_type_map = {}
let g:ale_use_neovim_diagnostics_api = v:false
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 'all'
let g:ale_warn_about_trailing_blank_lines = v:true
let g:ale_warn_about_trailing_whitespace = v:true

Command History:

(executable check - failure) clang-tidy
(executable check - failure) clazy-standalone
(finished - exit code 1) 'cmd /s/c "cd /d c:\path\to\repo && "C:\Program Files\Cppcheck Premium\cppcheck.exe" -q --language=c++ --template="{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n{code}" --project=BUILD_CMAKE\L031\compile_commands.json --file-filter=src\SourceFile.cpp --enable=style --premium=misra-c++-2023 --premium=misra-c-2025:all C:\Temp\V515173.tmp\SourceFile.cpp"'
(executable check - failure) cpplint
(executable check - failure) cquery
(executable check - failure) cspell
(executable check - failure) flawfinder
(executable check - failure) clang++
(executable check - failure) clang++
(finished - exit code 1) 'cmd /s/c "gcc -S -x c++ -o nul -iquote c:\path\to\repo\src -std=c++14 -Wall - < C:\Temp\VDH76ED.tmp\SourceFile.cpp"'

<<>>
:10:10: fatal error: cmsis.h: No such file or directory
compilation terminated.
<<>>

(executable check - failure) ccls
(executable check - failure) clang-check
(executable check - failure) clangd
(executable check - failure) clang-tidy
(executable check - failure) clazy-standalone
(finished - exit code 0) 'cmd /s/c ""C:\Program Files\Cppcheck Premium\cppcheck.exe" -q --language=c++ --template="{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n{code}" --enable=style --premium=misra-c++-2023 --premium=misra-c-2025:all -Ic:\path\to\repo\src C:\Temp\VEA78D3.tmp\SourceFile.cpp"'

<<>>

SNIPPED lots of output - cppcheck is working correctly despite the error further up

nofile:0:0: information: Active checkers: 722/1175 (use --checkers-report= to see details) [checkersReport]\

<<>>

(executable check - failure) cpplint
(executable check - failure) cquery
(executable check - failure) cspell
(executable check - failure) flawfinder

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions