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

fix: CPATH persistence #1014

Merged
merged 14 commits into from
Feb 12, 2025
15 changes: 9 additions & 6 deletions craft_parts/plugins/jlink_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,21 @@ def get_build_commands(self) -> list[str]:
commands.append("CPATH=.")
commands.append(
"""
find ${CRAFT_PART_BUILD}/tmp -type f -name *.jar | while IFS= read -r file; do
CPATH=$CPATH:${file}
for file in $(find "${CRAFT_PART_BUILD}/tmp" -type f -name "*.jar"); do
yanksyoon marked this conversation as resolved.
Show resolved Hide resolved
CPATH="$CPATH:${file}"
done
find ${CRAFT_STAGE} -type f -name *.jar | while IFS= read -r file; do
CPATH=$CPATH:${file}
for file in $(find "${CRAFT_STAGE}" -type f -name "*.jar"); do
CPATH="$CPATH:${file}"
done
"""
)
commands.append(
"""if [ "x${PROCESS_JARS}" != "x" ]; then
deps=$(${JDEPS} --class-path=${CPATH} -q --recursive --ignore-missing-deps \
--print-module-deps --multi-release ${MULTI_RELEASE} ${PROCESS_JARS})
deps=$(${JDEPS} --print-module-deps -q --recursive \
--ignore-missing-deps \
--multi-release ${MULTI_RELEASE} \
--class-path=${CPATH} \
${PROCESS_JARS})
else
deps=java.base
fi
Expand Down
1 change: 1 addition & 0 deletions docs/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bug fixes:

- Allow for a non-specific system Python interpreter when using the
:ref:`uv plugin<craft_parts_uv_plugin>`.
- Fix CPATH variable scope in the :ref:`jlink plugin<craft_parts_jlink_plugin>`.
yanksyoon marked this conversation as resolved.
Show resolved Hide resolved

For a complete list of commits, check out the `2.3.1`_ release on GitHub.

Expand Down
65 changes: 65 additions & 0 deletions tests/integration/plugins/test_jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,71 @@
from craft_parts import LifecycleManager, Step, errors


def test_jlink_plugin_embedded_jar(new_dir, partitions):
parts_yaml = textwrap.dedent(
"""
parts:
my-part:
plugin: jlink
source: https://github.com/canonical/chisel-releases
yanksyoon marked this conversation as resolved.
Show resolved Hide resolved
source-type: git
yanksyoon marked this conversation as resolved.
Show resolved Hide resolved
source-branch: ubuntu-24.04
jlink-jars: ["test.jar"]
after: ["stage-jar"]
stage-jar:
plugin: dump
source: .
"""
)
parts = yaml.safe_load(parts_yaml)

# build test jar
yanksyoon marked this conversation as resolved.
Show resolved Hide resolved
Path("Test.java").write_text(
"""
public class Test {
public static void main(String[] args) {
new Embedded();
}
}
"""
)
Path("Embedded.java").write_text(
"""
import javax.swing.*;
public class Embedded {
public Embedded() {
new JFrame("foo").setVisible(true);
}
}

"""
)
subprocess.run(
["javac", "Test.java", "Embedded.java"], check=True, capture_output=True
)
subprocess.run(
["jar", "cvf", "embedded.jar", "Embedded.class"],
check=True,
capture_output=True,
)
subprocess.run(
["jar", "cvf", "test.jar", "Test.class", "embedded.jar"],
check=True,
capture_output=True,
)

lf = LifecycleManager(
parts, application_name="test_jlink", cache_dir=new_dir, partitions=partitions
)
actions = lf.plan(Step.PRIME)

with lf.action_executor() as ctx:
ctx.execute(actions)

# java.desktop module should be included in the image
assert len(list(Path(f"{new_dir}/stage/usr/lib/jvm/").rglob("libawt.so"))) > 0


def test_jlink_plugin_with_jar(new_dir, partitions):
"""Test that jlink produces tailored modules"""

Expand Down
Loading