@@ -24,6 +24,8 @@ const macos_v3_caller_vexe_env = 'V_MACOS_V3_CALLER_VEXE'
2424const macos_v3_caller_vexe_present_env = 'V_MACOS_V3_CALLER_VEXE_PRESENT'
2525const macos_v3_caller_vchild_env = 'V_MACOS_V3_CALLER_VCHILD'
2626const macos_v3_caller_vchild_present_env = 'V_MACOS_V3_CALLER_VCHILD_PRESENT'
27+ const macos_v3_caller_no_fallback_env = 'V_MACOS_V3_CALLER_NO_FALLBACK'
28+ const macos_v3_caller_no_fallback_present_env = 'V_MACOS_V3_CALLER_NO_FALLBACK_PRESENT'
2729const macos_v3_embedded_env = 'V_MACOS_V3_EMBEDDED'
2830const macos_v3_retry_env = 'V_MACOS_V3_RETRY'
2931const macos_v3_no_fallback_env = 'V_MACOS_V3_NO_FALLBACK'
@@ -143,9 +145,8 @@ fn is_macos_v3_relevant_command(command string, prefs &pref.Preferences) bool {
143145 normalized_path := prefs.path.replace ('\\ ' , '/' ).trim_right ('/' )
144146 // cmd/v remains the command dispatcher. All other user compilation and test
145147 // modes use V3 by default.
146- if normalized_path == 'cmd/v' || normalized_path.starts_with ('cmd/v/' )
147- || normalized_path.contains ('/cmd/v/' ) || normalized_path.ends_with ('/cmd/v' )
148- || normalized_path == 'vlib/v3/v3.v' || normalized_path.ends_with ('/vlib/v3/v3.v' )
148+ if is_macos_v3_vroot_path (normalized_path, 'cmd/v' , true )
149+ || is_macos_v3_vroot_path (normalized_path, 'vlib/v3/v3.v' , false )
149150 || is_macos_v3_v1_compiler_source (normalized_path)
150151 || is_macos_v3_internal_tool_bootstrap (normalized_path, os.getenv ('VCHILD' ) == 'true' ) {
151152 return false
@@ -161,26 +162,35 @@ fn is_macos_v3_relevant_command(command string, prefs &pref.Preferences) bool {
161162}
162163
163164fn is_macos_v3_v1_compiler_source (normalized_path string ) bool {
164- is_compiler_source := normalized_path. starts_with ('vlib/v/ ' )
165- || normalized_path. contains ( '/vlib/v /' )
166- if ! is_compiler_source {
165+ compiler_dir := macos_v3_vroot_path_value ('vlib/v' )
166+ path := os. real_path ( normalized_path). replace ( ' \\ ' , '/' ). trim_right ( ' /' )
167+ if path != compiler_dir && ! path. starts_with (compiler_dir + '/' ) {
167168 return false
168169 }
169- if normalized_path.starts_with ('vlib/v3/' ) || normalized_path.contains ('/vlib/v3/' ) {
170+ relative := path[compiler_dir.len..].trim_left ('/' )
171+ if relative == 'v3' || relative.starts_with ('v3/' ) {
170172 return false
171173 }
172174 // The established compiler's implementation modules still require V1 to compile.
173175 // Keep the language-level regression suites on V3: their files are ordinary user
174176 // programs even though they live below the compiler tree.
175- return ! normalized_path.starts_with ('vlib/v/tests/' )
176- && ! normalized_path.contains ('/vlib/v/tests/' )
177- && ! normalized_path.starts_with ('vlib/v/slow_tests/' )
178- && ! normalized_path.contains ('/vlib/v/slow_tests/' )
177+ return relative != 'tests' && ! relative.starts_with ('tests/' ) && relative != 'slow_tests'
178+ && ! relative.starts_with ('slow_tests/' )
179+ }
180+
181+ fn macos_v3_vroot_path_value (relative string ) string {
182+ vroot := os.real_path (os.dir (pref.vexe_path ()))
183+ return os.real_path (os.join_path (vroot, relative)).replace ('\\ ' , '/' ).trim_right ('/' )
184+ }
185+
186+ fn is_macos_v3_vroot_path (normalized_path string , relative string , include_children bool ) bool {
187+ path := os.real_path (normalized_path).replace ('\\ ' , '/' ).trim_right ('/' )
188+ target := macos_v3_vroot_path_value (relative)
189+ return path == target || (include_children && path.starts_with (target + '/' ))
179190}
180191
181192fn is_macos_v3_internal_tool_bootstrap (normalized_path string , is_vchild bool ) bool {
182- return is_vchild
183- && (normalized_path.starts_with ('cmd/tools/' ) || normalized_path.contains ('/cmd/tools/' ))
193+ return is_vchild && is_macos_v3_vroot_path (normalized_path, 'cmd/tools' , true )
184194}
185195
186196fn launch_macos_v3_compiler (prefs & pref.Preferences, raw_args []string ) ? MacosV3 CErrorReport {
@@ -420,6 +430,9 @@ fn macos_v3_child_environment(vexe string, fallback_file string, caller_environm
420430 macos_v3_ caller_vexe_env, macos_v3_ caller_vexe_present_env)
421431 preserve_macos_v3_caller_environment_value (mut environment, caller_environment, 'VCHILD' ,
422432 macos_v3_ caller_vchild_env, macos_v3_ caller_vchild_present_env)
433+ preserve_macos_v3_caller_environment_value (mut environment, caller_environment,
434+ macos_v3_ no_fallback_env, macos_v3_ caller_no_fallback_env,
435+ macos_v3_ caller_no_fallback_present_env)
423436 for private_name in ['V_MACOS_V3_FALLBACK_FILE' , 'V_MACOS_V3_C_ERROR_DIR' , 'V_MACOS_V3_RETRY' ] {
424437 environment.delete (private_name)
425438 }
@@ -463,11 +476,18 @@ fn macos_v3_original_caller_environment(dispatch_environment map[string]string)
463476 restore_macos_v3_caller_environment_value (mut caller_environment, dispatch_environment,
464477 'VCHILD' , macos_v3_ caller_vchild_env, macos_v3_ caller_vchild_present_env)
465478 }
479+ no_fallback_present := dispatch_environment[macos_v3_ caller_no_fallback_present_env] or { '' }
480+ if no_fallback_present in ['0' , '1' ] {
481+ restore_macos_v3_caller_environment_value (mut caller_environment, dispatch_environment,
482+ macos_v3_ no_fallback_env, macos_v3_ caller_no_fallback_env,
483+ macos_v3_ caller_no_fallback_present_env)
484+ }
466485 for private_name in [macos_v3_ fallback_file_env, macos_v3_ c_error_dir_env, macos_v3_ vhash_env,
467486 macos_v3_ vcurrent_hash_env, macos_v3_ embedded_env, macos_v3_ retry_env,
468487 'V3_CRUN_BUILD_IDENTITY' , 'V3_INTERNAL_RESTART' , macos_v3_ caller_vexe_env,
469488 macos_v3_ caller_vexe_present_env, macos_v3_ caller_vchild_env,
470- macos_v3_ caller_vchild_present_env] {
489+ macos_v3_ caller_vchild_present_env, macos_v3_ caller_no_fallback_env,
490+ macos_v3_ caller_no_fallback_present_env] {
471491 caller_environment.delete (private_name)
472492 }
473493 return caller_environment
0 commit comments