mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(fex): the x86 runtime is built from files inside it so FEX finds its libraries (#2484)
* fix(fex): the x86 runtime is built from files inside it so FEX finds its libraries * fix(fex): the x86 runtime keeps the permissions of the directories it is built from * fix(fex): rebuilding the x86 runtime refreshes the Steam client links and removes read-only trees * fix(fex): rebuilding the x86 runtime removes old trees that contain unreadable directories * fix(fex): isolate generated rootfs files
This commit is contained in:
1 parent
ab7e17a09d
commit
a62933d023
2 files changed
+113
-14
No files matched your search
@@ -8,6 +8,7 @@ import os
|
||||
import re
|
||||
import runpy
|
||||
import shutil
|
||||
import stat
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -37,7 +38,9 @@ RUNTIMES = {SNIPER_APPID: ("sniper_platform_", "Steam Linux Runtime 3.0 (sniper"
|
||||
SLR4_APPID: ("steamrt4_platform_", "Steam Linux Runtime 4.0 (steamrt4")}
|
||||
MARKER = ".droiddeck-fex"
|
||||
LAYOUT = 1
|
||||
ROOTFS_LAYOUT = 2
|
||||
ROOTFS_LAYOUT = 4
|
||||
BLOB_DIRS = re.compile(r"^(?:\.ref|[0-9a-f]{2})$")
|
||||
ROOTFS_LIBRARY_DIRS = ("lib", "lib64")
|
||||
ARCH_DIRS = ("x86_64-linux-gnu", "i386-linux-gnu")
|
||||
INTERPRETERS = ("ld-linux-x86-64.so.2", "ld-linux.so.2")
|
||||
PROVIDED = frozenset((
|
||||
@@ -310,9 +313,38 @@ def provides_newer(base, provider):
|
||||
return True
|
||||
|
||||
|
||||
def mirror(source, provider, name, target):
|
||||
def clone(source, target, parents=()):
|
||||
real = os.path.realpath(source)
|
||||
if real in parents or not os.path.lexists(real):
|
||||
return
|
||||
if os.path.isdir(real):
|
||||
os.makedirs(target, exist_ok=True)
|
||||
for entry in os.listdir(real):
|
||||
clone(os.path.join(real, entry), os.path.join(target, entry), parents + (real,))
|
||||
shutil.copystat(real, target)
|
||||
return
|
||||
shutil.copy2(real, target)
|
||||
|
||||
|
||||
def remove_tree(path):
|
||||
if os.path.islink(path) or not os.path.isdir(path):
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.unlink(path)
|
||||
return
|
||||
os.chmod(path, os.lstat(path).st_mode | stat.S_IRWXU)
|
||||
for entry in os.listdir(path):
|
||||
remove_tree(os.path.join(path, entry))
|
||||
os.rmdir(path)
|
||||
|
||||
|
||||
def stays_in_libraries(root, target, link):
|
||||
resolved = os.path.normpath(os.path.join(os.path.relpath(target, root), link))
|
||||
return resolved.split(os.sep)[0] in ROOTFS_LIBRARY_DIRS
|
||||
|
||||
|
||||
def mirror(source, provider, name, target, root):
|
||||
if provider and name in PROVIDED and os.path.lexists(os.path.join(provider, name)):
|
||||
os.symlink(os.path.realpath(os.path.join(provider, name)), os.path.join(target, name))
|
||||
clone(os.path.join(provider, name), os.path.join(target, name))
|
||||
return
|
||||
path = os.path.join(source, name)
|
||||
link = os.readlink(path) if os.path.islink(path) else None
|
||||
@@ -322,10 +354,10 @@ def mirror(source, provider, name, target):
|
||||
link = os.path.join(os.path.dirname(link), name)
|
||||
if provider and GLIBC_BUILD.match(name):
|
||||
return
|
||||
if link and not link.startswith("/"):
|
||||
if link and not link.startswith("/") and stays_in_libraries(root, target, link):
|
||||
os.symlink(link, os.path.join(target, name))
|
||||
else:
|
||||
os.symlink(os.path.realpath(path), os.path.join(target, name))
|
||||
clone(path, os.path.join(target, name))
|
||||
|
||||
|
||||
def build_rootfs(base, provider):
|
||||
@@ -337,12 +369,12 @@ def build_rootfs(base, provider):
|
||||
return False
|
||||
for entry in os.listdir(STATE):
|
||||
if entry.startswith("rootfs."):
|
||||
shutil.rmtree(os.path.join(STATE, entry), ignore_errors=True)
|
||||
remove_tree(os.path.join(STATE, entry))
|
||||
tmp = "%s.%d.tmp" % (rootfs, os.getpid())
|
||||
os.makedirs(tmp)
|
||||
for entry in os.listdir(base_files):
|
||||
if entry not in ("lib", "lib64", "usr", MARKER):
|
||||
os.symlink(os.path.realpath(os.path.join(base_files, entry)), os.path.join(tmp, entry))
|
||||
if entry not in ("lib", "lib64", "usr", MARKER) and not BLOB_DIRS.match(entry):
|
||||
clone(os.path.join(base_files, entry), os.path.join(tmp, entry))
|
||||
os.symlink(".", os.path.join(tmp, "usr"))
|
||||
for top in ("lib", "lib64"):
|
||||
source = os.path.join(base_files, top)
|
||||
@@ -353,15 +385,15 @@ def build_rootfs(base, provider):
|
||||
provided = os.path.join(provider_files, top, entry)
|
||||
os.makedirs(os.path.join(tmp, top, entry))
|
||||
for name in set(os.listdir(path)) | {name for name in PROVIDED if os.path.lexists(os.path.join(provided, name))}:
|
||||
mirror(path, provided, name, os.path.join(tmp, top, entry))
|
||||
mirror(path, provided, name, os.path.join(tmp, top, entry), tmp)
|
||||
else:
|
||||
mirror(source, None, entry, os.path.join(tmp, top))
|
||||
mirror(source, None, entry, os.path.join(tmp, top), tmp)
|
||||
write_if_changed(os.path.join(tmp, MARKER), stamp)
|
||||
old = "%s.%d.old" % (rootfs, os.getpid())
|
||||
if os.path.lexists(rootfs):
|
||||
os.rename(rootfs, old)
|
||||
os.rename(tmp, rootfs)
|
||||
shutil.rmtree(old, ignore_errors=True)
|
||||
remove_tree(old)
|
||||
return True
|
||||
|
||||
|
||||
@@ -441,7 +473,7 @@ def link_guest_sdk(root):
|
||||
continue
|
||||
os.makedirs(os.path.dirname(link), exist_ok=True)
|
||||
if os.path.lexists(link):
|
||||
os.unlink(link)
|
||||
remove_tree(link)
|
||||
os.symlink(directory, link)
|
||||
|
||||
|
||||
@@ -513,8 +545,6 @@ def prepare(app=SNIPER_APPID):
|
||||
root = os.path.join(platform, "files")
|
||||
if materialize(platform):
|
||||
say("prepared %s as the x86 runtime" % os.path.basename(platform))
|
||||
install_preloads(root)
|
||||
install_fonts(root)
|
||||
provider = None
|
||||
if app == SNIPER_APPID:
|
||||
provider = graphics_platform()
|
||||
@@ -531,6 +561,8 @@ def prepare(app=SNIPER_APPID):
|
||||
say("built the x86 runtime from %s with the C and C++ libraries of %s"
|
||||
% (os.path.basename(platform), os.path.basename(provider)))
|
||||
root = os.path.join(STATE, "rootfs")
|
||||
install_preloads(root)
|
||||
install_fonts(root)
|
||||
with contextlib.suppress(OSError):
|
||||
link_guest_sdk(root)
|
||||
write_config(fex, root)
|
||||
|
||||
Reference in new issue
Block a user