Skip to content

Commit

Permalink
plugin: kernel: remove unused kernel-compiler-paths option
Browse files Browse the repository at this point in the history
Generic build-environment part option can be used instead.

Signed-off-by: Ondrej Kubik <ondrej.kubik@canonical.com>
  • Loading branch information
kubiko committed Sep 12, 2023
1 parent 280878b commit 05f8b40
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 112 deletions.
22 changes: 1 addition & 21 deletions snapcraft/parts/plugins/kernel_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -323,27 +316,14 @@ 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}",
"KERNEL_BUILD_ARCH_DIR": f"${{CRAFT_PART_BUILD}}/arch/{self._kernel_arch}/boot",
"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...")
Expand Down
28 changes: 1 addition & 27 deletions snapcraft_legacy/plugins/v2/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -337,27 +324,14 @@ 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}",
"KERNEL_BUILD_ARCH_DIR": f"${{SNAPCRAFT_PART_BUILD}}/arch/{self._kernel_arch}/boot",
"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...")
Expand Down
36 changes: 1 addition & 35 deletions tests/legacy/unit/plugins/v2/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -66,7 +65,6 @@ def _setup_test(
kernelwithfirmware=True,
kerneldevicetrees=None,
kernelcompiler=None,
kernelcompilerpaths=None,
kernelcompilerparameters=None,
kernelenablezfssupport=False,
kernelenableperf=False,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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",
)
Expand All @@ -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}",
},
)

Expand Down
30 changes: 1 addition & 29 deletions tests/unit/parts/plugins/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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):
Expand Down

0 comments on commit 05f8b40

Please sign in to comment.