2022-06-19 14:52:42 +02:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license that can be found in the LICENSE file.
|
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import v.util
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
vmodules := os.vmodules_dir()
|
|
|
|
c2v_dir := os.join_path(vmodules, 'c2v_alpha')
|
|
|
|
c2v_bin := os.join_path(c2v_dir, 'c2v')
|
|
|
|
// Git clone c2v
|
|
|
|
if !os.exists(c2v_dir) {
|
2022-06-19 15:19:56 +02:00
|
|
|
println('C2V is not installed. Cloning C2V to $c2v_dir ...')
|
2022-06-19 14:52:42 +02:00
|
|
|
os.chdir(vmodules)?
|
|
|
|
res := os.execute('git clone --depth 1 git@github.com:/vlang/c2v_alpha.git')
|
|
|
|
if res.exit_code != 0 {
|
|
|
|
eprintln('Failed to download C2V. Perhaps it is not released yet? Is it June 20 yet?')
|
2022-06-19 15:19:56 +02:00
|
|
|
exit(1)
|
2022-06-19 14:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Compile c2v
|
|
|
|
if !os.exists(c2v_bin) {
|
|
|
|
os.chdir(c2v_dir)?
|
2022-06-19 15:19:56 +02:00
|
|
|
println('Compiling c2v ...')
|
2022-06-19 14:52:42 +02:00
|
|
|
res2 := os.execute('v -d trace_verbose -g -o c2v -experimental -w .')
|
|
|
|
if res2.exit_code != 0 {
|
|
|
|
eprintln('Failed to compile C2V. This should never happen, please report it via GitHub.')
|
2022-06-19 15:19:56 +02:00
|
|
|
exit(2)
|
2022-06-19 14:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if os.args.len < 3 {
|
|
|
|
eprintln('Wrong number of args. Use `v translate file.c`.')
|
2022-06-19 15:19:56 +02:00
|
|
|
exit(3)
|
2022-06-19 14:52:42 +02:00
|
|
|
}
|
|
|
|
passed_args := util.args_quote_paths(os.args[2..])
|
|
|
|
// println(passed_args)
|
2022-06-19 15:19:56 +02:00
|
|
|
os.chdir(os.wd_at_startup)?
|
2022-06-19 14:52:42 +02:00
|
|
|
res := os.execute('$c2v_bin $passed_args')
|
|
|
|
if res.exit_code != 0 {
|
|
|
|
eprintln('C2V failed to translate this file. This should never happen, please report it via GitHub.')
|
2022-06-19 15:19:56 +02:00
|
|
|
exit(4)
|
2022-06-19 14:52:42 +02:00
|
|
|
}
|
|
|
|
println('Success!')
|
|
|
|
// println(res.output)
|
|
|
|
}
|