| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | import testing |
| 5 | import v.util |
| 6 | |
| 7 | // Note: tools like vdoc are compiled in their own subfolder |
| 8 | // => cmd/tools/vdoc/vdoc.exe |
| 9 | // Usually, they have several top level .v files in the subfolder, |
| 10 | // that cannot be compiled separately, but instead, the whole folder, |
| 11 | // should be compiled (v folder). |
| 12 | // To implement that, these folders are initially skipped, then added |
| 13 | // as a whole *after the testing.prepare_test_session call*. |
| 14 | const tools_in_subfolders = ['vast', 'vcreate', 'vdoc', 'vpm', 'vsqlite', 'vsymlink', 'vvet', |
| 15 | 'vwhere', 'vcover'] |
| 16 | |
| 17 | // non_packaged_tools are tools that should not be packaged with |
| 18 | // prebuild versions of V, to keep the size smaller. |
| 19 | // They are mainly useful for the V project itself, not to end users. |
| 20 | const non_packaged_tools = ['gen1m', 'gen_vc', 'fast', 'wyhash'] |
| 21 | |
| 22 | fn main() { |
| 23 | if os.getenv('VTEST_SANDBOXED_PACKAGING') == '' { |
| 24 | util.ensure_modules_for_all_tools_are_installed('-v' in os.args) |
| 25 | } |
| 26 | args_string := os.args[1..].join(' ') |
| 27 | vexe := os.getenv('VEXE') |
| 28 | vroot := os.dir(vexe) |
| 29 | os.chdir(vroot)! |
| 30 | folder := os.join_path('cmd', 'tools') |
| 31 | tfolder := os.join_path(vroot, 'cmd', 'tools') |
| 32 | main_label := 'Building ${folder} ...' |
| 33 | finish_label := 'building ${folder}' |
| 34 | |
| 35 | mut skips := []string{} |
| 36 | for stool in tools_in_subfolders { |
| 37 | skips << os.join_path(tfolder, stool).replace('\\', '/') |
| 38 | } |
| 39 | buildopts := args_string.all_before('build-tools') |
| 40 | mut session := testing.prepare_test_session(buildopts, folder, skips, main_label) |
| 41 | session.rm_binaries = false |
| 42 | session.build_tools = true |
| 43 | for stool in tools_in_subfolders { |
| 44 | session.add(os.join_path(tfolder, stool)) |
| 45 | } |
| 46 | // eprintln('> session.files: ${session.files}') |
| 47 | // eprintln('> session.skip_files: ${session.skip_files}') |
| 48 | session.test() |
| 49 | eprintln(session.benchmark.total_message(finish_label)) |
| 50 | if session.failed_cmds.len > 0 { |
| 51 | exit(1) |
| 52 | } |
| 53 | |
| 54 | mut executables := os.ls(session.vtmp_dir)! |
| 55 | executables.sort() |
| 56 | for texe in executables { |
| 57 | tname := texe.replace(os.file_ext(texe), '') |
| 58 | if tname in non_packaged_tools { |
| 59 | continue |
| 60 | } |
| 61 | // |
| 62 | tpath := os.join_path(session.vtmp_dir, texe) |
| 63 | if texe.ends_with('_builder') || texe.ends_with('_builder.exe') { |
| 64 | os.mv_by_cp(tpath, os.join_path(tfolder, 'builders', texe)) or { panic(err) } |
| 65 | continue |
| 66 | } |
| 67 | if tname in tools_in_subfolders { |
| 68 | os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err) } |
| 69 | continue |
| 70 | } |
| 71 | if os.is_dir(tpath) { |
| 72 | continue |
| 73 | } |
| 74 | target_path := os.join_path(tfolder, texe) |
| 75 | os.mv_by_cp(tpath, target_path) or { |
| 76 | emsg := err.msg() |
| 77 | if !emsg.contains('vbuild-tools') && !emsg.contains('vtest-all') { |
| 78 | eprintln('error while moving ${tpath} to ${target_path}: ${emsg}') |
| 79 | } |
| 80 | continue |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |