Fix usage of builtin file as variable name (#19018)
This commit is contained in:
parent
ac7c69e62e
commit
c8ac61979b
@ -807,14 +807,14 @@ def relocate_text(
|
||||
orig_sbang = '#!/bin/bash {0}/bin/sbang'.format(orig_spack)
|
||||
new_sbang = '#!/bin/bash {0}/bin/sbang'.format(new_spack)
|
||||
|
||||
for file in files:
|
||||
_replace_prefix_text(file, orig_install_prefix, new_install_prefix)
|
||||
for filename in files:
|
||||
_replace_prefix_text(filename, orig_install_prefix, new_install_prefix)
|
||||
for orig_dep_prefix, new_dep_prefix in new_prefixes.items():
|
||||
_replace_prefix_text(file, orig_dep_prefix, new_dep_prefix)
|
||||
_replace_prefix_text(file, orig_layout_root, new_layout_root)
|
||||
_replace_prefix_text(filename, orig_dep_prefix, new_dep_prefix)
|
||||
_replace_prefix_text(filename, orig_layout_root, new_layout_root)
|
||||
# relocate the sbang location only if the spack directory changed
|
||||
if orig_spack != new_spack:
|
||||
_replace_prefix_text(file, orig_sbang, new_sbang)
|
||||
_replace_prefix_text(filename, orig_sbang, new_sbang)
|
||||
|
||||
|
||||
def relocate_text_bin(
|
||||
@ -888,18 +888,18 @@ def is_relocatable(spec):
|
||||
return True
|
||||
|
||||
|
||||
def file_is_relocatable(file, paths_to_relocate=None):
|
||||
"""Returns True if the file passed as argument is relocatable.
|
||||
def file_is_relocatable(filename, paths_to_relocate=None):
|
||||
"""Returns True if the filename passed as argument is relocatable.
|
||||
|
||||
Args:
|
||||
file: absolute path of the file to be analyzed
|
||||
filename: absolute path of the file to be analyzed
|
||||
|
||||
Returns:
|
||||
True or false
|
||||
|
||||
Raises:
|
||||
|
||||
ValueError: if the file does not exist or the path is not absolute
|
||||
ValueError: if the filename does not exist or the path is not absolute
|
||||
"""
|
||||
default_paths_to_relocate = [spack.store.layout.root, spack.paths.prefix]
|
||||
paths_to_relocate = paths_to_relocate or default_paths_to_relocate
|
||||
@ -909,28 +909,28 @@ def file_is_relocatable(file, paths_to_relocate=None):
|
||||
msg = 'function currently implemented only for linux and macOS'
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
if not os.path.exists(file):
|
||||
raise ValueError('{0} does not exist'.format(file))
|
||||
if not os.path.exists(filename):
|
||||
raise ValueError('{0} does not exist'.format(filename))
|
||||
|
||||
if not os.path.isabs(file):
|
||||
raise ValueError('{0} is not an absolute path'.format(file))
|
||||
if not os.path.isabs(filename):
|
||||
raise ValueError('{0} is not an absolute path'.format(filename))
|
||||
|
||||
strings = executable.Executable('strings')
|
||||
|
||||
# Remove the RPATHS from the strings in the executable
|
||||
set_of_strings = set(strings(file, output=str).split())
|
||||
set_of_strings = set(strings(filename, output=str).split())
|
||||
|
||||
m_type, m_subtype = mime_type(file)
|
||||
m_type, m_subtype = mime_type(filename)
|
||||
if m_type == 'application':
|
||||
tty.debug('{0},{1}'.format(m_type, m_subtype))
|
||||
|
||||
if platform.system().lower() == 'linux':
|
||||
if m_subtype == 'x-executable' or m_subtype == 'x-sharedlib':
|
||||
rpaths = ':'.join(_elf_rpaths_for(file))
|
||||
rpaths = ':'.join(_elf_rpaths_for(filename))
|
||||
set_of_strings.discard(rpaths)
|
||||
if platform.system().lower() == 'darwin':
|
||||
if m_subtype == 'x-mach-binary':
|
||||
rpaths, deps, idpath = macholib_get_paths(file)
|
||||
rpaths, deps, idpath = macholib_get_paths(filename)
|
||||
set_of_strings.discard(set(rpaths))
|
||||
set_of_strings.discard(set(deps))
|
||||
if idpath is not None:
|
||||
@ -941,24 +941,24 @@ def file_is_relocatable(file, paths_to_relocate=None):
|
||||
# One binary has the root folder not in the RPATH,
|
||||
# meaning that this spec is not relocatable
|
||||
msg = 'Found "{0}" in {1} strings'
|
||||
tty.debug(msg.format(path_to_relocate, file))
|
||||
tty.debug(msg.format(path_to_relocate, filename))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def is_binary(file):
|
||||
def is_binary(filename):
|
||||
"""Returns true if a file is binary, False otherwise
|
||||
|
||||
Args:
|
||||
file: file to be tested
|
||||
filename: file to be tested
|
||||
|
||||
Returns:
|
||||
True or False
|
||||
"""
|
||||
m_type, _ = mime_type(file)
|
||||
m_type, _ = mime_type(filename)
|
||||
|
||||
msg = '[{0}] -> '.format(file)
|
||||
msg = '[{0}] -> '.format(filename)
|
||||
if m_type == 'application':
|
||||
tty.debug(msg + 'BINARY FILE')
|
||||
return True
|
||||
@ -968,18 +968,19 @@ def is_binary(file):
|
||||
|
||||
|
||||
@llnl.util.lang.memoized
|
||||
def mime_type(file):
|
||||
def mime_type(filename):
|
||||
"""Returns the mime type and subtype of a file.
|
||||
|
||||
Args:
|
||||
file: file to be analyzed
|
||||
filename: file to be analyzed
|
||||
|
||||
Returns:
|
||||
Tuple containing the MIME type and subtype
|
||||
"""
|
||||
file_cmd = executable.Executable('file')
|
||||
output = file_cmd('-b', '-h', '--mime-type', file, output=str, error=str)
|
||||
tty.debug('[MIME_TYPE] {0} -> {1}'.format(file, output.strip()))
|
||||
output = file_cmd(
|
||||
'-b', '-h', '--mime-type', filename, output=str, error=str)
|
||||
tty.debug('[MIME_TYPE] {0} -> {1}'.format(filename, output.strip()))
|
||||
# In corner cases the output does not contain a subtype prefixed with a /
|
||||
# In those cases add the / so the tuple can be formed.
|
||||
if '/' not in output:
|
||||
|
@ -117,13 +117,13 @@ def check_entry(path, data):
|
||||
return res
|
||||
|
||||
|
||||
def check_file_manifest(file):
|
||||
dirname = os.path.dirname(file)
|
||||
def check_file_manifest(filename):
|
||||
dirname = os.path.dirname(filename)
|
||||
|
||||
results = VerificationResults()
|
||||
while spack.store.layout.metadata_dir not in os.listdir(dirname):
|
||||
if dirname == os.path.sep:
|
||||
results.add_error(file, 'not owned by any package')
|
||||
results.add_error(filename, 'not owned by any package')
|
||||
return results
|
||||
dirname = os.path.dirname(dirname)
|
||||
|
||||
@ -132,20 +132,20 @@ def check_file_manifest(file):
|
||||
spack.store.layout.manifest_file_name)
|
||||
|
||||
if not os.path.exists(manifest_file):
|
||||
results.add_error(file, "manifest missing")
|
||||
results.add_error(filename, "manifest missing")
|
||||
return results
|
||||
|
||||
try:
|
||||
with open(manifest_file, 'r') as f:
|
||||
manifest = sjson.load(f)
|
||||
except Exception:
|
||||
results.add_error(file, "manifest corrupted")
|
||||
results.add_error(filename, "manifest corrupted")
|
||||
return results
|
||||
|
||||
if file in manifest:
|
||||
results += check_entry(file, manifest[file])
|
||||
if filename in manifest:
|
||||
results += check_entry(filename, manifest[filename])
|
||||
else:
|
||||
results.add_error(file, 'not owned by any package')
|
||||
results.add_error(filename, 'not owned by any package')
|
||||
return results
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user