Пример #1
0
    def upgrade(self):
        """Upgrade an existing linuxdeploy install."""
        if self.exists():
            self.command.logger.info("Removing old LinuxDeploy install...")
            self.appimage_path.unlink()

            self.install()
            self.command.logger.info("...done.")
        else:
            raise MissingToolError("linuxdeploy")
Пример #2
0
    def upgrade(self):
        """
        Upgrade an existing linuxdeploy install.
        """
        if self.exists():
            print("Removing old LinuxDeploy install...")
            self.appimage_path.unlink()

            self.install()
            print("...done.")
        else:
            raise MissingToolError('linuxdeploy')
Пример #3
0
    def upgrade(self):
        """Upgrade an existing WiX install."""
        if not self.managed_install:
            raise NonManagedToolError("WiX")
        elif not self.exists():
            raise MissingToolError("WiX")
        else:
            self.command.logger.info("Removing old WiX install...")
            self.command.shutil.rmtree(self.wix_home)

            self.install()
            self.command.logger.info("...done.")
Пример #4
0
    def upgrade(self):
        """Upgrade an existing JDK install."""
        if not self.managed_install:
            raise NonManagedToolError("Java")
        if not self.exists():
            raise MissingToolError("Java")
        self.command.logger.info("Removing old JDK install...")
        if self.command.host_os == "Darwin":
            self.command.shutil.rmtree(self.java_home.parent.parent)
        else:
            self.command.shutil.rmtree(self.java_home)

        self.install()
        self.command.logger.info("...done.")
Пример #5
0
    def upgrade(self):
        """
        Upgrade an existing WiX install.
        """
        if self.managed_install:
            if self.exists():
                print("Removing old WiX install...")
                self.command.shutil.rmtree(self.wix_home)

                self.install()
                print("...done.")
            else:
                raise MissingToolError('WiX')
        else:
            raise NonManagedToolError('WiX')
Пример #6
0
    def verify(cls, command, install=True):
        """Verify that LinuxDeploy is available.

        :param command: The command that needs to use linuxdeploy
        :param install: Should the tool be installed if it is not found?
        :returns: A valid LinuxDeploy SDK wrapper. If linuxdeploy is not
            available, and was not installed, raises MissingToolError.
        """
        linuxdeploy = LinuxDeploy(command)

        if not linuxdeploy.exists():
            if install:
                linuxdeploy.install()
            else:
                raise MissingToolError("linuxdeploy")

        return LinuxDeploy(command)
Пример #7
0
    def upgrade(self):
        """
        Upgrade an existing JDK install.
        """
        if self.managed_install:
            if self.exists():
                print("Removing old JDK install...")
                if self.command.host_os == 'Darwin':
                    self.command.shutil.rmtree(self.java_home.parent.parent)
                else:
                    self.command.shutil.rmtree(self.java_home)

                self.install()
                print("...done.")
            else:
                raise MissingToolError('Java')
        else:
            raise NonManagedToolError('Java')
Пример #8
0
    def verify(cls, command, install=True):
        """
        Verify that there is a WiX install available.

        If the WIX environment variable is set, that location will be checked
        for a valid WiX installation.

        If the location provided doesn't contain an SDK, or no location is provided,
        an SDK is downloaded.

        :param command: The command making the verification request.
        :param install: Should WiX be installed if it is not found?
        :returns: A valid WiX SDK wrapper. If WiX is not available, and was
            not installed, raises MissingToolError.
        """
        if command.host_os != 'Windows':
            raise BriefcaseCommandError("""
A Windows MSI installer can only be created on Windows.
""")

        # Look for the WIX environment variable
        wix_env = command.os.environ.get("WIX")
        if wix_env:
            wix_home = Path(wix_env)

            # Set up the paths for the WiX executables we will use.
            wix = WiX(command=command, wix_home=wix_home)

            if not wix.exists():
                raise BriefcaseCommandError("""
The WIX environment variable does not point to an install of the
WiX Toolset. Current value: {wix_home!r}
""".format(wix_home=wix_home))

        else:
            wix = WiX(command=command, bin_install=True)

            if not wix.exists():
                if install:
                    wix.install()
                else:
                    raise MissingToolError('WiX')

        return wix
