Skip to content

Commit

Permalink
Machine architecture checks
Browse files Browse the repository at this point in the history
- Prevent running on 32bit Windows or 32bit Python on 64bit Windows
- Support i386 for AppImage
- Support building Linux System packages on i386
- Support installing JDK for armv6/7/8
  • Loading branch information
rmartin16 committed Jul 18, 2023
1 parent 43fd921 commit 71684cf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/briefcase/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class BaseCommand(ABC):
cmd_line = "briefcase {command} {platform} {output_format}"
supported_host_os = {"Darwin", "Linux", "Windows"}
supported_host_os_reason = f"This command is not supported on {platform.system()}."
supported_host_arch: set()
supports_32bit_python = False
# defined by platform-specific subclasses
command: str
description: str
Expand Down Expand Up @@ -484,6 +486,21 @@ def verify_host(self):
if self.tools.host_os not in self.supported_host_os:
raise UnsupportedHostError(self.supported_host_os_reason)

if (
self.supported_host_arch
and self.tools.host_arch not in self.supported_host_arch
):
raise BriefcaseCommandError(
f"Briefcase is not supported on {platform.system()} for {platform.machine()}."
)

# if the machine's largest supported pointer address is less than 2^32,
# then assume the machine is 32 bits or Python itself is 32 bits
if not self.supports_32bit_python and self.tools.sys.maxsize <= 2**32:
raise BriefcaseCommandError(
f"This command is not supported for a 32bit {platform.machine()} or 32bit Python"
)

def verify_tools(self):
"""Verify that the tools needed to run this Command exist.
Expand Down
4 changes: 3 additions & 1 deletion src/briefcase/integrations/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def OpenJDK_download_url(self):
arch = {
"x86_64": "x64", # Linux\macOS x86-64
"aarch64": "aarch64", # Linux arm64
"armv6l": "arm", # Linux arm
"armv6l": "arm", # Linux armv6
"armv7l": "arm", # Linux armv7
"armv8l": "arm", # Linux armv8
"arm64": "aarch64", # macOS arm64
"AMD64": "x64", # Windows x86-64
}.get(self.tools.host_arch)
Expand Down
9 changes: 7 additions & 2 deletions src/briefcase/integrations/linuxdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def download_url(self) -> str:
def file_path(self) -> Path:
"""The folder on the local filesystem that contains the file_name."""

@property
def arch(self):
"""Return architecture for LinuxDeploy."""
return {"i686": "i386"}.get(self.tools.host_arch, self.tools.host_arch)

def exists(self) -> bool:
return (self.file_path / self.file_name).is_file()

Expand Down Expand Up @@ -208,7 +213,7 @@ class LinuxDeployQtPlugin(LinuxDeployPluginBase, ManagedTool):

@property
def file_name(self) -> str:
return f"linuxdeploy-plugin-qt-{self.tools.host_arch}.AppImage"
return f"linuxdeploy-plugin-qt-{self.arch}.AppImage"

@property
def download_url(self) -> str:
Expand Down Expand Up @@ -319,7 +324,7 @@ def file_path(self) -> Path:

@property
def file_name(self) -> str:
return f"linuxdeploy-{self.tools.host_arch}.AppImage"
return f"linuxdeploy-{self.arch}.AppImage"

@property
def download_url(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion src/briefcase/platforms/linux/appimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def project_path(self, app):

def binary_name(self, app):
safe_name = app.formal_name.replace(" ", "_")
return f"{safe_name}-{app.version}-{self.tools.host_arch}.AppImage"
arch = {"i686": "i386"}.get(self.tools.host_arch, self.tools.host_arch)
return f"{safe_name}-{app.version}-{arch}.AppImage"

def binary_path(self, app):
return self.bundle_path(app) / self.binary_name(app)
Expand Down
2 changes: 2 additions & 0 deletions src/briefcase/platforms/linux/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LinuxSystemPassiveMixin(LinuxMixin):
# Docker exists. It is used by commands that are "passive" from the
# perspective of the build system (e.g., Run).
output_format = "system"
supports_32bit_python = True
supported_host_os = {"Darwin", "Linux"}
supported_host_os_reason = (
"Linux system projects can only be built on Linux, or on macOS using Docker."
Expand Down Expand Up @@ -61,6 +62,7 @@ def linux_arch(self):
"x86_64": "amd64",
"aarch64": "arm64",
"armv6l": "armhf",
"i686": "i386",
}.get(self.tools.host_arch, self.tools.host_arch)

def build_path(self, app):
Expand Down
1 change: 1 addition & 0 deletions src/briefcase/platforms/windows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class WindowsMixin:
platform = "windows"
supported_host_os = {"Windows"}
supported_host_os_reason = "Windows applications can only be built on Windows."
supported_host_arch = {"AMD64"}

def binary_path(self, app):
return self.bundle_path(app) / self.packaging_root / f"{app.formal_name}.exe"
Expand Down

0 comments on commit 71684cf

Please sign in to comment.