Skip to content

Commit

Permalink
Improvements to version detect for get-generic-sys-util
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsuresh committed Nov 1, 2024
1 parent f467f5c commit bc32946
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion automation/script/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3980,7 +3980,10 @@ def parse_version(self, i):

string = r['string']

version = r['match'].group(group_number)
if r['match'].lastindex and r['match'].lastindex >= group_number:
version = r['match'].group(group_number)
else:
return {'return':1, 'error': 'Invalid version detection group number. Version was not detected. Last index of match = {}. Given group number = {}'.format(r['match'].lastindex, group_number)}

which_env[env_key] = version
which_env['CM_DETECTED_VERSION'] = version # to be recorded in the cache meta
Expand Down
6 changes: 5 additions & 1 deletion script/get-generic-sys-util/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,12 @@
},
"md5sha1sum": {
"env": {
"CM_SYS_UTIL_NAME": "md5sha1sum"
"CM_SYS_UTIL_NAME": "md5sha1sum",
"CM_SYS_UTIL_VERSION_CMD": "md5sum --version",
"CM_SYS_UTIL_VERSION_RE": "\\b(\\d+\\.\\d+(?:\\.\\d+)?)\\b",
"CM_TMP_VERSION_DETECT_GROUP_NUMBER": 0
},
"new_env_keys": ["CM_MD5SHA1SUM_VERSION"],
"state": {
"md5sha1sum": {
"apt": "",
Expand Down
10 changes: 6 additions & 4 deletions script/get-generic-sys-util/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def preprocess(i):
if env.get('CM_GENERIC_SYS_UTIL_RUN_MODE', '') == "detect":
if env.get('CM_SYS_UTIL_VERSION_CMD', '') != '':
r = automation.run_native_script({'run_script_input':i['run_script_input'], 'env':env, 'script_name':'detect'})
if r['return'] > 0: #detection failed, do install via prehook_deps
if r['return'] != 0: #detection failed, do install via prehook_deps
print("detection failed, going for installation")
env['CM_GENERIC_SYS_UTIL_INSTALL_NEEDED'] = "yes"
return {'return': 0}
else: #detection is successful, no need to install
Expand Down Expand Up @@ -104,13 +105,14 @@ def detect_version(i):
env = i['env']
version_env_key = f"CM_{env['CM_SYS_UTIL_NAME'].upper()}_VERSION"
version_check_re = env.get('CM_SYS_UTIL_VERSION_RE', '')
group_number = env.get('CM_TMP_VERSION_DETECT_GROUP_NUMBER', 1)

if version_check_re == '' or not os.path.exists("tmp-ver.out"):
version = "undetected"

else:
r = i['automation'].parse_version({'match_text': version_check_re,
'group_number': 1,
'group_number': group_number,
'env_key': version_env_key,
'which_env': env})
if r['return'] >0: return r
Expand All @@ -128,8 +130,8 @@ def postprocess(i):
if env.get('CM_SYS_UTIL_VERSION_CMD', '') != '' and (env['CM_GENERIC_SYS_UTIL_RUN_MODE'] == "install" or env.get(version_env_key, '') == '') :
automation = i['automation']
r = automation.run_native_script({'run_script_input':i['run_script_input'], 'env':env, 'script_name':'detect'})
if r['return'] > 0:
return r
if r['return'] > 0 and str(env.get('CM_GENERIC_SYS_UTIL_IGNORE_VERSION_DETECTION_FAILURE', '')).lower() not in [ "1", "yes", "true" ]:
return {'return': 1, 'error': 'Version detection failed after installation. Please check the provided version command or use env.CM_GENERIC_SYS_UTIL_IGNORE_VERSION_DETECTION_FAILURE=yes to ignore the error.'}

r = detect_version(i)

Expand Down

0 comments on commit bc32946

Please sign in to comment.