Skip to content

Commit

Permalink
build: use python f-strings
Browse files Browse the repository at this point in the history
Change-Id: I17695613bb737ac4ba297468c5859ceb18bfdf96
  • Loading branch information
Pesa committed Sep 8, 2023
1 parent 90d3a96 commit c996742
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions examples/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def build(bld):
# List all .cpp files (whole example in one .cpp)
for ex in bld.path.ant_glob('*.cpp'):
name = ex.change_ext('').path_from(bld.path.get_bld())
bld.program(name='example-%s' % name,
bld.program(name=f'example-{name}',
target=name,
source=[ex],
use='ndn-cxx',
Expand All @@ -15,7 +15,7 @@ def build(bld):
# List all directories (example can have multiple .cpp in the directory)
for subdir in bld.path.ant_glob('*', dir=True, src=False):
name = subdir.path_from(bld.path)
bld.program(name='example-%s' % name,
bld.program(name=f'example-{name}',
target=name,
source=subdir.ant_glob('**/*.cpp'),
use='ndn-cxx',
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarks/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ top = '../..'
def build(bld):
for test in bld.path.ant_glob('*.cpp'):
name = test.change_ext('').path_from(bld.path.get_bld())
bld.program(name='test-%s' % name,
bld.program(name=f'test-{name}',
target=name,
source=[test],
use='tests-common',
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ top = '../..'
def build(bld):
for test in bld.path.ant_glob('*.cpp'):
name = test.change_ext('').path_from(bld.path.get_bld())
bld.program(name='test-%s' % name,
bld.program(name=f'test-{name}',
target=name,
source=[test],
use='tests-common',
Expand Down
12 changes: 6 additions & 6 deletions tools/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

from waflib import Utils

top = '../'
top = '..'

def build(bld):
# Single object tools:
# tools/foo.cpp is a self-contained tool with a main() function
# and is built as build/bin/foo. These tools cannot be unit-tested.
for tool in bld.path.ant_glob('*.cpp'):
name = tool.change_ext('').path_from(bld.path.get_bld())
bld.program(name='tool-%s' % name,
target=top + 'bin/%s' % name,
bld.program(name=f'tool-{name}',
target=f'{top}/bin/{name}',
source=[tool],
use='ndn-cxx')

Expand All @@ -35,11 +35,11 @@ def build(bld):
srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
srcObjects = ''
if srcFiles:
srcObjects = 'tool-%s-objects' % name
srcObjects = f'tool-{name}-objects'
bld.objects(target=srcObjects,
source=srcFiles,
use='ndn-cxx')
bld.program(name='tool-%s' % name,
target=top + 'bin/%s' % name,
bld.program(name=f'tool-{name}',
target=f'{top}/bin/{name}',
source=[mainFile],
use='ndn-cxx ' + srcObjects)
72 changes: 35 additions & 37 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ def configure(conf):
# auto-detect
for candidate in ('backtrace', 'basic'):
try:
conf.check_boost(lib='stacktrace_%s' % candidate, mt=True)
conf.check_boost(lib=f'stacktrace_{candidate}', mt=True)
except conf.errors.ConfigurationError:
continue
stacktrace_backend = candidate
break
if stacktrace_backend:
conf.env.HAVE_STACKTRACE = True
conf.env.append_unique('DEFINES_BOOST', ['BOOST_STACKTRACE_DYN_LINK'])
boost_libs.append('stacktrace_%s' % stacktrace_backend)
boost_libs.append(f'stacktrace_{stacktrace_backend}')

if conf.env.WITH_TESTS:
boost_libs.append('unit_test_framework')
Expand Down Expand Up @@ -228,41 +228,39 @@ def build(bld):
pkgconfig_cxxflags = []
pkgconfig_defines = []
for lib in Utils.to_list(libndn_cxx['use']):
if bld.env['LIB_%s' % lib]:
pkgconfig_libs += Utils.to_list(bld.env['LIB_%s' % lib])
if bld.env['LIBPATH_%s' % lib]:
pkgconfig_ldflags += Utils.to_list(bld.env['LIBPATH_%s' % lib])
if bld.env['INCLUDES_%s' % lib]:
pkgconfig_includes += Utils.to_list(bld.env['INCLUDES_%s' % lib])
if bld.env['LINKFLAGS_%s' % lib]:
pkgconfig_linkflags += Utils.to_list(bld.env['LINKFLAGS_%s' % lib])
if bld.env['CXXFLAGS_%s' % lib]:
pkgconfig_cxxflags += Utils.to_list(bld.env['CXXFLAGS_%s' % lib])
if bld.env['DEFINES_%s' % lib]:
pkgconfig_defines += Utils.to_list(bld.env['DEFINES_%s' % lib])
if bld.env[f'LIB_{lib}']:
pkgconfig_libs += Utils.to_list(bld.env[f'LIB_{lib}'])
if bld.env[f'LIBPATH_{lib}']:
pkgconfig_ldflags += Utils.to_list(bld.env[f'LIBPATH_{lib}'])
if bld.env[f'INCLUDES_{lib}']:
pkgconfig_includes += Utils.to_list(bld.env[f'INCLUDES_{lib}'])
if bld.env[f'LINKFLAGS_{lib}']:
pkgconfig_linkflags += Utils.to_list(bld.env[f'LINKFLAGS_{lib}'])
if bld.env[f'CXXFLAGS_{lib}']:
pkgconfig_cxxflags += Utils.to_list(bld.env[f'CXXFLAGS_{lib}'])
if bld.env[f'DEFINES_{lib}']:
pkgconfig_defines += Utils.to_list(bld.env[f'DEFINES_{lib}'])

EXTRA_FRAMEWORKS = ''
if bld.env.HAVE_OSX_FRAMEWORKS:
EXTRA_FRAMEWORKS = '-framework CoreFoundation -framework Security -framework SystemConfiguration -framework Foundation -framework CoreWLAN'

def uniq(alist):
seen = set()
return [x for x in alist if x not in seen and not seen.add(x)]

pkconfig = bld(features='subst',
source='libndn-cxx.pc.in',
target='libndn-cxx.pc',
install_path='${LIBDIR}/pkgconfig',
VERSION=VERSION_BASE,

# This probably not the right thing to do, but to simplify life of apps
# that use the library
EXTRA_LIBS=' '.join([('-l%s' % i) for i in uniq(pkgconfig_libs)]),
EXTRA_LDFLAGS=' '.join([('-L%s' % i) for i in uniq(pkgconfig_ldflags)]),
EXTRA_LINKFLAGS=' '.join(uniq(pkgconfig_linkflags)),
EXTRA_INCLUDES=' '.join([('-I%s' % i) for i in uniq(pkgconfig_includes)]),
EXTRA_CXXFLAGS=' '.join(uniq(pkgconfig_cxxflags) + [('-D%s' % i) for i in uniq(pkgconfig_defines)]),
EXTRA_FRAMEWORKS=EXTRA_FRAMEWORKS)
return list(dict.fromkeys(alist))

bld(features='subst',
source='libndn-cxx.pc.in',
target='libndn-cxx.pc',
install_path='${LIBDIR}/pkgconfig',
VERSION=VERSION_BASE,
# This probably not the right thing to do, but to simplify life of apps
# that use the library
EXTRA_LIBS=' '.join([f'-l{i}' for i in uniq(pkgconfig_libs)]),
EXTRA_LDFLAGS=' '.join([f'-L{i}' for i in uniq(pkgconfig_ldflags)]),
EXTRA_LINKFLAGS=' '.join(uniq(pkgconfig_linkflags)),
EXTRA_INCLUDES=' '.join([f'-I{i}' for i in uniq(pkgconfig_includes)]),
EXTRA_CXXFLAGS=' '.join(uniq(pkgconfig_cxxflags) + [f'-D{i}' for i in uniq(pkgconfig_defines)]),
EXTRA_FRAMEWORKS=EXTRA_FRAMEWORKS)

if bld.env.WITH_TESTS:
bld.recurse('tests')
Expand Down Expand Up @@ -363,16 +361,16 @@ def version(ctx):
# first, try to get a version string from git
gotVersionFromGit = False
try:
cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
out = subprocess.check_output(cmd, universal_newlines=True).strip()
cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
if out:
gotVersionFromGit = True
if out.startswith(GIT_TAG_PREFIX):
Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
else:
# no tags matched
Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
except (OSError, subprocess.CalledProcessError):
Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
except (OSError, subprocess.SubprocessError):
pass

versionFile = ctx.path.find_node('VERSION.info')
Expand All @@ -390,14 +388,14 @@ def version(ctx):
# already up-to-date
return
except EnvironmentError as e:
Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
else:
versionFile = ctx.path.make_node('VERSION.info')

try:
versionFile.write(Context.g_module.VERSION)
except EnvironmentError as e:
Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Logs.warn(f'{versionFile} is not writable ({e.strerror})')

def dist(ctx):
ctx.algo = 'tar.xz'
Expand Down

0 comments on commit c996742

Please sign in to comment.