Skip to content

Commit

Permalink
Add PIE810 multiple-starts-ends-with
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Jul 27, 2024
1 parent 1f40c17 commit 5d6ddb6
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/arglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def extend_preserving_lflags(self, iterable: T.Iterable[str]) -> None:
normal_flags = []
lflags = []
for i in iterable:
if i not in self.always_dedup_args and (i.startswith('-l') or i.startswith('-L')):
if i not in self.always_dedup_args and (i.startswith(('-l', '-L'))):
lflags.append(i)
else:
normal_flags.append(i)
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ def generate_cs_resource_tasks(self, target):
rel_sourcefile = os.path.join(self.build_to_src, target.subdir, r)
if r.endswith('.resources'):
a = '-resource:' + rel_sourcefile
elif r.endswith('.txt') or r.endswith('.resx'):
elif r.endswith(('.txt', '.resx')):
ofilebase = os.path.splitext(os.path.basename(r))[0] + '.resources'
ofilename = os.path.join(self.get_target_private_dir(target), ofilebase)
elem = NinjaBuildElement(self.all_outputs, ofilename, "CUSTOM_COMMAND", rel_sourcefile)
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def split_link_args(args):
other.append(arg)
# It's ok if we miss libraries with non-standard extensions here.
# They will go into the general link arguments.
elif arg.endswith('.lib') or arg.endswith('.a'):
elif arg.endswith(('.lib', '.a')):
# De-dup
if arg not in libs:
libs.append(arg)
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/backend/xcodebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ def generate_single_build_target(self, objects_dict, target_name, target) -> Non
outputs = self.generator_outputs[target_name, generator_id]
generator_id += 1
for o_abs in outputs:
if o_abs.endswith('.o') or o_abs.endswith('.obj'):
if o_abs.endswith(('.o', '.obj')):
ldargs += [r'\"' + o_abs + r'\"']
else:
if isinstance(o, build.CustomTarget):
Expand Down Expand Up @@ -1750,7 +1750,7 @@ def generate_single_build_target(self, objects_dict, target_name, target) -> Non
# file. Since Xcode itself already discourages precompiled headers in favor of modules we don't try much harder here.
pchs = target.get_pch('c') + target.get_pch('cpp') + target.get_pch('objc') + target.get_pch('objcpp')
# Make sure to use headers (other backends require implementation files like *.c *.cpp, etc; these should not be used here)
pchs = [pch for pch in pchs if pch.endswith('.h') or pch.endswith('.hh') or pch.endswith('hpp')]
pchs = [pch for pch in pchs if pch.endswith(('.h', '.hh', 'hpp'))]
if pchs:
if len(pchs) > 1:
mlog.warning(f'Unsupported Xcode configuration: More than 1 precompiled header found "{pchs!s}". Target "{target.name}" might not compile correctly.')
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def _translate_args_to_nongnu(cls, args: T.List[str], info: MachineInfo, link_id
if suffix in link_flags_with_arg:
link_expect_arg = True

if suffix.startswith('-') or suffix.startswith('@'):
if suffix.startswith(('-', '@')):
# this is not search path
dcargs.append(arg)
continue
Expand All @@ -312,7 +312,7 @@ def _translate_args_to_nongnu(cls, args: T.List[str], info: MachineInfo, link_id
continue

# Make sure static library files are passed properly to the linker.
if arg.endswith('.a') or arg.endswith('.lib'):
if arg.endswith(('.a', '.lib')):
if len(suffix) > 0 and not suffix.startswith('-'):
dcargs.append('-L=' + suffix)
continue
Expand Down
4 changes: 1 addition & 3 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
continue
# cl.exe does not allow specifying both, so remove /utf-8 that we
# added automatically in the case the user overrides it manually.
elif (i.startswith('/source-charset:')
or i.startswith('/execution-charset:')
or i == '/validate-charset-'):
elif (i.startswith(('/source-charset:', '/execution-charset:')) or i == '/validate-charset-'):
try:
result.remove('/utf-8')
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def sanitize_prefix(self, prefix: str) -> str:
prefix = os.path.expanduser(prefix)
if not os.path.isabs(prefix):
raise MesonException(f'prefix value {prefix!r} must be an absolute path')
if prefix.endswith('/') or prefix.endswith('\\'):
if prefix.endswith(('/', '\\')):
# On Windows we need to preserve the trailing slash if the
# string is of type 'C:\' because 'C:' is not an absolute path.
if len(prefix) == 3 and prefix[1] == ':':
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_compile_args(self) -> T.List[str]:
if self.include_type == 'system':
converted = []
for i in self.compile_args:
if i.startswith('-I') or i.startswith('/I'):
if i.startswith(('-I', '/I')):
converted += ['-isystem' + i[2:]]
else:
converted += [i]
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/dependencies/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ def search_lib_dirs(path: str) -> bool:
# Check PATH
system_env: T.List[str] = []
for i in os.environ.get('PATH', '').split(os.pathsep):
if i.endswith('/bin') or i.endswith('\\bin'):
if i.endswith(('/bin', '\\bin')):
i = i[:-4]
if i.endswith('/sbin') or i.endswith('\\sbin'):
if i.endswith(('/sbin', '\\sbin')):
i = i[:-5]
system_env += [i]

Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/dependencies/dub.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def find_package_target(pkg: T.Dict[str, str]) -> bool:

for file in bs['sourceFiles']:
# sourceFiles may contain static libraries
if file.endswith('.lib') or file.endswith('.a'):
if file.endswith(('.lib', '.a')):
self.link_args.append(file)

for flag in bs['lflags']:
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/dependencies/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
debug_lib_name = self.qtpkgname + 'Core' + _get_modules_lib_suffix(self.version, self.env.machines[self.for_machine], True)
is_debug = False
for arg in self.get_link_args():
if arg == f'-l{debug_lib_name}' or arg.endswith(f'{debug_lib_name}.lib') or arg.endswith(f'{debug_lib_name}.a'):
if arg == f'-l{debug_lib_name}' or arg.endswith((f'{debug_lib_name}.lib', f'{debug_lib_name}.a')):
is_debug = True
break
libdir = self.get_variable(pkgconfig='libdir')
Expand Down
6 changes: 1 addition & 5 deletions mesonbuild/dependencies/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ def filter_args(args: T.List[str]) -> T.List[str]:
"""
result = []
for f in args:
if f.startswith('-D') \
or f.startswith('-f') \
or f.startswith('-I') \
or f == '-pthread' \
or (f.startswith('-W') and not f == '-Wall'):
if f.startswith(('-D', '-f', '-I')) or f == '-pthread' or f.startswith('-W') and not f == '-Wall':
result.append(f)
return result

Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def detect_cpu_family(compilers: CompilersDict) -> str:
elif trial.startswith('aarch64'):
# This can be `aarch64_be`
trial = 'aarch64'
elif trial.startswith('arm') or trial.startswith('earm'):
elif trial.startswith(('arm', 'earm')):
trial = 'arm'
elif trial.startswith(('powerpc64', 'ppc64')):
trial = 'ppc64'
Expand Down Expand Up @@ -409,7 +409,7 @@ def detect_cpu(compilers: CompilersDict) -> str:
# Same check as above for cpu_family
if any_compiler_has_define(compilers, '__i386__'):
trial = 'i686' # All 64 bit cpus have at least this level of x86 support.
elif trial.startswith('aarch64') or trial.startswith('arm64'):
elif trial.startswith(('aarch64', 'arm64')):
# Same check as above for cpu_family
if any_compiler_has_define(compilers, '__arm__'):
trial = 'arm'
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,7 @@ def _warn_about_builtin_args(self, args: T.List[str]) -> None:
elif arg in {'-fsanitize', '/fsanitize'} or arg.startswith(('-fsanitize=', '/fsanitize=')):
mlog.warning(f'Consider using the built-in option for sanitizers instead of using "{arg}".',
location=self.current_node)
elif arg.startswith('-std=') or arg.startswith('/std:'):
elif arg.startswith(('-std=', '/std:')):
mlog.warning(f'Consider using the built-in option for language standard version instead of using "{arg}".',
location=self.current_node)

Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/minstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def check_for_stampfile(fname: str) -> str:
whose names are not known at configure time.
Check if this is the case and return the real
file instead.'''
if fname.endswith('.so') or fname.endswith('.dll'):
if fname.endswith(('.so', '.dll')):
if os.stat(fname).st_size == 0:
(base, suffix) = os.path.splitext(fname)
files = glob(base + '-*' + suffix)
Expand All @@ -276,7 +276,7 @@ def check_for_stampfile(fname: str) -> str:
sys.exit(1)
if len(files) == 1:
return files[0]
elif fname.endswith('.a') or fname.endswith('.lib'):
elif fname.endswith(('.a', '.lib')):
if os.stat(fname).st_size == 0:
(base, suffix) = os.path.splitext(fname)
files = glob(base + '-*' + '.rlib')
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def perms_s_to_bits(cls, perms_s: T.Optional[str]) -> int:
See https://github.com/mesonbuild/meson/pull/8747 for the discussions."""
class File(HoldableObject):
def __init__(self, is_built: bool, subdir: str, fname: str):
if fname.endswith(".C") or fname.endswith(".H"):
if fname.endswith(('.C', '.H')):
mlog.warning(dot_C_dot_H_warning, once=True)
self.is_built = is_built
self.subdir = subdir
Expand Down
2 changes: 1 addition & 1 deletion test cases/common/208 link custom/custom_stlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def generate_lib(outfile, private_dir, compiler_array):
c_file = private_dir / 'flob.c'
c_file.write_text(contents)
for i in compiler_array:
if (i.endswith('cl') or i.endswith('cl.exe')) and 'clang-cl' not in i:
if (i.endswith(('cl', 'cl.exe'))) and 'clang-cl' not in i:
return generate_lib_msvc(outfile, c_file, private_dir, compiler_array)
return generate_lib_gnulike(outfile, c_file, private_dir, compiler_array)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def generate_lib(outfiles, private_dir, compiler_array):

cl_found = False
for cl_arg in compiler_array:
if (cl_arg.endswith('cl') or cl_arg.endswith('cl.exe')) and 'clang-cl' not in cl_arg:
if (cl_arg.endswith(('cl', 'cl.exe'))) and 'clang-cl' not in cl_arg:
ret = generate_lib_msvc(outfile, c_file, private_dir, compiler_array)
if ret > 0:
return ret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def generate_lib(outfiles, private_dir, compiler_array):

cl_found = False
for cl_arg in compiler_array:
if (cl_arg.endswith('cl') or cl_arg.endswith('cl.exe')) and 'clang-cl' not in cl_arg:
if (cl_arg.endswith(('cl', 'cl.exe'))) and 'clang-cl' not in cl_arg:
ret = generate_lib_msvc(outfile, c_file, private_dir, compiler_array)
if ret > 0:
return ret
Expand Down

0 comments on commit 5d6ddb6

Please sign in to comment.