diff --git a/cmd/tools/vshould-compile-all.v b/cmd/tools/vshould-compile-all.v index 10b039a832..b384096a74 100644 --- a/cmd/tools/vshould-compile-all.v +++ b/cmd/tools/vshould-compile-all.v @@ -34,30 +34,61 @@ fn main() { mut executables := []string{} mut failed_commands := []string{} mut project_folders := map[string]bool{} + mut skipped_files := []string{} for idx, example in files { folder_of_example := os.dir(example) 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.') + skipped_files << example 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] { + skipped_files << example continue } if os.is_file(os.join_path_single(folder_of_example, 'v.mod')) { log.info('>>> delaying compilation of entire project folder ${folder_of_example} ...') project_folders[folder_of_example] = true + skipped_files << example 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) { failed_commands << cmd } else { executables << executable_name(example) } } + + mut glsl_folders := map[string]bool{} mut pfi := 0 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) cmd := '${os.quoted_path(@VEXE)} -o ${exe_path} ${pf}' log.info('> compiling project ${pfi + 1:4}/${project_folders.len:-4}: ${cmd}') @@ -68,6 +99,7 @@ fn main() { } pfi++ } + if should_clean { log.info('Removing ${executables.len} successfully build 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.') 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' { diff --git a/examples/sokol/particles/modules/particle/v.mod b/examples/coroutines/.skip_should_compile_all similarity index 100% rename from examples/sokol/particles/modules/particle/v.mod rename to examples/coroutines/.skip_should_compile_all diff --git a/examples/macos_tray/.skip_should_compile_all b/examples/macos_tray/.skip_should_compile_all new file mode 100644 index 0000000000..e69de29bb2