Verified Commit 9f4476ce authored by Karel Koci's avatar Karel Koci 🤘
Browse files

Merge remote-tracking branch 'c-template/master' into meson

parents b022f6f5 a161d75f
Pipeline #99791 failed with stages
in 9 minutes and 22 seconds
Updater-ng
==========
Documentation
-------------
* [Language description](docs/language.html)
Other pages
-----------
* [Automatically generated test coverage](coverage/index.html).
* [Documentation index](docindex.html)
# Outputs
/pkgupdate
/pkgtransaction
/libupdater.la
/updater-*.tar.gz
/updater-*.tar.xz
/updater-*.zip
# Build
.libs
*.o
*.pc
*.lo
/src/lib/lua/*.lua.h
/tests/lua/*.lua.h
# Test outputs
/tests/c/unittests-lib
/tests/lua/lunit-launch
test-suite*.log
tests/**/*.log
tests/**/*.trs
# Coverage output
*.gcno
*.gcda
/updater-*-coverage*
## Autotools
/.m4
/.aux
# http://www.gnu.org/software/automake
Makefile
Makefile.in
.deps
.dirstamp
# http://www.gnu.org/software/autoconf
autom4te.cache
/autoscan.log
/autoscan-*.log
/aclocal.m4
/config.log
/config.status
/configure
/configure.scan
/aminclude_static.am
# https://www.gnu.org/software/libtool/
/ltmain.sh
/libtool
# http://www.gnu.org/software/texinfo
/texinfo.tex
/subprojects
!./subprojects/*.wrap
# Container for compilation test against musl system
# We choose AlpineLinux because OpenWRT compiler is not as easy to setup
FROM alpine:3.11
ENV HOME /root
RUN \
apk update upgrade && \
apk add \
ca-certificates curl git coreutils \
make cmake pkgconf gcc perl \
libtool automake autoconf autoconf-archive \
musl-dev \
curl-dev libevent-dev uriparser-dev \
libarchive-dev \
uthash-dev \
lua5.1-dev \
asciidoc bash
# argp-standalone with -fPIC
RUN \
wget "http://www.lysator.liu.se/~nisse/misc/argp-standalone-1.3.tar.gz" && \
tar -xzf "argp-standalone-1.3.tar.gz" && rm "argp-standalone-1.3.tar.gz" && \
cd "argp-standalone-1.3" && \
wget https://git.alpinelinux.org/aports/plain/main/argp-standalone/001-throw-in-funcdef.patch && \
wget https://git.alpinelinux.org/aports/plain/main/argp-standalone/gnu89-inline.patch && \
patch <001-throw-in-funcdef.patch && patch <gnu89-inline.patch && \
CFLAGS=-fPIC ./configure && make && \
cp argp.h /usr/include && cp libargp.a /usr/lib/ && \
cd .. && rm -rf "argp-standalone-1.3"
# Compile base64c
RUN \
git clone --branch "v0.2.1" "https://gitlab.nic.cz/turris/base64c.git" && \
cd base64c && \
./bootstrap && ./configure --prefix=/usr && make install && \
cd .. && \
rm -rf base64c
CMD [ "bash" ]
# vim: ft=dockerfile
# Container for compilation test against system used on build servers
FROM debian:stable
ENV HOME /root
RUN \
apt-get update && \
apt-get -y upgrade && \
apt-get -y install --no-install-recommends \
ca-certificates curl git bzip2 \
autoconf autoconf-archive automake libtool \
make cmake pkg-config gcc \
libcurl4-openssl-dev libevent-dev libssl-dev liburiparser-dev \
libarchive-dev \
uthash-dev \
liblua5.1-0-dev \
&& \
apt-get clean
# Compile base64c
RUN \
git clone --branch "v0.2.1" "https://gitlab.nic.cz/turris/base64c.git" && \
cd base64c && \
./bootstrap && ./configure --prefix=/usr && make install && \
cd .. && \
rm -rf base64c
CMD [ "bash" ]
# vim: ft=dockerfile
# Container used to run all tests and to generate documentation and gitlab pages.
FROM debian:unstable
ENV HOME /root
RUN \
apt-get update && \
apt-get -y upgrade && \
apt-get -y install --no-install-recommends \
busybox ca-certificates curl git bzip2 \
autoconf autoconf-archive automake libtool \
make cmake pkg-config gcc \
check cppcheck lua-check valgrind \
libcurl4-openssl-dev libevent-dev libssl-dev liburiparser-dev \
libarchive-dev \
uthash-dev \
liblua5.1-0-dev \
asciidoc lcov markdown libcommon-sense-perl \
&& \
apt-get clean
# Compile base64c
RUN \
git clone --branch "v0.2.1" "https://gitlab.nic.cz/turris/base64c.git" && \
cd base64c && \
./bootstrap && ./configure --prefix=/usr && make install && \
cd .. && \
rm -rf base64c
CMD [ "bash" ]
# vim: ft=dockerfile
#!/bin/sh
set -e
cd "$(dirname "$(readlink -f "$0")")"
registry="registry.nic.cz/turris/updater/updater"
img() {
local file="DockerFile_$1"
local tag="$2"
shift 2
docker build "$@" -t "$registry:$tag" - < "$file"
}
. ./images.sh
set -x
img tests tests
img debian debian
img alpine alpine
#!/bin/sh
set -ex
cd "$(dirname "$(readlink -f "$0")")"
registry="registry.nic.cz/turris/updater/updater"
img() {
docker push "$registry:$2"
}
. ./images.sh
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
- test
- coverage
## Build stage ###################################################################
.build:
stage: build
script:
- ./bootstrap
- ./configure
- make
artifacts:
when: on_failure
expire_in: 1 week
paths:
- config.log
build-debian-stable:
extends: .build
image: registry.nic.cz/turris/updater/updater:debian
build-debian-unstable:
extends: .build
image: registry.nic.cz/turris/updater/updater:tests
build-alpine:
extends: .build
image: registry.nic.cz/turris/updater/updater:alpine
## Test stage ####################################################################
.test:
stage: test
image: registry.nic.cz/turris/updater/updater:tests
before_script:
- ./bootstrap
- ./configure --enable-tests --enable-linters
.test-check:
extends: .test
artifacts:
when: on_failure
expire_in: 1 week
paths:
- 'test-suite*.log'
- 'tests/*/*.log'
- 'tests/*/*.trs'
check:
extends: .test-check
script:
- make check
valgrind-memcheck:
extends: .test-check
script:
- make check-valgrind-memcheck
lint-c:
extends: .test
allow_failure: true
script:
- make lint-c
lint-lua:
extends: .test
allow_failure: true
script:
- make lint-lua
## Code Coverage stage ###########################################################
coverage:
stage: coverage
needs: [check]
image: registry.nic.cz/turris/updater/updater:tests
script:
- ./bootstrap
- ./configure --enable-tests --enable-code-coverage
- make check-code-coverage V=1
- mv updater-*-coverage updater-coverage
coverage: '/lines\.\.\.\.\.\.: (\d+.\d+%)/'
artifacts:
expire_in: 1 month
expose_as: 'Code Coverage'
paths:
- 'updater-coverage/'
include:
- project: 'turris/c-template'
ref: base
file: '/base-ci.yml'
FROM registry.nic.cz/turris/c-template/baseimg:alpine
RUN apk add \
curl-dev libevent-dev uriparser-dev \
libarchive-dev \
libarchive-dev \
uthash-dev \
lua5.1-dev
# Compile base64c
RUN \
git clone --branch "v0.2.1" "https://gitlab.nic.cz/turris/base64c.git" && \
cd base64c && \
./bootstrap && ./configure --prefix=/usr && make install && \
cd .. && \
rm -rf base64c
FROM registry.nic.cz/turris/c-template/baseimg:debian
RUN apt-get update && apt-get -y install --no-install-recommends \
libcurl4-openssl-dev libevent-dev libssl-dev liburiparser-dev \
libarchive-dev \
uthash-dev \
liblua5.1-0-dev
# Compile base64c
RUN \
git clone --branch "v0.2.1" "https://gitlab.nic.cz/turris/base64c.git" && \
cd base64c && \
./bootstrap && ./configure --prefix=/usr && make install && \
cd .. && \
rm -rf base64c
#!/bin/bash
set -eu
NAME="c-template"
VERSION="$(echo "${CI_COMMIT_TAG}" | sed -nE 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\1.\2.\3/p')"
CHANGELOG="$(awk '
BEGIN {
flag = 0
}
/^## / {
if (!flag) {
flag = 1
next
} else
exit
}
flag {
print
}
' CHANGELOG.md)"
declare -a args
for dist in "$NAME"-*.tar.gz "$NAME"-*.tar.xz "$NAME"-*.zip; do
URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$NAME/${VERSION}/${dist}"
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "${dist}" "${URL}"
args+=("--assets-link" "{\"name\":\"${dist}\",\"url\":\"${URL}\"}")
done
release-cli create \
--name "Release ${CI_COMMIT_TAG#v}" \
--tag-name "$CI_COMMIT_TAG" \
--description "$CHANGELOG" \
"${args[@]}"
......@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Invalid keyword in documentation stating that transaction ends with `STOP` but
it is signaled by keyword `END` instead
## Changed
- Build system is now based on Meson
## [70.0.0] - 22-01-26
### Added
......
This diff is collapsed.
ACLOCAL_AMFLAGS = -I .m4
bin_PROGRAMS =
lib_LTLIBRARIES =
EXTRA_DIST =
CLEANFILES =
linted_sources =
include $(srcdir)/src/Makefile.am
include $(srcdir)/utils/helpers.mk
if ENABLE_DOCS
dist_doc_DATA = README.md
endif
if ENABLE_LINTERS
include $(srcdir)/utils/lint.am
endif
include $(srcdir)/tests/Makefile.am
= Updater (New generation)
CZ.NIC z.s.p.o. <packaging@turris.cz>
v0.0, 2022-03-04
:icons:
Updating software for Turris OS. This is alternative hands off package manager.
Requested system state (set of installed packages) are specified in Lua
configuration scripts.
== Dependencies
* https://mesonbuild.com/[Meson build system]
* https://www.gnu.org/software/gperf[gperf]
* https://www.perl.org/[Perl 5]
* https://www.lua.org/[Lua 5.1]
* https://curl.se/libcurl/[libcurl]
* https://libevent.org/[libevent2]
* https://troydhanson.github.io/uthash/[uthash]
* https://uriparser.github.io/[liburiparser]
* https://libarchive.org/[libarchive]
* https://gitlab.nic.cz/turris/base64c[base64c]
* On non-glibc http://www.lysator.liu.se/~nisse/misc[argp-standalone]
For tests:
* https://libcheck.github.io/check[check]
* https://bats-core.readthedocs.io/en/stable/index.html[bats]
* Optionally http://www.valgrind.org[valgrind]
For code coverage report:
* http://ltp.sourceforge.net/coverage/lcov.php[lcov]
For linting:
* https://github.com/danmar/cppcheck[cppcheck]
* https://dwheeler.com/flawfinder/[flawfinder]
* https://github.com/mpeterv/luacheck[luacheck]
== Compilation
To compile this project you have to run:
----
meson setup builddir
meson compile -C builddir
----
Subsequent installation can be done with `meson install -C builddir`.
== Running tests
This project contains basic tests in directory tests.
To run tests you have to either use `debug` build type (which is commonly the
default for meson) or explicitly enable them using `meson configure
-Dtests=enabled builddir`. To execute all tests run:
----
meson test -C builddir
----
You can also run tests with Valgrind tool such as `memcheck`:
----
VALGRIND=memcheck meson test -C builddir
----
=== Code coverage report
There is also possibility to generate code coverage report from test cases. To
do so you can run:
----
meson setup -Db_coverage=true builddir
meson test -C builddir
ninja -C builddir coverage-html
----
The coverage report is generated in directory:
`builddir/meson-logs/coveragereport`.
== Linting the code
The code can also be linted if linters are installed. There are two linter
supported at the moment. There is `cppcheck` and `flawfinder`. To run them you
can do:
----
meson setup builddir
meson compile -C builddir cppcheck
meson compile -C builddir flawfinder
----
Updater (New generation)
------------------------
Updating software for Turris OS. This is alternative hands off package manager.
Requested system state (set of installed packages) are specified in Lua
configuration scripts.
Dependencies
------------
Binary dependencies:
* Lua 5.1
* libcurl
* libevent2
* uthash
* liburiparser
* libarchive
* base64c
* (argp-standalone on non-glibc systems)
Build dependencies:
* C compiler (gcc preferred) with C11 support
* autoconf
* autoconf-archive
* automake
* libtool
* perl (with `File::Slurp` module)
Dependencies for tests:
* check (>=0.11)
* valgrind
Dependencies for linting the code:
* cppcheck
* luacheck
Documentation dependencies:
* asciidoc
Coverage info generation:
* perl (with `common::sense` module) for Lua coverage
* lcov
Running tests
-------------
There are two types of tests. Unit and integration tests. (Integration tests are
called as system one in this project).
You can run all tests using following command:
```
make check
```
To run single test (as an example `FOO`) you can use:
```
make check TESTS=FOO
```
All tests can also be executed with valgrind. You can do that by running `make
check-valgrind` instead of plain `check`. You can run memcheck:
```
make check-valgrind-memcheck
```
#!/bin/sh
# Directory used for m4 macros of autoconf
mkdir -p .m4 .aux
# On old versions of autoconf-archive this file is not present so fake it
[ -f aminclude_static.am ] || echo "# dummy" > aminclude_static.am
# And finally autoreconf
autoreconf --install --symlink
AC_INIT([updater-ng], [70.0.0], [tech.support@turris.cz])
AC_CONFIG_MACRO_DIRS([.m4])
AC_CONFIG_AUX_DIR([.aux])
AM_INIT_AUTOMAKE([
foreign silent-rules subdir-objects
-Wall -Wno-portability
dist-zip dist-xz
])
AM_SILENT_RULES([yes])
AC_PROG_CC
AC_GNU_SOURCE
AM_PROG_AR
LT_INIT
AX_CHECK_COMPILE_FLAG([-std=c11], , AC_MSG_ERROR([Compiler with C11 standard support is required]))
AX_APPEND_FLAG([-std=c11])
AC_ARG_WITH([embed-busybox], [AC_HELP_STRING([--with-embed-busybox=BUSYBOX], [Embed given busybox binary])])
AM_CONDITIONAL([BUSYBOX_EMBED], [test -n "$with_embed_busybox"])
AC_SUBST([BUSYBOX_EMBED], [$with_embed_busybox])
AS_IF([test -n "$with_embed_busybox"],
[
AS_IF([test -f "$with_embed_busybox"],,
[AC_MSG_ERROR([Invalid argument for --with-embed-busybox])])
AC_DEFINE_UNQUOTED([BUSYBOX_EMBED], [$with_embed_busybox], [Embded Busybox])
])
PKG_CHECK_MODULES([lua], [lua >= 5.1 lua < 5.2],,
[PKG_CHECK_MODULES([lua], [lua5.1])])
PKG_CHECK_MODULES([libevent], [libevent >= 2.0])
PKG_CHECK_MODULES([libarchive], [libarchive])
PKG_CHECK_MODULES([libcurl], [libcurl])
PKG_CHECK_MODULES([libcrypto], [libcrypto])
PKG_CHECK_MODULES([liburiparser], [liburiparser >= 0.9])
PKG_CHECK_MODULES([base64c], [base64c])
AC_CHECK_HEADERS([uthash.h], , AC_MSG_ERROR([uthash is required]))
AC_ARG_VAR(argp_LIBS, [linker flags for argp, overriding detection])
AS_IF([test -z "$argp_LIBS"],
AC_SEARCH_LIBS([argp_parse], [argp], [argp_LIBS="-largp"]))
AC_PATH_PROG([PERL], [perl])
AS_IF([test -z "$PERL"], [AC_MSG_ERROR([Missing perl interpreter])])
AC_PATH_PROG([XXDI], [xxdi.pl],, [$ac_abs_confdir/utils])
AS_IF([test -z "$XXDI"], [AC_MSG_ERROR([Not able to locate xxdi.pl])])
dnl Documentation
AC_ARG_ENABLE([docs], AC_HELP_STRING([--disable-docs], [Disable documentation]))
AM_CONDITIONAL([ENABLE_DOCS], [test "x$enable_docs" != "xno"])
dnl Tests
AC_ARG_ENABLE([tests], AC_HELP_STRING([--enable-tests], [Whether to enable unit tests]))
AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" = "xyes"])
AS_IF([test "x$enable_tests" = "xyes"], [