Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip prefix creation when running native Linux executables #302

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def setup_pfx(path: str) -> None:
user: str = getpwuid(os.getuid()).pw_name
wineuser: Path = Path(path).expanduser().joinpath("drive_c", "users", user)

if os.environ.get("UMU_NO_PROTON") == "1":
return

if pfx.is_symlink():
pfx.unlink()

Expand Down Expand Up @@ -112,17 +115,23 @@ def check_env(
err: str = "Environment variable is empty: WINEPREFIX"
raise ValueError(err)

if "WINEPREFIX" not in os.environ:
if (
os.environ.get("UMU_NO_PROTON") != "1"
and "WINEPREFIX" not in os.environ
):
pfx: Path = Path.home().joinpath("Games", "umu", env["GAMEID"])
pfx.mkdir(parents=True, exist_ok=True)
os.environ["WINEPREFIX"] = str(pfx)

if not Path(os.environ["WINEPREFIX"]).expanduser().is_dir():
if (
os.environ.get("UMU_NO_PROTON") != "1"
and not Path(os.environ["WINEPREFIX"]).expanduser().is_dir()
):
pfx: Path = Path(os.environ["WINEPREFIX"])
pfx.mkdir(parents=True, exist_ok=True)
os.environ["WINEPREFIX"] = str(pfx)

env["WINEPREFIX"] = os.environ["WINEPREFIX"]
env["WINEPREFIX"] = os.environ.get("WINEPREFIX", "")

# Skip Proton if running a native Linux executable
if os.environ.get("UMU_NO_PROTON") == "1":
Expand Down
77 changes: 77 additions & 0 deletions umu/umu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def setUp(self):
"STEAM_COMPAT_MEDIA_PATH": "",
"STEAM_FOSSILIZE_DUMP_PATH": "",
"DXVK_STATE_CACHE_PATH": "",
"UMU_NO_PROTON": "",
}
self.user = getpwuid(os.getuid()).pw_name
self.test_opts = "-foo -bar"
Expand Down Expand Up @@ -2914,6 +2915,26 @@ def test_setup_pfx_paths(self):
"Expected tracked_files to be a file",
)

def test_setup_pfx_noproton(self):
"""Test setup_pfx when configured to not use Proton."""
result = None
os.environ["UMU_NO_PROTON"] = "1"

result = umu_run.setup_pfx(self.test_file)
self.assertTrue(result is None, f"Expected None, received {result}")
self.assertFalse(
Path(self.test_file, "pfx").exists(),
f"Expected {self.test_file}/pfx to not exist",
)
self.assertFalse(
Path(self.test_file, "tracked_files").exists(),
f"Expected {self.test_file}/tracked_files to not exist",
)
self.assertFalse(
Path(self.test_file, "drive_c").exists(),
f"Expected {self.test_file}/drive_c to not exist",
)

def test_setup_pfx(self):
"""Test setup_pfx."""
result = None
Expand Down Expand Up @@ -3034,6 +3055,62 @@ def test_parse_args_config(self):
result, Namespace, "Expected a Namespace from parse_arg"
)

def test_env_nowine_noproton(self):
"""Test check_env when configured to not use Proton.

Expects the directory $HOME/Games/umu/$GAMEID to not be created
when UMU_NO_PROTON=1 and GAMEID is set in the host environment.
"""
result = None
# Mock $HOME
mock_home = Path(self.test_file)

with (
ThreadPoolExecutor() as thread_pool,
# Mock the internal call to Path.home(). Otherwise, some of our
# assertions may fail when running this test suite locally if
# the user already has that dir
patch.object(Path, "home", return_value=mock_home),
):
os.environ["UMU_NO_PROTON"] = "1"
os.environ["GAMEID"] = "foo"
result = umu_run.check_env(self.env, thread_pool)
self.assertTrue(result is self.env)
path = mock_home.joinpath("Games", "umu", os.environ["GAMEID"])
# Ensure we did not create the target nor its parents up to $HOME
self.assertFalse(path.exists(), f"Expected {path} to not exist")
self.assertFalse(
path.parent.exists(), f"Expected {path.parent} to not exist"
)
self.assertFalse(
path.parent.parent.exists(),
f"Expected {path.parent.parent} to not exist",
)
self.assertTrue(
mock_home.exists(), f"Expected {mock_home} to exist"
)

def test_env_wine_noproton(self):
"""Test check_env when configured to not use Proton.

Expects the WINE prefix directory to not be created when
UMU_NO_PROTON=1 and WINEPREFIX is set in the host environment.
"""
result = None

with (
ThreadPoolExecutor() as thread_pool,
):
os.environ["WINEPREFIX"] = "123"
os.environ["UMU_NO_PROTON"] = "1"
os.environ["GAMEID"] = "foo"
result = umu_run.check_env(self.env, thread_pool)
self.assertTrue(result is self.env)
self.assertFalse(
Path(os.environ["WINEPREFIX"]).exists(),
f"Expected directory {os.environ['WINEPREFIX']} to not exist",
)

def test_env_proton_nodir(self):
"""Test check_env when $PROTONPATH in the case we failed to set it.

Expand Down
Loading