From: Maria Matejka Date: Fri, 24 Jan 2025 09:34:42 +0000 (+0100) Subject: Releasing: a new tgz generator script X-Git-Tag: v2.17~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70798a6acdba53e453a88164274f1c4b447b0228;p=thirdparty%2Fbird.git Releasing: a new tgz generator script Also version detection is done by a separate script, not a magic line in the Makefile. --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2859a01c..be5c317f0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,12 +63,12 @@ docker-docbuilder: # Detect which make is available - MAKE=make - which gmake 2>/dev/null >/dev/null && MAKE=gmake - - $MAKE + - BRANCH=$CI_COMMIT_BRANCH $MAKE - $MAKE check # Build docs when tools are available - if which linuxdoc pdflatex sgmlsasp >/dev/null ; then $MAKE docs ; fi -build-only-doc: +build-release: image: registry.nic.cz/labs/bird:docbuilder stage: build tags: @@ -78,10 +78,12 @@ build-only-doc: - autoreconf - ./configure --with-protocols= --disable-client - make obj/doc/bird-singlepage.html + - BRANCH=$CI_COMMIT_BRANCH tools/make-archive artifacts: paths: - obj/doc/bird-singlepage.html - expire_in: 1 month + - bird-*.tar.gz + expire_in: 1 day .build-linux: &build-linux <<: *build-base @@ -293,7 +295,7 @@ build-only-static: stage: pkg script: - pip3 install apkg - - apkg build + - BRANCH=$CI_COMMIT_BRANCH ARCHIVE_DOCS=false apkg build #- apkg install -y pkg/pkgs/*/*/*.deb artifacts: paths: @@ -303,7 +305,7 @@ build-only-static: stage: pkg script: - pip3 install apkg - - apkg build + - BRANCH=$CI_COMMIT_BRANCH ARCHIVE_DOCS=false apkg build #- apkg install -y pkg/pkgs/*/*/*.rpm artifacts: paths: @@ -314,7 +316,7 @@ build-only-static: script: - sed -i "s/runstatedir/with-runtimedir/" distro/pkg/rpm/bird.spec - pip3 install apkg - - apkg build + - BRANCH=$CI_COMMIT_BRANCH ARCHIVE_DOCS=false apkg build #- apkg install -y pkg/pkgs/*/*/*.rpm artifacts: paths: @@ -425,7 +427,7 @@ build-netlab: - mkdir $BDIR - cd $BDIR - ../configure - - make + - BRANCH=$CI_COMMIT_BRANCH make artifacts: paths: - $BDIR/bird diff --git a/Makefile.in b/Makefile.in index 29e627e1f..3814b2974 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,6 @@ # Makefile for the BIRD Internet Routing Daemon # (c) 1999--2000 Martin Mares -# (c) 2016 Jan Moskyto Matejka +# (c) 2016--2025 Maria Matejka # Disable build-in rules MAKEFLAGS += -r @@ -42,10 +42,9 @@ srcdir := @srcdir@ objdir := @objdir@ exedir := @exedir@ -git-label:=$(strip $(shell cd $(srcdir) && [ "$$(git rev-parse --show-toplevel)" = "$$(readlink -f .)" ] && git describe --always --dirty=-x 2>/dev/null)) -ifneq ($(git-label),) - CFLAGS += -DGIT_LABEL="$(git-label)" -endif +# Find out which version we are actually building +VERSION := $(strip $(shell bash tools/version)) +CFLAGS += -DBIRD_VERSION='"$(VERSION)"' ifeq ($(objdir),.) objdir := $(realpath .) diff --git a/distro/README.md b/distro/README.md index ac1a75b0a..52d22b16d 100644 --- a/distro/README.md +++ b/distro/README.md @@ -25,7 +25,7 @@ or in case of disposable VM/container you can use faster direct host build apkg build -Hi -tools/make-dev-archive script is in charge of creating archive from source. +tools/make-archive script is in charge of creating archive from source. ## Create (source) package from upstream release diff --git a/distro/config/apkg.toml b/distro/config/apkg.toml index 73a79a3be..8766f3641 100644 --- a/distro/config/apkg.toml +++ b/distro/config/apkg.toml @@ -1,7 +1,7 @@ [project] name = "bird" # needed for make-archive -make_archive_script = "tools/make-dev-archive" +make_archive_script = "tools/make-archive" [upstream] # needed for get-archive diff --git a/sysdep/config.h b/sysdep/config.h index 8c482ec30..7782f9d15 100644 --- a/sysdep/config.h +++ b/sysdep/config.h @@ -6,16 +6,15 @@ #ifndef _BIRD_CONFIG_H_ #define _BIRD_CONFIG_H_ -#define XSTR2(X) #X -#define XSTR1(X) XSTR2(X) - /* BIRD version */ -#ifdef GIT_LABEL -#define BIRD_VERSION XSTR1(GIT_LABEL) -#else -#define BIRD_VERSION "2.16" +#ifndef BIRD_VERSION +#error "BIRD_VERSION not defined" #endif +/* ... is a string literal at least of 4 characters */ +_Static_assert(sizeof(BIRD_VERSION) >= 4, BIRD_VERSION); +_Static_assert(sizeof(BIRD_VERSION "") == sizeof(BIRD_VERSION), BIRD_VERSION); + /* Include parameters determined by configure script */ #include "sysdep/autoconf.h" diff --git a/tools/make-archive b/tools/make-archive new file mode 100755 index 000000000..b543687b2 --- /dev/null +++ b/tools/make-archive @@ -0,0 +1,97 @@ +#!/bin/bash +# +# Generate BIRD distribution tgz +# +# (c) 2025 CZ.NIC +# +# Based on an older script by Martin Mares and Ondrej Filip +# and another one by Jakub Ruzicka and Ondrej Zajicek + +set -e + +# Gather all required information +VERSION="$($(dirname $0)/version)" + +SRCPKG="bird-$VERSION" +DOCPKG="bird-doc-$VERSION" + +if [ -z "$ARCHIVE_DOCS" ]; then + ARCHIVE_DOCS=true +fi + +# Check that we are running on a clean repository +if ! git diff-index --quiet HEAD || ! git diff-index --cached --quiet HEAD; then + echo 'WARNING: git index has uncommitted changes!' +fi + +# Prepare a tempdir +T=$(mktemp -d) +function cleanup_tmpdir() { + rm -rf $T +} + +trap cleanup_tmpdir EXIT + +# Create a preliminary archive +echo "Building $VERSION" +git archive --format=tar --prefix="$SRCPKG/" HEAD -o $T/initial.tgz + +# Generate changelog +echo "Generating changelog" +mkdir $T/$SRCPKG +git log > $T/$SRCPKG/ChangeLog + +# Unpack the archive +pushd $T + tar xf initial.tgz + pushd $SRCPKG + + # Omit historical documents + rm -rf misc rfc doc/slides doc/slt2001 doc/old bird.conf + + # Fix the version string + sed -i 's/^VERSION := .*/VERSION := '${VERSION}'/' Makefile.in + + # Run autoconf + echo "Running autoreconf" + autoreconf -i + rm -rf autom4te*cache + + popd + + # Pack sources + echo "Packing source package" + tar czf $SRCPKG.tar.gz $SRCPKG + + if $ARCHIVE_DOCS; then + # Generate documentation + pushd $SRCPKG + echo "Creating documentation" + (./configure --with-protocols= --disable-client && make docs) > build.log 2>build.err || ( + echo "======== Build log ========" + cat build.log + echo "======== Error log ========" + cat build.err + echo "If you wish to not build documentation, set env ARCHIVE_DOCS=false" + false + ) + popd + + mkdir ${DOCPKG}{,/doc} + cp $SRCPKG/obj/doc/*.{html,pdf} ${DOCPKG}/doc + + # Pack sources + echo "Packing docs package" + tar czf $DOCPKG.tar.gz $DOCPKG + else + echo "Skipping documentation build" + fi + +popd + +if $ARCHIVE_DOCS; then + mv $T/$DOCPKG.tar.gz . +fi + +mv $T/$SRCPKG.tar.gz . +echo $SRCPKG.tar.gz diff --git a/tools/make-dev-archive b/tools/make-dev-archive index caaee121c..38c254b6c 100755 --- a/tools/make-dev-archive +++ b/tools/make-dev-archive @@ -3,7 +3,7 @@ # This a modified version of gendist script which generates development # archive (tarball) without docs from current sources. -BIRD_VERSION=`grep 'BIRD_VERSION \"' sysdep/config.h | sed '/BIRD_VERSION/!d;s/^.*"\(.*\)"$/\1/'` +BIRD_VERSION=$(bash tools/version) # differentiate dev tarballs from upstream ones GIT_HASH=$(git rev-parse --short HEAD ) TIMESTAMP=$(date -u +'%s' 2>/dev/null) diff --git a/tools/version b/tools/version new file mode 100755 index 000000000..1bfc45f62 --- /dev/null +++ b/tools/version @@ -0,0 +1,32 @@ +#!/bin/bash + +TAG=$(git tag --merged | sed -n 's/^v//p' | tail -n1) + +# Pack with zeros if needed +TM=$TAG +while [ -n "${TM/*.*.*/}" ]; do + TM="${TM}.0" +done + +if [ "$(git rev-parse HEAD)" == "$(git rev-parse v${TAG})" ]; then + echo $TM + exit 0 +fi + +HASH=$(git rev-parse --short=12 HEAD) + +# Add branch info if not passed via command line +if [ -z "${BRANCH}" ]; then + # There is also --show-current but it's too new to be portable. + BRANCH=$(git branch | sed -n 's/^[*] //p' | grep -v 'HEAD detached') +fi + +# Found a branch +if [ -n "$BRANCH" ]; then + LENGTH=$(git log --oneline v$TAG..HEAD | wc -l) + echo $TM+branch.$(echo $BRANCH | sed 's/[^a-zA-Z0-9]/./g').${HASH} + exit 0 +fi + +echo $TM+detached.${HASH} +exit 0