diff --git a/cmd/v/help/build-c.txt b/cmd/v/help/build-c.txt index 11844b6555..a1995b3179 100644 --- a/cmd/v/help/build-c.txt +++ b/cmd/v/help/build-c.txt @@ -239,7 +239,15 @@ see also `v help build`. -dump-c-flags file.txt Write all C flags into `file.txt`, one flag per line. - If `file.txt` is `-`, then write the flags to stdout, one flag per line. + If `file.txt` is `-`, write to stdout instead. + + -dump-modules file.txt + Write all module names used by the program in `file.txt`, one module per line. + If `file.txt` is `-`, write to stdout instead. + + -dump-files file.txt + Write all used V file paths used by the program in `file.txt`, one module per line. + If `file.txt` is `-`, write to stdout instead. -no-rsp By default, V passes all C compiler options to the backend C compiler diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index ae6c23ae02..07c599c3e9 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -215,6 +215,9 @@ pub fn (mut b Builder) parse_imports() { } exit(0) } + if b.pref.dump_files != '' { + b.dump_files(b.parsed_files.map(it.path)) + } b.rebuild_modules() } @@ -241,6 +244,7 @@ pub fn (mut b Builder) resolve_deps() { for node in deps_resolved.nodes { mods << node.name } + b.dump_modules(mods) if b.pref.is_verbose { eprintln('------ imported modules: ------') eprintln(mods.str()) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 3f10023a1f..a2c49adb97 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -483,17 +483,6 @@ fn (mut v Builder) setup_output_name() { v.ccoptions.o_args << '-o "$v.pref.out_name"' } -fn (mut v Builder) dump_c_options(all_args []string) { - if v.pref.dump_c_flags != '' { - non_empty_args := all_args.filter(it != '').join('\n') + '\n' - if v.pref.dump_c_flags == '-' { - print(non_empty_args) - } else { - os.write_file(v.pref.dump_c_flags, non_empty_args) or { panic(err) } - } - } -} - pub fn (mut v Builder) cc() { if os.executable().contains('vfmt') { return diff --git a/vlib/v/builder/dump_lists.v b/vlib/v/builder/dump_lists.v new file mode 100644 index 0000000000..26c81568cd --- /dev/null +++ b/vlib/v/builder/dump_lists.v @@ -0,0 +1,26 @@ +module builder + +import os + +pub fn (b &Builder) dump_c_options(all_args []string) { + dump_list(b.pref.dump_c_flags, all_args) +} + +pub fn (b &Builder) dump_modules(mods []string) { + dump_list(b.pref.dump_modules, mods) +} + +pub fn (b &Builder) dump_files(files []string) { + dump_list(b.pref.dump_files, files) +} + +fn dump_list(file_path string, list []string) { + if file_path != '' { + content := list.filter(it != '').join('\n') + '\n' + if file_path == '-' { + print(content) + } else { + os.write_file(file_path, content) or { panic(err) } + } + } +} diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index af09f065d7..a5d24c587e 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -139,6 +139,8 @@ pub mut: show_callgraph bool // -show-callgraph, print the program callgraph, in a Graphviz DOT format to stdout show_depgraph bool // -show-depgraph, print the program module dependency graph, in a Graphviz DOT format to stdout dump_c_flags string // `-dump-c-flags file.txt` - let V store all C flags, passed to the backend C compiler in `file.txt`, one C flag/value per line. + dump_modules string // `-dump-modules modules.txt` - let V store all V modules, that were used by the compiled program in `modules.txt`, one module per line. + dump_files string // `-dump-files files.txt` - let V store all V or .template file paths, that were used by the compiled program in `files.txt`, one path per line. use_cache bool // when set, use cached modules to speed up subsequent compilations, at the cost of slower initial ones (while the modules are cached) retry_compilation bool = true // retry the compilation with another C compiler, if tcc fails. // TODO Convert this into a []string @@ -528,6 +530,14 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin res.dump_c_flags = cmdline.option(current_args, arg, '-') i++ } + '-dump-modules' { + res.dump_modules = cmdline.option(current_args, arg, '-') + i++ + } + '-dump-files' { + res.dump_files = cmdline.option(current_args, arg, '-') + i++ + } '-experimental' { res.experimental = true }