Skip to content
Snippets Groups Projects
Unverified Commit 0892e321 authored by Jayesh Badwaik's avatar Jayesh Badwaik
Browse files

+ dev: added dev configuration for jayeshbadwaik

parent 6520e3c8
No related branches found
No related tags found
No related merge requests found
...@@ -19,3 +19,7 @@ License: Apache-2.0 ...@@ -19,3 +19,7 @@ License: Apache-2.0
Files: dev/etc/clang-tidy/linter.options Files: dev/etc/clang-tidy/linter.options
Copyright: (C) 2020 Jayesh Badwaik <j.badwaik@fz-juelich.de> Copyright: (C) 2020 Jayesh Badwaik <j.badwaik@fz-juelich.de>
License: Apache-2.0 License: Apache-2.0
Files: dev/share/devconfig/jayeshbadwaik/nvimrc.local
Copyright: (C) 2020 Jayesh Badwaik <j.badwaik@fz-juelich.de>
License: Apache-2.0
# REUSE-IgnoreStart
" --------------------------------------------------------------------------------------------------
" SPDX-License-Identifier: Apache-2.0
" SPDX-FileCopyrightText: (C) 2021-2021, Jayesh Badwaik <jayesh@badwaik.dev>
" -------------------------------------------------------------------------------------------------
" Indentations among other things
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
" Do not Confirm YCM Extra Configuration File
let g:ycm_confirm_extra_conf = 0
" Tagbar Plugin
let g:tagbar_left = 1
let g:tagbar_vertical = 20
let g:tagbar_previewwin_pos = "botright"
let g:ycm_autoclose_preview_window_after_insertion = 1
nmap <F10> :TagbarOpenAutoClose<CR>
" Do not Confirm YCM Extra Configuration File
let g:ycm_confirm_extra_conf = 0
nnoremap <F7> :YcmForceCompileAndDiagnostics <CR>
map <F9> :YcmCompleter FixIt<CR>
" Automatic C / C++ header guards
function! s:insert_gates()
set formatoptions-=cro
let gatename_0 = substitute(substitute(toupper(@%), "\\.", "_", "g"), "/", "_", "g")
let gatename_1 = substitute(gatename_0, "SRC_CPP_INCLUDE_", "", "g")
let gatename_2 = substitute(gatename_1, "TEST_COMMON_CPP_INCLUDE_", "", "g")
let gatename_3 = substitute(gatename_2, "BENCH_COMMON_CPP_INCLUDE_", "", "g")
let gatename_4 = substitute(gatename_3, "SRC_CUDA_INCLUDE_", "", "g")
let gatename_5 = substitute(gatename_4, "TEST_COMMON_CUDA_INCLUDE_", "", "g")
let gatename_6 = substitute(gatename_5, "BENCH_COMMON_CUDA_INCLUDE_", "", "g")
let gatename_7 = substitute(gatename_6, "SRC_HIP_INCLUDE_", "", "g")
let gatename_8 = substitute(gatename_7, "TEST_COMMON_HIP_INCLUDE_", "", "g")
let gatename_9 = substitute(gatename_8, "BENCH_COMMON_HIP_INCLUDE_", "", "g")
let gatename = gatename_9
execute "normal! o#ifndef " . gatename
execute "normal! o#define " . gatename
normal! o
execute "normal! Go#endif // " . gatename
set formatoptions-=cro
normal! k
endfunction
function! s:insert_license_cpp()
set formatoptions-=cro
execute "normal! i// -------------------------------------------------------------------------------------------------"
execute "normal! o// SPDX-License-Identifier: Apache-2.0"
execute "normal! o// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de>"
execute "normal! o// -------------------------------------------------------------------------------------------------"
normal! o
set formatoptions+=cro
endfunction
function! s:insert_license_cmake()
set formatoptions-=cro
execute "normal! i# --------------------------------------------------------------------------------------------------"
execute "normal! o# SPDX-License-Identifier: Apache-2.0"
execute "normal! o# SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de>"
execute "normal! o# --------------------------------------------------------------------------------------------------"
set formatoptions+=cro
endfunction
function! s:insert_license_bash()
set formatoptions-=cro
execute "normal! i# --------------------------------------------------------------------------------------------------"
execute "normal! o# SPDX-License-Identifier: Apache-2.0"
execute "normal! o# SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de>"
execute "normal! o# --------------------------------------------------------------------------------------------------"
set formatoptions+=cro
endfunction
function! s:insert_license_html()
set formatoptions-=cro
execute "normal! i<!--"
execute "normal! o- SPDX-License-Identifier: CC-BY-SA-4.0"
execute "normal! o- SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de>"
execute "normal! o-->"
set formatoptions+=cro
endfunction
# REUSE-IgnoreEnd
function! Insert_license_cpp()
execute "normal! O"
call s:insert_license_cpp()
endfunction
function! Insert_license_cmake()
execute "normal! O"
call s:insert_license_cmake()
endfunction
function! Insert_license_html()
execute "normal! O"
call s:insert_license_html()
endfunction
function! s:prepare_hpp()
call s:insert_license_cpp()
call s:insert_gates()
endfunction
autocmd BufNewFile *.{cuh} call <SID>prepare_hpp()
autocmd BufNewFile *.{cuhpp} call <SID>prepare_hpp()
autocmd BufNewFile *.{h} call <SID>prepare_hpp()
autocmd BufNewFile *.{c} call <SID>insert_license_cpp()
autocmd BufNewFile *.{hpp} call <SID>prepare_hpp()
autocmd BufNewFile *.{cpp} call <SID>insert_license_cpp()
autocmd BufNewFile *.{cu} call <SID>insert_license_cpp()
autocmd BufNewFile *.{ipp} call <SID>insert_license_cpp()
autocmd BufNewFile CMakeLists.txt call <SID>insert_license_cmake()
autocmd BufNewFile *.cmake call <SID>insert_license_cmake()
autocmd BufNewFile *.{bash} call <SID>insert_license_bash()
autocmd BufNewFile *.{sh} call <SID>insert_license_bash()
autocmd BufNewFile *.{md} call <SID>insert_license_html()
autocmd BufNewFile *.{rs} call <SID>insert_license_cpp()
autocmd BufNewFile *.{py} call <SID>insert_license_bash()
" Remove Trailing Whitespace on Save
autocmd BufWritePre * %s/\s\+$//e
" Show trailing whitespace:
highlight ExtraWhitespace ctermbg=red guibg=red
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
augroup filetypedetect
au BufRead,BufNewFile *.jnum set filetype=json
au BufRead,BufNewFile *.cuhpp set filetype=cuda
au BufRead,BufNewFile *.cuh set filetype=cuda
augroup END
# --------------------------------------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: (C) 2021-2021, Jayesh Badwaik <jayesh@badwaik.dev>
# --------------------------------------------------------------------------------------------------
import os
import ycm_core
import subprocess
import glob
cxxflags = [
'-Weverything',
'-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic',
'-Wno-covered-switch-default',
'-Wno-padded',
'-Wno-weak-vtables',
'-Wno-exit-time-destructors',
'-Wno-global-constructors',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++20',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-nostdinc++',
'-stdlib=libc++',
'-isystem',
'/usr/include/c++/v1/',
'-Isrc/cpp/include/',
'-Isrc/cuda/include/',
'-Itest/common/cpp/include/',
'-Itest/common/cuda/include/',
'-DMOL_COMPILE_TEST_DISABLE',
'-isystem',
'/home/work/zell/software/zell/cota/dep/usr/include',
'-isystem',
'/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/include/'
]
cflags = [
'-Wextra',
'-Wall',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c',
'-Isrc/c/include/',
'-Itest/common/c/include/',
'-DMOL_COMPILE_TEST_DISABLE',
'-isystem',
'/home/work/zell/software/zell/cota/dep/usr/include',
'-isystem',
'/opt/nvidia/hpc_sdk/Linux_x86_64/22.11/cuda/include/'
]
cudaflags = [
'-Wextra',
'-Wall',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++20',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'cuda',
'-D__CUDACC__',
'-nostdinc++',
'-stdlib=libc++',
'-isystem',
'/usr/include/c++/v1/',
'-Isrc/cpp/include/',
'-Isrc/cuda/include/',
'-Itest/common/cpp/include/',
'-Itest/common/cuda/include/',
'-DDGALE_RUN_CLANG_TIDY',
'-isystem',
'/home/work/zell/software/zell/cota/dep/usr/include',
'-isystem',
'/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/include/'
]
SOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc', '.c', '.m', '.mm', '.ipp']
def DirectoryOfThisScript():
return os.path.dirname(os.path.abspath(__file__))
def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
if not working_directory:
return list(flags)
new_flags = []
make_next_absolute = False
path_flags = ['-isystem', '-I', '-iquote', '--sysroot=']
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith('/'):
new_flag = os.path.join(working_directory, flag)
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith(path_flag):
path = flag[len(path_flag):]
new_flag = path_flag + os.path.join(working_directory, path)
break
if new_flag:
new_flags.append(new_flag)
return new_flags
def GetUnit(filename):
# Get the Directory Prefix
prefix = os.path.dirname(filename)
# Get the Basename
basename = os.path.basename(filename)
# Separate Basename into Name and Extension
baseroot, ext = os.path.splitext(basename)
if ext == '.ipp':
# Residue Base Root
headerroot = baseroot
# Header File Name
headerfilename = headerroot + ".hpp"
# absolute path for header file
headerfilepath = os.path.join(prefix, headerfilename)
if os.path.isfile(headerfilepath):
# Return headerfilepath
print(headerfilepath)
return headerfilepath
return filename
def GetCompilationInfoForFile(filename):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile(filename):
basename = os.path.splitext(filename)[0]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists(replacement_file):
compilation_info = database.GetCompilationInfoForFile(
replacement_file)
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile(filename)
def Settings(filename, **kwargs):
relative_to = DirectoryOfThisScript()
extension = os.path.splitext(filename)[1]
flags = []
print(extension)
if extension == ".c" or extension == ".h":
print("C Language Detected")
flags = cflags
elif extension == ".cu" or extension == ".cuh":
flags = cudaflags
else:
flags = cxxflags
print(flags)
final_flags = MakeRelativePathsInFlagsAbsolute(flags, relative_to)
translation_unit = GetUnit(filename)
return {
'flags': final_flags
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment