Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion cmd/v/macos_v3_args.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ fn macos_v3_non_compilation_command(command string) bool {
'interpret', 'get', 'translate']
}

// is_macos_v3_compiler_bootstrap reports whether `normalized_path` targets the
// `vlib/v3/v3.v` compiler bootstrap, which must build with the compatibility
// compiler rather than the embedded V3 driver. It matches the repo-relative path
// and any path ending in it, and also resolves a bare `v3.v` (for example when
// invoked from inside `vlib/v3`) through its real path, so the bootstrap is
// recognized regardless of the working directory. Both dispatch gates rely on
// it, so keep the detection in one place to stop them drifting.
@[markused]
fn is_macos_v3_compiler_bootstrap(normalized_path string) bool {
if normalized_path == 'vlib/v3/v3.v' || normalized_path.ends_with('/vlib/v3/v3.v') {
return true
}
// Only a file literally named `v3.v` can be the bootstrap; skip the real-path
// resolution (a filesystem lookup) for every other compilation target.
if os.base(normalized_path) != 'v3.v' {
return false
}
real_path := os.real_path(normalized_path).replace('\\', '/').trim_right('/')
return real_path == 'vlib/v3/v3.v' || real_path.ends_with('/vlib/v3/v3.v')
}

// macos_v3_force_requested reports whether `-new-compiler` should hand this
// invocation to the embedded V3 compiler. It gates on `-old-compiler`
// precedence, options/modes V3 cannot honor yet, and whether the command is an
Expand All @@ -44,7 +65,7 @@ fn macos_v3_force_requested(command string, prefs &pref.Preferences) bool {
normalized_path := prefs.path.replace('\\', '/').trim_right('/')
if normalized_path == 'cmd/v' || normalized_path.starts_with('cmd/v/')
|| normalized_path.contains('/cmd/v/') || normalized_path.ends_with('/cmd/v')
|| normalized_path == 'vlib/v3/v3.v' || normalized_path.ends_with('/vlib/v3/v3.v') {
|| is_macos_v3_compiler_bootstrap(normalized_path) {
return false
}
return command in ['run', 'build'] || prefs.is_script || os.is_dir(prefs.path)
Expand Down
2 changes: 1 addition & 1 deletion cmd/v/macos_v3_darwin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn is_macos_v3_relevant_command(command string, prefs &pref.Preferences) bool {
// modes use V3 by default.
if normalized_path == 'cmd/v' || normalized_path.starts_with('cmd/v/')
|| normalized_path.contains('/cmd/v/') || normalized_path.ends_with('/cmd/v')
|| normalized_path == 'vlib/v3/v3.v' || normalized_path.ends_with('/vlib/v3/v3.v')
|| is_macos_v3_compiler_bootstrap(normalized_path)
|| is_macos_v3_internal_tool_bootstrap(normalized_path, os.getenv('VCHILD') == 'true') {
return false
}
Expand Down
41 changes: 41 additions & 0 deletions cmd/v/macos_v3_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,47 @@ fn test_macos_v3_relevant_command_selects_user_compilation_and_tests() {
}
}

fn test_macos_v3_compiler_bootstrap_is_detected_from_any_cwd() {
// Repo-relative and absolute spellings are recognized directly.
assert is_macos_v3_compiler_bootstrap('vlib/v3/v3.v')
assert is_macos_v3_compiler_bootstrap('/home/user/v/vlib/v3/v3.v')
// Non-bootstrap targets stay on the V3 path.
assert !is_macos_v3_compiler_bootstrap('main.v')
assert !is_macos_v3_compiler_bootstrap('cmd/v')
assert !is_macos_v3_compiler_bootstrap('some/other/place/v3.v')

// A bare `v3.v` invoked from inside vlib/v3 must resolve to the bootstrap so
// it builds with the compatibility compiler instead of the embedded V3 driver.
// Use an isolated <tmp>/vlib/v3/v3.v so this exercises the real-path
// resolution unconditionally, independent of where this test file lives.
root := os.join_path(os.real_path(os.vtmp_dir()), 'macos_v3_bootstrap_${os.getpid()}')
v3_dir := os.join_path(root, 'vlib', 'v3')
other_dir := os.join_path(root, 'elsewhere')
os.rmdir_all(root) or {}
os.mkdir_all(v3_dir) or { panic(err) }
os.mkdir_all(other_dir) or { panic(err) }
defer {
os.rmdir_all(root) or {}
}
os.write_file(os.join_path(v3_dir, 'v3.v'), 'module main\n') or { panic(err) }
os.write_file(os.join_path(other_dir, 'v3.v'), 'module main\n') or { panic(err) }

saved := os.getwd()
defer {
os.chdir(saved) or {}
}
os.chdir(v3_dir) or { panic(err) }
bare := is_macos_v3_compiler_bootstrap('v3.v')
dotted := is_macos_v3_compiler_bootstrap('./v3.v')
// A bare `v3.v` that is not under vlib/v3 must stay on the V3 path.
os.chdir(other_dir) or { panic(err) }
non_bootstrap := is_macos_v3_compiler_bootstrap('v3.v')
os.chdir(saved) or {}
assert bare
assert dotted
assert !non_bootstrap
}

fn test_macos_v3_dispatch_allows_the_implicit_gc_default() {
$if macos {
implicit_gc, _ := pref.parse_args_and_show_errors([], ['', 'main.v'], false)
Expand Down
Loading
Loading