Skip to content

Commit

Permalink
many: Address reviews
Browse files Browse the repository at this point in the history
- doc: Add line break on Pydoc
- rust exporter: Fix error messages
- spread: Add case to test app-specific envfile
- spread: Fix test for verify alias overrite behavior
- fix: typo error
- fix: commentaries not being discarted in envfiles
- feat: add logs to check test execution
- fix: shellchek error
- fix: use absolute path for envfiles
- fix: address lint errors
- fix: PEP8 formating
- exporter program moved to:
  https://github.com/canonical/snappy-env

Signed-off-by: Lincoln Wallace <lincoln.wallace@canonical.com>
Co-authored-by: Farshid Tavakolizadeh <email@farshid.ws>
Co-authored-by: Callahan <callahan.kovacs@canonical.com>
  • Loading branch information
3 people committed Oct 1, 2024
1 parent f912dd5 commit 6fa6f67
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 271 deletions.
21 changes: 0 additions & 21 deletions extensions/env-injector/Cargo.toml

This file was deleted.

161 changes: 0 additions & 161 deletions extensions/env-injector/src/main.rs

This file was deleted.

49 changes: 23 additions & 26 deletions snapcraft/extensions/env_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

from overrides import overrides

from .extension import Extension, get_extensions_data_dir
from .extension import Extension


class EnvInjectorExtension(Extension):
class EnvInjector(Extension):
"""Extension to automatically set environment variables on snaps.
This extension allows you to transform snap options into environment
Expand All @@ -46,6 +46,10 @@ class EnvInjectorExtension(Extension):
.. code-block:: shell
sudo snap set <snap-name> env-file=<path-to-env-file>
- To set environment file for a specific app:
.. code-block:: shell
sudo snap set <snap-name> apps.<app-name>.envfile=<path-to-env-file>
"""

Expand Down Expand Up @@ -80,47 +84,40 @@ def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:

@overrides
def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
return {"build-environment": [{"SNAPCRAFT_ENV_INJECTOR_EXTENSION": "true"}]}
return {}

@overrides
def get_parts_snippet(self) -> Dict[str, Any]:
toolchain = self.get_toolchain()
toolchain = self.get_toolchain(self.arch)
if toolchain is None:
raise ValueError(
f"Unsupported architecture for env-injector extension: {self.arch}"
)

return {
"env-injector/env-injector": {
"source": f"{get_extensions_data_dir()}/env-injector",
"source": "https://github.com/canonical/snappy-env.git",
"source-tag": "v1.0.0-beta",
"plugin": "nil",
"build-snaps": [
"rustup",
],
"build-packages": [
"musl-tools", # for static linking
"upx-ucl", # for binary compression
],
"build-snaps": ["rustup"],
"build-packages": ["upx-ucl"], # for binary compression
"override-build": f"""
rustup default stable
rustup target add {toolchain}
rustup default stable
rustup target add {toolchain}
cargo build --target {toolchain} --release
mkdir -p $SNAPCRAFT_PART_INSTALL/bin/command-chain
cp target/{toolchain}/release/env-exporter $SNAPCRAFT_PART_INSTALL/bin/command-chain
# compress the binary
upx --best --lzma target/{toolchain}/release/env-exporter
cp target/{toolchain}/release/env-exporter $SNAPCRAFT_PART_INSTALL/bin/command-chain/env-exporter-upx
cargo build --target {toolchain} --release
mkdir -p $SNAPCRAFT_PART_INSTALL/bin/command-chain
# compress the binary
upx --best --lzma target/{toolchain}/release/env-exporter
cp target/{toolchain}/release/env-exporter $SNAPCRAFT_PART_INSTALL/bin/command-chain
""",
}
}

def get_toolchain(self):
def get_toolchain(self, arch: str):
"""Get the Rust toolchain for the current architecture."""
# Dictionary mapping architecture names
toolchain = {
"amd64": "x86_64-unknown-linux-gnu",
"arm64": "aarch64-unknown-linux-gnu",
Expand All @@ -129,4 +126,4 @@ def get_toolchain(self):
# 'ppc64el': 'powerpc64-unknown-linux-gnu', # Tier 2 toolchain
# 's390x': 's390x-unknown-linux-gnu', # Tier 2 toolchain
}
return toolchain.get(self.arch)
return toolchain.get(arch)
4 changes: 2 additions & 2 deletions snapcraft/extensions/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from snapcraft import errors

from .env_injector import EnvInjectorExtension
from .env_injector import EnvInjector
from .gnome import GNOME
from .kde_neon import KDENeon
from .kde_neon_6 import KDENeon6
Expand All @@ -39,7 +39,7 @@
ExtensionType = Type[Extension]

_EXTENSIONS: Dict[str, "ExtensionType"] = {
"env-injector": EnvInjectorExtension,
"env-injector": EnvInjector,
"gnome": GNOME,
"ros2-humble": ROS2HumbleExtension,
"ros2-humble-ros-core": ROS2HumbleRosCoreExtension,
Expand Down
Loading

0 comments on commit 6fa6f67

Please sign in to comment.