From d148920b54e2411a91690e0b610a8803d1d9cdb8 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 30 May 2020 11:06:16 +0300 Subject: [PATCH] v.util: prepare CI for the external markdown module (needed for vdoc) --- cmd/tools/vbuild-tools.v | 2 ++ vlib/v/builder/cc.v | 3 +- vlib/v/util/util.v | 71 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/cmd/tools/vbuild-tools.v b/cmd/tools/vbuild-tools.v index 36c02d7db2..b1c0fde386 100644 --- a/cmd/tools/vbuild-tools.v +++ b/cmd/tools/vbuild-tools.v @@ -2,6 +2,7 @@ module main import os import testing +import v.util fn main() { args := os.args @@ -10,6 +11,7 @@ fn main() { skips := [ 'cmd/tools/gen_vc.v' ] + util.ensure_modules_for_all_tools_are_installed('-v' in args) if testing.v_build_failing_skipped(args_string.all_before('build-tools'), 'cmd/tools', skips) { exit(1) } diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index f2c04b4292..053322cf5c 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -601,7 +601,8 @@ fn (v &Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CFlag } btarget := moduleflags.c_options_before_target() atarget := moduleflags.c_options_after_target() - cmd := '$v.pref.ccompiler $v.pref.third_party_option $btarget -c -o "$obj_path" $cfiles $atarget ' + cppoptions := if v.pref.ccompiler.contains('++') { ' -fpermissive -w ' } else { '' } + cmd := '$v.pref.ccompiler $cppoptions $v.pref.third_party_option $btarget -c -o "$obj_path" $cfiles $atarget ' res := os.exec(cmd) or { println('failed thirdparty object build cmd: $cmd') verror(err) diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index d52e0ce5a1..f11edd61b4 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -15,6 +15,10 @@ pub const ( builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash.wyhash', 'strings'] ) +pub const ( + external_module_dependencies_for_tool = {'vdoc': ['markdown']} +) + // vhash() returns the build string C.V_COMMIT_HASH . See cmd/tools/gen_vc.v . pub fn vhash() string { mut buf := [50]byte @@ -143,6 +147,12 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { println('launch_tool should_compile: $should_compile') } if should_compile { + emodules := external_module_dependencies_for_tool[tool_name] + for emodule in emodules { + util.check_module_is_installed(emodule, is_verbose) or { + panic(err) + } + } mut compilation_command := '"$vexe" ' compilation_command += '"$tool_source"' if is_verbose { @@ -256,3 +266,64 @@ pub fn join_env_vflags_and_os_args() []string { fn non_empty(arg []string) []string { return arg.filter(it != '') } + +pub fn check_module_is_installed(modulename string, is_verbose bool) ?bool { + mpath := os.join_path(os.home_dir(), '.vmodules', modulename) + mod_v_file := os.join_path(mpath, 'v.mod') + murl := 'https://github.com/vlang/$modulename' + if is_verbose { + eprintln('check_module_is_installed: mpath: $mpath') + eprintln('check_module_is_installed: mod_v_file: $mod_v_file') + eprintln('check_module_is_installed: murl: $murl') + } + if os.exists(mod_v_file) { + vexe := pref.vexe_path() + update_cmd := '"$vexe" update "${modulename}"' + if is_verbose { + eprintln('check_module_is_installed: updating with $update_cmd ...') + } + update_res := os.exec(update_cmd) or { + return error('can not start $update_cmd, error: $err') + } + if update_res.exit_code != 0 { + eprintln('Warning: `${modulename}` exists, but is not updated. +V will continue, since updates can fail due to temporary network problems, +and the existing module `${modulename}` may still work.') + if is_verbose { + eprintln('Details:') + eprintln(update_res.output) + } + eprintln('-'.repeat(50)) + } + return true + } + if is_verbose { + eprintln('check_module_is_installed: cloning from $murl ...') + } + cloning_res := os.exec('git clone $murl ~/.vmodules/$modulename') or { + return error('git is not installed, error: $err') + } + if cloning_res.exit_code != 0 { + return error('cloning failed, details: $cloning_res.output') + } + if !os.exists(mod_v_file) { + return error('even after cloning, $mod_v_file is still missing') + } + if is_verbose { + eprintln('check_module_is_installed: done') + } + return true +} + +pub fn ensure_modules_for_all_tools_are_installed(is_verbose bool) { + for tool_name, tool_modules in external_module_dependencies_for_tool { + if is_verbose { + eprintln('Installing modules for tool: $tool_name ...') + } + for emodule in tool_modules { + util.check_module_is_installed(emodule, is_verbose) or { + panic(err) + } + } + } +}