Пример #9
0
    def patch_elf_header(self):
        """Patch the ELF header of the AppImage to ensure it's always
        executable.

        This patch is necessary on Linux hosts that use AppImageLauncher.
        AppImages use a modified ELF binary header starting at offset 0x08
        for additional identification. If a system has AppImageLauncher,
        the Linux kernel module `binfmt-misc` will try to load the AppImage
        with AppImageLauncher. As this binary does not exist in the Docker
        container context, we patch the ELF header of linuxdeploy to remove
        the AppImage bits, thus making all systems treat it like a regular
        ELF binary.

        Citations:
        - https://github.com/AppImage/AppImageKit/issues/1027#issuecomment-1028232809
        - https://github.com/AppImage/AppImageKit/issues/828
        """

        if not self.exists():
            raise MissingToolError("linuxdeploy")
        with open(self.appimage_path, "r+b") as appimage:
            appimage.seek(ELF_PATCH_OFFSET)
            # Check if the header at the offset is the original value
            # If so, patch it.
            if appimage.read(
                    len(ELF_PATCH_ORIGINAL_BYTES)) == ELF_PATCH_ORIGINAL_BYTES:
                appimage.seek(ELF_PATCH_OFFSET)
                appimage.write(ELF_PATCH_PATCHED_BYTES)
                appimage.flush()
                appimage.seek(0)
                self.command.logger.info(
                    "Patched ELF header of linuxdeploy AppImage.")
            # Else if the header is the patched value, do nothing.
            elif (appimage.read(
                    len(ELF_PATCH_ORIGINAL_BYTES)) == ELF_PATCH_PATCHED_BYTES):
                self.command.logger.info(
                    "ELF header of linuxdeploy AppImage is already patched.")
            else:
                # We should only get here if the file at the AppImage patch doesn't have
                # The original or patched value. If this is the case, the file is likely
                # wrong and we should raise an exception.
                raise CorruptToolError("linuxdeploy")
Пример #10
0
    def verify(cls, command, install=True):
        """
        Verify that a Java 8 JDK exists.

        If ``JAVA_HOME`` is set, try that version. If it is a JRE, or its *not*
        a Java 8 JDK, download one.

        On macOS, also try invoking /usr/libexec/java_home. If that location
        points to a Java 8 JDK, use it.

        Otherwise, download a JDK from AdoptOpenJDK and unpack it into the
        ``~.briefcase`` path.

        :param command: The command that needs to perform the verification
            check.
        :param install: Should the tool be installed if it is not found?
        :returns: A valid Java JDK wrapper. If a JDK is not available, and was
            not installed, raises MissingToolError.
        """
        java_home = command.os.environ.get('JAVA_HOME', '')
        install_message = None

        # macOS has a helpful system utility to determine JAVA_HOME. Try it.
        if not java_home and command.host_os == 'Darwin':
            try:
                # If no JRE/JDK is installed, /usr/libexec/java_home
                # raises an error.
                java_home = command.subprocess.check_output(
                    ['/usr/libexec/java_home'],
                    universal_newlines=True,
                    stderr=subprocess.STDOUT,
                ).strip('\n')
            except subprocess.CalledProcessError:
                # No java on this machine.
                pass

        if java_home:
            try:
                # If JAVA_HOME is defined, try to invoke javac.
                # This verifies that we have a JDK, not a just a JRE.
                output = command.subprocess.check_output(
                    [
                        os.fsdecode(Path(java_home) / 'bin' / 'javac'),
                        '-version',
                    ],
                    universal_newlines=True,
                    stderr=subprocess.STDOUT,
                )
                # This should be a string of the form "javac 1.8.0_144\n"
                version_str = output.strip('\n').split(' ')[1]
                vparts = version_str.split('.')
                if len(vparts) == 3 and vparts[:2] == ['1', '8']:
                    # It appears to be a Java 8 JDK.
                    return JDK(command, java_home=Path(java_home))
                else:
                    # It's not a Java 8 JDK.
                    java_home = None
                    install_message = """
*************************************************************************
** WARNING: JAVA_HOME does not point to a Java 8 JDK                   **
*************************************************************************

    Android requires a Java 8 JDK, but the location pointed to by the
    JAVA_HOME environment variable:

    {java_home}

    isn't a Java 8 JDK (it appears to be Java {version_str}).

    Briefcase will use its own JDK instance.

*************************************************************************

""".format(java_home=java_home, version_str=version_str)

            except FileNotFoundError:
                java_home = None
                install_message = """
*************************************************************************
** WARNING: JAVA_HOME does not point to a JDK                          **
*************************************************************************

    The location pointed to by the JAVA_HOME environment variable:

    {java_home}

    does not appear to be a JDK. It may be a Java Runtime Environment.

    Briefcase will use its own JDK instance.

*************************************************************************

""".format(java_home=java_home)

            except subprocess.CalledProcessError:
                java_home = None
                install_message = """
    *************************************************************************
    ** WARNING: Unable to invoke the Java compiler                         **
    *************************************************************************

    Briefcase received an unexpected error when trying to invoke javac,
    the Java compiler, at the location indicated by the JAVA_HOME
    environment variable.

    Briefcase will continue by downloading and using its own JDK.

    Please report this as a bug at:

        https://github.com/beeware/briefcase/issues/new


    In your report, please including the output from running:

        {java_home}/bin/javac -version

    from the command prompt.

    *************************************************************************

    """.format(java_home=java_home)

            except IndexError:
                java_home = None
                install_message = """
    *************************************************************************
    ** WARNING: Unable to determine the version of Java that is installed  **
    *************************************************************************

    Briefcase was unable to interpret the version information returned
    by the Java compiler at the location indicated by the JAVA_HOME
    environment variable.

    Briefcase will continue by downloading and using its own JDK.

    Please report this as a bug at:

        https://github.com/beeware/briefcase/issues/new


    In your report, please including the output from running:

        {java_home}/bin/javac -version

    from the command prompt.

    *************************************************************************

    """.format(java_home=java_home)

        # If we've reached this point, any user-provided JAVA_HOME is broken;
        # use the Briefcase one.
        java_home = command.tools_path / 'java'

        # The macOS download has a weird layout (inherited from the official Oracle
        # release). The actual JAVA_HOME is deeper inside the directory structure.
        if command.host_os == 'Darwin':
            java_home = java_home / 'Contents' / 'Home'

        jdk = JDK(command, java_home=java_home)

        if jdk.exists():
            # Using briefcase-managed Java version
            return jdk
        else:
            if install:
                # We only display the warning messages on the pass where we actually
                # install the JDK.
                if install_message:
                    print(install_message)

                jdk.install()

                return jdk
            else:
                raise MissingToolError('Java')
