github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/packaging/arch/PKGBUILD (about)

     1  # Maintainer: aimileus <me at aimileus dot nl>
     2  # Maintainer: Maciej Borzecki <maciek.borzecki@gmail.com>
     3  # Contributor: Timothy Redaelli <timothy.redaelli@gmail.com>
     4  # Contributor: Zygmunt Krynicki <me at zygoon dot pl>
     5  #
     6  # Environment variables that can set by CI:
     7  # - WITH_TEST_KEYS=1 - enable use of testing keys
     8  
     9  pkgname=snapd
    10  pkgdesc="Service and tools for management of snap packages."
    11  depends=('squashfs-tools' 'libseccomp' 'libsystemd' 'apparmor')
    12  optdepends=('bash-completion: bash completion support'
    13              'xdg-desktop-portal: desktop integration')
    14  pkgver=2.51
    15  pkgrel=1
    16  arch=('x86_64' 'i686' 'armv7h' 'aarch64')
    17  url="https://github.com/snapcore/snapd"
    18  license=('GPL3')
    19  makedepends=('git' 'go' 'go-tools' 'libseccomp' 'libcap' 'systemd' 'xfsprogs' 'python-docutils' 'apparmor')
    20  # the following checkdepends are only required for static checks and unit tests,
    21  # unit tests are currently enabled
    22  checkdepends=('python' 'squashfs-tools' 'shellcheck')
    23  conflicts=('snap-confine')
    24  options=('!strip' 'emptydirs')
    25  install=snapd.install
    26  source=("git+https://github.com/snapcore/$pkgname.git")
    27  sha256sums=('SKIP')
    28  
    29  _gourl=github.com/snapcore/snapd
    30  
    31  pkgver() {
    32      cd "$srcdir/snapd"
    33      git describe --tag | sed -r 's/([^-]*-g)/r\1/; s/-/./g'
    34  }
    35  
    36  prepare() {
    37    cd "$pkgname"
    38  
    39    export GOPATH="$srcdir/go"
    40  
    41    # Have snapd checkout appear in a place suitable for subsequent GOPATH. This
    42    # way we don't have to go get it again and it is exactly what the tag/hash
    43    # above describes.
    44    mkdir -p "$(dirname "$srcdir/go/src/${_gourl}")"
    45    ln --no-target-directory -fs "$srcdir/$pkgname" "$srcdir/go/src/${_gourl}"
    46  }
    47  
    48  build() {
    49    cd "$pkgname"
    50    export GOPATH="$srcdir/go"
    51  
    52    # GOFLAGS may be modified by CI tools
    53    # GOFLAGS are the go build flags for all binaries, GOFLAGS_SNAP are for snap
    54    # build only.
    55    GOFLAGS=""
    56    GOFLAGS_SNAP="-tags nomanagers"
    57    if [[ "$WITH_TEST_KEYS" == 1 ]]; then
    58        GOFLAGS="$GOFLAGS -tags withtestkeys"
    59        GOFLAGS_SNAP="-tags nomanagers,withtestkeys"
    60    fi
    61    # snapd does not support modules yet, explicitly disable Go modules
    62    export GO111MODULE=off
    63  
    64    export CGO_ENABLED="1"
    65    export CGO_CFLAGS="${CFLAGS}"
    66    export CGO_CPPFLAGS="${CPPFLAGS}"
    67    export CGO_CXXFLAGS="${CXXFLAGS}"
    68    export CGO_LDFLAGS="${LDFLAGS}"
    69  
    70    ./mkversion.sh $pkgver-$pkgrel
    71  
    72    # Use get-deps.sh provided by upstream to fetch go dependencies using the
    73    # godeps tool and dependencies.tsv (maintained upstream).
    74    cd "$srcdir/go/src/${_gourl}"
    75    XDG_CONFIG_HOME="$srcdir" ./get-deps.sh
    76  
    77    # because argument expansion with quoting in bash is hard, and -ldflags=-extldflags='-foo'
    78    # is not exactly the same as -ldflags "-extldflags '-foo'" use the array trick
    79    # to pass exactly what we want
    80    flags=(-buildmode=pie -ldflags "-s -linkmode external -extldflags '$LDFLAGS'" -trimpath)
    81    staticflags=(-buildmode=pie -ldflags "-s -linkmode external -extldflags '$LDFLAGS -static'" -trimpath)
    82    # Build/install snap and snapd
    83    go build "${flags[@]}" -o "$srcdir/go/bin/snap" $GOFLAGS_SNAP "${_gourl}/cmd/snap"
    84    go build "${flags[@]}" -o "$srcdir/go/bin/snapd" $GOFLAGS "${_gourl}/cmd/snapd"
    85    go build "${flags[@]}" -o "$srcdir/go/bin/snap-seccomp" $GOFLAGS "${_gourl}/cmd/snap-seccomp"
    86    go build "${flags[@]}" -o "$srcdir/go/bin/snap-failure" $GOFLAGS "${_gourl}/cmd/snap-failure"
    87    # build snap-exec and snap-update-ns completely static for base snaps
    88    go build "${staticflags[@]}" -o "$srcdir/go/bin/snap-update-ns" $GOFLAGS "${_gourl}/cmd/snap-update-ns"
    89    go build "${staticflags[@]}" -o "$srcdir/go/bin/snap-exec" $GOFLAGS "${_gourl}/cmd/snap-exec"
    90    go build "${staticflags[@]}" -o "$srcdir/go/bin/snapctl" $GOFLAGS "${_gourl}/cmd/snapctl"
    91  
    92    # Generate data files such as real systemd units, dbus service, environment
    93    # setup helpers out of the available templates
    94    make -C data \
    95         BINDIR=/bin \
    96         LIBEXECDIR=/usr/lib \
    97         SYSTEMDSYSTEMUNITDIR=/usr/lib/systemd/system \
    98         SNAP_MOUNT_DIR=/var/lib/snapd/snap \
    99         SNAPD_ENVIRONMENT_FILE=/etc/default/snapd
   100  
   101    cd cmd
   102    autoreconf -i -f
   103    ./configure \
   104      --prefix=/usr \
   105      --libexecdir=/usr/lib/snapd \
   106      --with-snap-mount-dir=/var/lib/snapd/snap \
   107      --enable-apparmor \
   108      --enable-nvidia-biarch \
   109      --enable-merged-usr
   110    make $MAKEFLAGS
   111  }
   112  
   113  check() {
   114    export GOPATH="$srcdir/go"
   115    cd "$srcdir/go/src/${_gourl}"
   116  
   117    # make sure the binaries that need to be built statically really are
   118    for binary in snap-exec snap-update-ns snapctl; do
   119        LC_ALL=C ldd "$srcdir/go/bin/$binary" 2>&1 | grep -q 'not a dynamic executable'
   120    done
   121  
   122    SKIP_UNCLEAN=1 ./run-checks --unit
   123    # XXX: Static checks choke on autotools generated cruft. Let's not run them
   124    # here as they are designed to pass on a clean tree, before anything else is
   125    # done, not after building the tree.
   126    # ./run-checks --static
   127    TMPDIR=/tmp make -C cmd -k check
   128  
   129    mv $srcdir/xxx-info data/info
   130  }
   131  
   132  package() {
   133    cd "$pkgname"
   134    export GOPATH="$srcdir/go"
   135    # snapd does not use modules, setting GO111MODULE=on in the environment breaks
   136    # the build
   137    unset GO111MODULE
   138  
   139    # Install bash completion
   140    install -Dm644 data/completion/bash/snap \
   141      "$pkgdir/usr/share/bash-completion/completions/snap"
   142    install -Dm644 data/completion/bash/complete.sh \
   143      "$pkgdir/usr/lib/snapd/complete.sh"
   144    install -Dm644 data/completion/bash/etelpmoc.sh \
   145      "$pkgdir/usr/lib/snapd/etelpmoc.sh"
   146    # Install zsh completion
   147    install -Dm644 data/completion/zsh/_snap \
   148      "$pkgdir/usr/share/zsh/site-functions/_snap"
   149  
   150    # Install systemd units, dbus services and a script for environment variables
   151    make -C data/ install \
   152       DBUSSERVICESDIR=/usr/share/dbus-1/services \
   153       BINDIR=/usr/bin \
   154       SYSTEMDSYSTEMUNITDIR=/usr/lib/systemd/system \
   155       SNAP_MOUNT_DIR=/var/lib/snapd/snap \
   156       DESTDIR="$pkgdir"
   157  
   158    # Install polkit policy
   159    install -Dm644 data/polkit/io.snapcraft.snapd.policy \
   160      "$pkgdir/usr/share/polkit-1/actions/io.snapcraft.snapd.policy"
   161  
   162    # Install executables
   163    install -Dm755 "$srcdir/go/bin/snap" "$pkgdir/usr/bin/snap"
   164    install -Dm755 "$srcdir/go/bin/snapctl" "$pkgdir/usr/lib/snapd/snapctl"
   165    install -Dm755 "$srcdir/go/bin/snapd" "$pkgdir/usr/lib/snapd/snapd"
   166    install -Dm755 "$srcdir/go/bin/snap-seccomp" "$pkgdir/usr/lib/snapd/snap-seccomp"
   167    install -Dm755 "$srcdir/go/bin/snap-failure" "$pkgdir/usr/lib/snapd/snap-failure"
   168    install -Dm755 "$srcdir/go/bin/snap-update-ns" "$pkgdir/usr/lib/snapd/snap-update-ns"
   169    install -Dm755 "$srcdir/go/bin/snap-exec" "$pkgdir/usr/lib/snapd/snap-exec"
   170    # Ensure /usr/bin/snapctl is a symlink to /usr/libexec/snapd/snapctl
   171    ln -s /usr/lib/snapd/snapctl "$pkgdir/usr/bin/snapctl"
   172  
   173    # pre-create directories
   174    install -dm755 "$pkgdir/var/lib/snapd/snap"
   175    install -dm755 "$pkgdir/var/cache/snapd"
   176    install -dm755 "$pkgdir/var/lib/snapd/apparmor"
   177    install -dm755 "$pkgdir/var/lib/snapd/assertions"
   178    install -dm755 "$pkgdir/var/lib/snapd/dbus-1/services"
   179    install -dm755 "$pkgdir/var/lib/snapd/dbus-1/system-services"
   180    install -dm755 "$pkgdir/var/lib/snapd/desktop/applications"
   181    install -dm755 "$pkgdir/var/lib/snapd/device"
   182    install -dm755 "$pkgdir/var/lib/snapd/hostfs"
   183    install -dm755 "$pkgdir/var/lib/snapd/mount"
   184    install -dm755 "$pkgdir/var/lib/snapd/seccomp/bpf"
   185    install -dm755 "$pkgdir/var/lib/snapd/snap/bin"
   186    install -dm755 "$pkgdir/var/lib/snapd/snaps"
   187    install -dm755 "$pkgdir/var/lib/snapd/inhibit"
   188    install -dm755 "$pkgdir/var/lib/snapd/lib/gl"
   189    install -dm755 "$pkgdir/var/lib/snapd/lib/gl32"
   190    install -dm755 "$pkgdir/var/lib/snapd/lib/vulkan"
   191    install -dm755 "$pkgdir/var/lib/snapd/lib/glvnd"
   192    # these dirs have special permissions
   193    install -dm111 "$pkgdir/var/lib/snapd/void"
   194    install -dm700 "$pkgdir/var/lib/snapd/cookie"
   195    install -dm700 "$pkgdir/var/lib/snapd/cache"
   196  
   197    make -C cmd install DESTDIR="$pkgdir/"
   198  
   199    # Install man file
   200    mkdir -p "$pkgdir/usr/share/man/man8"
   201    "$srcdir/go/bin/snap" help --man > "$pkgdir/usr/share/man/man8/snap.8"
   202  
   203    # Install the "info" data file with snapd version
   204    install -m 644 -D "$srcdir/go/src/${_gourl}/data/info" \
   205            "$pkgdir/usr/lib/snapd/info"
   206  
   207    # Remove snappy core specific units
   208    rm -fv "$pkgdir/usr/lib/systemd/system/snapd.system-shutdown.service"
   209    rm -fv "$pkgdir/usr/lib/systemd/system/snapd.autoimport.service"
   210    rm -fv "$pkgdir/usr/lib/systemd/system/snapd.recovery-chooser-trigger.service"
   211    rm -fv "$pkgdir"/usr/lib/systemd/system/snapd.snap-repair.*
   212    rm -fv "$pkgdir"/usr/lib/systemd/system/snapd.core-fixup.*
   213    # and scripts
   214    rm -fv "$pkgdir/usr/lib/snapd/snapd.core-fixup.sh"
   215    rm -fv "$pkgdir/usr/bin/ubuntu-core-launcher"
   216    rm -fv "$pkgdir/usr/lib/snapd/system-shutdown"
   217  }