Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rec use meson to create dist file #15076

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions meson/version/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
gen_version_prog = find_program('gen-version', dirs: product_source_dir / 'builder-support', required: true)
gen_version_prog_res = run_command(gen_version_prog, check: true)
product_version = gen_version_prog_res.stdout().strip()
product_version = meson.project_version()
conf.set_quoted('VERSION', product_version, description: 'Version')
7 changes: 7 additions & 0 deletions pdns/recursordist/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Caddyfile export-ignore
/README.md export-ignore
docs export-ignore
examples export-ignore
make-ext-symlinks.py export-ignore
recursor-lsan.supp export-ignore
recursor-tsan.supp export-ignore
1 change: 0 additions & 1 deletion pdns/recursordist/NOTICE

This file was deleted.

16 changes: 16 additions & 0 deletions pdns/recursordist/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.

In addition, for the avoidance of any doubt, permission is granted to
link this program with OpenSSL and to (re)distribute the binaries
produced as the result of such linking.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1 change: 0 additions & 1 deletion pdns/recursordist/builder-support/gen-version

This file was deleted.

77 changes: 77 additions & 0 deletions pdns/recursordist/builder-support/gen-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh
if [ ! -z "${BUILDER_VERSION}" ]; then
printf ${BUILDER_VERSION}
exit 0
fi

VERSION="unknown"

DIRTY=""
git status | grep -q clean || DIRTY='.dirty'

# Special environment variable to signal that we are building a release, as this
# has consequenses for the version number.
if [ "${IS_RELEASE}" = "YES" ]; then
TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
if [ -n "${TAG}" ]; then
# We're on a tag
echo "${TAG}${DIRTY}" > .version
printf "${TAG}${DIRTY}"
exit 0
fi
echo 'This is not a tag, either tag this commit or do not set $IS_RELEASE' >&2
exit 1
fi

#
# Generate the version number based on the branch
#
if [ ! -z "$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" ]; then
if [ -n "${BUILDER_MODULES}" ]; then
match=${BUILDER_MODULES}
[ $match = "authoritative" ] && match='auth'
[ $match = "recursor" ] && match='rec'
GIT_VERSION="$(git describe --match=${match}-* --tags | cut -d- -f2-)"
if [ $(echo ${GIT_VERSION} | awk -F"-" '{print NF-1}') = '3' ]; then
# A prerelease happened before
LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1-2)"
COMMITS_SINCE_TAG="$(echo ${GIT_VERSION} | cut -d- -f3)"
GIT_HASH="$(echo ${GIT_VERSION} | cut -d- -f4)"
elif [ $(echo ${GIT_VERSION} | awk -F"-" '{print NF-1}') = '1' ]; then
# Exactly on a pre-release
LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1-2)"
else
LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1)"
COMMITS_SINCE_TAG="$(echo ${GIT_VERSION} | cut -d- -f2)"
GIT_HASH="$(echo ${GIT_VERSION} | cut -d- -f3)"
fi
fi

if [ -z "${GIT_VERSION}" ]; then
# BUILDER_SUPPORT has more than one product listed, fall back to the 0.0.0 logic

# We used 0.0.XXXXgHASH for master in the previous incarnation of our build pipeline.
# This now becomes 0.0.XXXX.0.gHASH, as 0.0.0.XXXX.gHASH (which is more correct)
# would break upgrades for those running master
# This _should_ be ok for forever is we stick to X.Y.Z for version numbers
LAST_TAG=0.0
COMMITS_SINCE_TAG="$(git rev-list --count 12c868770afc20b6cc0da439d881105151d557dd..HEAD 2> /dev/null).0"
[ "${COMMITS_SINCE_TAG}" = ".0" ] && COMMITS_SINCE_TAG=0.0
GIT_HASH="g$(git rev-parse HEAD | cut -c1-10 2> /dev/null)"
fi

BRANCH=".$(git rev-parse --abbrev-ref HEAD | perl -p -e 's/[^[:alnum:]]//g;')"

TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
if [ -n "${TAG}" ]; then # We're exactly on a tag
COMMITS_SINCE_TAG="0"
GIT_HASH="g$(git show --no-patch --format=format:%h HEAD 2>/dev/null)"
if [ -z "$GIT_HASH" ]; then
GIT_HASH="g$(git show --format=format:%h HEAD | head -n1)"
fi
fi

VERSION="${LAST_TAG}.${COMMITS_SINCE_TAG}${BRANCH}.${GIT_HASH}${DIRTY}"
fi

