nushell script to generate compilation database (compile_command.json) for clangd
compile_db.nu
34 lines 826 B view raw
1#!/usr/bin/env nu 2 3def main [] { 4 let config = { 5 output: "compile_commands.json", 6 compiler: "gcc" 7 src_dir: "src" 8 flags: [ 9 "-Isrc" 10 ] 11 } 12 13 let path_root = ($env.PWD | path expand | str replace --all '\' '/') 14 let sources = (glob $"($config.src_dir)/**/*.c") 15 16 let compile_db = ($sources | each { |path_file| 17 let path_file_normalized = ($path_file | str replace --all '\' '/') 18 { 19 arguments: [ 20 $config.compiler, 21 "-std=c99" 22 "-c", 23 ...$config.flags, 24 $path_file_normalized, 25 ] 26 directory: $path_root, 27 file: $path_file_normalized, 28 } 29 }) 30 31 $compile_db | to json | save -f $config.output 32 33 print "Done." 34}