Uniform the way environment variables are get and set.

This commit is contained in:
Xenega 2018-03-24 17:13:49 +01:00 committed by Mathieu Comandon
parent c1e38872ef
commit c6d94add8d
6 changed files with 50 additions and 38 deletions

View file

@ -295,36 +295,22 @@ class Game(object):
"%s" % terminal) "%s" % terminal)
self.state = self.STATE_STOPPED self.state = self.STATE_STOPPED
return return
# Env vars # Env vars
game_env = gameplay_info.get('env') or {} game_env = gameplay_info.get('env') or {}
env.update(game_env) env.update(game_env)
system_env = system_config.get('env') or {} ld_preload = gameplay_info.get('ld_preload')
env.update(system_env) if (ld_preload):
env["LD_PRELOAD"] = ld_preload
ld_preload = gameplay_info.get('ld_preload') or ''
env["LD_PRELOAD"] = ld_preload
dri_prime = system_config.get('dri_prime')
if dri_prime:
env["DRI_PRIME"] = "1"
else:
env["DRI_PRIME"] = "0"
# Runtime management
ld_library_path = ""
if self.runner.use_runtime():
runtime_env = runtime.get_env()
if 'STEAM_RUNTIME' in runtime_env and 'STEAM_RUNTIME' not in env:
env['STEAM_RUNTIME'] = runtime_env['STEAM_RUNTIME']
if 'LD_LIBRARY_PATH' in runtime_env:
ld_library_path = runtime_env['LD_LIBRARY_PATH']
game_ld_libary_path = gameplay_info.get('ld_library_path') game_ld_libary_path = gameplay_info.get('ld_library_path')
if game_ld_libary_path: if game_ld_libary_path:
ld_library_path = env.get("LD_LIBRARY_PATH")
if not ld_library_path: if not ld_library_path:
ld_library_path = '$LD_LIBRARY_PATH' ld_library_path = '$LD_LIBRARY_PATH'
ld_library_path = ":".join([game_ld_libary_path, ld_library_path]) ld_library_path = ":".join([game_ld_libary_path, ld_library_path])
env["LD_LIBRARY_PATH"] = ld_library_path env["LD_LIBRARY_PATH"] = ld_library_path
# /Env vars # /Env vars
include_processes = shlex.split(system_config.get('include_processes', '')) include_processes = shlex.split(system_config.get('include_processes', ''))

View file

@ -149,6 +149,39 @@ class Runner:
raise ValueError('runner_executable not set for {}'.format(self.name)) raise ValueError('runner_executable not set for {}'.format(self.name))
return os.path.join(settings.RUNNER_DIR, self.runner_executable) return os.path.join(settings.RUNNER_DIR, self.runner_executable)
def get_env(self, os_env=False):
env = {}
if os_env:
env.update(os.environ.copy())
system_env = self.system_config.get('env') or {}
env.update(system_env)
dri_prime = self.system_config.get('dri_prime')
if dri_prime:
env["DRI_PRIME"] = "1"
else:
env["DRI_PRIME"] = "0"
runtime_ld_library_path = None
if self.use_runtime():
runtime_env = runtime.get_env()
if 'STEAM_RUNTIME' in runtime_env and 'STEAM_RUNTIME' not in env:
env['STEAM_RUNTIME'] = runtime_env['STEAM_RUNTIME']
if 'LD_LIBRARY_PATH' in runtime_env:
runtime_ld_library_path = runtime_env['LD_LIBRARY_PATH']
if runtime_ld_library_path:
ld_library_path = env.get("LD_LIBRARY_PATH")
if not ld_library_path:
ld_library_path = '$LD_LIBRARY_PATH'
ld_library_path = ":".join([runtime_ld_library_path, ld_library_path])
env["LD_LIBRARY_PATH"] = ld_library_path
return env
def play(self): def play(self):
"""Dummy method, must be implemented by derived runnners.""" """Dummy method, must be implemented by derived runnners."""
raise NotImplementedError("Implement the play method in your runner") raise NotImplementedError("Implement the play method in your runner")
@ -158,11 +191,7 @@ class Runner:
Reimplement in derived runner if need be.""" Reimplement in derived runner if need be."""
exe = self.get_executable() exe = self.get_executable()
env = {} env = self.get_env()
try:
env = self.get_env()
except AttributeError:
pass
return {'command': [exe], 'env': env} return {'command': [exe], 'env': env}
@ -178,8 +207,6 @@ class Runner:
command_data = self.get_run_data() command_data = self.get_run_data()
command = command_data.get('command') command = command_data.get('command')
env = (command_data.get('env') or {}).copy() env = (command_data.get('env') or {}).copy()
if self.use_runtime():
env.update(runtime.get_env())
thread = LutrisThread(command, runner=self, env=env, watch=False) thread = LutrisThread(command, runner=self, env=env, watch=False)
thread.start() thread.start()

