From 340d08504141cc9b91e54ca1eeb5532ea14ccc1b Mon Sep 17 00:00:00 2001 From: Yanks Yoon <37652070+yanksyoon@users.noreply.github.com> Date: Mon, 10 Feb 2025 19:49:12 +0800 Subject: [PATCH 01/13] fix: CPATH persistence --- craft_parts/plugins/jlink_plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/craft_parts/plugins/jlink_plugin.py b/craft_parts/plugins/jlink_plugin.py index 593847337..c9266dbda 100644 --- a/craft_parts/plugins/jlink_plugin.py +++ b/craft_parts/plugins/jlink_plugin.py @@ -125,11 +125,11 @@ 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 + 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 """ ) From ca6898df504121055908bad6dc740cca63e27180 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Mon, 10 Feb 2025 11:55:12 +0000 Subject: [PATCH 02/13] docs: update changelog --- docs/reference/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index beda40ffb..ecca8f2f8 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -9,6 +9,7 @@ Bug fixes: - Allow for a non-specific system Python interpreter when using the :ref:`uv plugin`. +- Fix CPATH variable scope in the :ref:`jlink plugin`. For a complete list of commits, check out the `2.3.1`_ release on GitHub. From 2a05016938fb5194a9ca9b5dccaef85b07c2b031 Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Tue, 11 Feb 2025 09:21:35 +1300 Subject: [PATCH 03/13] fix: set --print-module-deps as first argument A bug in jdeps causes --print-module-deps to ignore recursive settings when it is present on classpath after --recursive. --- craft_parts/plugins/jlink_plugin.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/craft_parts/plugins/jlink_plugin.py b/craft_parts/plugins/jlink_plugin.py index c9266dbda..7d18e343d 100644 --- a/craft_parts/plugins/jlink_plugin.py +++ b/craft_parts/plugins/jlink_plugin.py @@ -135,8 +135,11 @@ def get_build_commands(self) -> list[str]: ) 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 From d35958ef5958a9fb0e869efcd381d633d7d5d65b Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Tue, 11 Feb 2025 09:21:51 +1300 Subject: [PATCH 04/13] test(jlink_plugin): add embedded jar test --- tests/integration/plugins/test_jlink.py | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/integration/plugins/test_jlink.py b/tests/integration/plugins/test_jlink.py index f7a6665a1..8b968d8f8 100644 --- a/tests/integration/plugins/test_jlink.py +++ b/tests/integration/plugins/test_jlink.py @@ -22,6 +22,62 @@ import yaml 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 + source-type: git + 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 + 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""" From bd8a0f6fb2a309db308322c1766646abbce78757 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 11 Feb 2025 00:36:39 +0000 Subject: [PATCH 05/13] chore: lint fixes --- tests/integration/plugins/test_jlink.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/integration/plugins/test_jlink.py b/tests/integration/plugins/test_jlink.py index 8b968d8f8..89721f56a 100644 --- a/tests/integration/plugins/test_jlink.py +++ b/tests/integration/plugins/test_jlink.py @@ -22,6 +22,7 @@ import yaml from craft_parts import LifecycleManager, Step, errors + def test_jlink_plugin_embedded_jar(new_dir, partitions): parts_yaml = textwrap.dedent( """ @@ -61,10 +62,18 @@ def test_jlink_plugin_embedded_jar(new_dir, partitions): """ ) - 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 + ["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( From 4dd8acd3bca84b62c988bc424314a6ac0b34abf4 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 11 Feb 2025 01:42:35 +0000 Subject: [PATCH 06/13] docs: add jdeps parameter ordering changes to changelog --- docs/reference/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index ecca8f2f8..3ff3f6d25 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -10,6 +10,7 @@ Bug fixes: - Allow for a non-specific system Python interpreter when using the :ref:`uv plugin`. - Fix CPATH variable scope in the :ref:`jlink plugin`. +- Fix Jdeps parameter ordering. For a complete list of commits, check out the `2.3.1`_ release on GitHub. From 0bbd6e1fca555b2e822697fdfde19e7304b8cd6c Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 11 Feb 2025 01:43:21 +0000 Subject: [PATCH 07/13] docs: add CPATH to wordlist --- docs/common/craft-parts/craft-parts.wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/common/craft-parts/craft-parts.wordlist.txt b/docs/common/craft-parts/craft-parts.wordlist.txt index 89d1bb9af..90c0c3ff4 100644 --- a/docs/common/craft-parts/craft-parts.wordlist.txt +++ b/docs/common/craft-parts/craft-parts.wordlist.txt @@ -44,6 +44,7 @@ Config ConfigDict CopyFileNotFound CopyTreeError +CPATH CraftCtl Craftctl DESTDIR From ac3de0a9229c216ff8f76ed50122b8b8753e43b9 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 11 Feb 2025 12:37:57 +0000 Subject: [PATCH 08/13] test: refactor test jar build part --- tests/integration/plugins/test_jlink.py | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/integration/plugins/test_jlink.py b/tests/integration/plugins/test_jlink.py index 89721f56a..53a4ebb03 100644 --- a/tests/integration/plugins/test_jlink.py +++ b/tests/integration/plugins/test_jlink.py @@ -22,26 +22,8 @@ import yaml 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 - source-type: git - 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 +@pytest.fixture() +def build_test_jar(): Path("Test.java").write_text( """ public class Test { @@ -76,6 +58,24 @@ def test_jlink_plugin_embedded_jar(new_dir, partitions): capture_output=True, ) +@pytest.mark.usefixtures("build_test_jar") +def test_jlink_plugin_embedded_jar(new_dir, partitions): + parts_yaml = textwrap.dedent( + """ + parts: + my-part: + plugin: jlink + source: . + source-branch: ubuntu-24.04 + jlink-jars: ["test.jar"] + after: ["stage-jar"] + stage-jar: + plugin: dump + source: . + """ + ) + parts = yaml.safe_load(parts_yaml) + lf = LifecycleManager( parts, application_name="test_jlink", cache_dir=new_dir, partitions=partitions ) From da5bd1aa017b3a2bd3d334de7cfb09761fdf14c2 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 11 Feb 2025 12:38:13 +0000 Subject: [PATCH 09/13] docs: update changelog --- docs/reference/changelog.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 3ff3f6d25..d339ff446 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -2,6 +2,15 @@ Changelog ********* +2.5.1 (2025-02-11) +------------------ + +Bug fixes: + +- Fix CPATH variable scope in the :ref:`jlink plugin`. +- Fix Jdeps parameter ordering. + + 2.3.1 (2025-02-07) ------------------ @@ -9,8 +18,6 @@ Bug fixes: - Allow for a non-specific system Python interpreter when using the :ref:`uv plugin`. -- Fix CPATH variable scope in the :ref:`jlink plugin`. -- Fix Jdeps parameter ordering. For a complete list of commits, check out the `2.3.1`_ release on GitHub. From 970655b2692ad21c30f2a576f9e97fc24542558a Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 11 Feb 2025 12:45:02 +0000 Subject: [PATCH 10/13] chore: fix lint errors in test --- tests/integration/plugins/test_jlink.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/plugins/test_jlink.py b/tests/integration/plugins/test_jlink.py index 53a4ebb03..87820ae08 100644 --- a/tests/integration/plugins/test_jlink.py +++ b/tests/integration/plugins/test_jlink.py @@ -22,6 +22,7 @@ import yaml from craft_parts import LifecycleManager, Step, errors + @pytest.fixture() def build_test_jar(): Path("Test.java").write_text( @@ -58,6 +59,7 @@ def build_test_jar(): capture_output=True, ) + @pytest.mark.usefixtures("build_test_jar") def test_jlink_plugin_embedded_jar(new_dir, partitions): parts_yaml = textwrap.dedent( From b0bba6b596eef5070b04d2f0633a451e9fb9f108 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Wed, 12 Feb 2025 04:44:20 +0000 Subject: [PATCH 11/13] test: explicit fixture deps --- tests/integration/plugins/test_jlink.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/plugins/test_jlink.py b/tests/integration/plugins/test_jlink.py index 87820ae08..4825d2ce2 100644 --- a/tests/integration/plugins/test_jlink.py +++ b/tests/integration/plugins/test_jlink.py @@ -24,7 +24,7 @@ @pytest.fixture() -def build_test_jar(): +def build_test_jar(new_dir): Path("Test.java").write_text( """ public class Test { @@ -68,7 +68,6 @@ def test_jlink_plugin_embedded_jar(new_dir, partitions): my-part: plugin: jlink source: . - source-branch: ubuntu-24.04 jlink-jars: ["test.jar"] after: ["stage-jar"] stage-jar: From c329eacc82126c9a086cc4178bf834d51c4c997b Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Wed, 12 Feb 2025 04:44:41 +0000 Subject: [PATCH 12/13] docs: update release date & add ref to jlinkfix --- docs/reference/changelog.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index d339ff446..875d2956c 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -2,13 +2,14 @@ Changelog ********* -2.5.1 (2025-02-11) +2.5.1 (2025-02-12) ------------------ Bug fixes: - Fix CPATH variable scope in the :ref:`jlink plugin`. -- Fix Jdeps parameter ordering. +- Fix Jdeps parameter ordering in the + :ref:`jlink plugin`. 2.3.1 (2025-02-07) From 3aa900c9c14ab5c965a5723a55b3e72db8b03375 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Wed, 12 Feb 2025 04:49:01 +0000 Subject: [PATCH 13/13] fix: linting --- tests/integration/plugins/test_jlink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/plugins/test_jlink.py b/tests/integration/plugins/test_jlink.py index 4825d2ce2..05a599982 100644 --- a/tests/integration/plugins/test_jlink.py +++ b/tests/integration/plugins/test_jlink.py @@ -23,7 +23,7 @@ from craft_parts import LifecycleManager, Step, errors -@pytest.fixture() +@pytest.fixture def build_test_jar(new_dir): Path("Test.java").write_text( """