launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29309
[Merge] ~andrey-fedoseev/launchpad:snap-base-features into launchpad:master
Andrey Fedoseev has proposed merging ~andrey-fedoseev/launchpad:snap-base-features into launchpad:master.
Commit message:
Use `SnapBase.features` in `snapcraft.yaml` parser
to determine whether duplicate build-on values are allowed instead of relying on snap base name
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~andrey-fedoseev/launchpad/+git/launchpad/+merge/431544
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~andrey-fedoseev/launchpad:snap-base-features into launchpad:master.
diff --git a/lib/lp/snappy/adapters/buildarch.py b/lib/lp/snappy/adapters/buildarch.py
index 102eb74..eb87a7d 100644
--- a/lib/lp/snappy/adapters/buildarch.py
+++ b/lib/lp/snappy/adapters/buildarch.py
@@ -9,6 +9,8 @@ from collections import Counter
from typing import Any, Dict, List, Optional, Union
from lp.services.helpers import english_list
+from lp.snappy.interfaces.snapbase import SnapBaseFeature
+from lp.snappy.model.snapbase import SnapBase
class SnapArchitecturesParserError(Exception):
@@ -146,7 +148,7 @@ class SnapBuildInstance:
def determine_architectures_to_build(
- snap_base: Optional[str],
+ snap_base: Optional[SnapBase],
snapcraft_data: Dict[str, Any],
supported_arches: List[str],
) -> List[SnapBuildInstance]:
@@ -184,7 +186,11 @@ def determine_architectures_to_build(
SnapArchitecture(build_on=a) for a in supported_arches
]
- if snap_base not in {"core22"}:
+ allow_duplicate_build_on = (
+ snap_base
+ and snap_base.features.get(SnapBaseFeature.ALLOW_DUPLICATE_BUILD_ON)
+ ) or False
+ if not allow_duplicate_build_on:
# Ensure that multiple `build-on` items don't include the same
# architecture; this is ambiguous and forbidden by snapcraft prior
# to core22. Checking this here means that we don't get duplicate
diff --git a/lib/lp/snappy/adapters/tests/test_buildarch.py b/lib/lp/snappy/adapters/tests/test_buildarch.py
index db52baf..8a9ef2e 100644
--- a/lib/lp/snappy/adapters/tests/test_buildarch.py
+++ b/lib/lp/snappy/adapters/tests/test_buildarch.py
@@ -11,7 +11,9 @@ from lp.snappy.adapters.buildarch import (
UnsupportedBuildOnError,
determine_architectures_to_build,
)
-from lp.testing import TestCase
+from lp.snappy.interfaces.snapbase import SnapBaseFeature
+from lp.testing import TestCase, TestCaseWithFactory
+from lp.testing.layers import ZopelessDatabaseLayer
class TestSnapArchitecture(WithScenarios, TestCase):
@@ -174,11 +176,12 @@ class TestSnapBuildInstanceError(TestCase):
self.assertEqual(["amd64"], raised.build_on)
-class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
-
+class TestDetermineArchitecturesToBuild(WithScenarios, TestCaseWithFactory):
# Scenarios taken from the architectures document:
# https://forum.snapcraft.io/t/architectures/4972
+ layer = ZopelessDatabaseLayer
+
scenarios = [
(
"none",
@@ -396,6 +399,9 @@ class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
(
"multiple build-for for the same build-on",
{
+ "snap_base_features": {
+ SnapBaseFeature.ALLOW_DUPLICATE_BUILD_ON: True
+ },
"architectures": [
{"build-on": "amd64", "build-for": ["amd64"]},
{"build-on": "amd64", "build-for": ["i386"]},
@@ -418,7 +424,9 @@ class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
(
"multiple build-for for the same build-on: old base",
{
- "snap_base": "core20",
+ "snap_base_features": {
+ SnapBaseFeature.ALLOW_DUPLICATE_BUILD_ON: False
+ },
"architectures": [
{"build-on": "amd64", "build-for": ["amd64"]},
{"build-on": "amd64", "build-for": ["i386"]},
@@ -431,7 +439,8 @@ class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
def test_parser(self):
snapcraft_data = {"architectures": self.architectures}
- snap_base = getattr(self, "snap_base", "core22")
+ snap_base_features = getattr(self, "snap_base_features", {})
+ snap_base = self.factory.makeSnapBase(features=snap_base_features)
if hasattr(self, "expected_exception"):
self.assertRaises(
self.expected_exception,
diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
index 7728ecf..e60040f 100644
--- a/lib/lp/snappy/model/snap.py
+++ b/lib/lp/snappy/model/snap.py
@@ -1009,7 +1009,7 @@ class Snap(Storm, WebhookTargetMixin):
)
)
architectures_to_build = determine_architectures_to_build(
- snap_base.name if snap_base is not None else None,
+ snap_base,
snapcraft_data,
list(supported_arches.keys()),
)