github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/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.46.1
    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 -extldflags '$LDFLAGS'")
    81    staticflags=(-buildmode=pie -ldflags "-s -linkmode external -extldflags '$LDFLAGS -static'")
    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  
   136    # Install bash completion
   137    install -Dm644 data/completion/bash/snap \
   138      "$pkgdir/usr/share/bash-completion/completions/snap"
   139    install -Dm644 data/completion/bash/complete.sh \
   140      "$pkgdir/usr/lib/snapd/complete.sh"
   141    install -Dm644 data/completion/bash/etelpmoc.sh \
   142      "$pkgdir/usr/lib/snapd/etelpmoc.sh"
   143    # Install zsh completion
   144    install -Dm644 data/completion/zsh/_snap \
   145      "$pkgdir/usr/share/zsh/site-functions/_snap"
   146  
   147    # Install systemd units, dbus services and a script for environment variables
   148    make -C data/ install \
   149       DBUSSERVICESDIR=/usr/share/dbus-1/services \
   150       BINDIR=/usr/bin \
   151       SYSTEMDSYSTEMUNITDIR=/usr/lib/systemd/system \
   152       SNAP_MOUNT_DIR=/var/lib/snapd/snap \
   153       DESTDIR="$pkgdir"
   154  
   155    # Install polkit policy
   156    install -Dm644 data/polkit/io.snapcraft.snapd.policy \
   157      "$pkgdir/usr/share/polkit-1/actions/io.snapcraft.snapd.policy"
   158  
   159    # Install executables
   160    install -Dm755 "$srcdir/go/bin/snap" "$pkgdir/usr/bin/snap"
   161    install -Dm755 "$srcdir/go/bin/snapctl" "$pkgdir/usr/lib/snapd/snapctl"
   162    install -Dm755 "$srcdir/go/bin/snapd" "$pkgdir/usr/lib/snapd/snapd"
   163    install -Dm755 "$srcdir/go/bin/snap-seccomp" "$pkgdir/usr/lib/snapd/snap-seccomp"
   164    install -Dm755 "$srcdir/go/bin/snap-failure" "$pkgdir/usr/lib/snapd/snap-failure"
   165    install -Dm755 "$srcdir/go/bin/snap-update-ns" "$pkgdir/usr/lib/snapd/snap-update-ns"
   166    install -Dm755 "$srcdir/go/bin/snap-exec" "$pkgdir/usr/lib/snapd/snap-exec"
   167    # Ensure /usr/bin/snapctl is a symlink to /usr/libexec/snapd/snapctl
   168    ln -s /usr/lib/snapd/snapctl "$pkgdir/usr/bin/snapctl"
   169  
   170    # pre-create directories
   171    install -dm755 "$pkgdir/var/lib/snapd/snap"
   172    install -dm755 "$pkgdir/var/cache/snapd"
   173    install -dm755 "$pkgdir/var/lib/snapd/apparmor"
   174    install -dm755 "$pkgdir/var/lib/snapd/assertions"
   175    install -dm755 "$pkgdir/var/lib/snapd/dbus-1/services"
   176    install -dm755 "$pkgdir/var/lib/snapd/dbus-1/system-services"
   177    install -dm755 "$pkgdir/var/lib/snapd/desktop/applications"
   178    install -dm755 "$pkgdir/var/lib/snapd/device"
   179    install -dm755 "$pkgdir/var/lib/snapd/hostfs"
   180    install -dm755 "$pkgdir/var/lib/snapd/mount"
   181    install -dm755 "$pkgdir/var/lib/snapd/seccomp/bpf"
   182    install -dm755 "$pkgdir/var/lib/snapd/snap/bin"
   183    install -dm755 "$pkgdir/var/lib/snapd/snaps"
   184    install -dm755 "$pkgdir/var/lib/snapd/inhibit"
   185    install -dm755 "$pkgdir/var/lib/snapd/lib/gl"
   186    install -dm755 "$pkgdir/var/lib/snapd/lib/gl32"
   187    install -dm755 "$pkgdir/var/lib/snapd/lib/vulkan"
   188    install -dm755 "$pkgdir/var/lib/snapd/lib/glvnd"
   189    # these dirs have special permissions
   190    install -dm111 "$pkgdir/var/lib/snapd/void"
   191    install -dm700 "$pkgdir/var/lib/snapd/cookie"
   192    install -dm700 "$pkgdir/var/lib/snapd/cache"
   193  
   194    make -C cmd install DESTDIR="$pkgdir/"
   195  
   196    # Install man file
   197    mkdir -p "$pkgdir/usr/share/man/man8"
   198    "$srcdir/go/bin/snap" help --man > "$pkgdir/usr/share/man/man8/snap.8"
   199  
   200    # Install the "info" data file with snapd version
   201    install -m 644 -D "$srcdir/go/src/${_gourl}/data/info" \
   202            "$pkgdir/usr/lib/snapd/info"
   203  
   204    # Remove snappy core specific units
   205    rm -fv "$pkgdir/usr/lib/systemd/system/snapd.system-shutdown.service"
   206    rm -fv "$pkgdir/usr/lib/systemd/system/snapd.autoimport.service"
   207    rm -fv "$pkgdir"/usr/lib/systemd/system/snapd.snap-repair.*
   208    rm -fv "$pkgdir"/usr/lib/systemd/system/snapd.core-fixup.*
   209    # and scripts
   210    rm -fv "$pkgdir/usr/lib/snapd/snapd.core-fixup.sh"
   211    rm -fv "$pkgdir/usr/bin/ubuntu-core-launcher"
   212    rm -fv "$pkgdir/usr/lib/snapd/system-shutdown"
   213  }