From 440bcfa50a345002f7f6912fefda051967db5ac9 Mon Sep 17 00:00:00 2001 From: Zhijie Yang Date: Mon, 23 Sep 2024 14:17:47 +0200 Subject: [PATCH 1/4] chore: move mock-rock to rocks-toolbox --- mock_rock/1.0/rockcraft.yaml | 16 ++++++++++++++++ mock_rock/1.1/rockcraft.yaml | 15 +++++++++++++++ mock_rock/1.2/rockcraft.yaml | 15 +++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 mock_rock/1.0/rockcraft.yaml create mode 100644 mock_rock/1.1/rockcraft.yaml create mode 100644 mock_rock/1.2/rockcraft.yaml diff --git a/mock_rock/1.0/rockcraft.yaml b/mock_rock/1.0/rockcraft.yaml new file mode 100644 index 0000000..0860734 --- /dev/null +++ b/mock_rock/1.0/rockcraft.yaml @@ -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 \ No newline at end of file diff --git a/mock_rock/1.1/rockcraft.yaml b/mock_rock/1.1/rockcraft.yaml new file mode 100644 index 0000000..8ab6e15 --- /dev/null +++ b/mock_rock/1.1/rockcraft.yaml @@ -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 \ No newline at end of file diff --git a/mock_rock/1.2/rockcraft.yaml b/mock_rock/1.2/rockcraft.yaml new file mode 100644 index 0000000..525f133 --- /dev/null +++ b/mock_rock/1.2/rockcraft.yaml @@ -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 \ No newline at end of file From a7313bb3b4797dcd95701c3fcf749fe18ae252cd Mon Sep 17 00:00:00 2001 From: Adrian Clay Lake Date: Tue, 15 Oct 2024 07:02:09 +0000 Subject: [PATCH 2/4] feat: rockcraft snap patcher --- rockcraft_snap_patcher/README.md | 21 +++++++++++++ rockcraft_snap_patcher/patcher.sh | 50 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 rockcraft_snap_patcher/README.md create mode 100755 rockcraft_snap_patcher/patcher.sh diff --git a/rockcraft_snap_patcher/README.md b/rockcraft_snap_patcher/README.md new file mode 100644 index 0000000..df39f3f --- /dev/null +++ b/rockcraft_snap_patcher/README.md @@ -0,0 +1,21 @@ +# Rockcraft Patcher + +`patcher.sh` enables quick rockcraft "builds" for development by patching +an existing snap package with changes made to dependancies 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-`. + +`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 \ No newline at end of file diff --git a/rockcraft_snap_patcher/patcher.sh b/rockcraft_snap_patcher/patcher.sh new file mode 100755 index 0000000..edbb87a --- /dev/null +++ b/rockcraft_snap_patcher/patcher.sh @@ -0,0 +1,50 @@ +#! /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="./.patcher/$(uuid)/" +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? + + +# modify snap rootfs +rm -rf "$snap_rootfs/lib/python3.10/site-packages/rockcraft" +rsync -r --chown=root:root "$rockcraft/rockcraft" "$snap_rootfs/lib/python3.10/site-packages/" + +rm -rf "$snap_rootfs/lib/python3.10/site-packages/craft_application" +rsync -r --chown=root:root "$craft_application/craft_application" "$snap_rootfs/lib/python3.10/site-packages/" + +rm -rf "$snap_rootfs/lib/python3.10/site-packages/craft_parts" +rsync -r --chown=root:root "$craft_parts/craft_parts" "$snap_rootfs/lib/python3.10/site-packages/" + +rm -rf "$snap_rootfs/lib/python3.10/site-packages/craft_providers" +rsync -r --chown=root:root "$craft_providers/craft_providers" "$snap_rootfs/lib/python3.10/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" From f20e996cae13b8df22825d134466d9562f071420 Mon Sep 17 00:00:00 2001 From: Adrian Clay Lake Date: Tue, 15 Oct 2024 07:04:28 +0000 Subject: [PATCH 3/4] fix(/workspaces/rocks-toolbox/rockcraft_snap_patcher/README.md): typo --- rockcraft_snap_patcher/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rockcraft_snap_patcher/README.md b/rockcraft_snap_patcher/README.md index df39f3f..315c0f8 100644 --- a/rockcraft_snap_patcher/README.md +++ b/rockcraft_snap_patcher/README.md @@ -1,7 +1,7 @@ # Rockcraft Patcher `patcher.sh` enables quick rockcraft "builds" for development by patching -an existing snap package with changes made to dependancies on the local +an existing snap package with changes made to dependencies on the local system. ## How to use From 48fbab216d4be819d65f722e32d3027cca331d51 Mon Sep 17 00:00:00 2001 From: Adrian Clay Lake Date: Wed, 30 Oct 2024 10:47:38 +0100 Subject: [PATCH 4/4] feat: dynamic python versions, swap uuid for mktemp --- rockcraft_snap_patcher/patcher.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/rockcraft_snap_patcher/patcher.sh b/rockcraft_snap_patcher/patcher.sh index edbb87a..3101203 100755 --- a/rockcraft_snap_patcher/patcher.sh +++ b/rockcraft_snap_patcher/patcher.sh @@ -14,7 +14,7 @@ craft_parts="../craft-parts/" # Path to craft_providers repo # setup -snap_rootfs="./.patcher/$(uuid)/" +snap_rootfs=$(mktemp -d -p "./.patcher/") sudo mkdir -p "$snap_rootfs" # unpack rootfs @@ -22,20 +22,22 @@ 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/python3.10/site-packages/rockcraft" -rsync -r --chown=root:root "$rockcraft/rockcraft" "$snap_rootfs/lib/python3.10/site-packages/" +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/python3.10/site-packages/craft_application" -rsync -r --chown=root:root "$craft_application/craft_application" "$snap_rootfs/lib/python3.10/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/python3.10/site-packages/craft_parts" -rsync -r --chown=root:root "$craft_parts/craft_parts" "$snap_rootfs/lib/python3.10/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/python3.10/site-packages/craft_providers" -rsync -r --chown=root:root "$craft_providers/craft_providers" "$snap_rootfs/lib/python3.10/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)"