]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Releasing: a new tgz generator script
authorMaria Matejka <mq@ucw.cz>
Fri, 24 Jan 2025 09:34:42 +0000 (10:34 +0100)
committerMaria Matejka <mq@ucw.cz>
Tue, 1 Apr 2025 10:09:34 +0000 (12:09 +0200)
Also version detection is done by a separate script, not a magic line in
the Makefile.

.gitlab-ci.yml
Makefile.in
distro/README.md
distro/config/apkg.toml
sysdep/config.h
tools/make-archive [new file with mode: 0755]
tools/make-dev-archive
tools/version [new file with mode: 0755]

index a2859a01c11406e02b556372add7c64999a3586b..be5c317f0391789fb17c391eff77ed8032752d13 100644 (file)
@@ -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
index 29e627e1f439c70f81edf160c4bf640b3641dc51..3814b2974c4ec6683ae506a55dcbe4befee186d5 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile for the BIRD Internet Routing Daemon
 # (c) 1999--2000 Martin Mares <mj@ucw.cz>
-# (c) 2016       Jan Moskyto Matejka <mq@ucw.cz>
+# (c) 2016--2025 Maria Matejka <mq@ucw.cz>
 
 # 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 .)
index ac1a75b0a106ecd887645fe327c67c46fbb09f8a..52d22b16d3139583add23e3a1e150e13ef8cc9aa 100644 (file)
@@ -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
index 73a79a3be262a01247adb2499c560d9587f537d6..8766f3641cde8cc72eecbe42a81d2f629327d55b 100644 (file)
@@ -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
index 8c482ec307517d110b7d99d618825b4c67679801..7782f9d157d9605632f48486f0ce5787223289d6 100644 (file)
@@ -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 (executable)
index 0000000..b543687
--- /dev/null
@@ -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
index caaee121c1728dbb875933783b1c688de07e717c..38c254b6c58a6e78ce743f4b30aa2a04327435d7 100755 (executable)
@@ -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 (executable)
index 0000000..1bfc45f
--- /dev/null
@@ -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