View file

@ -205,7 +205,7 @@ class steam(Runner):
return args return args
def get_env(self): def get_env(self):
env = {} env = super(steam, self).get_env()
if not self.runner_config.get('lsi_steam') and self.runner_config.get('steam_native_runtime'): if not self.runner_config.get('lsi_steam') and self.runner_config.get('steam_native_runtime'):
env['STEAM_RUNTIME'] = '0' env['STEAM_RUNTIME'] = '0'

View file

@ -150,11 +150,8 @@ class web(Runner):
] ]
runner_executable = 'web/electron/electron' runner_executable = 'web/electron/electron'
def get_env(self, full=True): def get_env(self, os_env=True):
if full: env = super(web, self).get_env(self, os_env)
env = os.environ.copy()
else:
env = {}
env['ENABLE_FLASH_PLAYER'] = '1' if self.runner_config['enable_flash'] else '0' env['ENABLE_FLASH_PLAYER'] = '1' if self.runner_config['enable_flash'] else '0'

View file

@ -900,7 +900,9 @@ class wine(Runner):
self.set_regedit_keys() self.set_regedit_keys()
return True return True
def get_env(self, full=True): def get_env(self, os_env=True):
env = super(wine, self).get_env(os_env)
if full: if full:
env = os.environ.copy() env = os.environ.copy()
else: else:
@ -980,7 +982,7 @@ class wine(Runner):
return {'error': 'FILE_NOT_FOUND', 'file': game_exe} return {'error': 'FILE_NOT_FOUND', 'file': game_exe}
launch_info = {} launch_info = {}
launch_info['env'] = self.get_env(full=False) launch_info['env'] = self.get_env(os_env=False)
if self.runner_config.get('x360ce-path'): if self.runner_config.get('x360ce-path'):
self.setup_x360ce(self.runner_config['x360ce-path']) self.setup_x360ce(self.runner_config['x360ce-path'])

View file

@ -412,14 +412,14 @@ class winesteam(wine.wine):
return True return True
def get_run_data(self): def get_run_data(self):
return {'command': self.launch_args, 'env': self.get_env(full=False)} return {'command': self.launch_args, 'env': self.get_env(os_env=False)}
def play(self): def play(self):
self.game_launch_time = time.localtime() self.game_launch_time = time.localtime()
game_args = self.game_config.get('args') or '' game_args = self.game_config.get('args') or ''
launch_info = {} launch_info = {}
launch_info['env'] = self.get_env(full=False) launch_info['env'] = self.get_env(os_env=False)
if self.runner_config.get('x360ce-path'): if self.runner_config.get('x360ce-path'):
self.setup_x360ce(self.runner_config['x360ce-path']) self.setup_x360ce(self.runner_config['x360ce-path'])
@ -487,7 +487,7 @@ class winesteam(wine.wine):
return False return False
appid = appid if appid else self.appid appid = appid if appid else self.appid
env = self.get_env(full=False) env = self.get_env(os_env=False)
command = self.launch_args + ['steam://uninstall/%s' % appid] command = self.launch_args + ['steam://uninstall/%s' % appid]
self.prelaunch() self.prelaunch()
thread = LutrisThread(command, runner=self, env=env, watch=False) thread = LutrisThread(command, runner=self, env=env, watch=False)