@@ -8,16 +8,47 @@ def preprocess(i):
88 if os_info ['platform' ] == 'windows' :
99 return {'return' : 1 , 'error' : 'Windows is not supported in this script yet' }
1010
11+ env = i ['env' ]
12+
13+ # Determine install prefix:
14+ # 1. If explicitly set via input, use that
15+ # 2. If sudo is available, default to "/" (installs to /opt/rocm)
16+ # 3. Otherwise, use MLC cache directory (no root needed)
17+ install_prefix = env .get ('MLC_ROCM_INSTALL_PREFIX' , '' ).strip ()
18+ if install_prefix == '' :
19+ if env .get ('MLC_SUDO_USER' , '' ) == 'yes' :
20+ install_prefix = '/'
21+ else :
22+ install_prefix = os .getcwd ()
23+
24+ env ['MLC_ROCM_INSTALL_PREFIX' ] = install_prefix
25+
1126 return {'return' : 0 }
1227
1328
1429def postprocess (i ):
1530
1631 env = i ['env' ]
1732
18- # Check standard and versioned ROCm install paths
33+ install_prefix = env .get ('MLC_ROCM_INSTALL_PREFIX' , '/' )
34+
35+ # Check install prefix paths first, then standard /opt paths
36+ search_dirs = []
37+
38+ # Custom prefix: ROCm installs to <prefix>/opt/rocm-<version>
39+ prefix_opt = os .path .join (install_prefix , 'opt' )
40+ if os .path .isdir (prefix_opt ):
41+ for p in [os .path .join (prefix_opt , 'rocm' , 'bin' )] + sorted (glob .glob (os .path .join (prefix_opt , 'rocm-*' , 'bin' )), reverse = True ):
42+ if os .path .isdir (p ):
43+ search_dirs .append (p )
44+
45+ # Standard paths as fallback
46+ for p in ["/opt/rocm/bin" ] + sorted (glob .glob ("/opt/rocm-*/bin" ), reverse = True ):
47+ if os .path .isdir (p ) and p not in search_dirs :
48+ search_dirs .append (p )
49+
1950 installed_path = ""
20- for candidate in [ "/opt/rocm/bin" ] + sorted ( glob . glob ( "/opt/rocm-*/bin" ), reverse = True ) :
51+ for candidate in search_dirs :
2152 if os .path .isfile (os .path .join (candidate , "rocminfo" )):
2253 installed_path = candidate
2354 break
0 commit comments