mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
tools: improve v should-compile-all .
with support for compiling .wasm.v and .js.v files; skip module name
files, compile projects that have .glsl files
This commit is contained in:
parent
8902f7dda0
commit
02a7355cfa
3 changed files with 35 additions and 3 deletions
|
@ -34,30 +34,61 @@ fn main() {
|
||||||
mut executables := []string{}
|
mut executables := []string{}
|
||||||
mut failed_commands := []string{}
|
mut failed_commands := []string{}
|
||||||
mut project_folders := map[string]bool{}
|
mut project_folders := map[string]bool{}
|
||||||
|
mut skipped_files := []string{}
|
||||||
for idx, example in files {
|
for idx, example in files {
|
||||||
folder_of_example := os.dir(example)
|
folder_of_example := os.dir(example)
|
||||||
if os.is_file(os.join_path_single(folder_of_example, '.skip_should_compile_all')) {
|
if os.is_file(os.join_path_single(folder_of_example, '.skip_should_compile_all')) {
|
||||||
log.info('>>> skipping file: ${example}, because a `.skip_should_compile_all` file is present next to it.')
|
log.info('>>> skipping file: ${example}, because a `.skip_should_compile_all` file is present next to it.')
|
||||||
|
skipped_files << example
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// project folders usually contain many .v files, that are *all* part of the same program.
|
||||||
|
// NOTE: => projects should be compiled with `v project/`.
|
||||||
|
// To do that, just record the presence of such a folder for now, and try to compile it separately later.
|
||||||
if project_folders[folder_of_example] {
|
if project_folders[folder_of_example] {
|
||||||
|
skipped_files << example
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if os.is_file(os.join_path_single(folder_of_example, 'v.mod')) {
|
if os.is_file(os.join_path_single(folder_of_example, 'v.mod')) {
|
||||||
log.info('>>> delaying compilation of entire project folder ${folder_of_example} ...')
|
log.info('>>> delaying compilation of entire project folder ${folder_of_example} ...')
|
||||||
project_folders[folder_of_example] = true
|
project_folders[folder_of_example] = true
|
||||||
|
skipped_files << example
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cmd := '${os.quoted_path(@VEXE)} ${os.quoted_path(example)}'
|
//
|
||||||
log.info('> compiling ${idx + 1:4}/${files.len:-4}: ${cmd}')
|
mut backend_options := '-b c'
|
||||||
|
if example.ends_with('.wasm.v') {
|
||||||
|
backend_options = '-b wasm -os browser'
|
||||||
|
}
|
||||||
|
if example.ends_with('.js.v') {
|
||||||
|
backend_options = '-b js'
|
||||||
|
}
|
||||||
|
lines := os.read_lines(example)!#[..50].filter(it.starts_with('module'))
|
||||||
|
if lines.len > 0 && lines[0] != 'module main' {
|
||||||
|
log.info('>>> skipping non main module file: ${example}')
|
||||||
|
skipped_files << example
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cmd := '${os.quoted_path(@VEXE)} ${backend_options} ${os.quoted_path(example)}'
|
||||||
|
log.info('> compiling program ${idx + 1:4}/${files.len:-4}: ${cmd}')
|
||||||
if 0 != os.system(cmd) {
|
if 0 != os.system(cmd) {
|
||||||
failed_commands << cmd
|
failed_commands << cmd
|
||||||
} else {
|
} else {
|
||||||
executables << executable_name(example)
|
executables << executable_name(example)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mut glsl_folders := map[string]bool{}
|
||||||
mut pfi := 0
|
mut pfi := 0
|
||||||
for pf, _ in project_folders {
|
for pf, _ in project_folders {
|
||||||
|
glsl_files := os.glob(os.join_path(pf, '*.glsl'))!
|
||||||
|
if glsl_files.len > 0 {
|
||||||
|
if pf !in glsl_folders {
|
||||||
|
log.debug('>>> found .glsl files in ${pf} ... running `v shader ${pf}` ...')
|
||||||
|
os.system('${os.quoted_path(@VEXE)} shader ${os.quoted_path(pf)}')
|
||||||
|
glsl_folders[pf] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
exe_path := os.join_path(pf, os.file_name(pf) + exe_extension)
|
exe_path := os.join_path(pf, os.file_name(pf) + exe_extension)
|
||||||
cmd := '${os.quoted_path(@VEXE)} -o ${exe_path} ${pf}'
|
cmd := '${os.quoted_path(@VEXE)} -o ${exe_path} ${pf}'
|
||||||
log.info('> compiling project ${pfi + 1:4}/${project_folders.len:-4}: ${cmd}')
|
log.info('> compiling project ${pfi + 1:4}/${project_folders.len:-4}: ${cmd}')
|
||||||
|
@ -68,6 +99,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
pfi++
|
pfi++
|
||||||
}
|
}
|
||||||
|
|
||||||
if should_clean {
|
if should_clean {
|
||||||
log.info('Removing ${executables.len} successfully build executables...')
|
log.info('Removing ${executables.len} successfully build executables...')
|
||||||
for f in executables {
|
for f in executables {
|
||||||
|
@ -81,7 +113,7 @@ fn main() {
|
||||||
log.info('Summary: ${failed_commands.len:4}/${files.len:-4} file(s) failed to compile.')
|
log.info('Summary: ${failed_commands.len:4}/${files.len:-4} file(s) failed to compile.')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
log.info('Summary: all ${files.len} file(s) compiled successfully.')
|
log.info('Summary: all ${files.len} program file(s), and ${project_folders.len} project(s) compiled successfully. Skipped files: ${skipped_files.len} .')
|
||||||
}
|
}
|
||||||
|
|
||||||
const exe_extension = if os.user_os() == 'windows' {
|
const exe_extension = if os.user_os() == 'windows' {
|
||||||
|
|
0
examples/macos_tray/.skip_should_compile_all
Normal file
0
examples/macos_tray/.skip_should_compile_all
Normal file
Loading…
Add table
Add a link
Reference in a new issue