diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2023-07-13 08:58:39 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2023-07-24 14:48:14 +0530 |
commit | 4de470e93d202888e82b0000663ed1243faa4032 (patch) | |
tree | 43375c8720da846d80f4e62af5ccbd9ef337f85d | |
parent | 14f2a763c7abcce0efde1f88fdb234fbf7b1cbe1 (diff) |
cerbero: Fix entering build environment on Windows1.22.5
MSYS2 and MSYS support starting up a prompt in the current terminal
directly, which means entering the build env will actually work when
running cerbero remotely over SSH.
Also, MSYS2 wasn't preserving PATH correctly, so hack around it.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1227>
-rw-r--r-- | cerbero/build/oven.py | 2 | ||||
-rw-r--r-- | cerbero/commands/shell.py | 4 | ||||
-rw-r--r-- | cerbero/utils/shell.py | 21 |
3 files changed, 19 insertions, 8 deletions
diff --git a/cerbero/build/oven.py b/cerbero/build/oven.py index 2f196698..01435d2f 100644 --- a/cerbero/build/oven.py +++ b/cerbero/build/oven.py @@ -452,7 +452,7 @@ class Oven (object): else: source_dir = recipe.get_for_arch(be.arch, 'build_dir') shell.enter_build_environment(self.config.target_platform, - be.arch, source_dir, env=environ) + be.arch, self.config.distro, source_dir, env=environ) raise be elif action == RecoveryActions.RETRY_ALL: shutil.rmtree(recipe.get_for_arch(be.arch, 'build_dir')) diff --git a/cerbero/commands/shell.py b/cerbero/commands/shell.py index 820ddfaf..e3582746 100644 --- a/cerbero/commands/shell.py +++ b/cerbero/commands/shell.py @@ -46,8 +46,8 @@ class Shell(Command): add_system_libs(config, env, config.env) shell.enter_build_environment(config.target_platform, - config.target_arch, sourcedir=None, env=env, - bash_completions=config.bash_completions) + config.target_arch, config.distro, sourcedir=None, + env=env, bash_completions=config.bash_completions) register_command(Shell) diff --git a/cerbero/utils/shell.py b/cerbero/utils/shell.py index f6964363..50f99c64 100644 --- a/cerbero/utils/shell.py +++ b/cerbero/utils/shell.py @@ -551,7 +551,7 @@ def files_checksum(paths): return m.digest() -def enter_build_environment(platform, arch, sourcedir=None, bash_completions=None, env=None): +def enter_build_environment(platform, arch, distro, sourcedir=None, bash_completions=None, env=None): ''' Enters to a new shell with the build environment ''' @@ -561,14 +561,21 @@ source ~/{rc_file} fi {sourcedirsh} {prompt} +# For some reason MSYS2 refuses to inherit PATH from the env, so force it +if [ "$MSYSTEM" = "UCRT64" ]; then + PATH=$(cygpath -p "{path}") +fi BASH_COMPLETION_SCRIPTS="{bash_completions}" BASH_COMPLETION_PATH="$CERBERO_PREFIX/share/bash-completion/completions" for f in $BASH_COMPLETION_SCRIPTS; do [ -f "$BASH_COMPLETION_PATH/$f" ] && . "$BASH_COMPLETION_PATH/$f" done ''' - MSYSBAT = ''' -start bash.exe --rcfile %s + MSYSBAT = ''' +C:\\MinGW\\msys\\1.0\\bin\\bash.exe --rcfile %s +''' + MSYS2BAT = ''' +C:\\msys64\\msys2_shell.cmd -ucrt64 -defterm -no-start -here -use-full-path -c 'bash --rcfile %s' ''' if sourcedir: sourcedirsh = 'cd ' + sourcedir @@ -594,14 +601,18 @@ start bash.exe --rcfile %s prompt = 'PS1="\[\033[01;32m\][cerbero-{platform}-{arch}]\[\033[00m\] $PS1"'.format( platform=platform, arch=arch) shellrc = SHELLRC.format(rc_file=rc_file, sourcedirsh=sourcedirsh, - prompt=prompt, bash_completions=bash_completions) + prompt=prompt, bash_completions=bash_completions, path=env['PATH']) if PLATFORM == Platform.WINDOWS: + if distro == Distro.MSYS: + bat_tpl = MSYSBAT + else: + bat_tpl = MSYS2BAT msysbatdir = tempfile.mkdtemp() msysbat = os.path.join(msysbatdir, "msys.bat") bashrc = os.path.join(msysbatdir, "bash.rc") with open(msysbat, 'w+') as f: - f.write(MSYSBAT % bashrc) + f.write(bat_tpl % bashrc) with open(bashrc, 'w+') as f: f.write(shellrc) subprocess.check_call(msysbat, shell=True, env=env) |