Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
beh-10257 committed Oct 22, 2024
2 parents b8b226e + 59c0499 commit 212d34d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
1 change: 1 addition & 0 deletions tests/test_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ curl -LJO "https://repo.steampowered.com/steamrt3/images/0.20240916.101795/Steam
tar xaf SteamLinuxRuntime_sniper.tar.xz
mv SteamLinuxRuntime_sniper/* "$HOME/.local/share/umu"
mv "$HOME/.local/share/umu/_v2-entry-point" "$HOME/.local/share/umu/umu"
echo "$@" > "$HOME/.local/share/umu/umu-shim" && chmod 700 "$HOME/.local/share/umu/umu-shim"

# Perform a preflight step, where we ensure everything is in order and create '$HOME/.local/share/umu/var'
# Afterwards, run a 2nd time to perform the runtime update and ensure '$HOME/.local/share/umu/var' is removed
Expand Down
6 changes: 5 additions & 1 deletion umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from subprocess import Popen
from typing import Any

from filelock import FileLock
from Xlib import X, Xatom, display
from Xlib.error import DisplayConnectionError
from Xlib.protocol.request import GetProperty
Expand Down Expand Up @@ -817,8 +818,11 @@ def main() -> int: # noqa: D103
opts = args[1] # Reference the executable options
check_env(env, thread_pool)

UMU_LOCAL.mkdir(parents=True, exist_ok=True)

# Prepare the prefix
setup_pfx(env["WINEPREFIX"])
with FileLock(f"{UMU_LOCAL}/pfx.lock"):
setup_pfx(env["WINEPREFIX"])

# Configure the environment
set_env(env, args)
Expand Down
46 changes: 31 additions & 15 deletions umu/umu_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,48 @@
has_data_filter: bool = False


def create_shim(file_path=None):
def create_shim(file_path: Path | None = None):
"""Create a shell script shim at the specified file path.
This script sets the DISPLAY environment variable if certain conditions
are met and executes the passed command.
Args:
file_path (Path, optional): The path where the shim script will be created.
Defaults to UMU_LOCAL.joinpath("umu-shim").
"""
# Set the default path if none is provided
if file_path is None:
file_path = UMU_LOCAL.joinpath("umu-shim")
# Define the content of the shell script
script_content = """#!/bin/sh
if [ "${XDG_CURRENT_DESKTOP}" = "gamescope" ] || [ "${XDG_SESSION_DESKTOP}" = "gamescope" ]; then
# Check if STEAM_MULTIPLE_XWAYLANDS is set to 1
if [ "${STEAM_MULTIPLE_XWAYLANDS}" = "1" ]; then
# Check if DISPLAY is set, if not, set it to ":1"
if [ -z "${DISPLAY}" ]; then
export DISPLAY=":1"
if [ "${XDG_CURRENT_DESKTOP}" = "gamescope" ] || [ "${XDG_SESSION_DESKTOP}" = "gamescope" ]; then
# Check if STEAM_MULTIPLE_XWAYLANDS is set to 1
if [ "${STEAM_MULTIPLE_XWAYLANDS}" = "1" ]; then
# Check if DISPLAY is set, if not, set it to ":1"
if [ -z "${DISPLAY}" ]; then
export DISPLAY=":1"
fi
fi
fi
fi
# Execute the passed command
"$@"
"""
# Execute the passed command
"$@"
# Capture the exit status
status=$?
echo "Command exited with status: $status"
exit $status
"""

# Write the script content to the specified file path
with open(file_path, 'w') as file:
with file_path.open('w') as file:
file.write(script_content)

# Make the script executable
os.chmod(file_path, 0o755)
file_path.chmod(0o700)

def _install_umu(
json: dict[str, Any],
Expand Down Expand Up @@ -397,8 +412,9 @@ def _update_umu(
rmtree(str(runtime))
log.debug("Released file lock '%s'", lock.lock_file)

if not UMU_LOCAL.joinpath("umu-shim").exists():
create_shim()
# Restore shim
if not local.joinpath("umu-shim").exists():
create_shim()

log.console("steamrt is up to date")

Expand Down
12 changes: 9 additions & 3 deletions umu/umu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,10 @@ def test_build_command(self):
# Mock the proton file
Path(self.test_file, "proton").touch()

# Mock the shim file
shim_path = Path(self.test_local_share, "umu-shim")
shim_path.touch()

with (
patch("sys.argv", ["", self.test_exe]),
ThreadPoolExecutor() as thread_pool,
Expand Down Expand Up @@ -1350,10 +1354,10 @@ def test_build_command(self):
)
self.assertEqual(
len(test_command),
7,
f"Expected 7 elements, received {len(test_command)}",
8,
f"Expected 8 elements, received {len(test_command)}",
)
entry_point, opt1, verb, opt2, proton, verb2, exe = [*test_command]
entry_point, opt1, verb, opt2, shim, proton, verb2, exe = [*test_command]
# The entry point dest could change. Just check if there's a value
self.assertTrue(entry_point, "Expected an entry point")
self.assertIsInstance(
Expand All @@ -1362,6 +1366,8 @@ def test_build_command(self):
self.assertEqual(opt1, "--verb", "Expected --verb")
self.assertEqual(verb, self.test_verb, "Expected a verb")
self.assertEqual(opt2, "--", "Expected --")
self.assertIsInstance(shim, os.PathLike, "Expected shim to be PathLike")
self.assertEqual(shim, shim_path, "Expected the shim file")
self.assertIsInstance(proton, os.PathLike, "Expected proton to be PathLike")
self.assertEqual(
proton,
Expand Down
8 changes: 7 additions & 1 deletion umu/umu_test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ def test_build_command_toml(self):
Path(self.test_file + "/proton").touch()
Path(toml_path).touch()

# Mock the shim file
shim_path = Path(self.test_local_share, "umu-shim")
shim_path.touch()

with Path(toml_path).open(mode="w", encoding="utf-8") as file:
file.write(toml_str)

Expand Down Expand Up @@ -380,7 +384,7 @@ def test_build_command_toml(self):
test_command = umu_run.build_command(self.env, self.test_local_share)

# Verify contents of the command
entry_point, opt1, verb, opt2, proton, verb2, exe = [*test_command]
entry_point, opt1, verb, opt2, shim, proton, verb2, exe = [*test_command]
# The entry point dest could change. Just check if there's a value
self.assertTrue(entry_point, "Expected an entry point")
self.assertIsInstance(
Expand All @@ -389,6 +393,8 @@ def test_build_command_toml(self):
self.assertEqual(opt1, "--verb", "Expected --verb")
self.assertEqual(verb, self.test_verb, "Expected a verb")
self.assertEqual(opt2, "--", "Expected --")
self.assertIsInstance(shim, os.PathLike, "Expected shim to be PathLike")
self.assertEqual(shim, shim_path, "Expected the shim file")
self.assertIsInstance(proton, os.PathLike, "Expected proton to be PathLike")
self.assertEqual(
proton,
Expand Down

0 comments on commit 212d34d

Please sign in to comment.