From 3795f422f149d9f4a5183843806623f0e95a1f26 Mon Sep 17 00:00:00 2001 From: Tiago Nobrega Date: Fri, 17 Jan 2025 11:10:48 -0300 Subject: [PATCH 1/2] fix: use source-subdir in go-use plugin It's possible, and somewhat common, for a go module to be defined inside a repo's subdir; in this case we can define source-subdir, but the go-use plugin needs to use this - otherwise the repo root gets used. Fixes #978 --- craft_parts/plugins/go_use_plugin.py | 2 +- tests/unit/plugins/test_go_use_plugin.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/craft_parts/plugins/go_use_plugin.py b/craft_parts/plugins/go_use_plugin.py index 8700beb3c..441db3c45 100644 --- a/craft_parts/plugins/go_use_plugin.py +++ b/craft_parts/plugins/go_use_plugin.py @@ -100,5 +100,5 @@ def get_build_commands(self) -> list[str]: ) return [ - f"go work use {self._part_info.part_src_dir}", + f"go work use {self._part_info.part_src_subdir}", ] diff --git a/tests/unit/plugins/test_go_use_plugin.py b/tests/unit/plugins/test_go_use_plugin.py index 0a59b889c..ed5f239a9 100644 --- a/tests/unit/plugins/test_go_use_plugin.py +++ b/tests/unit/plugins/test_go_use_plugin.py @@ -167,7 +167,7 @@ def test_get_build_commands(mocker, part_info, go_workspace): ) assert plugin.get_build_commands() == [ - f"go work use {plugin._part_info.part_src_dir}", + f"go work use {plugin._part_info.part_src_subdir}", ] run_mock.assert_called_once_with( ["go", "work", "init"], capture_output=True, check=True, cwd=go_workspace.parent @@ -182,6 +182,24 @@ def test_get_build_commands_workspace_in_use(mocker, part_info): run_mock = mocker.patch("subprocess.run") assert plugin.get_build_commands() == [ - f"go work use {plugin._part_info.part_src_dir}", + f"go work use {plugin._part_info.part_src_subdir}", + ] + run_mock.assert_not_called() + + +@pytest.mark.usefixtures("go_workspace") +def test_get_build_commands_subdir(mocker, new_dir): + part_spec = {"source": ".", "source-subdir": "my/subdir"} + part_info = PartInfo( + project_info=ProjectInfo(application_name="test", cache_dir=new_dir), + part=Part("my-part", part_spec), + ) + properties = GoUsePlugin.properties_class.unmarshal(part_spec) + plugin = GoUsePlugin(properties=properties, part_info=part_info) + + run_mock = mocker.patch("subprocess.run") + + assert plugin.get_build_commands() == [ + f"go work use {plugin._part_info.part_src_subdir}", ] run_mock.assert_not_called() From ff28191e355da4e28eda289b9b83a9cad7f64c29 Mon Sep 17 00:00:00 2001 From: Tiago Nobrega Date: Fri, 17 Jan 2025 13:54:06 -0300 Subject: [PATCH 2/2] docs: fix changelog, add go-use bugfix --- docs/reference/changelog.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 3c669509f..75757c067 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -2,18 +2,28 @@ Changelog ********* -2.2.2 (2025-MM-DD) +X.Y.Z (2025-MM-DD) ------------------ Bug fixes: - Make sure the :ref:`uv plugin` is re-entrant on source changes. +- Correctly handle ``source-subdir`` values on the ``go-use`` plugin. Documentation: - Correct the Maven plugin docstring to refer to Maven from Go. + +2.2.2 (2025-MM-DD) +------------------ + +Documentation: + +- Add a cross-reference target for Poetry external links. + + 2.2.1 (2024-12-19) ------------------