Skip to content

Commit

Permalink
fix(jlink_plugin): drop chiselling dependencies
Browse files Browse the repository at this point in the history
Until canonical/craft-parts#833
is implemented, the Java dependencies will be chiselled by a separate
part.

JLink plugin may implement validation of the dependencies in a separate
PR.
  • Loading branch information
vpa1977 committed Aug 30, 2024
1 parent d23ed5f commit 3ba87e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
11 changes: 0 additions & 11 deletions rockcraft/plugins/jlink_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class JLinkPluginProperties(PluginProperties, frozen=True):
plugin: Literal["jlink"] = "jlink"
jlink_java_version: int = 21
jlink_jars: list[str] = []
jlink_dep_slices: list[str] = []


class JLinkPlugin(Plugin):
Expand All @@ -55,16 +54,6 @@ def get_build_commands(self) -> List[str]:
options = cast(JLinkPluginProperties, self._options)

commands = []
slices = " ".join(options.jlink_dep_slices)
if len(slices) == 0:
slices = f"base-files_base openjdk-{options.jlink_java_version}-jre-headless_core"

if hasattr(options, "source") and isinstance(options.source, str):
commands.append(
"chisel cut --release ./ --root ${CRAFT_PART_INSTALL} " + slices
)
else:
commands.append("chisel cut --root ${CRAFT_PART_INSTALL} " + slices)

if len(options.jlink_jars) > 0:
jars = " ".join(["${CRAFT_STAGE}/" + x for x in options.jlink_jars])
Expand Down
46 changes: 11 additions & 35 deletions tests/unit/plugins/test_jlink_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,57 +61,33 @@ def test_get_build_environment(self, setup_method_fixture, new_dir):

assert plugin.get_build_environment() == {}

def test_get_build_commands_default(self, setup_method_fixture, new_dir):
plugin = setup_method_fixture(new_dir)
@pytest.mark.parametrize("version", [None, "21", "17"])
def test_get_build_commands(self, setup_method_fixture, new_dir, version):

commands = plugin.get_build_commands()
assert (
"chisel cut --root ${CRAFT_PART_INSTALL} base-files_base openjdk-21-jre-headless_core"
in commands
)
assert "PROCESS_JARS=$(find ${CRAFT_STAGE} -type f -name *.jar)" in commands

def test_get_build_commands_17(self, setup_method_fixture, new_dir):
plugin = setup_method_fixture(new_dir, properties={"jlink-java-version": "17"})
if version is None:
plugin = setup_method_fixture(new_dir)
version = "21"
else:
plugin = setup_method_fixture(new_dir, properties={"jlink-java-version": version})

commands = plugin.get_build_commands()
assert (
"chisel cut --root ${CRAFT_PART_INSTALL} base-files_base openjdk-17-jre-headless_core"
in commands
)
assert "PROCESS_JARS=$(find ${CRAFT_STAGE} -type f -name *.jar)" in commands
assert (
"""if [ "x${PROCESS_JARS}" != "x" ]; then
deps=$(jdeps --class-path=${CPATH} -q --recursive --ignore-missing-deps \
--print-module-deps --multi-release 17 ${PROCESS_JARS}); else deps=java.base; fi
--print-module-deps --multi-release """+version+ """ ${PROCESS_JARS}); else deps=java.base; fi
"""
in commands
)
assert (
"INSTALL_ROOT=${CRAFT_PART_INSTALL}/usr/lib/jvm/java-17-openjdk-${CRAFT_TARGET_ARCH}/"
"INSTALL_ROOT=${CRAFT_PART_INSTALL}/usr/lib/jvm/java-"+version+ "-openjdk-${CRAFT_TARGET_ARCH}/"
in commands
)
assert (
"(cd ${CRAFT_PART_INSTALL} && mkdir -p usr/bin && ln -s --relative usr/lib/jvm/java-17-openjdk-${CRAFT_TARGET_ARCH}/bin/java usr/bin/)"
"(cd ${CRAFT_PART_INSTALL} && mkdir -p usr/bin && ln -s --relative usr/lib/jvm/java-"+version+ "-openjdk-${CRAFT_TARGET_ARCH}/bin/java usr/bin/)"
in commands
)

def test_get_build_commands_chisel_source(self, setup_method_fixture, new_dir):
plugin = setup_method_fixture(new_dir, properties={"source": "foo"})

commands = plugin.get_build_commands()
assert (
"chisel cut --release ./ --root ${CRAFT_PART_INSTALL} base-files_base openjdk-21-jre-headless_core"
in commands
)
assert "PROCESS_JARS=$(find ${CRAFT_STAGE} -type f -name *.jar)" in commands

def test_get_build_commands_jars(self, setup_method_fixture, new_dir):
plugin = setup_method_fixture(new_dir, properties={"jlink-jars": ["foo.jar"]})
assert "PROCESS_JARS=${CRAFT_STAGE}/foo.jar" in plugin.get_build_commands()

def test_get_build_commands_deps(self, setup_method_fixture, new_dir):
plugin = setup_method_fixture(
new_dir, properties={"jlink-dep-slices": ["base-files_base"]}
)
commands = plugin.get_build_commands()
assert "chisel cut --root ${CRAFT_PART_INSTALL} base-files_base" in commands

0 comments on commit 3ba87e2

Please sign in to comment.