From 5dc7e1713df24528a70237bb776bf1f206b47f35 Mon Sep 17 00:00:00 2001 From: Stefan Liebl Date: Mon, 10 Feb 2025 15:03:10 +0100 Subject: [PATCH] Improve options for make --- vimfiles.stefan/plugin/toptica.vim | 83 +++++++++++++++++------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/vimfiles.stefan/plugin/toptica.vim b/vimfiles.stefan/plugin/toptica.vim index 32365b1..754a1ae 100644 --- a/vimfiles.stefan/plugin/toptica.vim +++ b/vimfiles.stefan/plugin/toptica.vim @@ -19,7 +19,6 @@ command -nargs=? -complete=dir DeCoF call s:ProjectSet('decof', '') command DeviceFirmwareUpdate call s:DeviceFirmwareUpdate() command -nargs=? -complete=file JenkinsLinter call s:Jenkins_linter('') -let s:path_orig = $PATH set titlestring= function! s:ProjectSet(project_type, project_base_dir) @@ -77,22 +76,6 @@ function! s:ProjectSet(project_type, project_base_dir) " Direnv 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 execute 'cd '.s:ProjectSrcDir execute 'set path-=./**' @@ -249,6 +232,23 @@ let g:BuildType = 'Default' compiler gcc command! -complete=customlist,GetAllMakeCompletions -nargs=* MakeCmd call s:Make('', '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 augroup QuickfixStatus autocmd BufWinEnter quickfix setlocal @@ -260,28 +260,39 @@ augroup END " Make " ==== -" Add default value for all given options, if not already set -function! s:SetDefaults(commandline, option_defaults) +function! s:getDefaultforOption(option_name) + 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 = [ - \ {'name': '--project', 'value': g:project_type}, - \ {'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}, - \ ] +" Add default value for all given options, if not already set +function! s:SetDefaults(commandline) let commandline = a:commandline let task = split(commandline)[0] - let options_allowed = system(s:invoke.' --complete -- '.task.' -') - for option_default in a:option_defaults - let option = option_default['name'] - let value = option_default['value'] - if options_allowed =~ option && commandline !~ option + let l:options_allowed = system(s:invoke.' --complete -- '.task.' -') + for option in split(l:options_allowed) + let value = s:getDefaultforOption(option) + if value != '' && commandline !~ option let commandline .= ' '.option.'='.value endif endfor @@ -290,7 +301,7 @@ endfunction function! s:Make(args, async_mode) " 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') call system(s:invoke.' -e '.l:options.'&')