aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-05-29 20:29:28 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2018-03-19 23:45:43 +0200
commitd012b5b997e917a971bca1236a065453493c780d (patch)
treeb7e0737ea9d22d2a6b0b3a0a29bdc7c78d824ea5
parente984e1072b28abfa4ac278992a8ef6d138c15608 (diff)
downloadmeson-d012b5b997e917a971bca1236a065453493c780d.zip
meson-d012b5b997e917a971bca1236a065453493c780d.tar.gz
meson-d012b5b997e917a971bca1236a065453493c780d.tar.bz2
Create a helper for checking if a string has a path component
This is used in a number of places, and in some places it is incomplete. Use a helper to ensure it's used properly.
-rw-r--r--mesonbuild/backend/ninjabackend.py10
-rw-r--r--mesonbuild/build.py8
-rw-r--r--mesonbuild/interpreter.py4
-rw-r--r--mesonbuild/mesonlib.py6
-rw-r--r--mesonbuild/scripts/yelphelper.py5
5 files changed, 20 insertions, 13 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index ba249ed..9500d69 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -27,7 +27,7 @@ from .. import compilers
from ..compilers import CompilerArgs
from ..linkers import ArLinker
from ..mesonlib import File, MesonException, OrderedSet
-from ..mesonlib import get_compiler_for_source
+from ..mesonlib import get_compiler_for_source, has_path_sep
from .backends import CleanTrees, InstallData
from ..build import InvalidArguments
@@ -1335,7 +1335,7 @@ int dummy;
# Set runtime-paths so we can run executables without needing to set
# LD_LIBRARY_PATH, etc in the environment. Doesn't work on Windows.
- if '/' in target.name or '\\' in target.name:
+ if has_path_sep(target.name):
# Target names really should not have slashes in them, but
# unfortunately we did not check for that and some downstream projects
# now have them. Once slashes are forbidden, remove this bit.
@@ -2324,7 +2324,7 @@ rule FORTRAN_DEP_HACK
# FIXME FIXME: The usage of this is a terrible and unreliable hack
if isinstance(fname, File):
return fname.subdir != ''
- return '/' in fname or '\\' in fname
+ return has_path_sep(fname)
# Fortran is a bit weird (again). When you link against a library, just compiling a source file
# requires the mod files that are output when single files are built. To do this right we would need to
@@ -2370,7 +2370,7 @@ rule FORTRAN_DEP_HACK
pch = target.get_pch(lang)
if not pch:
continue
- if '/' not in pch[0] or '/' not in pch[-1]:
+ if not has_path_sep(pch[0]) or not has_path_sep(pch[-1]):
msg = 'Precompiled header of {!r} must not be in the same ' \
'directory as source, please put it in a subdirectory.' \
''.format(target.get_basename())
@@ -2547,7 +2547,7 @@ rule FORTRAN_DEP_HACK
commands += linker.get_option_link_args(self.environment.coredata.compiler_options)
# Set runtime-paths so we can run executables without needing to set
# LD_LIBRARY_PATH, etc in the environment. Doesn't work on Windows.
- if '/' in target.name or '\\' in target.name:
+ if has_path_sep(target.name):
# Target names really should not have slashes in them, but
# unfortunately we did not check for that and some downstream projects
# now have them. Once slashes are forbidden, remove this bit.
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 5c9f346..a1662f7 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -23,7 +23,7 @@ from . import mlog
from .mesonlib import File, MesonException, listify, extract_as_list
from .mesonlib import typeslistify, stringlistify, classify_unity_sources
from .mesonlib import get_filenames_templates_dict, substitute_values
-from .mesonlib import for_windows, for_darwin, for_cygwin, for_android
+from .mesonlib import for_windows, for_darwin, for_cygwin, for_android, has_path_sep
from .compilers import is_object, clike_langs, sort_clike, lang_suffixes
known_basic_kwargs = {'install': True,
@@ -286,7 +286,7 @@ class EnvironmentVariables:
class Target:
def __init__(self, name, subdir, subproject, build_by_default):
- if '/' in name or '\\' in name:
+ if has_path_sep(name):
# Fix failing test 53 when this becomes an error.
mlog.warning('''Target "%s" has a path separator in its name.
This is not supported, it can cause unexpected failures and will become
@@ -1067,7 +1067,7 @@ class Generator:
raise InvalidArguments('"output" may only contain strings.')
if '@BASENAME@' not in rule and '@PLAINNAME@' not in rule:
raise InvalidArguments('Every element of "output" must contain @BASENAME@ or @PLAINNAME@.')
- if '/' in rule or '\\' in rule:
+ if has_path_sep(rule):
raise InvalidArguments('"outputs" must not contain a directory separator.')
if len(outputs) > 1:
for o in outputs:
@@ -1666,7 +1666,7 @@ class CustomTarget(Target):
raise InvalidArguments('Output must not be empty.')
if i.strip() == '':
raise InvalidArguments('Output must not consist only of whitespace.')
- if '/' in i:
+ if has_path_sep(i):
raise InvalidArguments('Output must not contain a path segment.')
if '@INPUT@' in i or '@INPUT0@' in i:
m = 'Output cannot contain @INPUT@ or @INPUT0@, did you ' \
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index cab8bf3..1a1f6b4 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -21,7 +21,7 @@ from . import optinterpreter
from . import compilers
from .wrap import wrap, WrapMode
from . import mesonlib
-from .mesonlib import FileMode, Popen_safe, listify, extract_as_list
+from .mesonlib import FileMode, Popen_safe, listify, extract_as_list, has_path_sep
from .dependencies import ExternalProgram
from .dependencies import InternalDependency, Dependency, DependencyException
from .interpreterbase import InterpreterBase
@@ -1863,7 +1863,7 @@ external dependencies (including libraries) must go to "dependencies".''')
raise InterpreterException('Subproject name must not contain a ".." path segment.')
if os.path.isabs(dirname):
raise InterpreterException('Subproject name must not be an absolute path.')
- if '\\' in dirname or '/' in dirname:
+ if has_path_sep(dirname):
mlog.warning('Subproject name has a path separator. This may cause unexpected behaviour.')
if dirname in self.subproject_stack:
fullstack = self.subproject_stack + [dirname]
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 4e72600..247b4f9 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -519,6 +519,12 @@ def get_library_dirs():
unixdirs += glob('/lib/' + plat + '*')
return unixdirs
+def has_path_sep(name, sep='/\\'):
+ 'Checks if any of the specified @sep path separators are in @name'
+ for each in sep:
+ if each in name:
+ return True
+ return False
def do_replacement(regex, line, confdata):
missing_variables = set()
diff --git a/mesonbuild/scripts/yelphelper.py b/mesonbuild/scripts/yelphelper.py
index ab99267..0f8b0b8 100644
--- a/mesonbuild/scripts/yelphelper.py
+++ b/mesonbuild/scripts/yelphelper.py
@@ -17,6 +17,7 @@ import subprocess
import shutil
import argparse
from .. import mlog
+from ..mesonlib import has_path_sep
from . import destdir_join
from .gettext import read_linguas
@@ -79,7 +80,7 @@ def install_help(srcdir, blddir, sources, media, langs, install_dir, destdir, pr
elif symlinks:
srcfile = os.path.join(c_install_dir, m)
mlog.log('Symlinking %s to %s.' % (outfile, srcfile))
- if '/' in m or '\\' in m:
+ if has_path_sep(m):
os.makedirs(os.path.dirname(outfile), exist_ok=True)
try:
try:
@@ -94,7 +95,7 @@ def install_help(srcdir, blddir, sources, media, langs, install_dir, destdir, pr
# Lang doesn't have media file so copy it over 'C' one
infile = os.path.join(srcdir, 'C', m)
mlog.log('Installing %s to %s' % (infile, outfile))
- if '/' in m or '\\' in m:
+ if has_path_sep(m):
os.makedirs(os.path.dirname(outfile), exist_ok=True)
shutil.copyfile(infile, outfile)
shutil.copystat(infile, outfile)