From d5cb90cf395738cd42ee196ead4f6b9cb8bb7b0f Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Wed, 2 Aug 2023 10:39:08 +0300 Subject: [PATCH] plugin: kernel: remove unused kernel-compiler-paths option Generic build-environment part option can be used instead. Signed-off-by: Ondrej Kubik --- snapcraft/parts/plugins/kernel_plugin.py | 22 +------------ snapcraft_legacy/plugins/v2/kernel.py | 28 +--------------- tests/legacy/unit/plugins/v2/test_kernel.py | 36 +-------------------- tests/unit/parts/plugins/test_kernel.py | 30 +---------------- 4 files changed, 4 insertions(+), 112 deletions(-) diff --git a/snapcraft/parts/plugins/kernel_plugin.py b/snapcraft/parts/plugins/kernel_plugin.py index 575750edc51..cd9cc8a18e5 100644 --- a/snapcraft/parts/plugins/kernel_plugin.py +++ b/snapcraft/parts/plugins/kernel_plugin.py @@ -63,12 +63,6 @@ Optional, define compiler to use, by default gcc compiler is used. Other permitted compilers: clang - - kernel-compiler-paths - (array of strings; default: none) - Optional, define the compiler path to be added to the PATH. - Path is relative to the stage directory. - Default value is empty. - - kernel-compiler-parameters (array of string) Optional, define extra compiler parameters to be passed to the compiler. @@ -127,7 +121,6 @@ class KernelPluginProperties(plugins.PluginProperties, plugins.PluginModel): kernel_with_firmware: bool = True kernel_device_trees: Optional[List[str]] kernel_compiler: Optional[str] - kernel_compiler_paths: Optional[List[str]] kernel_compiler_parameters: Optional[List[str]] kernel_enable_zfs_support: bool = False kernel_enable_perf: bool = False @@ -323,7 +316,7 @@ def get_build_environment(self) -> Dict[str, str]: logger.info("Getting build env...") self._init_build_env() - env = { + return { "CROSS_COMPILE": "${CRAFT_ARCH_TRIPLET}-", "ARCH": self._kernel_arch, "DEB_ARCH": "${CRAFT_TARGET_ARCH}", @@ -331,19 +324,6 @@ def get_build_environment(self) -> Dict[str, str]: "KERNEL_IMAGE_TARGET": self.kernel_image_target, } - # check if there is custom path to be included - if self.options.kernel_compiler_paths: - custom_paths = [ - os.path.join("${CRAFT_STAGE}", f) - for f in self.options.kernel_compiler_paths - ] - path = custom_paths + [ - "${PATH}", - ] - env["PATH"] = ":".join(path) - - return env - @overrides def get_build_commands(self) -> List[str]: logger.info("Getting build commands...") diff --git a/snapcraft_legacy/plugins/v2/kernel.py b/snapcraft_legacy/plugins/v2/kernel.py index 78681e4b95f..2fcdcffc1db 100644 --- a/snapcraft_legacy/plugins/v2/kernel.py +++ b/snapcraft_legacy/plugins/v2/kernel.py @@ -63,12 +63,6 @@ Optional, define compiler to use, by default gcc compiler is used. Other permitted compilers: clang - - kernel-compiler-paths - (array of strings; default: none) - Optional, define the compiler path to be added to the PATH. - Path is relative to the stage directory. - Default value is empty. - - kernel-compiler-parameters (array of string) Optional, define extra compiler parameters to be passed to the compiler. @@ -156,13 +150,6 @@ def get_schema(cls) -> Dict[str, Any]: "type": "string", "default": "", }, - "kernel-compiler-paths": { - "type": "array", - "minitems": 1, - "uniqueItems": True, - "items": {"type": "string"}, - "default": [], - }, "kernel-compiler-parameters": { "type": "array", "minitems": 1, @@ -337,7 +324,7 @@ def get_build_environment(self) -> Dict[str, str]: logger.info("Getting build env...") self._init_build_env() - env = { + return { "CROSS_COMPILE": "${SNAPCRAFT_ARCH_TRIPLET}-", "ARCH": self._kernel_arch, "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", @@ -345,19 +332,6 @@ def get_build_environment(self) -> Dict[str, str]: "KERNEL_IMAGE_TARGET": self.kernel_image_target, } - # check if there is custom path to be included - if self.options.kernel_compiler_paths: - custom_paths = [ - os.path.join("${SNAPCRAFT_STAGE}", f) - for f in self.options.kernel_compiler_paths - ] - path = custom_paths + [ - "${PATH}", - ] - env["PATH"] = ":".join(path) - - return env - @overrides def get_build_commands(self) -> List[str]: logger.info("Getting build commands...") diff --git a/tests/legacy/unit/plugins/v2/test_kernel.py b/tests/legacy/unit/plugins/v2/test_kernel.py index 2122569aa92..91d4b3b54ba 100644 --- a/tests/legacy/unit/plugins/v2/test_kernel.py +++ b/tests/legacy/unit/plugins/v2/test_kernel.py @@ -40,7 +40,6 @@ class Kernelv2PluginProperties: kernel_with_firmware: bool = True kernel_device_trees: [str] = None kernel_compiler: str = None - kernel_compiler_paths: [str] = None kernel_compiler_parameters: [str] = None kernel_enable_zfs_support: bool = False kernel_enable_perf: bool = False @@ -66,7 +65,6 @@ def _setup_test( kernelwithfirmware=True, kerneldevicetrees=None, kernelcompiler=None, - kernelcompilerpaths=None, kernelcompilerparameters=None, kernelenablezfssupport=False, kernelenableperf=False, @@ -83,7 +81,6 @@ class Options(Kernelv2PluginProperties): kernel_with_firmware = kernelwithfirmware kernel_device_trees = kerneldevicetrees kernel_compiler = kernelcompiler - kernel_compiler_paths = kernelcompilerpaths kernel_compiler_parameters = kernelcompilerparameters kernel_enable_zfs_support = kernelenablezfssupport kernel_enable_perf = kernelenableperf @@ -154,13 +151,6 @@ def test_schema(self): "type": "string", "default": "", }, - "kernel-compiler-paths": { - "type": "array", - "minitems": 1, - "uniqueItems": True, - "items": {"type": "string"}, - "default": [], - }, "kernel-compiler-parameters": { "type": "array", "minitems": 1, @@ -266,7 +256,6 @@ def test_check_configuration_simple(self): self.assertTrue(opt.kernel_with_firmware) self.assertEqual(opt.kernel_device_trees, None) self.assertEqual(opt.kernel_compiler, None) - self.assertEqual(opt.kernel_compiler_paths, None) self.assertEqual(opt.kernel_compiler_parameters, None) self.assertFalse(opt.kernel_enable_zfs_support) self.assertFalse(opt.kernel_enable_perf) @@ -287,7 +276,6 @@ def test_check_configuration_kde_config(self): self.assertTrue(opt.kernel_with_firmware) self.assertIs(opt.kernel_device_trees, None) self.assertIs(opt.kernel_compiler, None) - self.assertIs(opt.kernel_compiler_paths, None) self.assertIs(opt.kernel_compiler_parameters, None) self.assertFalse(opt.kernel_enable_zfs_support) self.assertFalse(opt.kernel_enable_perf) @@ -311,7 +299,6 @@ def test_check_configuration_image_target(self): self.assertTrue(opt.kernel_with_firmware) self.assertIs(opt.kernel_device_trees, None) self.assertIs(opt.kernel_compiler, None) - self.assertIs(opt.kernel_compiler_paths, None) self.assertIs(opt.kernel_compiler_parameters, None) self.assertFalse(opt.kernel_enable_zfs_support) self.assertFalse(opt.kernel_enable_perf) @@ -335,7 +322,6 @@ def test_check_configuration_konfig_file(self): self.assertTrue(opt.kernel_with_firmware) self.assertIs(opt.kernel_device_trees, None) self.assertIs(opt.kernel_compiler, None) - self.assertIs(opt.kernel_compiler_paths, None) self.assertIs(opt.kernel_compiler_parameters, None) self.assertFalse(opt.kernel_enable_zfs_support) self.assertFalse(opt.kernel_enable_perf) @@ -356,9 +342,8 @@ def test_check_get_build_environment(self): }, ) - def test_check_get_build_environment_compiler_paths_cross(self): + def test_check_get_build_environment_cross(self): plugin = self._setup_test( - kernelcompilerpaths=["gcc-11/bin"], kernelimagetarget={"arm64": "Image", "armhf": "Image.gz"}, arch="armv7l", ) @@ -372,25 +357,6 @@ def test_check_get_build_environment_compiler_paths_cross(self): "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", "KERNEL_BUILD_ARCH_DIR": "${SNAPCRAFT_PART_BUILD}/arch/arm/boot", "KERNEL_IMAGE_TARGET": "Image.gz", - "PATH": "${SNAPCRAFT_STAGE}/gcc-11/bin:${PATH}", - }, - ) - - def test_check_get_build_environment_compiler_paths(self): - plugin = self._setup_test( - kernelcompilerpaths=["gcc-11/bin", "gcc-11/sbin"], - ) - plugin._kernel_arch = "amd64" - - self.assertEqual( - plugin.get_build_environment(), - { - "CROSS_COMPILE": "${SNAPCRAFT_ARCH_TRIPLET}-", - "ARCH": plugin._kernel_arch, - "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", - "KERNEL_BUILD_ARCH_DIR": f"${{SNAPCRAFT_PART_BUILD}}/arch/{plugin._kernel_arch}/boot", - "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, - "PATH": "${SNAPCRAFT_STAGE}/gcc-11/bin:${SNAPCRAFT_STAGE}/gcc-11/sbin:${PATH}", }, ) diff --git a/tests/unit/parts/plugins/test_kernel.py b/tests/unit/parts/plugins/test_kernel.py index 865ace22e3a..21aceb3b552 100644 --- a/tests/unit/parts/plugins/test_kernel.py +++ b/tests/unit/parts/plugins/test_kernel.py @@ -150,7 +150,6 @@ def test_check_configuration_simple(self, setup_method_fixture, new_dir): assert opt.kernel_with_firmware assert opt.kernel_device_trees is None assert opt.kernel_compiler is None - assert opt.kernel_compiler_paths is None assert opt.kernel_compiler_parameters is None assert not opt.kernel_enable_zfs_support assert not opt.kernel_enable_perf @@ -174,7 +173,6 @@ def test_check_configuration_kde_config(self, setup_method_fixture, new_dir): assert opt.kernel_with_firmware assert opt.kernel_device_trees is None assert opt.kernel_compiler is None - assert opt.kernel_compiler_paths is None assert opt.kernel_compiler_parameters is None assert not opt.kernel_enable_zfs_support assert not opt.kernel_enable_perf @@ -198,7 +196,6 @@ def test_check_configuration_image_target(self, setup_method_fixture, new_dir): assert opt.kernel_with_firmware assert opt.kernel_device_trees is None assert opt.kernel_compiler is None - assert opt.kernel_compiler_paths is None assert opt.kernel_compiler_parameters is None assert not opt.kernel_enable_zfs_support assert not opt.kernel_enable_perf @@ -222,7 +219,6 @@ def test_check_configuration_konfig_file(self, setup_method_fixture, new_dir): assert opt.kernel_with_firmware assert opt.kernel_device_trees is None assert opt.kernel_compiler is None - assert opt.kernel_compiler_paths is None assert opt.kernel_compiler_parameters is None assert not opt.kernel_enable_zfs_support assert not opt.kernel_enable_perf @@ -259,13 +255,10 @@ def test_check_get_build_environment(self, setup_method_fixture, new_dir): "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, } - def test_check_get_build_environment_compiler_paths_cross( - self, setup_method_fixture, new_dir - ): + def test_check_get_build_environment_cross(self, setup_method_fixture, new_dir): plugin = setup_method_fixture( new_dir, properties={ - "kernel-compiler-paths": ["gcc-11/bin"], "kernel-image-target": {"arm64": "Image", "armhf": "Image.gz"}, }, arch="armv7l", @@ -277,27 +270,6 @@ def test_check_get_build_environment_compiler_paths_cross( "DEB_ARCH": "${CRAFT_TARGET_ARCH}", "KERNEL_BUILD_ARCH_DIR": "${CRAFT_PART_BUILD}/arch/arm/boot", "KERNEL_IMAGE_TARGET": "Image.gz", - "PATH": "${CRAFT_STAGE}/gcc-11/bin:${PATH}", - } - - def test_check_get_build_environment_compiler_paths( - self, setup_method_fixture, new_dir - ): - plugin = setup_method_fixture( - new_dir, - properties={ - "kernel-compiler-paths": ["gcc-11/bin", "gcc-11/sbin"], - }, - ) - plugin._kernel_arch = "amd64" - - assert plugin.get_build_environment() == { - "CROSS_COMPILE": "${CRAFT_ARCH_TRIPLET}-", - "ARCH": plugin._kernel_arch, - "DEB_ARCH": "${CRAFT_TARGET_ARCH}", - "KERNEL_BUILD_ARCH_DIR": f"${{CRAFT_PART_BUILD}}/arch/{plugin._kernel_arch}/boot", - "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, - "PATH": "${CRAFT_STAGE}/gcc-11/bin:${CRAFT_STAGE}/gcc-11/sbin:${PATH}", } def test_check_get_build_command(self, setup_method_fixture, new_dir):