Skip to content

Commit

Permalink
Merge pull request #189 from kloptops/main
Browse files Browse the repository at this point in the history
Added glibc detection, fixed a bug with pm_signature, moved key presses from info to debug.
  • Loading branch information
kloptops authored Nov 22, 2024
2 parents ac01746 + 1e97725 commit fcc882c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
6 changes: 6 additions & 0 deletions PortMaster/pylibs/harbourmaster/harbour.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ def match_requirements(self, port_info):

runtime = port_info.get('attr', {}).get('runtime', None)

min_glibc = port_info.get('attr', {}).get('min_glibc', "")

if min_glibc not in ("", None) and isinstance(min_glibc, str):
if version_parse(min_glibc.strip()) < version_parse(self.device['glibc']):
return False

if runtime is not None:
if not runtime.endswith('.squashfs'):
runtime += '.squashfs'
Expand Down
74 changes: 74 additions & 0 deletions PortMaster/pylibs/harbourmaster/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"rk3399": {"capabilities": ["armhf", "aarch64"], "primary_arch": "aarch64"},
"rk3566": {"capabilities": ["armhf", "aarch64"], "primary_arch": "aarch64"},
"rk3588": {"capabilities": ["armhf", "aarch64"], "primary_arch": "aarch64"},
"h700-knulli": {"capabilities": ["aarch64"], "primary_arch": "aarch64"},
"h700-batocera": {"capabilities": ["aarch64"], "primary_arch": "aarch64"},
"h700-muos": {"capabilities": ["armhf", "aarch64"], "primary_arch": "aarch64"},
"h700": {"capabilities": ["armhf", "aarch64"], "primary_arch": "aarch64"},
Expand All @@ -185,6 +186,17 @@
}


GLIBC_INFO = {
"arkos-*": "3.30",
"trimui-*": "3.33",
"knulli-*": "3.38",
"muos-*": "3.38",
"rocknix-*": "3.40",

"default": "3.30",
}


def cpu_info_v2(info):
if Path('/lib/ld-linux-armhf.so.3').exists():
info["capabilities"].append("armhf")
Expand All @@ -211,6 +223,51 @@ def cpu_info_v2(info):
info['primary_arch'] = "aarch64"


_GLIBC_VER=None
def get_glibc_version():
global _GLIBC_VER

lib_paths = [
# Most likely
'/lib/',
'/lib64/',
'/lib/aarch64-linux-gnu/',
'/lib32/',
'/lib/arm-linux-gnueabihf/',
# Least likely
'/usr/lib/',
'/usr/lib64/',
'/usr/lib32/',
]

if _GLIBC_VER is None:
for lib_path in lib_paths:
libc_path = Path(lib_path) / 'libc.so.6'

if not libc_path.is_file():
continue

try:
result = subprocess.run(
[str(libc_path), "--version"],
capture_output=True, text=True, check=True)

# The first line contains the glibc version
_GLIBC_VER = result.stdout.splitlines()[0].strip().split(' ')[-1].rstrip('.')

except Exception as e:
logger.error(f"Error retrieving glibc version: {e}")
# Failsafe
_GLIBC_VER = GLIBC_INFO['default']

break

else:
_GLIBC_VER = GLIBC_INFO['default']

return _GLIBC_VER


def safe_cat(file_name):
if isinstance(file_name, str):
file_name = pathlib.Path(file_name)
Expand Down Expand Up @@ -496,6 +553,23 @@ def expand_info(info, override_resolution=None, override_ram=None, use_old_cpu_i
if override_ram is not None:
info['ram'] = override_ram

if use_old_cpu_info:
_name, _device = info['name'].lower(), info['device'].lower()
if f"{_name}-{_device}" in GLIBC_INFO:
_merge_info(info, GLIBC_INFO[f"{_name}-{_device}"])

elif f"{_name}-*" in GLIBC_INFO:
_merge_info(info, GLIBC_INFO[f"{_name}-*"])

elif f"*-{_device}" in GLIBC_INFO:
_merge_info(info, GLIBC_INFO[f"*-{_device}"])

else:
_merge_info(info, GLIBC_INFO['default'])

else:
info['glibc'] = get_glibc_version()

display_gcd = math.gcd(info['resolution'][0], info['resolution'][1])
display_ratio = f"{info['resolution'][0] // display_gcd}:{info['resolution'][1] // display_gcd}"

Expand Down
1 change: 1 addition & 0 deletions PortMaster/pylibs/harbourmaster/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'rtr': False,
'exp': False,
'runtime': None,
'min_glibc': "",
'reqs': [],
'arch': [],
}
Expand Down
6 changes: 6 additions & 0 deletions PortMaster/pylibs/harbourmaster/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def load_pm_signature(file_name):
if 'PORTMASTER:' not in line:
continue

