@@ -5565,29 +5565,54 @@ def run_postprocess(customize_code, customize_common_input, recursion_spaces,
5565
5565
5566
5566
5567
5567
def get_script_name (env , path , script_name = 'run' ):
5568
- """
5569
- Internal: find the most appropriate run script name for the detected OS
5570
- """
5568
+ # Extract environment variables safely, defaulting to empty strings if
5569
+ # missing
5570
+ os_flavor = env .get ('MLC_HOST_OS_FLAVOR' , '' )
5571
+ os_flavor_like = env .get ('MLC_HOST_OS_FLAVOR_LIKE' , '' )
5572
+ os_type = env .get ('MLC_HOST_OS_TYPE' , '' )
5573
+ # Only use version if flavor exists
5574
+ os_version = env .get ('MLC_HOST_OS_VERSION' , '' ) if os_flavor else ''
5575
+ platform_flavor = env .get ('MLC_HOST_PLATFORM_FLAVOR' , '' )
5576
+
5577
+ # Get a list of all files in the directory
5578
+ try :
5579
+ available_files = set (os .listdir (path ))
5580
+ except FileNotFoundError :
5581
+ # Default if directory doesn't exist
5582
+ return os .path .join (path , f"{ script_name } .sh" )
5583
+
5584
+ # Check if any script with a "script_name-" prefix exists
5585
+ has_prefixed_scripts = any (f .startswith (
5586
+ f"{ script_name } -" ) for f in available_files )
5587
+
5588
+ # Helper function to construct script filenames dynamically
5589
+ def script_filename (* parts ):
5590
+ # Remove empty values to avoid extra '-'
5591
+ suffix = "-" .join (filter (None , parts ))
5592
+ return f"{ script_name } -{ suffix } .sh" if suffix else f"{ script_name } .sh"
5593
+
5594
+ # Define file search order based on priority
5595
+ candidates = [
5596
+ script_filename (os_flavor , os_version , platform_flavor ),
5597
+ script_filename (os_flavor , os_version ),
5598
+ script_filename (os_flavor , platform_flavor ),
5599
+ script_filename (os_flavor ),
5600
+ script_filename (os_flavor_like , platform_flavor ),
5601
+ script_filename (os_flavor_like ),
5602
+ script_filename (os_type , platform_flavor ),
5603
+ script_filename (os_type ),
5604
+ script_filename (platform_flavor ),
5605
+ ]
5606
+
5607
+ # If prefixed scripts exist, check for the first matching candidate
5608
+ if has_prefixed_scripts :
5609
+ for candidate in candidates :
5610
+ if candidate in available_files :
5611
+ return os .path .join (path , candidate )
5612
+
5613
+ # Fallback to the default script
5614
+ return os .path .join (path , f"{ script_name } .sh" )
5571
5615
5572
- from os .path import exists
5573
-
5574
- tmp_suff1 = env .get ('MLC_HOST_OS_FLAVOR' , '' )
5575
- tmp_suff2 = env .get ('MLC_HOST_OS_VERSION' , '' )
5576
- tmp_suff3 = env .get ('MLC_HOST_PLATFORM_FLAVOR' , '' )
5577
-
5578
- if exists (os .path .join (path , script_name + '-' + tmp_suff1 +
5579
- '-' + tmp_suff2 + '-' + tmp_suff3 + '.sh' )):
5580
- return script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '-' + tmp_suff3 + '.sh'
5581
- elif exists (os .path .join (path , script_name + '-' + tmp_suff1 + '-' + tmp_suff3 + '.sh' )):
5582
- return script_name + '-' + tmp_suff1 + '-' + tmp_suff3 + '.sh'
5583
- elif exists (os .path .join (path , script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '.sh' )):
5584
- return script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '.sh'
5585
- elif exists (os .path .join (path , script_name + '-' + tmp_suff1 + '.sh' )):
5586
- return script_name + '-' + tmp_suff1 + '.sh'
5587
- elif exists (os .path .join (path , script_name + '-' + tmp_suff3 + '.sh' )):
5588
- return script_name + '-' + tmp_suff3 + '.sh'
5589
- else :
5590
- return script_name + '.sh'
5591
5616
5592
5617
##############################################################################
5593
5618
0 commit comments