From 32967ebff648bb4fae75af77e89e34f316025b95 Mon Sep 17 00:00:00 2001 From: stealthycoin Date: Mon, 10 Oct 2022 11:02:52 -0700 Subject: [PATCH] Fix install on windows --- backends/build_system/constants.py | 2 +- backends/build_system/install.py | 26 ++++++++++++++----- backends/build_system/utils.py | 3 +++ .../build_system/integration/__init__.py | 6 ++--- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/backends/build_system/constants.py b/backends/build_system/constants.py index b0413462f134..d3f3adf2066b 100644 --- a/backends/build_system/constants.py +++ b/backends/build_system/constants.py @@ -27,7 +27,7 @@ BIN_DIRNAME = "Scripts" if IS_WINDOWS else "bin" PYTHON_EXE_NAME = "python.exe" if IS_WINDOWS else "python" PYINSTALLER_EXE_NAME = "pyinstaller.exe" if IS_WINDOWS else "pyinstaller" -CLI_EXECUTABLES = ["aws.cmd"] if IS_WINDOWS else ["aws", "aws_completer"] +CLI_SCRIPTS = ["aws.cmd"] if IS_WINDOWS else ["aws", "aws_completer"] LOCK_SUFFIX = "win-lock.txt" if IS_WINDOWS else "lock.txt" # Requirements files diff --git a/backends/build_system/install.py b/backends/build_system/install.py index 588611c1b520..de9b02e1dc7b 100644 --- a/backends/build_system/install.py +++ b/backends/build_system/install.py @@ -13,7 +13,7 @@ import os import functools -from constants import CLI_EXECUTABLES +from constants import CLI_SCRIPTS from constants import IS_WINDOWS from constants import BIN_DIRNAME from constants import PYTHON_EXE_NAME @@ -21,6 +21,10 @@ from utils import Utils +TEMPLATE = """@echo off +{path} %* +""" + class Uninstaller: def __init__(self, utils: Utils = None): if utils is None: @@ -30,7 +34,7 @@ def __init__(self, utils: Utils = None): def uninstall(self, install_dir: str, bin_dir: str): if self._utils.isdir(install_dir): self._utils.rmtree(install_dir) - for exe in CLI_EXECUTABLES: + for exe in CLI_SCRIPTS: exe_path = os.path.join(bin_dir, exe) if self._utils.islink(exe_path): self._utils.remove(exe_path) @@ -45,7 +49,7 @@ def __init__(self, build_dir: str, utils: Utils = None): def install(self, install_dir: str, bin_dir: str): self._copy_to_install_dir(install_dir) - self._symlink_executables(install_dir, bin_dir) + self._install_executables(install_dir, bin_dir) @functools.cached_property def artifact_type(self): @@ -66,14 +70,24 @@ def _get_build_lib(self): return os.path.join(self._build_dir, "exe", "aws", "dist") return os.path.join(self._build_dir, "venv") + def _install_executables(self, install_dir, bin_dir): + if IS_WINDOWS and self.artifact_type == ArtifactType.PORTABLE_EXE: + self._install_executables_on_windows(install_dir, bin_dir) + else: + self._symlink_executables(install_dir, bin_dir) + + def _install_executables_on_windows(self, install_dir, bin_dir): + with open(os.path.join(bin_dir, "aws.cmd"), "w") as f: + f.write(TEMPLATE.format(path=os.path.join(install_dir, "aws.exe"))) def _symlink_executables(self, install_dir, bin_dir): if not self._utils.path_exists(bin_dir): self._utils.makedirs(bin_dir) - for exe in CLI_EXECUTABLES: + for exe in CLI_SCRIPTS: + print(exe) exe_path = os.path.join(bin_dir, exe) if self._utils.islink(exe_path): self._utils.remove(exe_path) - self._utils.symlink( + self._utils.link( self._get_install_bin_exe(install_dir, exe), exe_path ) @@ -87,7 +101,7 @@ def _update_script_header(self, install_dir): python_exe_path = self._get_install_bin_exe( install_dir, PYTHON_EXE_NAME ) - for exe in CLI_EXECUTABLES: + for exe in CLI_SCRIPTS: exe_path = self._get_install_bin_exe(install_dir, exe) lines = self._utils.read_file_lines(exe_path) lines[0] = self._get_script_header(python_exe_path) diff --git a/backends/build_system/utils.py b/backends/build_system/utils.py index 7bf3ddb570f1..bb2f6e1edf24 100644 --- a/backends/build_system/utils.py +++ b/backends/build_system/utils.py @@ -157,6 +157,9 @@ def makedirs(self, path: str): def symlink(self, src: str, dst: str): os.symlink(src, dst) + def link(self, src: str, dst: str): + os.link(src, dst) + def read_file_lines(self, path: str) -> List[str]: return open(path, "r").readlines() diff --git a/tests/backends/build_system/integration/__init__.py b/tests/backends/build_system/integration/__init__.py index 13ee65d5d2ac..82076213f85b 100644 --- a/tests/backends/build_system/integration/__init__.py +++ b/tests/backends/build_system/integration/__init__.py @@ -24,7 +24,6 @@ BIN_DIRNAME = "Scripts" if IS_WINDOWS else "bin" PYTHON_EXE_NAME = "python.exe" if IS_WINDOWS else "python" CLI_SCRIPT_NAME = "aws.cmd" if IS_WINDOWS else "aws" -CLI_EXE_NAME = "aws.exe" if IS_WINDOWS else "aws" LOCK_SUFFIX = "win-lock.txt" if IS_WINDOWS else "lock.txt" ROOT = Path(__file__).parents[4] @@ -72,7 +71,6 @@ def assert_built_venv_is_correct(self, venv_dir): def assert_venv_is_correct(self, venv_dir): files = os.listdir(venv_dir) - print(files) assert "Include" in files or "include" in files assert "Lib" in files or "lib" in files or "lib64" in files assert "pyvenv.cfg" in files @@ -92,7 +90,7 @@ def assert_built_exe_is_correct(self, root_dir): self.assert_version_string_is_correct(aws_exe) def assert_installed_exe_is_correct(self, exe_dir): - self.assert_version_string_is_correct(exe_dir / CLI_EXE_NAME) + self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME) def assert_installed_venv_is_correct(self, exe_dir, lib_dir): self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME) @@ -201,7 +199,7 @@ def call_install(self, bin_path: str, lib_path: str): "--lib-dir", lib_path, "--build-dir", - "build" + "build", ] return self.subprocess(args)