Skip to content

Commit 5171f87

Browse files
committed
Fix some quirks with build dir finding especially on Travis CI
Signed-off-by: Squareys <[email protected]>
1 parent a14c1ad commit 5171f87

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

plugin/cmake.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ function! s:find_build_dir()
3434
endif
3535

3636
let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build')
37-
let b:build_dir = finddir(g:cmake_build_dir, expand(".") . ';')
37+
let b:build_dir = finddir(g:cmake_build_dir, ';')
3838

3939
if b:build_dir == ""
4040
" Find build directory in path of current file
41-
let b:build_dir = finddir(g:cmake_build_dir, expand("%:p:h") . ';')
41+
let b:build_dir = finddir(g:cmake_build_dir, s:fnameescape(expand("%:p:h")) . ';')
4242
endif
4343

4444
if b:build_dir != ""

test/cmake.vader

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@ Before:
88
let test_dir = fnamemodify(getcwd(), ':p')
99
endif
1010

11-
Assert !isdirectory("test project/build"), "TEST ERROR: build directory was not properly deleted"
12-
echo system("mkdir 'test project/build'")
13-
Assert isdirectory("test project/build"), "TEST ERROR: build directory was not created"
11+
Assert !isdirectory("test project/tmp-build"), "TEST ERROR: build directory was not properly deleted"
12+
echo system("mkdir 'test project/tmp-build'")
13+
Assert isdirectory("test project/tmp-build"), "TEST ERROR: build directory was not created"
1414

15+
" Under travis CI the entire project is in a build/ directory
16+
" which will make the search from cwd always return a result.
17+
" To be able to test searching build dir from current file, the
18+
" build dir needs to be named differently as a workaround.
19+
let g:cmake_build_dir = "tmp-build"
1520
After:
1621
exec "cd" fnameescape(test_dir)
17-
echo system("rm -rf 'test project/build'")
22+
echo system("rm -rf 'test project/tmp-build'")
1823
echo system("rm -f 'test project/compile_commands.json'")
1924

2025
Execute (Find build directory from working dir):
2126
cd test\ project
2227
CMake
2328

24-
Assert filereadable("build/CMakeCache.txt"), "CMakeCache.txt should be generated"
25-
Assert !filereadable("build/compile_commands.json"), "Compile commands should not be exported by default"
29+
Assert filereadable("tmp-build/CMakeCache.txt"), "CMakeCache.txt should be generated"
30+
Assert !filereadable("tmp-build/compile_commands.json"), "Compile commands should not be exported by default"
2631

2732
Execute (Find build directory from currently open file):
2833
e test\ project/CMakeLists.txt
2934
CMake
30-
Assert filereadable("test project/build/CMakeCache.txt"), "CMakeCache.txt should be generated"
35+
Assert filereadable("test project/tmp-build/CMakeCache.txt"), "CMakeCache.txt should be generated"
3136

3237
Execute (Create symlink to compilation database):
3338
let g:cmake_export_compile_commands = 1
@@ -37,12 +42,12 @@ Execute (Create symlink to compilation database):
3742

3843
" Exporting compile commands does not work with Visual Studio generator
3944
if !has("win32") && !has("win32unix")
40-
Assert filereadable("build/compile_commands.json"), "Compile commands should be exported"
45+
Assert filereadable("tmp-build/compile_commands.json"), "Compile commands should be exported"
4146
Assert filereadable(resolve("compile_commands.json")), "A symlink should be generated"
4247
endif
4348

4449
Execute (Open already configured cmake project):
45-
cd test\ project/build
50+
cd test\ project/tmp-build
4651
silent !cmake .. -DWITH_BYE=ON
4752
e ../CMakeLists.txt
4853
CMake

0 commit comments

Comments
 (0)