Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove distutils for newer python versions #15517

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/test/toolchains/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_detect_duplicates(filenames):
@settings(max_examples=20)
def test_path_specified_gcc(gcc_loc, exists_at_loc, exists_in_path):
with patch('tools.toolchains.gcc.exists') as _exists:
with patch('tools.toolchains.gcc.find_executable') as _find:
with patch('tools.toolchains.gcc.which') as _find:
_exists.return_value = exists_at_loc
_find.return_value = exists_in_path
TOOLCHAIN_PATHS['GCC_ARM'] = gcc_loc
Expand Down
13 changes: 9 additions & 4 deletions tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
from os import makedirs, write, remove
from tempfile import mkstemp
from shutil import rmtree
from distutils.version import LooseVersion
from sys import version_info

from tools.toolchains.mbed_toolchain import (
mbedToolchain, TOOLCHAIN_PATHS, should_replace_small_c_lib
)
from tools.utils import mkdir, NotSupportedException, run_cmd
from tools.resources import FileRef

if version_info >= (3,10):
from packaging.version import Version
else:
from distutils.version import LooseVersion as Version

ARMC5_MIGRATION_WARNING = (
"Warning: Arm Compiler 5 is no longer supported as of Mbed 6. "
"Please upgrade your environment to Arm Compiler 6 "
Expand Down Expand Up @@ -59,7 +64,7 @@ class ARM(mbedToolchain):
"Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4", "Cortex-M4F",
"Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A5", "Cortex-A9"
]
ARMCC_RANGE = (LooseVersion("5.06"), LooseVersion("5.07"))
ARMCC_RANGE = (Version("5.06"), Version("5.07"))
ARMCC_PRODUCT_RE = re.compile(b"Product: (.*)")
ARMCC_VERSION_RE = re.compile(b"Component: ARM Compiler (\d+\.\d+)")

Expand Down Expand Up @@ -142,7 +147,7 @@ def version_check(self):
output = stdout.encode("utf-8")
match = self.ARMCC_VERSION_RE.search(output)
if match:
found_version = LooseVersion(match.group(1).decode("utf-8"))
found_version = Version(match.group(1).decode("utf-8"))
else:
found_version = None
min_ver, max_ver = self.ARMCC_RANGE
Expand Down Expand Up @@ -546,7 +551,7 @@ class ARMC6(ARM_STD):
"Cortex-M33-NS", "Cortex-M33F-NS", "Cortex-M33FE-NS", "Cortex-M33FE",
"Cortex-A5", "Cortex-A9"
]
ARMCC_RANGE = (LooseVersion("6.10"), LooseVersion("7.0"))
ARMCC_RANGE = (Version("6.10"), Version("7.0"))
LD_DIAGNOSTIC_PATTERN = re.compile(
'(?P<severity>Warning|Error): (?P<message>.+)'
)
Expand Down
16 changes: 11 additions & 5 deletions tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@
import fnmatch
from os.path import join, basename, splitext, dirname, exists
from os import getcwd, getenv
from distutils.spawn import find_executable
from distutils.version import LooseVersion
from sys import version_info

from tools.toolchains.mbed_toolchain import (
mbedToolchain, TOOLCHAIN_PATHS, should_replace_small_c_lib
)
from tools.utils import run_cmd

if version_info >= (3,10):
from shutil import which
from packaging.version import Version
else:
from distutils.spawn import find_executable as which
from distutils.version import LooseVersion as Version


class GCC(mbedToolchain):
OFFICIALLY_SUPPORTED = True
Expand All @@ -36,7 +42,7 @@ class GCC(mbedToolchain):
STD_LIB_NAME = "lib%s.a"
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')

GCC_RANGE = (LooseVersion("9.0.0"), LooseVersion("10.0.0"))
GCC_RANGE = (Version("9.0.0"), Version("10.0.0"))
GCC_VERSION_RE = re.compile(b"\d+\.\d+\.\d+")
DWARF_PRODUCER_RE = re.compile(r'(DW_AT_producer)(.*:\s*)(?P<producer>.*)')

Expand Down Expand Up @@ -183,7 +189,7 @@ def version_check(self):
msg = None
match = self.GCC_VERSION_RE.search(stdout.encode("utf-8"))
if match:
found_version = LooseVersion(match.group(0).decode('utf-8'))
found_version = Version(match.group(0).decode('utf-8'))
else:
found_version = None
min_ver, max_ver = self.GCC_RANGE
Expand Down Expand Up @@ -395,7 +401,7 @@ def check_executable():
not TOOLCHAIN_PATHS['GCC_ARM'] or
not exists(TOOLCHAIN_PATHS['GCC_ARM'])
):
if find_executable('arm-none-eabi-gcc'):
if which('arm-none-eabi-gcc'):
TOOLCHAIN_PATHS['GCC_ARM'] = ''
return True
else:
Expand Down
12 changes: 8 additions & 4 deletions tools/toolchains/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
import re
from os import remove
from os.path import join, splitext, exists
from distutils.version import LooseVersion

from sys import version_info
from tools.toolchains.mbed_toolchain import (
mbedToolchain, TOOLCHAIN_PATHS, should_replace_small_c_lib
)
from tools.utils import run_cmd

if version_info >= (3,10):
from packaging.version import Version
else:
from distutils.version import LooseVersion as Version

class IAR(mbedToolchain):
OFFICIALLY_SUPPORTED = True
LIBRARY_EXT = '.a'
Expand All @@ -34,7 +38,7 @@ class IAR(mbedToolchain):
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)')
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
IAR_VERSION_RE = re.compile(b"IAR ANSI C/C\+\+ Compiler V(\d+\.\d+)")
IAR_VERSION = LooseVersion("8.32")
IAR_VERSION = Version("8.32")

@staticmethod
def check_executable():
Expand Down Expand Up @@ -123,7 +127,7 @@ def version_check(self):
msg = None
match = self.IAR_VERSION_RE.search(stdout.encode("utf-8"))
found_version = match.group(1).decode("utf-8") if match else None
if found_version and LooseVersion(found_version) != self.IAR_VERSION:
if found_version and Version(found_version) != self.IAR_VERSION:
msg = "Compiler version mismatch: Have {}; expected {}".format(
found_version, self.IAR_VERSION)
elif not match or len(match.groups()) != 1:
Expand Down
9 changes: 7 additions & 2 deletions tools/toolchains/mbed_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
from copy import deepcopy
from collections import namedtuple
from abc import ABCMeta, abstractmethod
from distutils.spawn import find_executable
from multiprocessing import Pool, cpu_count
from hashlib import md5
from sys import version_info

from ..utils import (
run_cmd,
Expand All @@ -52,6 +52,11 @@
from ..settings import ARM_PATH, ARMC6_PATH, GCC_ARM_PATH, IAR_PATH
from future.utils import with_metaclass

if version_info >= (3,10):
from shutil import which
else:
from distutils.spawn import find_executable as which


TOOLCHAIN_PATHS = {
'ARM': ARM_PATH,
Expand Down Expand Up @@ -1143,7 +1148,7 @@ def generic_check_executable(tool_key, executable_name, levels_up,
"""
if (not TOOLCHAIN_PATHS[tool_key] or
not exists(TOOLCHAIN_PATHS[tool_key])):
exe = find_executable(executable_name)
exe = which(executable_name)
if not exe:
return False
for level in range(levels_up):
Expand Down