printf $VERSION
2 changes: 2 additions & 0 deletions pdns/recursordist/docs/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ docutils!=0.15,<0.18
jinja2<3.1.0
alabaster==0.7.13
pbr==6.1.0 # setup-requires for sphinxcontrib-fulltoc
standard-imghdr
standard-pipes
10 changes: 9 additions & 1 deletion pdns/recursordist/docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --generate-hashes requirements.in
Expand Down Expand Up @@ -265,6 +265,14 @@ sphinxcontrib-websupport==1.2.4 \
--hash=sha256:4edf0223a0685a7c485ae5a156b6f529ba1ee481a1417817935b20bde1956232 \
--hash=sha256:6fc9287dfc823fe9aa432463edd6cea47fa9ebbf488d7f289b322ffcfca075c7
# via sphinx
standard-imghdr==3.13.0 \
--hash=sha256:30a1bff5465605bb496f842a6ac3cc1f2131bf3025b0da28d4877d6d4b7cc8e9 \
--hash=sha256:8d9c68058d882f6fc3542a8d39ef9ff94d2187dc90bd0c851e0902776b7b7a42
# via -r requirements.in
standard-pipes==3.13.0 \
--hash=sha256:5805d0738fa17192e58cc4dea26dcfe9b8c5cd9c77e78d5dbded8bc3bda428c9 \
--hash=sha256:cde270ae625064211dbcd1c8f35a540b70d8ccd7443b099a496f8e6a44fed2f3
# via -r requirements.in
urllib3==2.2.3 \
--hash=sha256:ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac \
--hash=sha256:e7d814a81dad81e6caf2ec9fdedb284ecc9c73076b62654547cc64ccdcae26e9
Expand Down
37 changes: 37 additions & 0 deletions pdns/recursordist/meson-dist-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh -e

echo Running meson-dist-script
echo PWD=$(pwd)
echo MESON_SOURCE_ROOT=$MESON_SOURCE_ROOT
echo MESON_PROJECT_DIST_ROOT=$MESON_PROJECT_DIST_ROOT

cd "$MESON_PROJECT_DIST_ROOT"

# Get all symlinks
symlinks=$(find . -type l)

# Get the dereffed symbolic links (the actual files being pointed to) from the source dir
# Extract them over the existing symbolic links
tar -C "$MESON_SOURCE_ROOT" -hcf - $symlinks | tar -xf - -C "$MESON_PROJECT_DIST_ROOT"

# Run autoconf for people using autotools to build, this creates a configure script with VERSION set
echo Running autoreconf -vi so distfile is still usable for autotools building
# Run autoconf for people using autotools to build, this creates a configure sc
autoreconf -vi

# Generate man pages
cd "$MESON_PROJECT_BUILD_ROOT"
ninja man-pages
cp -vp rec-man-pages/*.1 "$MESON_PROJECT_DIST_ROOT"

rm -rf "$MESON_PROJECT_DIST_ROOT"/autom4te.cache


# Generate a few files to reduce build dependencies
echo 'If the below command generates an error, remove dnslabeltext.cc from source dir (remains of an autotools build?) and start again with a clean meson setup'
ninja librec-dnslabeltext.a.p/dnslabeltext.cc
cp -vp librec-dnslabeltext.a.p/dnslabeltext.cc "$MESON_PROJECT_DIST_ROOT"
echo 'If the below command generates an error, remove effective_tld_names.dat and pubsuffix.cc from source dir (remains of an autotools build?) and start again with a clean meson setup'
ninja effective_tld_names.dat
cp -vp effective_tld_names.dat "$MESON_PROJECT_DIST_ROOT"

8 changes: 7 additions & 1 deletion pdns/recursordist/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'pdns-recursor',
['c', 'cpp'],
version: run_command('../../builder-support' / 'gen-version', check: true).stdout().strip(),
version: run_command('version.sh', 'get-vcs', check: true).stdout().strip(),
license: 'GPLv2',
license_files: 'NOTICE',
meson_version: '>= 1.2.1',
Expand All @@ -11,6 +11,12 @@ project(
'cpp_std=c++17',
],
)
meson.add_dist_script('meson-dist-script.sh')

# When runniog meson dist, the command below produces multiple lines on stderr:
# Unable to evaluate subdir([]) in AstInterpreter --> Skipping
meson.add_dist_script('version.sh', 'set-dist', meson.project_version())

add_project_arguments('-DRECURSOR', language: 'cpp')


Expand Down
9 changes: 9 additions & 0 deletions pdns/recursordist/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ "$1" = "get-vcs" ]; then
builder-support/gen-version
elif [ "$1" = "set-dist" ]; then
$MESONREWRITE -V --sourcedir="$MESON_PROJECT_DIST_ROOT" kwargs set project / version "$2"
else
exit 1
fi
Loading