Improve options for make

This commit is contained in:
Stefan Liebl 2025-02-10 15:03:10 +01:00
parent 938e69e791
commit 5dc7e1713d

View File

@ -19,7 +19,6 @@ command -nargs=? -complete=dir DeCoF call s:ProjectSet('decof', '<args>')
command DeviceFirmwareUpdate call s:DeviceFirmwareUpdate() command DeviceFirmwareUpdate call s:DeviceFirmwareUpdate()
command -nargs=? -complete=file JenkinsLinter call s:Jenkins_linter('<args>') command -nargs=? -complete=file JenkinsLinter call s:Jenkins_linter('<args>')
let s:path_orig = $PATH
set titlestring= set titlestring=
function! s:ProjectSet(project_type, project_base_dir) function! s:ProjectSet(project_type, project_base_dir)
@ -77,22 +76,6 @@ function! s:ProjectSet(project_type, project_base_dir)
" Direnv " Direnv
let $DIRENV_DIR = s:ProjectBaseDir let $DIRENV_DIR = s:ProjectBaseDir
function! g:Compiler_version()
if exists('g:ProjectBuildDir')
let cmakefile = g:ProjectBuildDir . '/CMakeCache.txt'
if filereadable(cmakefile)
for line in readfile(cmakefile)
if match(line, 'NEW_COMPILER:BOOL=OFF') >= 0
return 'old'
elseif match(line, 'NEW_COMPILER:BOOL=ON') >= 0
return 'new'
endif
endfor
endif
endif
return 0
endfunction
" vim path " vim path
execute 'cd '.s:ProjectSrcDir execute 'cd '.s:ProjectSrcDir
execute 'set path-=./**' execute 'set path-=./**'
@ -249,6 +232,23 @@ let g:BuildType = 'Default'
compiler gcc compiler gcc
command! -complete=customlist,GetAllMakeCompletions -nargs=* MakeCmd call s:Make('<args>', 'async') command! -complete=customlist,GetAllMakeCompletions -nargs=* MakeCmd call s:Make('<args>', 'async')
" Get compiler-version for DLCpro
function! g:Compiler_version()
if exists('g:ProjectBuildDir')
let cmakefile = g:ProjectBuildDir . '/CMakeCache.txt'
if filereadable(cmakefile)
for line in readfile(cmakefile)
if match(line, 'NEW_COMPILER:BOOL=OFF') >= 0
return 'old'
elseif match(line, 'NEW_COMPILER:BOOL=ON') >= 0
return 'new'
endif
endfor
endif
endif
return 0
endfunction
" configure quickfix window for asyncrun " configure quickfix window for asyncrun
augroup QuickfixStatus augroup QuickfixStatus
autocmd BufWinEnter quickfix setlocal autocmd BufWinEnter quickfix setlocal
@ -260,28 +260,39 @@ augroup END
" Make " Make
" ==== " ====
" Add default value for all given options, if not already set function! s:getDefaultforOption(option_name)
function! s:SetDefaults(commandline, option_defaults) if a:option_name == '--project'
return g:project_type
elseif a:option_name == '--device-ip'
return g:DeviceIP
elseif a:option_name == '--build-type'
return g:BuildType
elseif a:option_name == '--firmware-file'
return s:firmware_file
elseif a:option_name == '--version-file'
return g:ProjectBuildDir.'/artifacts/VERSION'
elseif a:option_name == '--laser1-type'
return g:DeviceType
elseif a:option_name == '--powerswitch-ip'
return g:PowerswitchIP
elseif a:option_name == '--powerplug'
return g:Powerplug
elseif a:option_name == '--firmware-file'
return s:firmware_file
else
return ""
endif
endfunction
let g:option_defaults = [ " Add default value for all given options, if not already set
\ {'name': '--project', 'value': g:project_type}, function! s:SetDefaults(commandline)
\ {'name': '--device-ip', 'value': g:DeviceIP},
\ {'name': '--build-type', 'value': g:BuildType},
\ {'name': '--firmware-file', 'value': s:firmware_file},
\ {'name': '--version-file', 'value': g:ProjectBuildDir.'/artifacts/VERSION'},
\ {'name': '--laser1-type', 'value': g:DeviceType},
\ {'name': '--powerswitch-ip', 'value': g:PowerswitchIP},
\ {'name': '--powerplug', 'value': g:Powerplug},
\ {'name': '--firmware-file', 'value': s:firmware_file},
\ ]
let commandline = a:commandline let commandline = a:commandline
let task = split(commandline)[0] let task = split(commandline)[0]
let options_allowed = system(s:invoke.' --complete -- '.task.' -') let l:options_allowed = system(s:invoke.' --complete -- '.task.' -')
for option_default in a:option_defaults for option in split(l:options_allowed)
let option = option_default['name'] let value = s:getDefaultforOption(option)
let value = option_default['value'] if value != '' && commandline !~ option
if options_allowed =~ option && commandline !~ option
let commandline .= ' '.option.'='.value let commandline .= ' '.option.'='.value
endif endif
endfor endfor
@ -290,7 +301,7 @@ endfunction
function! s:Make(args, async_mode) function! s:Make(args, async_mode)
" Add defaults for options " Add defaults for options
let l:options = s:SetDefaults(a:args, g:option_defaults) let l:options = s:SetDefaults(a:args)
if (a:async_mode == 'background') if (a:async_mode == 'background')
call system(s:invoke.' -e '.l:options.'&') call system(s:invoke.' -e '.l:options.'&')