blob: 93f2c84cb9654eb83234359718cd091369d88186 [file] [log] [blame]
Alexander Afanasyev2aa39622014-01-22 11:51:11 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07002"""
Davide Pesavento39c67f62023-02-15 00:26:26 -05003Copyright (c) 2014-2023, Regents of the University of California,
taylorchu5ae28772015-03-08 17:45:52 -07004 Arizona Board of Regents,
5 Colorado State University,
6 University Pierre & Marie Curie, Sorbonne University,
7 Washington University in St. Louis,
8 Beijing Institute of Technology,
9 The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010
11This file is part of NFD (Named Data Networking Forwarding Daemon).
12See AUTHORS.md for complete list of NFD authors and contributors.
13
14NFD is free software: you can redistribute it and/or modify it under the terms
15of the GNU General Public License as published by the Free Software Foundation,
16either version 3 of the License, or (at your option) any later version.
17
18NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20PURPOSE. See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License along with
23NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24"""
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080025
Davide Pesavento0064c1d2018-03-03 18:43:53 -050026from waflib import Context, Logs, Utils
27import os, subprocess
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070028
Davide Pesavento3bc8e192022-12-31 01:40:11 -050029VERSION = '22.12'
Davide Pesavento0064c1d2018-03-03 18:43:53 -050030APPNAME = 'nfd'
Davide Pesavento0064c1d2018-03-03 18:43:53 -050031GIT_TAG_PREFIX = 'NFD-'
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080032
33def options(opt):
Alexander Afanasyev5cda2e02014-04-11 13:58:44 -070034 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento40641272023-03-16 13:31:12 -040035 opt.load(['default-compiler-flags', 'pch',
36 'coverage', 'sanitizers', 'boost',
Davide Pesavento67f30272016-08-10 01:55:16 +000037 'dependency-checker', 'unix-socket', 'websocket',
38 'doxygen', 'sphinx_build'],
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070039 tooldir=['.waf-tools'])
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080040
Davide Pesavento17521592020-05-14 19:01:32 -040041 optgrp = opt.add_option_group('NFD Options')
Davide Pesavento67f30272016-08-10 01:55:16 +000042
Davide Pesavento17521592020-05-14 19:01:32 -040043 opt.addUnixOptions(optgrp)
44 opt.addDependencyOptions(optgrp, 'libresolv')
45 opt.addDependencyOptions(optgrp, 'librt')
46 opt.addDependencyOptions(optgrp, 'libpcap')
47 optgrp.add_option('--without-libpcap', action='store_true', default=False,
Davide Pesavento0064c1d2018-03-03 18:43:53 -050048 help='Disable libpcap (Ethernet face support will be disabled)')
Davide Pesavento17521592020-05-14 19:01:32 -040049 optgrp.add_option('--without-systemd', action='store_true', default=False,
Davide Pesavento774071c2018-11-15 21:33:23 -050050 help='Disable systemd integration')
Davide Pesavento17521592020-05-14 19:01:32 -040051 opt.addWebsocketOptions(optgrp)
Alexander Afanasyev5cda2e02014-04-11 13:58:44 -070052
Davide Pesavento17521592020-05-14 19:01:32 -040053 optgrp.add_option('--with-tests', action='store_true', default=False,
Davide Pesavento0064c1d2018-03-03 18:43:53 -050054 help='Build unit tests')
Davide Pesavento17521592020-05-14 19:01:32 -040055 optgrp.add_option('--with-other-tests', action='store_true', default=False,
Davide Pesavento0064c1d2018-03-03 18:43:53 -050056 help='Build other tests')
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -060057
Davide Pesavento0064c1d2018-03-03 18:43:53 -050058PRIVILEGE_CHECK_CODE = '''
59#include <unistd.h>
60#include <grp.h>
61#include <pwd.h>
62int main()
63{
64 sysconf(_SC_GETGR_R_SIZE_MAX);
65
66 char buffer[100];
67 group grp;
68 group* grpRes;
69 getgrnam_r("nogroup", &grp, buffer, 100, &grpRes);
70 passwd pwd;
71 passwd* pwdRes;
72 getpwnam_r("nobody", &pwd, buffer, 100, &pwdRes);
73
74 int ret = setegid(grp.gr_gid);
75 ret = seteuid(pwd.pw_uid);
76 (void)(ret);
77
78 getegid();
79 geteuid();
80}
81'''
Alexander Afanasyev8269a052015-02-09 16:25:36 -080082
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080083def configure(conf):
Beichuan Zhang55b8ed42014-04-26 22:25:44 -070084 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento40641272023-03-16 13:31:12 -040085 'default-compiler-flags', 'pch',
86 'boost', 'dependency-checker', 'websocket',
Davide Pesavento67f30272016-08-10 01:55:16 +000087 'doxygen', 'sphinx_build'])
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070088
Davide Pesavento6ecc3f82019-02-17 22:23:08 -050089 conf.env.WITH_TESTS = conf.options.with_tests
90 conf.env.WITH_OTHER_TESTS = conf.options.with_other_tests
Davide Pesavento774071c2018-11-15 21:33:23 -050091
Davide Pesavento2150da82022-07-08 18:18:51 -040092 conf.find_program('bash')
93 conf.find_program('dot', mandatory=False)
94
95 # Prefer pkgconf if it's installed, because it gives more correct results
96 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
97 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
98 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesaventof0ae4422014-05-05 16:32:12 +020099
Davide Pesaventodeb54272022-03-11 18:51:05 -0500100 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento3bc8e192022-12-31 01:40:11 -0500101 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesaventodeb54272022-03-11 18:51:05 -0500102 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Davide Pesavento44deacc2014-02-19 10:48:07 +0100103
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500104 if not conf.options.without_systemd:
105 conf.check_cfg(package='libsystemd', args=['--cflags', '--libs'],
106 uselib_store='SYSTEMD', mandatory=False)
Davide Pesavento774071c2018-11-15 21:33:23 -0500107
Davide Pesaventob499a602014-11-18 22:36:56 +0100108 conf.checkDependency(name='librt', lib='rt', mandatory=False)
109 conf.checkDependency(name='libresolv', lib='resolv', mandatory=False)
110
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500111 conf.check_cxx(msg='Checking if privilege drop/elevation is supported', mandatory=False,
112 define_name='HAVE_PRIVILEGE_DROP_AND_ELEVATE', fragment=PRIVILEGE_CHECK_CODE)
Alexander Afanasyev748e9892015-01-28 15:07:41 -0800113
Davide Pesaventoaaa5dd32016-09-02 12:33:33 +0000114 conf.check_cxx(header_name='valgrind/valgrind.h', define_name='HAVE_VALGRIND', mandatory=False)
Alexander Afanasyev49343f62015-01-26 21:58:07 -0800115
Davide Pesavento2bdf60c2019-02-19 18:23:45 -0500116 boost_libs = ['system', 'program_options', 'filesystem']
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500117 if conf.env.WITH_TESTS or conf.env.WITH_OTHER_TESTS:
118 boost_libs.append('unit_test_framework')
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400119
Yumin Xiaab497452016-05-10 20:23:24 +0800120 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoc52cd5e2022-03-05 20:40:54 -0500121 if conf.env.BOOST_VERSION_NUMBER < 106501:
Davide Pesavento17521592020-05-14 19:01:32 -0400122 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
123 'Please upgrade your distribution or manually install a newer version of Boost.\n'
124 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800125
126 conf.load('unix-socket')
Davide Pesavento44deacc2014-02-19 10:48:07 +0100127
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700128 if not conf.options.without_libpcap:
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500129 conf.checkDependency(name='libpcap', lib='pcap',
Davide Pesavento5f35f642018-05-10 19:36:03 -0400130 errmsg='not found, but required for Ethernet face support. '
131 'Specify --without-libpcap to disable Ethernet face support.')
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -0700132
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500133 conf.checkWebsocket()
Davide Pesavento774071c2018-11-15 21:33:23 -0500134
Alexander Afanasyevb5220702017-09-21 18:57:00 -0400135 conf.check_compiler_flags()
136
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500137 # Loading "late" to prevent tests from being compiled with profiling flags
Alexander Afanasyev689569b2014-02-16 20:20:07 -0800138 conf.load('coverage')
Eric Newberry27bdd1a2016-11-01 18:02:54 -0700139 conf.load('sanitizers')
140
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500141 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
142 conf.define_cond('WITH_OTHER_TESTS', conf.env.WITH_OTHER_TESTS)
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500143 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nfd.conf' % conf.env.SYSCONFDIR)
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500144 # The config header will contain all defines that were added using conf.define()
145 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
146 # will not appear in the config header, but will instead be passed directly to the
147 # compiler on the command line.
Davide Pesavento264af772021-02-09 21:48:24 -0500148 conf.write_config_header('core/config.hpp', define_prefix='NFD_')
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800149
Junxiao Shi09bf7c42014-01-31 11:10:25 -0700150def build(bld):
Davide Pesavento03f45d22019-04-04 12:34:26 -0400151 versionhpp(bld)
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700152
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500153 bld(features='subst',
Davide Pesavento03f45d22019-04-04 12:34:26 -0400154 name='version.cpp',
155 source='core/version.cpp.in',
156 target='core/version.cpp',
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700157 install_path=None,
158 VERSION_STRING=VERSION_BASE,
Davide Pesavento03f45d22019-04-04 12:34:26 -0400159 VERSION_BUILD=VERSION)
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700160
Davide Pesaventoa3148082018-04-12 18:21:54 -0400161 bld.objects(
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700162 target='core-objects',
Davide Pesavento03f45d22019-04-04 12:34:26 -0400163 source=bld.path.find_node('core').ant_glob('*.cpp') + ['core/version.cpp'],
164 use='version.cpp version.hpp NDN_CXX BOOST LIBRT',
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500165 includes='.',
Davide Pesaventoa9b09b62022-06-04 14:07:25 -0400166 export_includes='.')
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700167
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500168 nfd_objects = bld.objects(
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700169 target='daemon-objects',
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500170 source=bld.path.ant_glob('daemon/**/*.cpp',
Davide Pesaventofe0580c2017-05-12 02:02:10 -0400171 excl=['daemon/face/*ethernet*.cpp',
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500172 'daemon/face/pcap*.cpp',
173 'daemon/face/unix*.cpp',
174 'daemon/face/websocket*.cpp',
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -0700175 'daemon/main.cpp']),
Davide Pesaventoa9b09b62022-06-04 14:07:25 -0400176 features='pch',
177 headers='daemon/nfd-pch.hpp',
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500178 use='core-objects',
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600179 includes='daemon',
Davide Pesavento67f30272016-08-10 01:55:16 +0000180 export_includes='daemon')
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700181
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500182 if bld.env.HAVE_LIBPCAP:
Davide Pesaventofe0580c2017-05-12 02:02:10 -0400183 nfd_objects.source += bld.path.ant_glob('daemon/face/*ethernet*.cpp')
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500184 nfd_objects.source += bld.path.ant_glob('daemon/face/pcap*.cpp')
Alexander Afanasyev5cda2e02014-04-11 13:58:44 -0700185 nfd_objects.use += ' LIBPCAP'
Davide Pesavento44deacc2014-02-19 10:48:07 +0100186
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500187 if bld.env.HAVE_UNIX_SOCKETS:
188 nfd_objects.source += bld.path.ant_glob('daemon/face/unix*.cpp')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800189
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500190 if bld.env.HAVE_WEBSOCKET:
191 nfd_objects.source += bld.path.ant_glob('daemon/face/websocket*.cpp')
192 nfd_objects.use += ' WEBSOCKET'
Wentao Shang53df1632014-04-21 12:01:32 -0700193
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500194 if bld.env.WITH_OTHER_TESTS:
Eric Newberry69b63dc2017-11-04 15:42:46 -0700195 nfd_objects.source += bld.path.ant_glob('tests/other/fw/*.cpp')
196
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500197 bld.program(name='nfd',
198 target='bin/nfd',
199 source='daemon/main.cpp',
Davide Pesavento1b077f62019-02-19 19:19:44 -0500200 use='daemon-objects SYSTEMD')
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700201
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500202 bld.recurse('tools')
203 bld.recurse('tests')
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400204
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500205 bld(features='subst',
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -0700206 source='nfd.conf.sample.in',
207 target='nfd.conf.sample',
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500208 install_path='${SYSCONFDIR}/ndn',
209 IF_HAVE_LIBPCAP='' if bld.env.HAVE_LIBPCAP else '; ',
Eric Newberry22974902020-04-06 23:41:00 -0700210 IF_HAVE_WEBSOCKET='' if bld.env.HAVE_WEBSOCKET else '; ',
211 UNIX_SOCKET_PATH='/run/nfd.sock' if Utils.unversioned_sys_platform() == 'linux' else '/var/run/nfd.sock')
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800212
Davide Pesaventof392b8f2019-01-08 20:51:55 -0500213 bld.install_files('${SYSCONFDIR}/ndn', 'autoconfig.conf.sample')
214
Davide Pesavento6ecc3f82019-02-17 22:23:08 -0500215 if bld.env.HAVE_SYSTEMD:
Davide Pesaventof392b8f2019-01-08 20:51:55 -0500216 systemd_units = bld.path.ant_glob('systemd/*.in')
217 bld(features='subst',
218 name='systemd-units',
219 source=systemd_units,
220 target=[u.change_ext('') for u in systemd_units])
221
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500222 if bld.env.SPHINX_BUILD:
223 bld(features='sphinx',
224 name='manpages',
225 builder='man',
226 config='docs/conf.py',
227 outdir='docs/manpages',
Davide Pesavento08b91c82019-04-13 19:42:10 -0400228 source=bld.path.ant_glob('docs/manpages/*.rst'),
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500229 install_path='${MANDIR}',
Davide Pesavento08b91c82019-04-13 19:42:10 -0400230 version=VERSION_BASE,
231 release=VERSION)
Junxiao Shi6c135622016-11-21 14:30:33 +0000232 bld.symlink_as('${MANDIR}/man1/nfdc-channel.1', 'nfdc-face.1')
Junxiao Shi6c135622016-11-21 14:30:33 +0000233 bld.symlink_as('${MANDIR}/man1/nfdc-fib.1', 'nfdc-route.1')
234 bld.symlink_as('${MANDIR}/man1/nfdc-register.1', 'nfdc-route.1')
235 bld.symlink_as('${MANDIR}/man1/nfdc-unregister.1', 'nfdc-route.1')
236 bld.symlink_as('${MANDIR}/man1/nfdc-set-strategy.1', 'nfdc-strategy.1')
237 bld.symlink_as('${MANDIR}/man1/nfdc-unset-strategy.1', 'nfdc-strategy.1')
Alexander Afanasyev49272f72014-04-06 21:49:46 -0700238
Davide Pesavento03f45d22019-04-04 12:34:26 -0400239def versionhpp(bld):
240 version(bld)
241
Alexander Afanasyev5006c1d2022-01-27 14:31:20 -0500242 vmajor = int(VERSION_SPLIT[0])
243 vminor = int(VERSION_SPLIT[1]) if len(VERSION_SPLIT) >= 2 else 0
244 vpatch = int(VERSION_SPLIT[2]) if len(VERSION_SPLIT) >= 3 else 0
245
Davide Pesavento03f45d22019-04-04 12:34:26 -0400246 bld(features='subst',
247 name='version.hpp',
248 source='core/version.hpp.in',
249 target='core/version.hpp',
250 install_path=None,
Alexander Afanasyev5006c1d2022-01-27 14:31:20 -0500251 VERSION=vmajor * 1000000 + vminor * 1000 + vpatch,
252 VERSION_MAJOR=str(vmajor),
253 VERSION_MINOR=str(vminor),
254 VERSION_PATCH=str(vpatch))
Davide Pesavento03f45d22019-04-04 12:34:26 -0400255
Alexander Afanasyev284257b2014-04-11 14:16:51 -0700256def docs(bld):
257 from waflib import Options
258 Options.commands = ['doxygen', 'sphinx'] + Options.commands
259
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800260def doxygen(bld):
Davide Pesavento03f45d22019-04-04 12:34:26 -0400261 versionhpp(bld)
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700262
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800263 if not bld.env.DOXYGEN:
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500264 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Beichuan Zhang55b8ed42014-04-26 22:25:44 -0700265
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500266 bld(features='subst',
267 name='doxygen.conf',
268 source=['docs/doxygen.conf.in',
269 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
270 target=['docs/doxygen.conf',
271 'docs/named_data_theme/named_data_footer-with-analytics.html'],
272 VERSION=VERSION,
Davide Pesaventoa47cca22021-04-16 02:30:11 -0400273 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500274 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
275 if os.getenv('GOOGLE_ANALYTICS', None) \
276 else '../docs/named_data_theme/named_data_footer.html',
277 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
278
279 bld(features='doxygen',
280 doxyfile='docs/doxygen.conf',
Davide Pesavento03f45d22019-04-04 12:34:26 -0400281 use='doxygen.conf version.hpp')
Alexander Afanasyev49272f72014-04-06 21:49:46 -0700282
283def sphinx(bld):
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700284 version(bld)
285
Beichuan Zhang55b8ed42014-04-26 22:25:44 -0700286 if not bld.env.SPHINX_BUILD:
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500287 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
288
289 bld(features='sphinx',
290 config='docs/conf.py',
291 outdir='docs',
292 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento08b91c82019-04-13 19:42:10 -0400293 version=VERSION_BASE,
294 release=VERSION)
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700295
296def version(ctx):
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500297 # don't execute more than once
Alexander Afanasyev26181532014-05-07 23:38:51 -0700298 if getattr(Context.g_module, 'VERSION_BASE', None):
299 return
300
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700301 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500302 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700303
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500304 # first, try to get a version string from git
305 gotVersionFromGit = False
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700306 try:
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700307 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500308 out = subprocess.check_output(cmd, universal_newlines=True).strip()
309 if out:
310 gotVersionFromGit = True
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700311 if out.startswith(GIT_TAG_PREFIX):
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500312 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700313 else:
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500314 # no tags matched
315 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento5f35f642018-05-10 19:36:03 -0400316 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700317 pass
318
Alexander Afanasyev34b2b572020-05-28 22:08:01 -0400319 versionFile = ctx.path.find_node('VERSION.info')
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500320 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700321 try:
322 Context.g_module.VERSION = versionFile.read()
323 return
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500324 except EnvironmentError:
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700325 pass
326
327 # version was obtained from git, update VERSION file if necessary
328 if versionFile is not None:
329 try:
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500330 if versionFile.read() == Context.g_module.VERSION:
331 # already up-to-date
332 return
333 except EnvironmentError as e:
334 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700335 else:
Alexander Afanasyev34b2b572020-05-28 22:08:01 -0400336 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700337
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700338 try:
339 versionFile.write(Context.g_module.VERSION)
Davide Pesavento0064c1d2018-03-03 18:43:53 -0500340 except EnvironmentError as e:
341 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev48f5a3c2014-08-22 22:33:01 -0700342
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700343def dist(ctx):
Davide Pesavento39c67f62023-02-15 00:26:26 -0500344 ctx.algo = 'tar.xz'
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700345 version(ctx)
346
347def distcheck(ctx):
Davide Pesavento39c67f62023-02-15 00:26:26 -0500348 ctx.algo = 'tar.xz'
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700349 version(ctx)