if ',' not in line.split(':', 1)[1]:
continue

return [
item.strip()
for item in line.split(':', 1)[1].strip().split(',', 1)]
Expand All @@ -207,6 +210,7 @@ def load_pm_signature(file_name):

return None


def add_pm_signature(file_name, info):
## Adds the portmaster signature to a bash script.

Expand Down Expand Up @@ -471,6 +475,7 @@ def get_dict_list(base_dict, key):

return result


def remove_dict_list(base_dict, key, value):
if key not in base_dict:
return
Expand All @@ -491,6 +496,7 @@ def remove_dict_list(base_dict, key, value):
elif len(result) == 1:
base_dict[key] = result[0]


def get_path_fs(path):
"""
Get the fs type of the specified path.
Expand Down
16 changes: 8 additions & 8 deletions PortMaster/pylibs/pySDL2gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ def handle_events(self):

key = self.KEY_MAP.get(event.key.keysym.sym, None)
if key is not None:
logger.info(f'PRESSED {key}')
logger.debug(f'PRESSED {key}')
self.buttons[key] = True

if key in self.repeat:
Expand All @@ -1507,7 +1507,7 @@ def handle_events(self):
elif event.type == sdl2.SDL_KEYUP:
key = self.KEY_MAP.get(event.key.keysym.sym, None)
if key is not None:
logger.info(f'RELEASED {key}')
logger.debug(f'RELEASED {key}')
self.buttons[key] = False

if key in self.repeat:
Expand All @@ -1516,7 +1516,7 @@ def handle_events(self):
elif event.type == sdl2.SDL_CONTROLLERBUTTONDOWN:
key = self.BUTTON_MAP.get(event.cbutton.button, None)
if key is not None:
logger.info(f'PRESSED {key}')
logger.debug(f'PRESSED {key}')
self.buttons[key] = True

if key in self.repeat:
Expand All @@ -1525,7 +1525,7 @@ def handle_events(self):
elif event.type == sdl2.SDL_CONTROLLERBUTTONUP:
key = self.BUTTON_MAP.get(event.cbutton.button, None)
if key is not None:
logger.info(f'RELEASED {key}')
logger.debug(f'RELEASED {key}')
self.buttons[key] = False

if key in self.repeat:
Expand All @@ -1542,27 +1542,27 @@ def handle_events(self):

if axis_key is not None:
if last_axis_key is None:
logger.info(f"PRESSED {axis_key}")
logger.debug(f"PRESSED {axis_key}")
self.buttons[axis_key] = True

if axis_key in self.repeat:
self.repeat[axis_key] = ticks_now + self.REPEAT_DELAY

elif last_axis_key != axis_key:
logger.info(f"RELEASED {last_axis_key}")
logger.debug(f"RELEASED {last_axis_key}")
self.buttons[last_axis_key] = False
if last_axis_key in self.repeat:
self.repeat[last_axis_key] = None

logger.info(f"PRESSED {axis_key}")
logger.debug(f"PRESSED {axis_key}")
self.buttons[axis_key] = True

if axis_key in self.repeat:
self.repeat[axis_key] = ticks_now + self.REPEAT_DELAY

else:
if last_axis_key is not None:
logger.info(f"RELEASED {last_axis_key}")
logger.debug(f"RELEASED {last_axis_key}")
self.buttons[last_axis_key] = False
if last_axis_key in self.repeat:
self.repeat[last_axis_key] = None
Expand Down

0 comments on commit fcc882c

Please sign in to comment.