Skip to content

Commit

Permalink
Merge branch 'main' into feat_yaml_check
Browse files Browse the repository at this point in the history
  • Loading branch information
clay-lake authored Dec 6, 2024
2 parents 5241995 + 78db3b8 commit cd3dc26
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mock_rock/1.0/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: mock-rock
summary: Hello World
description: The most basic example of a rock.
version: "1.0"
base: bare
build-base: ubuntu@22.04
license: Apache-2.0
platforms:
amd64:
arm64:

parts:
hello:
plugin: nil
stage-packages:
- hello
15 changes: 15 additions & 0 deletions mock_rock/1.1/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: mock-rock
summary: Hello World
description: The most basic example of a rock.
version: "1.1"
base: bare
build-base: ubuntu@22.04
license: Apache-2.0
platforms:
amd64:

parts:
hello:
plugin: nil
stage-packages:
- hello
15 changes: 15 additions & 0 deletions mock_rock/1.2/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: mock-rock
summary: Hello World
description: The most basic example of a rock.
version: "1.2"
base: bare
build-base: ubuntu@22.04
license: Apache-2.0
platforms:
amd64:

parts:
hello:
plugin: nil
stage-packages:
- hello
21 changes: 21 additions & 0 deletions rockcraft_snap_patcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Rockcraft Patcher

`patcher.sh` enables quick rockcraft "builds" for development by patching
an existing snap package with changes made to dependencies on the local
system.

## How to use

0. Clone rockcraft, craft-application, craft-providers and craft-parts.
1. Build a Rockcraft snap package to use as a donor for the patched package.
2. Place the the `patcher.sh` sciprt in the rockcraft source directory.
3. Edit the paths in the script to point to the other craft repositories on
your system as well as the donor package.
4. Run `patcher.sh` to create the patched package and install it to the system.
The installation can be verified by checking `snap list`. Rockcraft should show
a version number similar to `local-patch-<timestamp>`.

`patcher.sh` can be run as needed for testing changes made to the local repos.

## TODO:
- Support debugging Python in rockcraft. Include VSCodes launch.json
52 changes: 52 additions & 0 deletions rockcraft_snap_patcher/patcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /bin/bash

# Rockcraft snap package patcher
# Version 4

set -xe

# configurable vars
src_snap="rockcraft_1.5.3.post51+gc99aa44.d20241011_amd64.snap" # snap package to modify
rockcraft="." # Path to rockcraft repo
craft_application="../craft-application/" # Path to craft_application repo
craft_providers="../craft-providers/" # Path to craft_providers repo
craft_parts="../craft-parts/" # Path to craft_providers repo


# setup
snap_rootfs=$(mktemp -d -p "./.patcher/")
sudo mkdir -p "$snap_rootfs"

# unpack rootfs
unsquashfs -f -d "$snap_rootfs" "$src_snap"
snap_name=$(yq '.name' "$snap_rootfs/meta/snap.yaml")
# snap_src_version=$(yq '.version' "$snap_rootfs/meta/snap.yaml")
snap_arch=$(yq '.architectures[0]' "$snap_rootfs/meta/snap.yaml") #TODO: support multi arch?
snap_python_bin=$(readlink -f "$snap_rootfs/bin/python")
snap_python_name=$(basename $snap_python_bin) # used in locating craft libraries


# modify snap rootfs
rm -rf "$snap_rootfs/lib/$snap_python_name/site-packages/rockcraft"
rsync -r --chown=root:root "$rockcraft/rockcraft" "$snap_rootfs/lib/$snap_python_name/site-packages/"

rm -rf "$snap_rootfs/lib/$snap_python_name/site-packages/craft_application"
rsync -r --chown=root:root "$craft_application/craft_application" "$snap_rootfs/lib/$snap_python_name/site-packages/"

rm -rf "$snap_rootfs/lib/$snap_python_name/site-packages/craft_parts"
rsync -r --chown=root:root "$craft_parts/craft_parts" "$snap_rootfs/lib/$snap_python_name/site-packages/"

rm -rf "$snap_rootfs/lib/$snap_python_name/site-packages/craft_providers"
rsync -r --chown=root:root "$craft_providers/craft_providers" "$snap_rootfs/lib/$snap_python_name/site-packages/"

# repack and install snap rootfs
export snap_dst_version="local-patch-$(date +%s)"
yq e -i ".version= env(snap_dst_version)" "$snap_rootfs/meta/snap.yaml"
dst_snap="${snap_name}_${snap_dst_version}_${snap_arch}.snap"

rm -f "$dst_snap"
mksquashfs "$snap_rootfs" "$dst_snap" -noappend -comp lzo -no-fragments
sudo snap install "$dst_snap" --dangerous --classic

# cleanup
rm -rf "$snap_rootfs"

0 comments on commit cd3dc26

Please sign in to comment.