-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtranslate_esbuild.vsh
More file actions
executable file
·122 lines (106 loc) · 3 KB
/
Copy pathtranslate_esbuild.vsh
File metadata and controls
executable file
·122 lines (106 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env -S v run
// Translate all esbuild Go files to V in parallel
import os
import sync
import runtime
const esbuild_src = os.home_dir() + '/code/3rd/esbuild'
const esbuild_v = '/Users/alex/code/go2v/esbuild_v'
const go2v = '/Users/alex/code/go2v/go2v'
struct Result {
file string
success bool
}
fn translate_file(file string, results_ch chan Result) {
src_file := '${esbuild_src}/${file}'
mut v_file := file.replace('.go', '.v')
// Flatten directory structure - remove internal/ and pkg/ prefixes
// This avoids V module resolution issues with nested directories
v_file = v_file.replace('internal/', '').replace('pkg/', '')
dest_file := '${esbuild_v}/${v_file}'
dest_dir := os.dir(dest_file)
// Ensure destination directory exists
os.mkdir_all(dest_dir) or {}
// Run go2v on the source file
res := os.execute('${go2v} "${src_file}" 2>/dev/null')
if res.exit_code == 0 {
// The translator creates the .v file next to the .go file
generated := src_file.replace('.go', '.v')
if os.exists(generated) {
os.mv(generated, dest_file) or {
results_ch <- Result{file, false}
return
}
results_ch <- Result{file, true}
return
}
}
results_ch <- Result{file, false}
}
fn collect_go_files_recursive(dir string) []string {
mut files := []string{}
entries := os.ls(dir) or { return files }
for entry in entries {
full_path := '${dir}/${entry}'
if os.is_dir(full_path) {
// Skip vendor and testdata directories
if entry == 'vendor' || entry == 'testdata' {
continue
}
files << collect_go_files_recursive(full_path)
} else if entry.ends_with('.go') && !entry.ends_with('_test.go')
&& !entry.ends_with('_wasm.go') && !entry.ends_with('_unix.go')
&& !entry.ends_with('_other.go') && entry !in ['fs_zip.go', 'js_ident.go', 'unicode.go'] {
// Convert absolute path to relative
rel_path := full_path.replace(esbuild_src + '/', '')
files << rel_path
}
}
return files
}
fn main() {
mut files := collect_go_files_recursive(esbuild_src)
files.sort()
num_threads := runtime.nr_cpus()
println('Using ${num_threads} threads to translate ${files.len} files...')
println('')
results_ch := chan Result{cap: files.len}
mut wg := sync.new_waitgroup()
wg.add(files.len)
// Spawn all translation tasks
for file in files {
spawn fn (f string, ch chan Result, mut w sync.WaitGroup) {
translate_file(f, ch)
w.done()
}(file, results_ch, mut wg)
}
// Wait for all tasks to complete
wg.wait()
results_ch.close()
// Collect results
mut success := 0
mut failed := 0
mut failed_files := []string{}
for {
res := <-results_ch or { break }
if res.success {
success++
println('OK: ${res.file}')
} else {
failed++
failed_files << res.file
println('FAIL: ${res.file}')
}
}
println('')
println('=========================================')
println('Translation complete!')
println('Success: ${success}')
println('Failed: ${failed}')
if failed > 0 {
println('')
println('Failed files:')
for f in failed_files {
println(' - ${f}')
}
}
}