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

remove chisel part from Rockcraft's snap #758

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/how-to/code/create-slice/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ execute: |

cp openssl.yaml "${local_release}/slices"

snap install chisel --channel=latest/candidate
snap install chisel

chisel cut --release "${local_release}" --root "${local_root}" openssl_bins

Expand Down
5 changes: 4 additions & 1 deletion docs/how-to/code/install-slice/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ parts:
plugin: nil
source: chisel-releases/
source-type: local
override-build:
build-snaps:
- "chisel/latest/stable"
override-build: |
craftctl default
chisel cut --release ./ --root ${CRAFT_PART_INSTALL} openssl_bins
2 changes: 1 addition & 1 deletion docs/how-to/code/install-slice/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ execute: |
git clone -b ubuntu-22.04 https://github.com/canonical/chisel-releases/
# [docs:clone-chisel-releases-end]

sudo snap install chisel --channel=latest/candidate
sudo snap install chisel

# [docs:slice-exists]
chisel find --release=./chisel-releases/ openssl_bins
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
"craft-application>=4.0.0",
"craft-archives>=2.0.0",
"craft-cli",
"craft-parts>=2.1.2,!=2.1.3",
"craft-parts>=2.1.3",
"craft-platforms~=0.3",
"craft-providers>=2.0.4",
"overrides",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ craft-cli==2.10.1
# rockcraft (pyproject.toml)
craft-grammar==2.0.1
# via craft-application
craft-parts==2.1.2
craft-parts==2.1.3
# via
# craft-application
# rockcraft (pyproject.toml)
Expand Down
2 changes: 1 addition & 1 deletion requirements-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ craft-cli==2.10.1
# rockcraft (pyproject.toml)
craft-grammar==2.0.1
# via craft-application
craft-parts==2.1.2
craft-parts==2.1.3
# via
# craft-application
# rockcraft (pyproject.toml)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ craft-cli==2.10.1
# rockcraft (pyproject.toml)
craft-grammar==2.0.1
# via craft-application
craft-parts==2.1.2
craft-parts==2.1.3
# via
# craft-application
# rockcraft (pyproject.toml)
Expand Down
2 changes: 1 addition & 1 deletion rockcraft/extensions/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _apply_extension(
extension: Extension,
) -> None:
# Apply the root components of the extension (if any)
root_extension = extension.get_root_snippet()
root_extension = extension.get_root_snippet_extended()
for property_name, property_value in root_extension.items():
yaml_data[property_name] = _apply_extension_property(
yaml_data.get(property_name), property_value
Expand Down
36 changes: 36 additions & 0 deletions rockcraft/extensions/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,42 @@ def get_part_snippet(self) -> dict[str, Any]:
def get_parts_snippet(self) -> dict[str, Any]:
"""Return the parts to add to parts."""

@final
def is_chisel_installed(self) -> bool:
"""Determine whether chisel is installed in any part."""
has_chisel = False
parts = self.get_root_snippet().get("parts", {})

for data in parts.values():
if any(
s
for s in data.get("build-snaps", [])
if s == "chisel" or s.startswith("chisel/")
):
has_chisel = True
break

if not has_chisel:
return False
return True

@final
def get_root_snippet_extended(self) -> dict[str, Any]:
"""Inject chisel as build-snap if needed."""
root_snippet = self.get_root_snippet()
if not self.is_chisel_installed():
for part, data in root_snippet.get("parts", {}).items():
if any("_" in p for p in data.get("stage-packages", [])):
if root_snippet["parts"][part].get("build-snaps"):
root_snippet["parts"][part]["build-snaps"].append(
"chisel/latest/stable"
)
else:
root_snippet["parts"][part]["build-snaps"] = [
"chisel/latest/stable"
]
return root_snippet

@final
def validate(self, extension_name: str) -> None:
"""Validate that the extension can be used with the current project.
Expand Down
9 changes: 0 additions & 9 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,3 @@ parts:
- libbtrfs-dev
- libdevmapper-dev
- pkg-config

chisel:
plugin: nil
stage-snaps:
- chisel/latest/candidate
organize:
bin/chisel: libexec/rockcraft/chisel
stage:
- libexec/rockcraft/chisel
3 changes: 3 additions & 0 deletions tests/unit/extensions/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_fastapi_extension_default(tmp_path, fastapi_input_yaml, packages):
"fastapi-framework/runtime": {
"plugin": "nil",
"stage-packages": ["ca-certificates_data"],
"build-snaps": ["chisel/latest/stable"],
},
},
"services": {
Expand Down Expand Up @@ -219,11 +220,13 @@ def test_fastapi_extension_bare(tmp_path):
"source": ".",
"python-packages": ["uvicorn"],
"python-requirements": ["requirements.txt"],
"build-snaps": ["chisel/latest/stable"],
}
assert applied["parts"]["fastapi-framework/runtime"] == {
"plugin": "nil",
"override-build": "mkdir -m 777 ${CRAFT_PART_INSTALL}/tmp",
"stage-packages": ["bash_bins", "coreutils_bins", "ca-certificates_data"],
"build-snaps": ["chisel/latest/stable"],
}


Expand Down
1 change: 1 addition & 0 deletions tests/unit/extensions/test_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_go_extension_default(tmp_path, go_input_yaml):
"stage-packages": [
"ca-certificates_data",
],
"build-snaps": ["chisel/latest/stable"],
},
},
"services": {
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/extensions/test_gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_flask_extension_default(tmp_path, flask_input_yaml, packages):
"flask-framework/runtime": {
"plugin": "nil",
"stage-packages": ["ca-certificates_data"],
"build-snaps": ["chisel/latest/stable"],
},
"flask-framework/statsd-exporter": {
"build-snaps": ["go"],
Expand Down Expand Up @@ -297,6 +298,7 @@ def test_flask_extension_bare(tmp_path):
"plugin": "nil",
"override-build": "mkdir -m 777 ${CRAFT_PART_INSTALL}/tmp",
"stage-packages": ["bash_bins", "coreutils_bins", "ca-certificates_data"],
"build-snaps": ["chisel/latest/stable"],
}
assert applied["parts"]["flask-framework/dependencies"] == {
"plugin": "python",
Expand All @@ -305,6 +307,7 @@ def test_flask_extension_bare(tmp_path):
"source": ".",
"stage-packages": ["python3.10-venv_ensurepip"],
"build-environment": [{"PARTS_PYTHON_INTERPRETER": "python3.10"}],
"build-snaps": ["chisel/latest/stable"],
}


Expand Down Expand Up @@ -485,6 +488,7 @@ def test_django_extension_default(tmp_path, django_input_yaml):
"django-framework/runtime": {
"plugin": "nil",
"stage-packages": ["ca-certificates_data"],
"build-snaps": ["chisel/latest/stable"],
},
"django-framework/statsd-exporter": {
"build-snaps": ["go"],
Expand Down
Loading