Пример #11
0
def NonInstalledSDK():
    sdk = MagicMock()
    sdk.name = 'non-installed'
    sdk.full_name = 'Non Installed'
    sdk.verify.side_effect = MissingToolError('non-installed')
    return sdk
Пример #12
0
    def verify(cls, command, install=True, jdk=None):
        """
        Verify an Android SDK is available.

        If the ANDROID_SDK_ROOT environment variable is set, that location will
        be checked for a valid SDK.

        If the location provided doesn't contain an SDK, or no location is provided,
        an SDK is downloaded.

        :param command: The command making the verification request.
        :param install: Should the tool be installed if it is not found?
        :param jdk: The JDK instance to use.
        :returns: A valid Android SDK wrapper. If Android SDK is not
            available, and was not installed, raises MissingToolError.
        """
        if jdk is None:
            jdk = JDK.verify(command, install=install)

        sdk_root = command.os.environ.get("ANDROID_SDK_ROOT")
        if sdk_root:
            sdk = AndroidSDK(command=command, jdk=jdk, root_path=Path(sdk_root))

            if sdk.exists():
                # Ensure licenses have been accepted
                sdk.verify_license()
                return sdk
            else:
                print(
                    """
*************************************************************************
** WARNING: ANDROID_SDK_ROOT does not point to an Android SDK          **
*************************************************************************

    The location pointed to by the ANDROID_SDK_ROOT environment
    variable:

    {sdk_root}

    doesn't appear to contain an Android SDK.

    Briefcase will use its own SDK instance.

*************************************************************************

    """.format(
                        sdk_root=sdk_root
                    )
                )

        # Build an SDK wrapper for the Briefcase SDK instance.
        sdk = AndroidSDK(
            command=command,
            jdk=jdk,
            root_path=command.tools_path / "android_sdk"
        )

        if sdk.exists():
            # Ensure licenses have been accepted
            sdk.verify_license()
            return sdk

        if install:
            sdk.install()
            return sdk
        else:
            raise MissingToolError('Android SDK')