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.
pull/3273/head
Nirbheek Chauhan 8 years ago committed by Jussi Pakkanen
parent e984e1072b
commit d012b5b997
  1. 10
      mesonbuild/backend/ninjabackend.py
  2. 8
      mesonbuild/build.py
  3. 4
      mesonbuild/interpreter.py
  4. 6
      mesonbuild/mesonlib.py
  5. 5
      mesonbuild/scripts/yelphelper.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.

@ -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 ' \

@ -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]

@ -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()

@ -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)

Loading…
Cancel
Save