Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions snapcraft/linters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ def __init__(
name: str,
snap_metadata: "SnapMetadata",
lint: models.Lint | None,
build_base: str | None = None,
):
self._name = name
self._snap_metadata = snap_metadata
self._lint = lint or models.Lint(ignore=[])
self._build_base = build_base

@abc.abstractmethod
def run(self) -> list[LinterIssue]:
Expand Down
4 changes: 2 additions & 2 deletions snapcraft/linters/gpu_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def run(self) -> list[LinterIssue]:
current_path = Path()
issues: list[LinterIssue] = []

base = self._snap_metadata.base or "core24"
base = self._snap_metadata.base or self._build_base or "core24"
if base == "bare":
base = "core24"
base = self._build_base or "core24"

elf_files = elf_utils.get_elf_files(current_path)

Expand Down
4 changes: 3 additions & 1 deletion snapcraft/linters/linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def _update_status(status: LinterStatus, result: LinterResult) -> LinterStatus:
return status


def run_linters(location: Path, *, lint: models.Lint | None) -> list[LinterIssue]:
def run_linters(
location: Path, *, lint: models.Lint | None, build_base: str | None = None
) -> list[LinterIssue]:
"""Run all the defined linters.

:param location: The root of the snap payload subtree to run linters on.
Expand Down
54 changes: 53 additions & 1 deletion tests/unit/linters/test_gpu_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,5 +411,57 @@ def test_gpu_linter_classic_confinement(mocker, new_dir, mock_elf_files, base, f

issues = linters.run_linters(new_dir, lint=None)

# Classic confinement snaps should never trigger GPU linter warnings
assert len(issues) == 0


@pytest.mark.parametrize(
"base,build_base,expected_url",
[
pytest.param(
"bare",
"core26",
"https://ubuntu.com/frame/docs/26/how-to/use-snap-graphics/",
id="bare-with-build-base",
),
pytest.param(
None,
"core22",
"https://ubuntu.com/frame/docs/22/how-to/use-snap-graphics/",
id="none-with-build-base",
),
pytest.param(
"bare",
None,
"https://ubuntu.com/frame/docs/24/how-to/use-snap-graphics/",
id="bare-no-build-base-fallback",
),
],
)
def test_gpu_linter_build_base(mocker, base, build_base, expected_url):
"""Test that GPU linter respects build_base when base is bare or undefined."""
# 1. Create a dummy file object
mock_elf = Mock()
mock_elf.path = "lib/x86_64-linux-gnu/libGL.so.1"

# 2. Mock the file reader
mocker.patch(
"snapcraft.linters.gpu_linter.elf_utils.get_elf_files", return_value=[mock_elf]
)

# 3. Create a simple mock metadata object
mock_metadata = Mock()
mock_metadata.type = "app"
mock_metadata.confinement = "strict"
mock_metadata.base = base

# 4. Instantiate the linter DIRECTLY
linter = GpuLinter(
name="gpu", snap_metadata=mock_metadata, lint=None, build_base=build_base
)

# 5. Run the linter
issues = linter.run()

# 6. Verify the URL logic
assert len(issues) == 1
assert issues[0].url == expected_url