aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-04-22 15:54:16 -0700
committerDylan Baker <dylan@pnwbakers.com>2019-04-25 12:28:51 -0700
commit5678468c2cc1f4639c68a95fb71f8212c846459b (patch)
treeeeedb656ffa320932b052043355e297809b90633 /mesonbuild
parent8e1670cc60cc853c7ddc81dceb65dc93fa45bfa9 (diff)
downloadmeson-5678468c2cc1f4639c68a95fb71f8212c846459b.zip
meson-5678468c2cc1f4639c68a95fb71f8212c846459b.tar.gz
meson-5678468c2cc1f4639c68a95fb71f8212c846459b.tar.bz2
Don't use len() to test for container emptiness
I ran the numbers once before (it's in the meson history) but it's *much* faster to *not* use len for testing if a container is empty or not.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/xcodebackend.py4
-rw-r--r--mesonbuild/compilers/c.py2
-rw-r--r--mesonbuild/compilers/compilers.py2
-rw-r--r--mesonbuild/dependencies/boost.py4
-rw-r--r--mesonbuild/mesonmain.py2
-rw-r--r--mesonbuild/minit.py2
-rw-r--r--mesonbuild/mintro.py4
-rw-r--r--mesonbuild/modules/cmake.py2
-rw-r--r--mesonbuild/modules/qt.py12
-rw-r--r--mesonbuild/modules/rpm.py6
-rw-r--r--mesonbuild/modules/unstable_icestorm.py2
-rw-r--r--mesonbuild/modules/unstable_simd.py2
-rw-r--r--mesonbuild/scripts/dist.py2
-rw-r--r--mesonbuild/scripts/gtkdochelper.py14
-rw-r--r--mesonbuild/scripts/meson_exe.py2
-rw-r--r--mesonbuild/scripts/symbolextractor.py4
16 files changed, 33 insertions, 33 deletions
diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py
index 990b824..7dd3674 100644
--- a/mesonbuild/backend/xcodebackend.py
+++ b/mesonbuild/backend/xcodebackend.py
@@ -748,7 +748,7 @@ class XCodeBackend(backends.Backend):
gargs = self.build.global_args.get(lang, [])
targs = target.get_extra_args(lang)
args = pargs + gargs + targs
- if len(args) > 0:
+ if args:
langargs[langnamemap[lang]] = args
symroot = os.path.join(self.environment.get_build_dir(), target.subdir)
self.write_line('%s /* %s */ = {' % (valid, buildtype))
@@ -783,7 +783,7 @@ class XCodeBackend(backends.Backend):
self.write_line('GCC_PREFIX_HEADER = "$(PROJECT_DIR)/%s";' % relative_pch_path)
self.write_line('GCC_PREPROCESSOR_DEFINITIONS = "";')
self.write_line('GCC_SYMBOLS_PRIVATE_EXTERN = NO;')
- if len(headerdirs) > 0:
+ if headerdirs:
quotedh = ','.join(['"\\"%s\\""' % i for i in headerdirs])
self.write_line('HEADER_SEARCH_PATHS=(%s);' % quotedh)
self.write_line('INSTALL_PATH = "%s";' % install_path)
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index da9a5dc..94ef336 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -248,7 +248,7 @@ class CCompiler(Compiler):
for d in dirs:
files = [f for f in os.listdir(d) if f.endswith('.so') and os.path.isfile(os.path.join(d, f))]
# if no files, accept directory and move on
- if len(files) == 0:
+ if not files:
retval.append(d)
continue
file_to_check = os.path.join(d, files[0])
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 79eefd1..87a83e5 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1506,7 +1506,7 @@ def gnulike_default_include_dirs(compiler, lang):
break
else:
paths.append(line[1:])
- if len(paths) == 0:
+ if not paths:
mlog.warning('No include directory found parsing "{cmd}" output'.format(cmd=" ".join(cmd)))
return paths
diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py
index 62a652a..381824c 100644
--- a/mesonbuild/dependencies/boost.py
+++ b/mesonbuild/dependencies/boost.py
@@ -209,7 +209,7 @@ class BoostDependency(ExternalDependency):
for root in self.boost_roots:
globtext = os.path.join(root, 'include', 'boost-*')
incdirs = glob.glob(globtext)
- if len(incdirs) > 0:
+ if incdirs:
return incdirs[0]
incboostdir = os.path.join(root, 'include', 'boost')
if os.path.isdir(incboostdir):
@@ -427,7 +427,7 @@ class BoostDependency(ExternalDependency):
for entry in globber2_matches:
fname = os.path.basename(entry)
self.lib_modules[self.modname_from_filename(fname)] = [fname]
- if len(globber2_matches) == 0:
+ if not globber2_matches:
# FIXME - why are we only looking for *.lib? Mingw provides *.dll.a and *.a
for entry in glob.glob(os.path.join(self.libdir, globber1 + '.lib')):
if self.static:
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index f80dfdd..4326c20 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -110,7 +110,7 @@ class CommandLineParser:
# If first arg is not a known command, assume user wants to run the setup
# command.
known_commands = list(self.commands.keys()) + ['-h', '--help']
- if len(args) == 0 or args[0] not in known_commands:
+ if not args or args[0] not in known_commands:
args = ['setup'] + args
# Hidden commands have their own parser instead of using the global one
diff --git a/mesonbuild/minit.py b/mesonbuild/minit.py
index 394fe40..4ae0ae3 100644
--- a/mesonbuild/minit.py
+++ b/mesonbuild/minit.py
@@ -442,7 +442,7 @@ def add_arguments(parser):
parser.add_argument('--version', default='0.1')
def run(options):
- if len(glob('*')) == 0:
+ if not glob('*'):
autodetect_options(options, sample=True)
if not options.language:
print('Defaulting to generating a C language project.')
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 32931b6..a4a6978 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -343,7 +343,7 @@ def list_projinfo_from_source(sourcedir: str, intr: IntrospectionInterpreter):
return intr.project_data
def print_results(options, results, indent):
- if len(results) == 0 and not options.force_dict:
+ if not results and not options.force_dict:
print('No command specified')
return 1
elif len(results) == 1 and not options.force_dict:
@@ -487,7 +487,7 @@ def write_meson_info_file(builddata: build.Build, errors: list, build_files_upda
'build_files_updated': build_files_updated,
}
- if len(errors) > 0:
+ if errors:
info_data['error'] = True
info_data['error_list'] = [x if isinstance(x, str) else str(x) for x in errors]
else:
diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py
index d98213d..2878134 100644
--- a/mesonbuild/modules/cmake.py
+++ b/mesonbuild/modules/cmake.py
@@ -158,7 +158,7 @@ class CmakeModule(ExtensionModule):
@permittedKwargs({'input', 'name', 'install_dir', 'configuration'})
def configure_package_config_file(self, interpreter, state, args, kwargs):
- if len(args) > 0:
+ if args:
raise mesonlib.MesonException('configure_package_config_file takes only keyword arguments.')
if 'input' not in kwargs:
diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py
index 0b252ac..11289c4 100644
--- a/mesonbuild/modules/qt.py
+++ b/mesonbuild/modules/qt.py
@@ -129,13 +129,13 @@ class QtBaseModule(ExtensionModule):
self._detect_tools(state.environment, method)
err_msg = "{0} sources specified and couldn't find {1}, " \
"please check your qt{2} installation"
- if len(moc_headers) + len(moc_sources) > 0 and not self.moc.found():
+ if (moc_headers or moc_sources) and not self.moc.found():
raise MesonException(err_msg.format('MOC', 'moc-qt{}'.format(self.qt_version), self.qt_version))
- if len(rcc_files) > 0:
+ if rcc_files:
if not self.rcc.found():
raise MesonException(err_msg.format('RCC', 'rcc-qt{}'.format(self.qt_version), self.qt_version))
# custom output name set? -> one output file, multiple otherwise
- if len(args) > 0:
+ if args:
qrc_deps = []
for i in rcc_files:
qrc_deps += self.parse_qrc(state, i)
@@ -160,7 +160,7 @@ class QtBaseModule(ExtensionModule):
'depend_files': qrc_deps}
res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs)
sources.append(res_target)
- if len(ui_files) > 0:
+ if ui_files:
if not self.uic.found():
raise MesonException(err_msg.format('UIC', 'uic-qt{}'.format(self.qt_version), self.qt_version))
arguments = uic_extra_arguments + ['-o', '@OUTPUT@', '@INPUT@']
@@ -183,14 +183,14 @@ class QtBaseModule(ExtensionModule):
'either an external dependency (returned by find_library() or '
'dependency()) or an internal dependency (returned by '
'declare_dependency()).'.format(type(dep).__name__))
- if len(moc_headers) > 0:
+ if moc_headers:
arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@']
moc_kwargs = {'output': 'moc_@BASENAME@.cpp',
'arguments': arguments}
moc_gen = build.Generator([self.moc], moc_kwargs)
moc_output = moc_gen.process_files('Qt{} moc header'.format(self.qt_version), moc_headers, state)
sources.append(moc_output)
- if len(moc_sources) > 0:
+ if moc_sources:
arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@']
moc_kwargs = {'output': '@BASENAME@.moc',
'arguments': arguments}
diff --git a/mesonbuild/modules/rpm.py b/mesonbuild/modules/rpm.py
index 9774286..7c1cefb 100644
--- a/mesonbuild/modules/rpm.py
+++ b/mesonbuild/modules/rpm.py
@@ -58,7 +58,7 @@ class RPMModule(ExtensionModule):
elif isinstance(target, TypelibTarget) and target.should_install():
files.add('%%{_libdir}/girepository-1.0/%s' % target.get_filename()[0])
for header in coredata.headers:
- if len(header.get_install_subdir()) > 0:
+ if header.get_install_subdir():
files_devel.add('%%{_includedir}/%s/' % header.get_install_subdir())
else:
for hdr_src in header.get_sources():
@@ -66,7 +66,7 @@ class RPMModule(ExtensionModule):
for man in coredata.man:
for man_file in man.get_sources():
files.add('%%{_mandir}/man%u/%s.*' % (int(man_file.split('.')[-1]), man_file))
- if len(files_devel) > 0:
+ if files_devel:
devel_subpkg = True
filename = os.path.join(coredata.environment.get_build_dir(),
@@ -122,7 +122,7 @@ class RPMModule(ExtensionModule):
fn.write('\n')
fn.write('%install\n')
fn.write('%meson_install\n')
- if len(to_delete) > 0:
+ if to_delete:
fn.write('rm -vf %s\n' % ' '.join(to_delete))
fn.write('\n')
fn.write('%check\n')
diff --git a/mesonbuild/modules/unstable_icestorm.py b/mesonbuild/modules/unstable_icestorm.py
index 051dc5f..268c394 100644
--- a/mesonbuild/modules/unstable_icestorm.py
+++ b/mesonbuild/modules/unstable_icestorm.py
@@ -36,7 +36,7 @@ class IceStormModule(ExtensionModule):
def project(self, interpreter, state, args, kwargs):
if not self.yosys_bin:
self.detect_binaries(interpreter)
- if not len(args):
+ if not args:
raise mesonlib.MesonException('Project requires at least one argument, which is the project name.')
proj_name = args[0]
arg_sources = args[1:]
diff --git a/mesonbuild/modules/unstable_simd.py b/mesonbuild/modules/unstable_simd.py
index b64242a..18a1099 100644
--- a/mesonbuild/modules/unstable_simd.py
+++ b/mesonbuild/modules/unstable_simd.py
@@ -65,7 +65,7 @@ class SimdModule(ExtensionModule):
if args is None:
mlog.log('Compiler supports %s:' % iset, mlog.red('NO'))
continue
- if len(args) > 0:
+ if args:
if not compiler.has_multi_arguments(args, state.environment):
mlog.log('Compiler supports %s:' % iset, mlog.red('NO'))
continue
diff --git a/mesonbuild/scripts/dist.py b/mesonbuild/scripts/dist.py
index 309a032..47fde23 100644
--- a/mesonbuild/scripts/dist.py
+++ b/mesonbuild/scripts/dist.py
@@ -133,7 +133,7 @@ def create_dist_hg(dist_name, src_root, bld_root, dist_sub, dist_scripts):
tarname = os.path.join(dist_sub, dist_name + '.tar')
xzname = tarname + '.xz'
subprocess.check_call(['hg', 'archive', '-R', src_root, '-S', '-t', 'tar', tarname])
- if len(dist_scripts) > 0:
+ if dist_scripts:
mlog.warning('dist scripts are not supported in Mercurial projects')
with lzma.open(xzname, 'wb') as xf, open(tarname, 'rb') as tf:
shutil.copyfileobj(tf, xf)
diff --git a/mesonbuild/scripts/gtkdochelper.py b/mesonbuild/scripts/gtkdochelper.py
index 01ced5b..11d31b6 100644
--- a/mesonbuild/scripts/gtkdochelper.py
+++ b/mesonbuild/scripts/gtkdochelper.py
@@ -175,7 +175,7 @@ def build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs,
mkdb_cmd.append('--name-space=' + namespace)
if modeflag:
mkdb_cmd.append(modeflag)
- if len(main_file) > 0:
+ if main_file:
# Yes, this is the flag even if the file is in xml.
mkdb_cmd.append('--main-sgml-file=' + main_file)
# Add user-specified arguments
@@ -187,7 +187,7 @@ def build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs,
'--path=' + ':'.join((doc_src, abs_out)),
module,
] + html_args
- if len(main_file) > 0:
+ if main_file:
mkhtml_cmd.append('../' + main_file)
else:
mkhtml_cmd.append('%s-docs.xml' % module)
@@ -212,23 +212,23 @@ def install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module):
def run(args):
options = parser.parse_args(args)
- if len(options.htmlargs) > 0:
+ if options.htmlargs:
htmlargs = options.htmlargs.split('@@')
else:
htmlargs = []
- if len(options.scanargs) > 0:
+ if options.scanargs:
scanargs = options.scanargs.split('@@')
else:
scanargs = []
- if len(options.scanobjsargs) > 0:
+ if options.scanobjsargs:
scanobjsargs = options.scanobjsargs.split('@@')
else:
scanobjsargs = []
- if len(options.fixxrefargs) > 0:
+ if options.fixxrefargs:
fixxrefargs = options.fixxrefargs.split('@@')
else:
fixxrefargs = []
- if len(options.mkdbargs) > 0:
+ if options.mkdbargs:
mkdbargs = options.mkdbargs.split('@@')
else:
mkdbargs = []
diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py
index 23c7334..a862ec5 100644
--- a/mesonbuild/scripts/meson_exe.py
+++ b/mesonbuild/scripts/meson_exe.py
@@ -60,7 +60,7 @@ def run_exe(exe):
cmd = exe.fname
child_env = os.environ.copy()
child_env.update(exe.env)
- if len(exe.extra_paths) > 0:
+ if exe.extra_paths:
child_env['PATH'] = (os.pathsep.join(exe.extra_paths + ['']) +
child_env['PATH'])
if exe.exe_runner and mesonlib.substring_is_in_list('wine', exe.exe_runner.get_command()):
diff --git a/mesonbuild/scripts/symbolextractor.py b/mesonbuild/scripts/symbolextractor.py
index 95ea0ec..410cb33 100644
--- a/mesonbuild/scripts/symbolextractor.py
+++ b/mesonbuild/scripts/symbolextractor.py
@@ -69,7 +69,7 @@ def linux_syms(libfilename, outfilename):
if pnm.returncode != 0:
raise RuntimeError('nm does not work.')
for line in output.split('\n'):
- if len(line) == 0:
+ if not line:
continue
line_split = line.split()
entry = line_split[0:2]
@@ -91,7 +91,7 @@ def osx_syms(libfilename, outfilename):
pnm, output = Popen_safe(['nm', '-g', '-P', libfilename])[0:2]
if pnm.returncode != 0:
raise RuntimeError('nm does not work.')
- result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0 and not x.endswith('U')]
+ result += [' '.join(x.split()[0:2]) for x in output.split('\n') if x and not x.endswith('U')]
write_if_changed('\n'.join(result) + '\n', outfilename)
def gen_symbols(libfilename, outfilename, cross_host):