Skip to content

Commit

Permalink
conan-io#5026 Support custom platform
Browse files Browse the repository at this point in the history
- User is able to specify prefix/suffix according the arch

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed May 27, 2019
1 parent ca34e73 commit b78d392
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
77 changes: 35 additions & 42 deletions conans/client/tools/system_pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def update(self):
self._is_up_to_date = True
self._tool.update()

def install(self, packages, update=True, force=False):
def install(self, packages, update=True, force=False, platforms=None):
"""
Get the system package tool install command.
'"""
packages = [packages] if isinstance(packages, str) else list(packages)
packages = self._parse_packages_arch(packages)
packages = self._parse_packages_arch(packages, platforms)

mode = self._get_sysrequire_mode()

Expand All @@ -116,14 +116,15 @@ def install(self, packages, update=True, force=False):
self.update()
self._install_any(packages)

def _parse_packages_arch(self, packages):
def _parse_packages_arch(self, packages, platforms):
if self._settings and cross_building(self._settings):
_, _, _, host_arch = get_cross_building_settings(self._settings)
_, build_arch, _, host_arch = get_cross_building_settings(self._settings)
arch = host_arch or build_arch
parsed_packages = []
for package in packages:
if isinstance(package, str):
for package_name in package.split(" "):
parsed_packages.append(self._tool._parse_package(package_name, host_arch))
parsed_packages.append(self._tool._parse_package(package_name, arch, platforms))
return parsed_packages
return packages

Expand Down Expand Up @@ -152,6 +153,9 @@ class BaseTool(object):
def __init__(self, output=None):
self._output = default_output(output, 'conans.client.tools.system_pm.BaseTool')

def _parse_package(self, package, arch, platforms):
return package


class NullTool(BaseTool):
def add_repository(self, repository, repo_key=None):
Expand All @@ -167,9 +171,6 @@ def install(self, package_name):
def installed(self, package_name):
return False

def _parse_package(self, package, arch):
return package


class AptTool(BaseTool):
def add_repository(self, repository, repo_key=None):
Expand All @@ -194,15 +195,16 @@ def installed(self, package_name):
def _platforms(self):
return

def _parse_package(self, package, arch):
platforms = {"x86_64": "amd64",
"x86": "i386",
"ppc32": "powerpc",
"ppc64le": "ppc64el",
"armv7": "arm",
"armv7hf": "armhf",
"armv8": "arm64",
"s390x": "s390x"}
def _parse_package(self, package, arch, platforms):
if platforms is None:
platforms = {"x86_64": "amd64",
"x86": "i386",
"ppc32": "powerpc",
"ppc64le": "ppc64el",
"armv7": "arm",
"armv7hf": "armhf",
"armv8": "arm64",
"s390x": "s390x"}
if arch in platforms:
return "%s:%s" % (package, platforms[arch])
return package
Expand All @@ -224,15 +226,16 @@ def installed(self, package_name):
exit_code = self._runner("rpm -q %s" % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
platforms = {"x86_64": "x86_64",
"x86": "i?86",
"ppc32": "powerpc",
"ppc64le": "ppc64le",
"armv7": "armv7",
"armv7hf": "armv7hl",
"armv8": "aarch64",
"s390x": "s390x"}
def _parse_package(self, package, arch, platforms):
if platforms is None:
platforms = {"x86_64": "x86_64",
"x86": "i?86",
"ppc32": "powerpc",
"ppc64le": "ppc64le",
"armv7": "armv7",
"armv7hf": "armv7hl",
"armv8": "aarch64",
"s390x": "s390x"}
if arch in platforms:
return "%s.%s" % (package, platforms[arch])
return package
Expand All @@ -252,9 +255,6 @@ def installed(self, package_name):
exit_code = self._runner('test -n "$(brew ls --versions %s)"' % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
return package


class PkgTool(BaseTool):
def add_repository(self, repository, repo_key=None):
Expand All @@ -271,9 +271,6 @@ def installed(self, package_name):
exit_code = self._runner("pkg info %s" % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
return package


class PkgUtilTool(BaseTool):
def add_repository(self, repository, repo_key=None):
Expand All @@ -290,9 +287,6 @@ def installed(self, package_name):
exit_code = self._runner('test -n "`pkgutil --list %s`"' % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
return package


class ChocolateyTool(BaseTool):
def add_repository(self, repository, repo_key=None):
Expand All @@ -309,9 +303,6 @@ def installed(self, package_name):
'findstr /c:"1 packages installed."' % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
return package


class PacManTool(BaseTool):
def add_repository(self, repository, repo_key=None):
Expand All @@ -328,8 +319,9 @@ def installed(self, package_name):
exit_code = self._runner("pacman -Qi %s" % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
platforms = {"x86": "lib32"}
def _parse_package(self, package, arch, platforms):
if platforms is None:
platforms = {"x86": "lib32"}
if arch in platforms:
return "%s-%s" % (platforms[arch], package)
return package
Expand All @@ -350,8 +342,9 @@ def installed(self, package_name):
exit_code = self._runner("rpm -q %s" % package_name, None)
return exit_code == 0

def _parse_package(self, package, arch):
platforms = {"x86": "i586"}
def _parse_package(self, package, arch, platforms):
if platforms is None:
platforms = {"x86": "i586"}
if arch in platforms:
return "%s.%s" % (platforms[arch], package)
return package
Expand Down
11 changes: 11 additions & 0 deletions conans/test/unittests/client/tools/system_pm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ def system_package_tool_test(self):
self.assertEqual(runner.command_called,
"apt-get install -y --no-install-recommends a_package%s" % distro_arch)

for arch, distro_arch in {"x86_64": "", "x86": ":all"}.items():
settings = MockSettings({"arch": arch,
"arch_build": "x86_64",
"os": "Linux",
"os_build": "Linux"})
spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out,
settings=settings)
spt.install("a_package", force=True, platforms={"x86": "all"})
self.assertEqual(runner.command_called,
"apt-get install -y --no-install-recommends a_package%s" % distro_arch)

os_info.is_macos = True
os_info.is_linux = False
os_info.is_windows = False
Expand Down

0 comments on commit b78d392

Please sign in to comment.