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