Rollup merge of #68947 - chrissimpkins:python-fmt, r=alexcrichton
Python script PEP8 style guide space formatting and minor Python source cleanup This PR includes the following changes in the Python sources based on a flake8 3.7.9 (mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.6 on Darwin lint: - PEP8 style guide spacing updates *without* line length changes - removal of unused local variable assignments in context managers and exception handling - removal of unused Python import statements - removal of unnecessary semicolons
This commit is contained in:
commit
931005d549
12 changed files with 114 additions and 85 deletions
|
@ -80,7 +80,7 @@ def _download(path, url, probably_big, verbose, exception):
|
||||||
option = "-s"
|
option = "-s"
|
||||||
run(["curl", option,
|
run(["curl", option,
|
||||||
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
|
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
|
||||||
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
|
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
|
||||||
"--retry", "3", "-Sf", "-o", path, url],
|
"--retry", "3", "-Sf", "-o", path, url],
|
||||||
verbose=verbose,
|
verbose=verbose,
|
||||||
exception=exception)
|
exception=exception)
|
||||||
|
@ -332,7 +332,6 @@ class RustBuild(object):
|
||||||
self.use_vendored_sources = ''
|
self.use_vendored_sources = ''
|
||||||
self.verbose = False
|
self.verbose = False
|
||||||
|
|
||||||
|
|
||||||
def download_stage0(self):
|
def download_stage0(self):
|
||||||
"""Fetch the build system for Rust, written in Rust
|
"""Fetch the build system for Rust, written in Rust
|
||||||
|
|
||||||
|
@ -351,7 +350,7 @@ class RustBuild(object):
|
||||||
try:
|
try:
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||||
temp_path = temp_file.name
|
temp_path = temp_file.name
|
||||||
with tarfile.open(temp_path, "w:xz") as tar:
|
with tarfile.open(temp_path, "w:xz"):
|
||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
except tarfile.CompressionError:
|
except tarfile.CompressionError:
|
||||||
|
@ -825,7 +824,7 @@ class RustBuild(object):
|
||||||
if not os.path.exists(vendor_dir):
|
if not os.path.exists(vendor_dir):
|
||||||
print('error: vendoring required, but vendor directory does not exist.')
|
print('error: vendoring required, but vendor directory does not exist.')
|
||||||
print(' Run `cargo vendor` without sudo to initialize the '
|
print(' Run `cargo vendor` without sudo to initialize the '
|
||||||
'vendor directory.')
|
'vendor directory.')
|
||||||
raise Exception("{} not found".format(vendor_dir))
|
raise Exception("{} not found".format(vendor_dir))
|
||||||
|
|
||||||
if self.use_vendored_sources:
|
if self.use_vendored_sources:
|
||||||
|
@ -839,7 +838,7 @@ class RustBuild(object):
|
||||||
"\n"
|
"\n"
|
||||||
"[source.vendored-sources]\n"
|
"[source.vendored-sources]\n"
|
||||||
"directory = '{}/vendor'\n"
|
"directory = '{}/vendor'\n"
|
||||||
.format(self.rust_root))
|
.format(self.rust_root))
|
||||||
else:
|
else:
|
||||||
if os.path.exists('.cargo'):
|
if os.path.exists('.cargo'):
|
||||||
shutil.rmtree('.cargo')
|
shutil.rmtree('.cargo')
|
||||||
|
|
|
@ -393,11 +393,12 @@ for target in configured_targets:
|
||||||
|
|
||||||
|
|
||||||
def is_number(value):
|
def is_number(value):
|
||||||
try:
|
try:
|
||||||
float(value)
|
float(value)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Here we walk through the constructed configuration we have from the parsed
|
# Here we walk through the constructed configuration we have from the parsed
|
||||||
# command line arguments. We then apply each piece of configuration by
|
# command line arguments. We then apply each piece of configuration by
|
||||||
|
|
|
@ -148,11 +148,11 @@ else:
|
||||||
print('unknown platform', sys.platform)
|
print('unknown platform', sys.platform)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
cur_state = State();
|
cur_state = State()
|
||||||
print("Time,Idle")
|
print("Time,Idle")
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1);
|
time.sleep(1)
|
||||||
next_state = State();
|
next_state = State()
|
||||||
now = datetime.datetime.utcnow().isoformat()
|
now = datetime.datetime.utcnow().isoformat()
|
||||||
idle = next_state.idle_since(cur_state)
|
idle = next_state.idle_since(cur_state)
|
||||||
print("%s,%s" % (now, idle))
|
print("%s,%s" % (now, idle))
|
||||||
|
|
|
@ -212,7 +212,6 @@ class Type(object):
|
||||||
# REGULAR STRUCT
|
# REGULAR STRUCT
|
||||||
return TYPE_KIND_REGULAR_STRUCT
|
return TYPE_KIND_REGULAR_STRUCT
|
||||||
|
|
||||||
|
|
||||||
def __classify_union(self):
|
def __classify_union(self):
|
||||||
assert self.get_dwarf_type_kind() == DWARF_TYPE_CODE_UNION
|
assert self.get_dwarf_type_kind() == DWARF_TYPE_CODE_UNION
|
||||||
|
|
||||||
|
@ -233,7 +232,6 @@ class Type(object):
|
||||||
else:
|
else:
|
||||||
return TYPE_KIND_REGULAR_UNION
|
return TYPE_KIND_REGULAR_UNION
|
||||||
|
|
||||||
|
|
||||||
def __conforms_to_field_layout(self, expected_fields):
|
def __conforms_to_field_layout(self, expected_fields):
|
||||||
actual_fields = self.get_fields()
|
actual_fields = self.get_fields()
|
||||||
actual_field_count = len(actual_fields)
|
actual_field_count = len(actual_fields)
|
||||||
|
@ -363,6 +361,7 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
|
||||||
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
|
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
|
||||||
return (tail, head, data_ptr, capacity)
|
return (tail, head, data_ptr, capacity)
|
||||||
|
|
||||||
|
|
||||||
def extract_length_and_ptr_from_slice(slice_val):
|
def extract_length_and_ptr_from_slice(slice_val):
|
||||||
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
|
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
|
||||||
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
|
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
|
||||||
|
@ -376,8 +375,10 @@ def extract_length_and_ptr_from_slice(slice_val):
|
||||||
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
|
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
|
||||||
return (length, data_ptr)
|
return (length, data_ptr)
|
||||||
|
|
||||||
|
|
||||||
UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"])
|
UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"])
|
||||||
|
|
||||||
|
|
||||||
def extract_type_name(qualified_type_name):
|
def extract_type_name(qualified_type_name):
|
||||||
"""Extracts the type name from a fully qualified path"""
|
"""Extracts the type name from a fully qualified path"""
|
||||||
if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS:
|
if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS:
|
||||||
|
@ -393,6 +394,7 @@ def extract_type_name(qualified_type_name):
|
||||||
else:
|
else:
|
||||||
return qualified_type_name[index + 2:]
|
return qualified_type_name[index + 2:]
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
compat_str = unicode # Python 2
|
compat_str = unicode # Python 2
|
||||||
except NameError:
|
except NameError:
|
||||||
|
|
|
@ -14,7 +14,6 @@ is used because (u64, i16) has a ton of padding which would make the table
|
||||||
even larger, and it's already uncomfortably large (6 KiB).
|
even larger, and it's already uncomfortably large (6 KiB).
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
|
||||||
from math import ceil, log
|
from math import ceil, log
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
@ -82,6 +81,7 @@ def error(f, e, z):
|
||||||
ulp_err = abs_err / Fraction(2) ** z.exp
|
ulp_err = abs_err / Fraction(2) ** z.exp
|
||||||
return float(ulp_err)
|
return float(ulp_err)
|
||||||
|
|
||||||
|
|
||||||
HEADER = """
|
HEADER = """
|
||||||
//! Tables of approximations of powers of ten.
|
//! Tables of approximations of powers of ten.
|
||||||
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`
|
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`
|
||||||
|
|
|
@ -9,7 +9,7 @@ import debugger_pretty_printers_common as rustpp
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
xrange = range
|
xrange = range
|
||||||
|
|
||||||
rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string = True)
|
rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string=True)
|
||||||
|
|
||||||
# The btree pretty-printers fail in a confusing way unless
|
# The btree pretty-printers fail in a confusing way unless
|
||||||
# https://sourceware.org/bugzilla/show_bug.cgi?id=21763 is fixed.
|
# https://sourceware.org/bugzilla/show_bug.cgi?id=21763 is fixed.
|
||||||
|
@ -21,9 +21,10 @@ if _match:
|
||||||
if int(_match.group(1)) > 8 or (int(_match.group(1)) == 8 and int(_match.group(2)) >= 1):
|
if int(_match.group(1)) > 8 or (int(_match.group(1)) == 8 and int(_match.group(2)) >= 1):
|
||||||
gdb_81 = True
|
gdb_81 = True
|
||||||
|
|
||||||
#===============================================================================
|
# ===============================================================================
|
||||||
# GDB Pretty Printing Module for Rust
|
# GDB Pretty Printing Module for Rust
|
||||||
#===============================================================================
|
# ===============================================================================
|
||||||
|
|
||||||
|
|
||||||
class GdbType(rustpp.Type):
|
class GdbType(rustpp.Type):
|
||||||
|
|
||||||
|
@ -133,39 +134,39 @@ def rust_pretty_printer_lookup_function(gdb_val):
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
|
if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
|
||||||
return RustStructPrinter(val,
|
return RustStructPrinter(val,
|
||||||
omit_first_field = False,
|
omit_first_field=False,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = False)
|
is_tuple_like=False)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
|
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
|
||||||
return RustStructPrinter(val,
|
return RustStructPrinter(val,
|
||||||
omit_first_field = True,
|
omit_first_field=True,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = False)
|
is_tuple_like=False)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_STR_SLICE:
|
if type_kind == rustpp.TYPE_KIND_STR_SLICE:
|
||||||
return RustStringSlicePrinter(val)
|
return RustStringSlicePrinter(val)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_TUPLE:
|
if type_kind == rustpp.TYPE_KIND_TUPLE:
|
||||||
return RustStructPrinter(val,
|
return RustStructPrinter(val,
|
||||||
omit_first_field = False,
|
omit_first_field=False,
|
||||||
omit_type_name = True,
|
omit_type_name=True,
|
||||||
is_tuple_like = True)
|
is_tuple_like=True)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_TUPLE_STRUCT:
|
if type_kind == rustpp.TYPE_KIND_TUPLE_STRUCT:
|
||||||
return RustStructPrinter(val,
|
return RustStructPrinter(val,
|
||||||
omit_first_field = False,
|
omit_first_field=False,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = True)
|
is_tuple_like=True)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_CSTYLE_VARIANT:
|
if type_kind == rustpp.TYPE_KIND_CSTYLE_VARIANT:
|
||||||
return RustCStyleVariantPrinter(val.get_child_at_index(0))
|
return RustCStyleVariantPrinter(val.get_child_at_index(0))
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_TUPLE_VARIANT:
|
if type_kind == rustpp.TYPE_KIND_TUPLE_VARIANT:
|
||||||
return RustStructPrinter(val,
|
return RustStructPrinter(val,
|
||||||
omit_first_field = True,
|
omit_first_field=True,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = True)
|
is_tuple_like=True)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_SINGLETON_ENUM:
|
if type_kind == rustpp.TYPE_KIND_SINGLETON_ENUM:
|
||||||
variant = get_field_at_index(gdb_val, 0)
|
variant = get_field_at_index(gdb_val, 0)
|
||||||
|
@ -189,9 +190,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
#=------------------------------------------------------------------------------
|
# =------------------------------------------------------------------------------
|
||||||
# Pretty Printer Classes
|
# Pretty Printer Classes
|
||||||
#=------------------------------------------------------------------------------
|
# =------------------------------------------------------------------------------
|
||||||
class RustEmptyPrinter(object):
|
class RustEmptyPrinter(object):
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.__val = val
|
self.__val = val
|
||||||
|
@ -355,6 +356,7 @@ def children_of_node(boxed_node, height, want_values):
|
||||||
else:
|
else:
|
||||||
yield keys[i]['value']['value']
|
yield keys[i]['value']['value']
|
||||||
|
|
||||||
|
|
||||||
class RustStdBTreeSetPrinter(object):
|
class RustStdBTreeSetPrinter(object):
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.__val = val
|
self.__val = val
|
||||||
|
@ -429,6 +431,7 @@ class RustOsStringPrinter(object):
|
||||||
def display_hint(self):
|
def display_hint(self):
|
||||||
return "string"
|
return "string"
|
||||||
|
|
||||||
|
|
||||||
class RustCStyleVariantPrinter(object):
|
class RustCStyleVariantPrinter(object):
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_ENUM
|
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_ENUM
|
||||||
|
|
|
@ -8,7 +8,8 @@ derives have spans that point to the fields, rather than the
|
||||||
sample usage: src/etc/generate-deriving-span-tests.py
|
sample usage: src/etc/generate-deriving-span-tests.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, stat
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
TEST_DIR = os.path.abspath(
|
TEST_DIR = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(__file__), '../test/ui/derives/'))
|
os.path.join(os.path.dirname(__file__), '../test/ui/derives/'))
|
||||||
|
@ -56,6 +57,7 @@ struct Struct(
|
||||||
|
|
||||||
ENUM_TUPLE, ENUM_STRUCT, STRUCT_FIELDS, STRUCT_TUPLE = range(4)
|
ENUM_TUPLE, ENUM_STRUCT, STRUCT_FIELDS, STRUCT_TUPLE = range(4)
|
||||||
|
|
||||||
|
|
||||||
def create_test_case(type, trait, super_traits, error_count):
|
def create_test_case(type, trait, super_traits, error_count):
|
||||||
string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type]
|
string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type]
|
||||||
all_traits = ','.join([trait] + super_traits)
|
all_traits = ','.join([trait] + super_traits)
|
||||||
|
@ -63,8 +65,9 @@ def create_test_case(type, trait, super_traits, error_count):
|
||||||
error_deriving = '#[derive(%s)]' % super_traits if super_traits else ''
|
error_deriving = '#[derive(%s)]' % super_traits if super_traits else ''
|
||||||
|
|
||||||
errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count))
|
errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count))
|
||||||
code = string.format(traits = all_traits, errors = errors)
|
code = string.format(traits=all_traits, errors=errors)
|
||||||
return TEMPLATE.format(error_deriving=error_deriving, code = code)
|
return TEMPLATE.format(error_deriving=error_deriving, code=code)
|
||||||
|
|
||||||
|
|
||||||
def write_file(name, string):
|
def write_file(name, string):
|
||||||
test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name)
|
test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name)
|
||||||
|
@ -86,10 +89,10 @@ ALL = STRUCT | ENUM
|
||||||
|
|
||||||
traits = {
|
traits = {
|
||||||
'Default': (STRUCT, [], 1),
|
'Default': (STRUCT, [], 1),
|
||||||
'FromPrimitive': (0, [], 0), # only works for C-like enums
|
'FromPrimitive': (0, [], 0), # only works for C-like enums
|
||||||
|
|
||||||
'Decodable': (0, [], 0), # FIXME: quoting gives horrible spans
|
'Decodable': (0, [], 0), # FIXME: quoting gives horrible spans
|
||||||
'Encodable': (0, [], 0), # FIXME: quoting gives horrible spans
|
'Encodable': (0, [], 0), # FIXME: quoting gives horrible spans
|
||||||
}
|
}
|
||||||
|
|
||||||
for (trait, supers, errs) in [('Clone', [], 1),
|
for (trait, supers, errs) in [('Clone', [], 1),
|
||||||
|
|
|
@ -11,7 +11,6 @@ sample usage: src/etc/generate-keyword-tests.py as break
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import datetime
|
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ try:
|
||||||
except NameError:
|
except NameError:
|
||||||
unichr = chr
|
unichr = chr
|
||||||
|
|
||||||
|
|
||||||
class CustomHTMLParser(HTMLParser):
|
class CustomHTMLParser(HTMLParser):
|
||||||
"""simplified HTML parser.
|
"""simplified HTML parser.
|
||||||
|
|
||||||
|
@ -169,21 +170,25 @@ class CustomHTMLParser(HTMLParser):
|
||||||
HTMLParser.close(self)
|
HTMLParser.close(self)
|
||||||
return self.__builder.close()
|
return self.__builder.close()
|
||||||
|
|
||||||
|
|
||||||
Command = namedtuple('Command', 'negated cmd args lineno context')
|
Command = namedtuple('Command', 'negated cmd args lineno context')
|
||||||
|
|
||||||
|
|
||||||
class FailedCheck(Exception):
|
class FailedCheck(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvalidCheck(Exception):
|
class InvalidCheck(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def concat_multi_lines(f):
|
def concat_multi_lines(f):
|
||||||
"""returns a generator out of the file object, which
|
"""returns a generator out of the file object, which
|
||||||
- removes `\\` then `\n` then a shared prefix with the previous line then
|
- removes `\\` then `\n` then a shared prefix with the previous line then
|
||||||
optional whitespace;
|
optional whitespace;
|
||||||
- keeps a line number (starting from 0) of the first line being
|
- keeps a line number (starting from 0) of the first line being
|
||||||
concatenated."""
|
concatenated."""
|
||||||
lastline = None # set to the last line when the last line has a backslash
|
lastline = None # set to the last line when the last line has a backslash
|
||||||
firstlineno = None
|
firstlineno = None
|
||||||
catenated = ''
|
catenated = ''
|
||||||
for lineno, line in enumerate(f):
|
for lineno, line in enumerate(f):
|
||||||
|
@ -208,6 +213,7 @@ def concat_multi_lines(f):
|
||||||
if lastline is not None:
|
if lastline is not None:
|
||||||
print_err(lineno, line, 'Trailing backslash at the end of the file')
|
print_err(lineno, line, 'Trailing backslash at the end of the file')
|
||||||
|
|
||||||
|
|
||||||
LINE_PATTERN = re.compile(r'''
|
LINE_PATTERN = re.compile(r'''
|
||||||
(?<=(?<!\S)@)(?P<negated>!?)
|
(?<=(?<!\S)@)(?P<negated>!?)
|
||||||
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
|
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
|
||||||
|
@ -252,7 +258,7 @@ def flatten(node):
|
||||||
|
|
||||||
def normalize_xpath(path):
|
def normalize_xpath(path):
|
||||||
if path.startswith('//'):
|
if path.startswith('//'):
|
||||||
return '.' + path # avoid warnings
|
return '.' + path # avoid warnings
|
||||||
elif path.startswith('.//'):
|
elif path.startswith('.//'):
|
||||||
return path
|
return path
|
||||||
else:
|
else:
|
||||||
|
@ -316,7 +322,7 @@ class CachedFiles(object):
|
||||||
|
|
||||||
def check_string(data, pat, regexp):
|
def check_string(data, pat, regexp):
|
||||||
if not pat:
|
if not pat:
|
||||||
return True # special case a presence testing
|
return True # special case a presence testing
|
||||||
elif regexp:
|
elif regexp:
|
||||||
return re.search(pat, data, flags=re.UNICODE) is not None
|
return re.search(pat, data, flags=re.UNICODE) is not None
|
||||||
else:
|
else:
|
||||||
|
@ -353,7 +359,7 @@ def check_tree_text(tree, path, pat, regexp):
|
||||||
ret = check_string(value, pat, regexp)
|
ret = check_string(value, pat, regexp)
|
||||||
if ret:
|
if ret:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print('Failed to get path "{}"'.format(path))
|
print('Failed to get path "{}"'.format(path))
|
||||||
raise
|
raise
|
||||||
return ret
|
return ret
|
||||||
|
@ -363,6 +369,7 @@ def get_tree_count(tree, path):
|
||||||
path = normalize_xpath(path)
|
path = normalize_xpath(path)
|
||||||
return len(tree.findall(path))
|
return len(tree.findall(path))
|
||||||
|
|
||||||
|
|
||||||
def stderr(*args):
|
def stderr(*args):
|
||||||
if sys.version_info.major < 3:
|
if sys.version_info.major < 3:
|
||||||
file = codecs.getwriter('utf-8')(sys.stderr)
|
file = codecs.getwriter('utf-8')(sys.stderr)
|
||||||
|
@ -371,6 +378,7 @@ def stderr(*args):
|
||||||
|
|
||||||
print(*args, file=file)
|
print(*args, file=file)
|
||||||
|
|
||||||
|
|
||||||
def print_err(lineno, context, err, message=None):
|
def print_err(lineno, context, err, message=None):
|
||||||
global ERR_COUNT
|
global ERR_COUNT
|
||||||
ERR_COUNT += 1
|
ERR_COUNT += 1
|
||||||
|
@ -381,31 +389,33 @@ def print_err(lineno, context, err, message=None):
|
||||||
if context:
|
if context:
|
||||||
stderr("\t{}".format(context))
|
stderr("\t{}".format(context))
|
||||||
|
|
||||||
|
|
||||||
ERR_COUNT = 0
|
ERR_COUNT = 0
|
||||||
|
|
||||||
|
|
||||||
def check_command(c, cache):
|
def check_command(c, cache):
|
||||||
try:
|
try:
|
||||||
cerr = ""
|
cerr = ""
|
||||||
if c.cmd == 'has' or c.cmd == 'matches': # string test
|
if c.cmd == 'has' or c.cmd == 'matches': # string test
|
||||||
regexp = (c.cmd == 'matches')
|
regexp = (c.cmd == 'matches')
|
||||||
if len(c.args) == 1 and not regexp: # @has <path> = file existence
|
if len(c.args) == 1 and not regexp: # @has <path> = file existence
|
||||||
try:
|
try:
|
||||||
cache.get_file(c.args[0])
|
cache.get_file(c.args[0])
|
||||||
ret = True
|
ret = True
|
||||||
except FailedCheck as err:
|
except FailedCheck as err:
|
||||||
cerr = str(err)
|
cerr = str(err)
|
||||||
ret = False
|
ret = False
|
||||||
elif len(c.args) == 2: # @has/matches <path> <pat> = string test
|
elif len(c.args) == 2: # @has/matches <path> <pat> = string test
|
||||||
cerr = "`PATTERN` did not match"
|
cerr = "`PATTERN` did not match"
|
||||||
ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp)
|
ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp)
|
||||||
elif len(c.args) == 3: # @has/matches <path> <pat> <match> = XML tree test
|
elif len(c.args) == 3: # @has/matches <path> <pat> <match> = XML tree test
|
||||||
cerr = "`XPATH PATTERN` did not match"
|
cerr = "`XPATH PATTERN` did not match"
|
||||||
tree = cache.get_tree(c.args[0])
|
tree = cache.get_tree(c.args[0])
|
||||||
pat, sep, attr = c.args[1].partition('/@')
|
pat, sep, attr = c.args[1].partition('/@')
|
||||||
if sep: # attribute
|
if sep: # attribute
|
||||||
tree = cache.get_tree(c.args[0])
|
tree = cache.get_tree(c.args[0])
|
||||||
ret = check_tree_attr(tree, pat, attr, c.args[2], regexp)
|
ret = check_tree_attr(tree, pat, attr, c.args[2], regexp)
|
||||||
else: # normalized text
|
else: # normalized text
|
||||||
pat = c.args[1]
|
pat = c.args[1]
|
||||||
if pat.endswith('/text()'):
|
if pat.endswith('/text()'):
|
||||||
pat = pat[:-7]
|
pat = pat[:-7]
|
||||||
|
@ -413,16 +423,16 @@ def check_command(c, cache):
|
||||||
else:
|
else:
|
||||||
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
|
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
|
||||||
|
|
||||||
elif c.cmd == 'count': # count test
|
elif c.cmd == 'count': # count test
|
||||||
if len(c.args) == 3: # @count <path> <pat> <count> = count test
|
if len(c.args) == 3: # @count <path> <pat> <count> = count test
|
||||||
expected = int(c.args[2])
|
expected = int(c.args[2])
|
||||||
found = get_tree_count(cache.get_tree(c.args[0]), c.args[1])
|
found = get_tree_count(cache.get_tree(c.args[0]), c.args[1])
|
||||||
cerr = "Expected {} occurrences but found {}".format(expected, found)
|
cerr = "Expected {} occurrences but found {}".format(expected, found)
|
||||||
ret = expected == found
|
ret = expected == found
|
||||||
else:
|
else:
|
||||||
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
|
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
|
||||||
elif c.cmd == 'has-dir': # has-dir test
|
elif c.cmd == 'has-dir': # has-dir test
|
||||||
if len(c.args) == 1: # @has-dir <path> = has-dir test
|
if len(c.args) == 1: # @has-dir <path> = has-dir test
|
||||||
try:
|
try:
|
||||||
cache.get_dir(c.args[0])
|
cache.get_dir(c.args[0])
|
||||||
ret = True
|
ret = True
|
||||||
|
@ -448,11 +458,13 @@ def check_command(c, cache):
|
||||||
except InvalidCheck as err:
|
except InvalidCheck as err:
|
||||||
print_err(c.lineno, c.context, str(err))
|
print_err(c.lineno, c.context, str(err))
|
||||||
|
|
||||||
|
|
||||||
def check(target, commands):
|
def check(target, commands):
|
||||||
cache = CachedFiles(target)
|
cache = CachedFiles(target)
|
||||||
for c in commands:
|
for c in commands:
|
||||||
check_command(c, cache)
|
check_command(c, cache)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
stderr('Usage: {} <doc dir> <template>'.format(sys.argv[0]))
|
stderr('Usage: {} <doc dir> <template>'.format(sys.argv[0]))
|
||||||
|
|
|
@ -157,6 +157,7 @@ def start_watchdog():
|
||||||
# ~main
|
# ~main
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
print("usage: python lldb_batchmode.py target-path script-path")
|
print("usage: python lldb_batchmode.py target-path script-path")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import lldb
|
import lldb
|
||||||
import re
|
|
||||||
import debugger_pretty_printers_common as rustpp
|
import debugger_pretty_printers_common as rustpp
|
||||||
|
|
||||||
#===============================================================================
|
# ===============================================================================
|
||||||
# LLDB Pretty Printing Module for Rust
|
# LLDB Pretty Printing Module for Rust
|
||||||
#===============================================================================
|
# ===============================================================================
|
||||||
|
|
||||||
|
|
||||||
class LldbType(rustpp.Type):
|
class LldbType(rustpp.Type):
|
||||||
|
|
||||||
|
@ -84,16 +84,16 @@ def print_val(lldb_val, internal_dict):
|
||||||
type_kind == rustpp.TYPE_KIND_EMPTY):
|
type_kind == rustpp.TYPE_KIND_EMPTY):
|
||||||
return print_struct_val(val,
|
return print_struct_val(val,
|
||||||
internal_dict,
|
internal_dict,
|
||||||
omit_first_field = False,
|
omit_first_field=False,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = False)
|
is_tuple_like=False)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
|
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
|
||||||
return print_struct_val(val,
|
return print_struct_val(val,
|
||||||
internal_dict,
|
internal_dict,
|
||||||
omit_first_field = True,
|
omit_first_field=True,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = False)
|
is_tuple_like=False)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_SLICE:
|
if type_kind == rustpp.TYPE_KIND_SLICE:
|
||||||
return print_vec_slice_val(val, internal_dict)
|
return print_vec_slice_val(val, internal_dict)
|
||||||
|
@ -110,16 +110,16 @@ def print_val(lldb_val, internal_dict):
|
||||||
if type_kind == rustpp.TYPE_KIND_TUPLE:
|
if type_kind == rustpp.TYPE_KIND_TUPLE:
|
||||||
return print_struct_val(val,
|
return print_struct_val(val,
|
||||||
internal_dict,
|
internal_dict,
|
||||||
omit_first_field = False,
|
omit_first_field=False,
|
||||||
omit_type_name = True,
|
omit_type_name=True,
|
||||||
is_tuple_like = True)
|
is_tuple_like=True)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_TUPLE_STRUCT:
|
if type_kind == rustpp.TYPE_KIND_TUPLE_STRUCT:
|
||||||
return print_struct_val(val,
|
return print_struct_val(val,
|
||||||
internal_dict,
|
internal_dict,
|
||||||
omit_first_field = False,
|
omit_first_field=False,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = True)
|
is_tuple_like=True)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_CSTYLE_VARIANT:
|
if type_kind == rustpp.TYPE_KIND_CSTYLE_VARIANT:
|
||||||
return val.type.get_unqualified_type_name()
|
return val.type.get_unqualified_type_name()
|
||||||
|
@ -127,9 +127,9 @@ def print_val(lldb_val, internal_dict):
|
||||||
if type_kind == rustpp.TYPE_KIND_TUPLE_VARIANT:
|
if type_kind == rustpp.TYPE_KIND_TUPLE_VARIANT:
|
||||||
return print_struct_val(val,
|
return print_struct_val(val,
|
||||||
internal_dict,
|
internal_dict,
|
||||||
omit_first_field = True,
|
omit_first_field=True,
|
||||||
omit_type_name = False,
|
omit_type_name=False,
|
||||||
is_tuple_like = True)
|
is_tuple_like=True)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_SINGLETON_ENUM:
|
if type_kind == rustpp.TYPE_KIND_SINGLETON_ENUM:
|
||||||
return print_val(lldb_val.GetChildAtIndex(0), internal_dict)
|
return print_val(lldb_val.GetChildAtIndex(0), internal_dict)
|
||||||
|
@ -157,9 +157,9 @@ def print_val(lldb_val, internal_dict):
|
||||||
return lldb_val.GetValue()
|
return lldb_val.GetValue()
|
||||||
|
|
||||||
|
|
||||||
#=--------------------------------------------------------------------------------------------------
|
# =---------------------------------------------------------------------------------------
|
||||||
# Type-Specialized Printing Functions
|
# Type-Specialized Printing Functions
|
||||||
#=--------------------------------------------------------------------------------------------------
|
# =---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def print_struct_val(val, internal_dict, omit_first_field, omit_type_name, is_tuple_like):
|
def print_struct_val(val, internal_dict, omit_first_field, omit_type_name, is_tuple_like):
|
||||||
"""
|
"""
|
||||||
|
@ -212,6 +212,7 @@ def print_struct_val(val, internal_dict, omit_first_field, omit_type_name, is_tu
|
||||||
return template % {"type_name": type_name,
|
return template % {"type_name": type_name,
|
||||||
"body": body}
|
"body": body}
|
||||||
|
|
||||||
|
|
||||||
def print_pointer_val(val, internal_dict):
|
def print_pointer_val(val, internal_dict):
|
||||||
"""Prints a pointer value with Rust syntax"""
|
"""Prints a pointer value with Rust syntax"""
|
||||||
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_PTR
|
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_PTR
|
||||||
|
@ -253,18 +254,21 @@ def print_std_vec_val(val, internal_dict):
|
||||||
length,
|
length,
|
||||||
internal_dict)
|
internal_dict)
|
||||||
|
|
||||||
|
|
||||||
def print_str_slice_val(val, internal_dict):
|
def print_str_slice_val(val, internal_dict):
|
||||||
(length, data_ptr) = rustpp.extract_length_and_ptr_from_slice(val)
|
(length, data_ptr) = rustpp.extract_length_and_ptr_from_slice(val)
|
||||||
return read_utf8_string(data_ptr, length)
|
return read_utf8_string(data_ptr, length)
|
||||||
|
|
||||||
|
|
||||||
def print_std_string_val(val, internal_dict):
|
def print_std_string_val(val, internal_dict):
|
||||||
vec = val.get_child_at_index(0)
|
vec = val.get_child_at_index(0)
|
||||||
(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(vec)
|
(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(vec)
|
||||||
return read_utf8_string(data_ptr, length)
|
return read_utf8_string(data_ptr, length)
|
||||||
|
|
||||||
#=--------------------------------------------------------------------------------------------------
|
# =-----------------------------------------------------------------------
|
||||||
# Helper Functions
|
# Helper Functions
|
||||||
#=--------------------------------------------------------------------------------------------------
|
# =-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def print_array_of_values(array_name, data_ptr_val, length, internal_dict):
|
def print_array_of_values(array_name, data_ptr_val, length, internal_dict):
|
||||||
"""Prints a contiguous memory range, interpreting it as values of the
|
"""Prints a contiguous memory range, interpreting it as values of the
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
## This script publishes the new "current" toolstate in the toolstate repo (not to be
|
# This script publishes the new "current" toolstate in the toolstate repo (not to be
|
||||||
## confused with publishing the test results, which happens in
|
# confused with publishing the test results, which happens in
|
||||||
## `src/ci/docker/x86_64-gnu-tools/checktools.sh`).
|
# `src/ci/docker/x86_64-gnu-tools/checktools.sh`).
|
||||||
## It is set as callback for `src/ci/docker/x86_64-gnu-tools/repo.sh` by the CI scripts
|
# It is set as callback for `src/ci/docker/x86_64-gnu-tools/repo.sh` by the CI scripts
|
||||||
## when a new commit lands on `master` (i.e., after it passed all checks on `auto`).
|
# when a new commit lands on `master` (i.e., after it passed all checks on `auto`).
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ def validate_maintainers(repo, github_token):
|
||||||
print("The build will fail due to this.")
|
print("The build will fail due to this.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def read_current_status(current_commit, path):
|
def read_current_status(current_commit, path):
|
||||||
'''Reads build status of `current_commit` from content of `history/*.tsv`
|
'''Reads build status of `current_commit` from content of `history/*.tsv`
|
||||||
'''
|
'''
|
||||||
|
@ -113,14 +114,17 @@ def read_current_status(current_commit, path):
|
||||||
return json.loads(status)
|
return json.loads(status)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def gh_url():
|
def gh_url():
|
||||||
return os.environ['TOOLSTATE_ISSUES_API_URL']
|
return os.environ['TOOLSTATE_ISSUES_API_URL']
|
||||||
|
|
||||||
|
|
||||||
def maybe_delink(message):
|
def maybe_delink(message):
|
||||||
if os.environ.get('TOOLSTATE_SKIP_MENTIONS') is not None:
|
if os.environ.get('TOOLSTATE_SKIP_MENTIONS') is not None:
|
||||||
return message.replace("@", "")
|
return message.replace("@", "")
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
def issue(
|
def issue(
|
||||||
tool,
|
tool,
|
||||||
status,
|
status,
|
||||||
|
@ -164,6 +168,7 @@ def issue(
|
||||||
))
|
))
|
||||||
response.read()
|
response.read()
|
||||||
|
|
||||||
|
|
||||||
def update_latest(
|
def update_latest(
|
||||||
current_commit,
|
current_commit,
|
||||||
relevant_pr_number,
|
relevant_pr_number,
|
||||||
|
@ -194,7 +199,7 @@ def update_latest(
|
||||||
for status in latest:
|
for status in latest:
|
||||||
tool = status['tool']
|
tool = status['tool']
|
||||||
changed = False
|
changed = False
|
||||||
create_issue_for_status = None # set to the status that caused the issue
|
create_issue_for_status = None # set to the status that caused the issue
|
||||||
|
|
||||||
for os, s in current_status.items():
|
for os, s in current_status.items():
|
||||||
old = status[os]
|
old = status[os]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue