Skip to content

Commit

Permalink
build(snap): add git as craft.git to snapcraft (#5149)
Browse files Browse the repository at this point in the history
Adds a `git` binary as a `craft.git`, that'll be used by the `craft`
libraries for the operation which require git client.

Signed-off-by: Dariusz Duda <[email protected]>
  • Loading branch information
dariuszd21 authored Nov 21, 2024
1 parent cf70893 commit c7d11ac
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions snap/local/craft.git
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

GIT_EXEC_PATH="${SNAP}/usr/lib/git-core" exec "${SNAP}/usr/lib/git-core/git" "$@"
25 changes: 25 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ parts:
stage:
- snapcraft-completion

snapcraft-scripts:
source: snap/local
plugin: dump
organize:
craft.git: libexec/snapcraft/craft.git
stage:
- "libexec/"

git:
plugin: nil
stage-packages: [git]
build-attributes:
- enable-patchelf
prime:
- "usr/lib/git-core"
- "usr/share/git-core"
- "usr/lib/x86_64-linux-gnu/libcurl-gnutls*"
- "usr/lib/x86_64-linux-gnu/libpsl*"
- "usr/lib/x86_64-linux-gnu/librtmp*"
- "usr/lib/x86_64-linux-gnu/libnghttp2*"
- "usr/lib/x86_64-linux-gnu/libldap*"
- "usr/lib/x86_64-linux-gnu/liblber*"
- "usr/lib/x86_64-linux-gnu/libsasl2*"


patchelf:
plugin: autotools
source: https://github.com/canonical/patchelf
Expand Down
23 changes: 23 additions & 0 deletions tests/spread/core24/craftgit/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: craftgit-test
base: core24
version: '0.1'
summary: Echo
description: Just a dummy build to check if craft.git from package works
confinement: strict

parts:
craftgit-test:
plugin: nil
override-pull: |
echo "checking if craft.git from snap is available during pull"
which craft.git | grep "$SNAP/libexec/snapcraft/craft.git"
craft.git clone --depth 1 https://git.launchpad.net/ubuntu/+source/hello
override-build: |
echo "checking if craft.git from snap is available during build"
which craft.git | grep "$SNAP/libexec/snapcraft/craft.git"
override-stage: |
echo "checking if craft.git from snap is available during stage"
which craft.git | grep "$SNAP/libexec/snapcraft/craft.git"
override-prime: |
echo "checking if craft.git from snap is available during prime"
which craft.git | grep "$SNAP/libexec/snapcraft/craft.git"
8 changes: 8 additions & 0 deletions tests/spread/core24/craftgit/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
summary: Pack a snap that uses craft.git

restore: |
snapcraft clean
rm -f ./*.snap
execute: |
snapcraft pack

0 comments on commit c7d11ac

Please sign in to comment.