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 = ['vdoc', 'vvet', 'vast', 'vwhere', 'vcreate'] |
15 | |
16 | // non_packaged_tools are tools that should not be packaged with |
17 | // prebuild versions of V, to keep the size smaller. |
18 | // They are mainly usefull for the V project itself, not to end users. |
19 | const non_packaged_tools = ['gen1m', 'gen_vc', 'fast', 'wyhash'] |
20 | |
21 | fn main() { |
22 | util.ensure_modules_for_all_tools_are_installed('-v' in os.args) |
23 | args_string := os.args[1..].join(' ') |
24 | vexe := os.getenv('VEXE') |
25 | vroot := os.dir(vexe) |
26 | os.chdir(vroot)! |
27 | folder := os.join_path('cmd', 'tools') |
28 | tfolder := os.join_path(vroot, 'cmd', 'tools') |
29 | main_label := 'Building ${folder} ...' |
30 | finish_label := 'building ${folder}' |
31 | // |
32 | mut skips := []string{} |
33 | for stool in tools_in_subfolders { |
34 | skips << os.join_path(tfolder, stool).replace('\\', '/') |
35 | } |
36 | buildopts := args_string.all_before('build-tools') |
37 | mut session := testing.prepare_test_session(buildopts, folder, skips, main_label) |
38 | session.rm_binaries = false |
39 | for stool in tools_in_subfolders { |
40 | session.add(os.join_path(tfolder, stool)) |
41 | } |
42 | // eprintln('> session.files: $session.files') |
43 | // eprintln('> session.skip_files: $session.skip_files') |
44 | session.test() |
45 | eprintln(session.benchmark.total_message(finish_label)) |
46 | if session.failed_cmds.len > 0 { |
47 | exit(1) |
48 | } |
49 | // |
50 | mut executables := os.ls(session.vtmp_dir)! |
51 | executables.sort() |
52 | for texe in executables { |
53 | tname := texe.replace(os.file_ext(texe), '') |
54 | if tname in non_packaged_tools { |
55 | continue |
56 | } |
57 | // |
58 | tpath := os.join_path(session.vtmp_dir, texe) |
59 | if texe.ends_with('_builder') || texe.ends_with('_builder.exe') { |
60 | os.mv_by_cp(tpath, os.join_path(tfolder, 'builders', texe)) or { panic(err) } |
61 | continue |
62 | } |
63 | if tname in tools_in_subfolders { |
64 | os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err) } |
65 | continue |
66 | } |
67 | if os.is_dir(tpath) { |
68 | continue |
69 | } |
70 | target_path := os.join_path(tfolder, texe) |
71 | os.mv_by_cp(tpath, target_path) or { |
72 | emsg := err.msg() |
73 | if !emsg.contains('vbuild-tools') && !emsg.contains('vtest-all') { |
74 | eprintln('error while moving ${tpath} to ${target_path}: ${emsg}') |
75 | } |
76 | continue |
77 | } |
78 | } |
79 | } |