summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-02-25 14:51:20 -0700
committerCommit Bot <commit-bot@chromium.org>2022-02-28 18:28:43 +0000
commit0ac172fe2bca63a31daecfe1042eac8fa180d00e (patch)
tree08b0839083cf5b58dd3d5a2dc51b29ce76b0e02a
parent8feab3528995459ad8f0b098ced4188b18db5fe8 (diff)
downloadchrome-ec-0ac172fe2bca63a31daecfe1042eac8fa180d00e.tar.gz
zmake: Make cros lint happy for toolchains
Made changes for pylint. BRANCH=None BUG=None TEST=black . && ./run_tests.sh && \ cros lint tests/test_toolchains.py zmake/toolchains.py Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I60eff964fdb619a5688c439e101f8f28c239585d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3491407 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/zmake/.pylintrc4
-rw-r--r--zephyr/zmake/tests/test_toolchains.py55
-rw-r--r--zephyr/zmake/zmake/toolchains.py14
3 files changed, 52 insertions, 21 deletions
diff --git a/zephyr/zmake/.pylintrc b/zephyr/zmake/.pylintrc
index dc6b05c654..341cb4d687 100644
--- a/zephyr/zmake/.pylintrc
+++ b/zephyr/zmake/.pylintrc
@@ -9,3 +9,7 @@ disable=bad-continuation,bad-whitespace,format,fixme
max-line-length=88
string-quote=double
+
+[BASIC]
+good-names=
+ e,
diff --git a/zephyr/zmake/tests/test_toolchains.py b/zephyr/zmake/tests/test_toolchains.py
index fb1953052a..4b4d24e267 100644
--- a/zephyr/zmake/tests/test_toolchains.py
+++ b/zephyr/zmake/tests/test_toolchains.py
@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+"""Tests for toolchains.py."""
+
import os
import pathlib
@@ -11,6 +13,8 @@ import zmake.output_packers
import zmake.project as project
import zmake.toolchains as toolchains
+# pylint:disable=redefined-outer-name,unused-argument
+
@pytest.fixture
def mockfs(monkeypatch, tmp_path):
@@ -33,12 +37,14 @@ def mockfs(monkeypatch, tmp_path):
@pytest.fixture
def coreboot_sdk_exists(mockfs):
+ """Provide a mock coreboot-sdk."""
coreboot_sdk_dir = mockfs / "opt" / "coreboot-sdk"
coreboot_sdk_dir.mkdir(parents=True)
@pytest.fixture
def llvm_exists(mockfs):
+ """Provide a mock llvm."""
llvm_file = mockfs / "usr" / "bin" / "x86_64-pc-linux-gnu-clang"
llvm_file.parent.mkdir(parents=True)
llvm_file.write_text("")
@@ -46,6 +52,7 @@ def llvm_exists(mockfs):
@pytest.fixture
def host_toolchain_exists(mockfs, monkeypatch):
+ """Provide a mock host toolchain."""
monkeypatch.setattr(os, "environ", {})
gcc_file = mockfs / "usr" / "bin" / "gcc"
@@ -55,6 +62,7 @@ def host_toolchain_exists(mockfs, monkeypatch):
@pytest.fixture
def zephyr_exists(mockfs):
+ """Provide a mock zephyr sdk."""
zephyr_sdk_version_file = mockfs / "opt" / "zephyr-sdk" / "sdk_version"
zephyr_sdk_version_file.parent.mkdir(parents=True)
zephyr_sdk_version_file.write_text("")
@@ -62,6 +70,7 @@ def zephyr_exists(mockfs):
@pytest.fixture
def fake_project(tmp_path):
+ """Create a project that can be used in all the tests."""
return project.Project(
project.ProjectConfig(
project_name="foo",
@@ -83,11 +92,12 @@ module_paths = {
}
-def test_coreboot_sdk(fake_project, coreboot_sdk_exists):
- tc = fake_project.get_toolchain(module_paths)
- assert isinstance(tc, toolchains.CorebootSdkToolchain)
+def test_coreboot_sdk(fake_project: project.Project, coreboot_sdk_exists):
+ """Test that the corebook sdk can be found."""
+ chain = fake_project.get_toolchain(module_paths)
+ assert isinstance(chain, toolchains.CorebootSdkToolchain)
- config = tc.get_build_config()
+ config = chain.get_build_config()
assert config.cmake_defs == {
"ZEPHYR_TOOLCHAIN_VARIANT": "coreboot-sdk",
"TOOLCHAIN_ROOT": "/mnt/host/source/src/platform/ec/zephyr",
@@ -95,21 +105,23 @@ def test_coreboot_sdk(fake_project, coreboot_sdk_exists):
def test_llvm(fake_project, llvm_exists):
- tc = fake_project.get_toolchain(module_paths)
- assert isinstance(tc, toolchains.LlvmToolchain)
+ """Test that llvm can be found."""
+ chain = fake_project.get_toolchain(module_paths)
+ assert isinstance(chain, toolchains.LlvmToolchain)
- config = tc.get_build_config()
+ config = chain.get_build_config()
assert config.cmake_defs == {
"ZEPHYR_TOOLCHAIN_VARIANT": "llvm",
"TOOLCHAIN_ROOT": "/mnt/host/source/src/platform/ec/zephyr",
}
-def test_zephyr(fake_project, zephyr_exists):
- tc = fake_project.get_toolchain(module_paths)
- assert isinstance(tc, toolchains.ZephyrToolchain)
+def test_zephyr(fake_project: project.Project, zephyr_exists):
+ """Test that the zephyr sdk can be found in a standard location."""
+ chain = fake_project.get_toolchain(module_paths)
+ assert isinstance(chain, toolchains.ZephyrToolchain)
- config = tc.get_build_config()
+ config = chain.get_build_config()
assert config.cmake_defs == {
"ZEPHYR_TOOLCHAIN_VARIANT": "zephyr",
"ZEPHYR_SDK_INSTALL_DIR": str(pathlib.Path("/opt/zephyr-sdk")),
@@ -120,16 +132,17 @@ def test_zephyr(fake_project, zephyr_exists):
def test_zephyr_from_env(mockfs, monkeypatch, fake_project):
+ """Test that the zephyr sdk can be found from env variable."""
zephyr_sdk_path = mockfs / "zsdk"
zephyr_sdk_path.mkdir()
environ = {"ZEPHYR_SDK_INSTALL_DIR": str(zephyr_sdk_path)}
monkeypatch.setattr(os, "environ", environ)
- tc = fake_project.get_toolchain(module_paths)
- assert isinstance(tc, toolchains.ZephyrToolchain)
+ chain = fake_project.get_toolchain(module_paths)
+ assert isinstance(chain, toolchains.ZephyrToolchain)
- config = tc.get_build_config()
+ config = chain.get_build_config()
assert config.cmake_defs == {
"ZEPHYR_TOOLCHAIN_VARIANT": "zephyr",
"ZEPHYR_SDK_INSTALL_DIR": str(zephyr_sdk_path),
@@ -140,17 +153,19 @@ def test_zephyr_from_env(mockfs, monkeypatch, fake_project):
def test_host_toolchain(fake_project, host_toolchain_exists):
- tc = fake_project.get_toolchain(module_paths)
- assert isinstance(tc, toolchains.HostToolchain)
+ """Test that the host toolchain can be found."""
+ chain = fake_project.get_toolchain(module_paths)
+ assert isinstance(chain, toolchains.HostToolchain)
- config = tc.get_build_config()
+ config = chain.get_build_config()
assert config.cmake_defs == {
"ZEPHYR_TOOLCHAIN_VARIANT": "host",
}
def test_toolchain_override(mockfs, fake_project):
- tc = fake_project.get_toolchain(module_paths, override="foo")
- config = tc.get_build_config()
- assert isinstance(tc, toolchains.GenericToolchain)
+ """Test that the toolchain can be overridden."""
+ chain = fake_project.get_toolchain(module_paths, override="foo")
+ config = chain.get_build_config()
+ assert isinstance(chain, toolchains.GenericToolchain)
assert config.cmake_defs == {"ZEPHYR_TOOLCHAIN_VARIANT": "foo"}
diff --git a/zephyr/zmake/zmake/toolchains.py b/zephyr/zmake/zmake/toolchains.py
index 671c539c0f..13ee30de08 100644
--- a/zephyr/zmake/zmake/toolchains.py
+++ b/zephyr/zmake/zmake/toolchains.py
@@ -20,7 +20,7 @@ class GenericToolchain:
self.name = name
self.modules = modules or {}
- def probe(self):
+ def probe(self): # pylint:disable=no-self-use
"""Probe if the toolchain is available on the system."""
# Since the toolchain is not known to zmake, we have no way to
# know if it's installed. Simply return False to indicate not
@@ -43,6 +43,8 @@ class GenericToolchain:
class CorebootSdkToolchain(GenericToolchain):
+ """Coreboot SDK toolchain installed in default location."""
+
def probe(self):
# For now, we always assume it's at /opt/coreboot-sdk, since
# that's where it's installed in the chroot. We may want to
@@ -63,6 +65,12 @@ class CorebootSdkToolchain(GenericToolchain):
class ZephyrToolchain(GenericToolchain):
+ """Zephyr SDK toolchain.
+
+ Either set the environment var ZEPHYR_SDK_INSTALL_DIR, or install
+ the SDK in one of the common known locations.
+ """
+
def __init__(self, *args, **kwargs):
self.zephyr_sdk_install_dir = self._find_zephyr_sdk()
super().__init__(*args, **kwargs)
@@ -122,6 +130,8 @@ class ZephyrToolchain(GenericToolchain):
class LlvmToolchain(GenericToolchain):
+ """LLVM toolchain as used in the chroot."""
+
def probe(self):
# TODO: differentiate chroot llvm path vs. something more
# generic?
@@ -141,6 +151,8 @@ class LlvmToolchain(GenericToolchain):
class HostToolchain(GenericToolchain):
+ """GCC toolchain found in the PATH."""
+
def probe(self):
# "host" toolchain for Zephyr means GCC.
for search_path in os.getenv("PATH", "/usr/bin").split(":"):