Auto merge of #27007 - saschanaz:py3-flake, r=jdm

Upgrade flake8/pyflakes for Py3 compatibility

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-06-21 11:35:20 -04:00 committed by GitHub
commit 3f999ce785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 377 additions and 357 deletions

View file

@ -170,5 +170,6 @@ def update_test_file(cachedir):
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":
update_test_file(tempfile.gettempdir()) update_test_file(tempfile.gettempdir())

View file

@ -359,17 +359,17 @@ class CGMethodCall(CGThing):
# First check for null or undefined # First check for null or undefined
pickFirstSignature("%s.get().is_null_or_undefined()" % distinguishingArg, pickFirstSignature("%s.get().is_null_or_undefined()" % distinguishingArg,
lambda s: (s[1][distinguishingIndex].type.nullable() or lambda s: (s[1][distinguishingIndex].type.nullable()
s[1][distinguishingIndex].type.isDictionary())) or s[1][distinguishingIndex].type.isDictionary()))
# Now check for distinguishingArg being an object that implements a # Now check for distinguishingArg being an object that implements a
# non-callback interface. That includes typed arrays and # non-callback interface. That includes typed arrays and
# arraybuffers. # arraybuffers.
interfacesSigs = [ interfacesSigs = [
s for s in possibleSignatures s for s in possibleSignatures
if (s[1][distinguishingIndex].type.isObject() or if (s[1][distinguishingIndex].type.isObject()
s[1][distinguishingIndex].type.isUnion() or or s[1][distinguishingIndex].type.isUnion()
s[1][distinguishingIndex].type.isNonCallbackInterface())] or s[1][distinguishingIndex].type.isNonCallbackInterface())]
# There might be more than one of these; we need to check # There might be more than one of these; we need to check
# which ones we unwrap to. # which ones we unwrap to.
@ -424,24 +424,24 @@ class CGMethodCall(CGThing):
pickFirstSignature("%s.get().is_object() && is_array_like(*cx, %s)" % pickFirstSignature("%s.get().is_object() && is_array_like(*cx, %s)" %
(distinguishingArg, distinguishingArg), (distinguishingArg, distinguishingArg),
lambda s: lambda s:
(s[1][distinguishingIndex].type.isSequence() or (s[1][distinguishingIndex].type.isSequence()
s[1][distinguishingIndex].type.isObject())) or s[1][distinguishingIndex].type.isObject()))
# Check for vanilla JS objects # Check for vanilla JS objects
# XXXbz Do we need to worry about security wrappers? # XXXbz Do we need to worry about security wrappers?
pickFirstSignature("%s.get().is_object()" % pickFirstSignature("%s.get().is_object()" %
distinguishingArg, distinguishingArg,
lambda s: (s[1][distinguishingIndex].type.isCallback() or lambda s: (s[1][distinguishingIndex].type.isCallback()
s[1][distinguishingIndex].type.isCallbackInterface() or or s[1][distinguishingIndex].type.isCallbackInterface()
s[1][distinguishingIndex].type.isDictionary() or or s[1][distinguishingIndex].type.isDictionary()
s[1][distinguishingIndex].type.isObject())) or s[1][distinguishingIndex].type.isObject()))
# The remaining cases are mutually exclusive. The # The remaining cases are mutually exclusive. The
# pickFirstSignature calls are what change caseBody # pickFirstSignature calls are what change caseBody
# Check for strings or enums # Check for strings or enums
if pickFirstSignature(None, if pickFirstSignature(None,
lambda s: (s[1][distinguishingIndex].type.isString() or lambda s: (s[1][distinguishingIndex].type.isString()
s[1][distinguishingIndex].type.isEnum())): or s[1][distinguishingIndex].type.isEnum())):
pass pass
# Check for primitives # Check for primitives
elif pickFirstSignature(None, elif pickFirstSignature(None,
@ -482,9 +482,9 @@ class CGMethodCall(CGThing):
def dictionaryHasSequenceMember(dictionary): def dictionaryHasSequenceMember(dictionary):
return (any(typeIsSequenceOrHasSequenceMember(m.type) for m in return (any(typeIsSequenceOrHasSequenceMember(m.type) for m in
dictionary.members) or dictionary.members)
(dictionary.parent and or (dictionary.parent
dictionaryHasSequenceMember(dictionary.parent))) and dictionaryHasSequenceMember(dictionary.parent)))
def typeIsSequenceOrHasSequenceMember(type): def typeIsSequenceOrHasSequenceMember(type):
@ -618,21 +618,21 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
def onFailureNotAnObject(failureCode): def onFailureNotAnObject(failureCode):
return CGWrapper( return CGWrapper(
CGGeneric( CGGeneric(
failureCode or failureCode
('throw_type_error(*cx, "%s is not an object.");\n' or ('throw_type_error(*cx, "%s is not an object.");\n'
'%s' % (firstCap(sourceDescription), exceptionCode))), '%s' % (firstCap(sourceDescription), exceptionCode))),
post="\n") post="\n")
def onFailureInvalidEnumValue(failureCode, passedVarName): def onFailureInvalidEnumValue(failureCode, passedVarName):
return CGGeneric( return CGGeneric(
failureCode or failureCode
('throw_type_error(*cx, &format!("\'{}\' is not a valid enum value for enumeration \'%s\'.", %s)); %s' or ('throw_type_error(*cx, &format!("\'{}\' is not a valid enum value for enumeration \'%s\'.", %s)); %s'
% (type.name, passedVarName, exceptionCode))) % (type.name, passedVarName, exceptionCode)))
def onFailureNotCallable(failureCode): def onFailureNotCallable(failureCode):
return CGGeneric( return CGGeneric(
failureCode or failureCode
('throw_type_error(*cx, \"%s is not callable.\");\n' or ('throw_type_error(*cx, \"%s is not callable.\");\n'
'%s' % (firstCap(sourceDescription), exceptionCode))) '%s' % (firstCap(sourceDescription), exceptionCode)))
# A helper function for handling default values. # A helper function for handling default values.
@ -660,16 +660,16 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
# Handle the non-object cases by wrapping up the whole # Handle the non-object cases by wrapping up the whole
# thing in an if cascade. # thing in an if cascade.
templateBody = ( templateBody = (
"if ${val}.get().is_object() {\n" + "if ${val}.get().is_object() {\n"
CGIndenter(CGGeneric(templateBody)).define() + "\n") + CGIndenter(CGGeneric(templateBody)).define() + "\n")
if type.nullable(): if type.nullable():
templateBody += ( templateBody += (
"} else if ${val}.get().is_null_or_undefined() {\n" "} else if ${val}.get().is_null_or_undefined() {\n"
" %s\n") % nullValue " %s\n") % nullValue
templateBody += ( templateBody += (
"} else {\n" + "} else {\n"
CGIndenter(onFailureNotAnObject(failureCode)).define() + + CGIndenter(onFailureNotAnObject(failureCode)).define()
"}") + "}")
return templateBody return templateBody
assert not (isEnforceRange and isClamp) # These are mutually exclusive assert not (isEnforceRange and isClamp) # These are mutually exclusive
@ -713,9 +713,9 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
for memberType in type.unroll().flatMemberTypes for memberType in type.unroll().flatMemberTypes
if memberType.isDictionary() if memberType.isDictionary()
] ]
if (defaultValue and if (defaultValue
not isinstance(defaultValue, IDLNullValue) and and not isinstance(defaultValue, IDLNullValue)
not isinstance(defaultValue, IDLDefaultDictionaryValue)): and not isinstance(defaultValue, IDLDefaultDictionaryValue)):
tag = defaultValue.type.tag() tag = defaultValue.type.tag()
if tag is IDLType.Tags.bool: if tag is IDLType.Tags.bool:
default = "%s::Boolean(%s)" % ( default = "%s::Boolean(%s)" % (
@ -1626,13 +1626,13 @@ class PropertyDefiner:
prefableSpecs.append( prefableSpecs.append(
prefableTemplate % (cond, name + "_specs", len(specs) - 1)) prefableTemplate % (cond, name + "_specs", len(specs) - 1))
specsArray = ("const %s_specs: &'static [&'static[%s]] = &[\n" + specsArray = ("const %s_specs: &'static [&'static[%s]] = &[\n"
",\n".join(specs) + "\n" + + ",\n".join(specs) + "\n"
"];\n") % (name, specType) + "];\n") % (name, specType)
prefArray = ("const %s: &'static [Guard<&'static [%s]>] = &[\n" + prefArray = ("const %s: &'static [Guard<&'static [%s]>] = &[\n"
",\n".join(prefableSpecs) + "\n" + + ",\n".join(prefableSpecs) + "\n"
"];\n") % (name, specType) + "];\n") % (name, specType)
return specsArray + prefArray return specsArray + prefArray
@ -1660,9 +1660,9 @@ class MethodDefiner(PropertyDefiner):
# Ignore non-static methods for callback interfaces # Ignore non-static methods for callback interfaces
if not descriptor.interface.isCallback() or static: if not descriptor.interface.isCallback() or static:
methods = [m for m in descriptor.interface.members if methods = [m for m in descriptor.interface.members if
m.isMethod() and m.isStatic() == static and m.isMethod() and m.isStatic() == static
not m.isIdentifierLess() and and not m.isIdentifierLess()
MemberIsUnforgeable(m, descriptor) == unforgeable] and MemberIsUnforgeable(m, descriptor) == unforgeable]
else: else:
methods = [] methods = []
self.regular = [{"name": m.identifier.name, self.regular = [{"name": m.identifier.name,
@ -1683,10 +1683,10 @@ class MethodDefiner(PropertyDefiner):
# Generate the keys/values/entries aliases for value iterables. # Generate the keys/values/entries aliases for value iterables.
maplikeOrSetlikeOrIterable = descriptor.interface.maplikeOrSetlikeOrIterable maplikeOrSetlikeOrIterable = descriptor.interface.maplikeOrSetlikeOrIterable
if (not static and not unforgeable and if (not static and not unforgeable
(maplikeOrSetlikeOrIterable and and maplikeOrSetlikeOrIterable
maplikeOrSetlikeOrIterable.isIterable() and and maplikeOrSetlikeOrIterable.isIterable()
maplikeOrSetlikeOrIterable.isValueIterator())): and maplikeOrSetlikeOrIterable.isValueIterator()):
m = maplikeOrSetlikeOrIterable m = maplikeOrSetlikeOrIterable
# Add our keys/values/entries/forEach # Add our keys/values/entries/forEach
@ -1805,8 +1805,8 @@ class AttrDefiner(PropertyDefiner):
self.regular = [ self.regular = [
m m
for m in descriptor.interface.members if for m in descriptor.interface.members if
m.isAttr() and m.isStatic() == static and m.isAttr() and m.isStatic() == static
MemberIsUnforgeable(m, descriptor) == unforgeable and MemberIsUnforgeable(m, descriptor) == unforgeable
] ]
self.static = static self.static = static
self.unforgeable = unforgeable self.unforgeable = unforgeable
@ -1902,6 +1902,7 @@ class ConstDefiner(PropertyDefiner):
'ConstantSpec', 'ConstantSpec',
PropertyDefiner.getControllingCondition, specData) PropertyDefiner.getControllingCondition, specData)
# We'll want to insert the indent at the beginnings of lines, but we # We'll want to insert the indent at the beginnings of lines, but we
# don't want to indent empty lines. So only indent lines that have a # don't want to indent empty lines. So only indent lines that have a
# non-newline character on them. # non-newline character on them.
@ -2003,8 +2004,8 @@ class CGImports(CGWrapper):
def isImportable(type): def isImportable(type):
if not type.isType(): if not type.isType():
assert (type.isInterface() or type.isDictionary() or assert (type.isInterface() or type.isDictionary()
type.isEnum() or type.isNamespace()) or type.isEnum() or type.isNamespace())
return True return True
return not (type.builtin or type.isSequence() or type.isUnion()) return not (type.builtin or type.isSequence() or type.isUnion())
@ -2878,8 +2879,8 @@ class CGIDLInterface(CGThing):
def define(self): def define(self):
interface = self.descriptor.interface interface = self.descriptor.interface
name = self.descriptor.concreteType name = self.descriptor.concreteType
if (interface.getUserData("hasConcreteDescendant", False) or if (interface.getUserData("hasConcreteDescendant", False)
interface.getUserData("hasProxyDescendant", False)): or interface.getUserData("hasProxyDescendant", False)):
depth = self.descriptor.prototypeDepth depth = self.descriptor.prototypeDepth
check = "class.interface_chain[%s] == PrototypeList::ID::%s" % (depth, name) check = "class.interface_chain[%s] == PrototypeList::ID::%s" % (depth, name)
elif self.descriptor.proxy: elif self.descriptor.proxy:
@ -3466,9 +3467,9 @@ assert!(!proto.is_null());""" % (function,))
def needCx(returnType, arguments, considerTypes): def needCx(returnType, arguments, considerTypes):
return (considerTypes and return (considerTypes
(typeNeedsCx(returnType, True) or and (typeNeedsCx(returnType, True)
any(typeNeedsCx(a.type) for a in arguments))) or any(typeNeedsCx(a.type) for a in arguments)))
class CGCallGenerator(CGThing): class CGCallGenerator(CGThing):
@ -3775,9 +3776,9 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.method) self.method)
return CGWrapper(CGMethodCall([], nativeName, self.method.isStatic(), return CGWrapper(CGMethodCall([], nativeName, self.method.isStatic(),
self.descriptor, self.method), self.descriptor, self.method),
pre="let cx = SafeJSContext::from_ptr(cx);\n" + pre="let cx = SafeJSContext::from_ptr(cx);\n"
("let this = &*(this as *const %s);\n" % self.descriptor.concreteType) + + ("let this = &*(this as *const %s);\n" % self.descriptor.concreteType)
"let args = &*args;\n" + "let args = &*args;\n"
"let argc = args.argc_;\n") "let argc = args.argc_;\n")
@staticmethod @staticmethod
@ -3868,8 +3869,8 @@ class CGSpecializedGetter(CGAbstractExternMethod):
return CGWrapper(CGGetterCall([], self.attr.type, nativeName, return CGWrapper(CGGetterCall([], self.attr.type, nativeName,
self.descriptor, self.attr), self.descriptor, self.attr),
pre="let cx = SafeJSContext::from_ptr(cx);\n" + pre="let cx = SafeJSContext::from_ptr(cx);\n"
("let this = &*(this as *const %s);\n" % self.descriptor.concreteType)) + ("let this = &*(this as *const %s);\n" % self.descriptor.concreteType))
@staticmethod @staticmethod
def makeNativeName(descriptor, attr): def makeNativeName(descriptor, attr):
@ -3924,8 +3925,8 @@ class CGSpecializedSetter(CGAbstractExternMethod):
self.attr) self.attr)
return CGWrapper(CGSetterCall([], self.attr.type, nativeName, return CGWrapper(CGSetterCall([], self.attr.type, nativeName,
self.descriptor, self.attr), self.descriptor, self.attr),
pre="let cx = SafeJSContext::from_ptr(cx);\n" + pre="let cx = SafeJSContext::from_ptr(cx);\n"
("let this = &*(this as *const %s);\n" % self.descriptor.concreteType)) + ("let this = &*(this as *const %s);\n" % self.descriptor.concreteType))
@staticmethod @staticmethod
def makeNativeName(descriptor, attr): def makeNativeName(descriptor, attr):
@ -4191,8 +4192,8 @@ class CGMemberJITInfo(CGThing):
# don't want them coalesced with each other or loop-hoisted, since # don't want them coalesced with each other or loop-hoisted, since
# their return value can change even if nothing is going on from our # their return value can change even if nothing is going on from our
# point of view. # point of view.
return (affects == "Nothing" and return (affects == "Nothing"
(dependsOn != "Everything" and dependsOn != "DeviceState")) and (dependsOn != "Everything" and dependsOn != "DeviceState"))
def aliasSet(self): def aliasSet(self):
"""Returns the alias set to store in the jitinfo. This may not be the """Returns the alias set to store in the jitinfo. This may not be the
@ -4282,10 +4283,10 @@ class CGMemberJITInfo(CGThing):
if type == existingType: if type == existingType:
return existingType return existingType
if ((type == "JSVAL_TYPE_DOUBLE" and if ((type == "JSVAL_TYPE_DOUBLE"
existingType == "JSVAL_TYPE_INT32") or and existingType == "JSVAL_TYPE_INT32")
(existingType == "JSVAL_TYPE_DOUBLE" and or (existingType == "JSVAL_TYPE_DOUBLE"
type == "JSVAL_TYPE_INT32")): and type == "JSVAL_TYPE_INT32")):
# Promote INT32 to DOUBLE as needed # Promote INT32 to DOUBLE as needed
return "JSVAL_TYPE_DOUBLE" return "JSVAL_TYPE_DOUBLE"
# Different types # Different types
@ -5206,8 +5207,8 @@ class CGProxyNamedOperation(CGProxySpecialOperation):
argName = self.arguments[0].identifier.name argName = self.arguments[0].identifier.name
return ("let %s = jsid_to_string(*cx, Handle::from_raw(id)).expect(\"Not a string-convertible JSID?\");\n" return ("let %s = jsid_to_string(*cx, Handle::from_raw(id)).expect(\"Not a string-convertible JSID?\");\n"
"let this = UnwrapProxy(proxy);\n" "let this = UnwrapProxy(proxy);\n"
"let this = &*this;\n" % argName + "let this = &*this;\n" % argName
CGProxySpecialOperation.define(self)) + CGProxySpecialOperation.define(self))
class CGProxyNamedGetter(CGProxyNamedOperation): class CGProxyNamedGetter(CGProxyNamedOperation):
@ -5288,11 +5289,11 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
'successCode': fillDescriptor, 'successCode': fillDescriptor,
'pre': 'rooted!(in(*cx) let mut result_root = UndefinedValue());' 'pre': 'rooted!(in(*cx) let mut result_root = UndefinedValue());'
} }
get += ("if let Some(index) = index {\n" + get += ("if let Some(index) = index {\n"
" let this = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n"
" let this = &*this;\n" + + " let this = &*this;\n"
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n" + + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n"
"}\n") + "}\n")
namedGetter = self.descriptor.operations['NamedGetter'] namedGetter = self.descriptor.operations['NamedGetter']
if namedGetter: if namedGetter:
@ -5373,16 +5374,16 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
indexedSetter = self.descriptor.operations['IndexedSetter'] indexedSetter = self.descriptor.operations['IndexedSetter']
if indexedSetter: if indexedSetter:
set += ("let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n" + set += ("let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n"
"if let Some(index) = index {\n" + + "if let Some(index) = index {\n"
" let this = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n"
" let this = &*this;\n" + + " let this = &*this;\n"
CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() + + CGIndenter(CGProxyIndexedSetter(self.descriptor)).define()
" return (*opresult).succeed();\n" + + " return (*opresult).succeed();\n"
"}\n") + "}\n")
elif self.descriptor.operations['IndexedGetter']: elif self.descriptor.operations['IndexedGetter']:
set += ("if get_array_index_from_id(*cx, Handle::from_raw(id)).is_some() {\n" + set += ("if get_array_index_from_id(*cx, Handle::from_raw(id)).is_some() {\n"
" return (*opresult).failNoIndexedSetter();\n" + " return (*opresult).failNoIndexedSetter();\n"
"}\n") "}\n")
namedSetter = self.descriptor.operations['NamedSetter'] namedSetter = self.descriptor.operations['NamedSetter']
@ -5390,14 +5391,14 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
if self.descriptor.hasUnforgeableMembers: if self.descriptor.hasUnforgeableMembers:
raise TypeError("Can't handle a named setter on an interface that has " raise TypeError("Can't handle a named setter on an interface that has "
"unforgeables. Figure out how that should work!") "unforgeables. Figure out how that should work!")
set += ("if RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id) {\n" + set += ("if RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id) {\n"
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + + CGIndenter(CGProxyNamedSetter(self.descriptor)).define()
" return (*opresult).succeed();\n" + + " return (*opresult).succeed();\n"
"}\n") + "}\n")
elif self.descriptor.operations['NamedGetter']: elif self.descriptor.operations['NamedGetter']:
set += ("if RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id) {\n" + set += ("if RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id) {\n"
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + + CGIndenter(CGProxyNamedGetter(self.descriptor)).define()
" if result.is_some() {\n" + " if result.is_some() {\n"
" return (*opresult).failNoNamedSetter();\n" " return (*opresult).failNoNamedSetter();\n"
" }\n" " }\n"
"}\n") "}\n")
@ -5488,8 +5489,8 @@ class CGDOMJSProxyHandler_ownPropertyKeys(CGAbstractExternMethod):
class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod): class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod):
def __init__(self, descriptor): def __init__(self, descriptor):
assert (descriptor.operations["IndexedGetter"] and assert (descriptor.operations["IndexedGetter"]
descriptor.interface.getExtendedAttribute("LegacyUnenumerableNamedProperties")) and descriptor.interface.getExtendedAttribute("LegacyUnenumerableNamedProperties"))
args = [Argument('*mut JSContext', 'cx'), args = [Argument('*mut JSContext', 'cx'),
Argument('RawHandleObject', 'proxy'), Argument('RawHandleObject', 'proxy'),
Argument('RawMutableHandleIdVector', 'props')] Argument('RawMutableHandleIdVector', 'props')]
@ -5543,14 +5544,14 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
indexedGetter = self.descriptor.operations['IndexedGetter'] indexedGetter = self.descriptor.operations['IndexedGetter']
indexed = "let cx = SafeJSContext::from_ptr(cx);\n" indexed = "let cx = SafeJSContext::from_ptr(cx);\n"
if indexedGetter: if indexedGetter:
indexed += ("let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n" + indexed += ("let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n"
"if let Some(index) = index {\n" + + "if let Some(index) = index {\n"
" let this = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n"
" let this = &*this;\n" + + " let this = &*this;\n"
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" + + CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n"
" *bp = result.is_some();\n" + + " *bp = result.is_some();\n"
" return true;\n" + + " return true;\n"
"}\n\n") + "}\n\n")
namedGetter = self.descriptor.operations['NamedGetter'] namedGetter = self.descriptor.operations['NamedGetter']
condition = "RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id)" condition = "RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id)"
@ -5624,11 +5625,11 @@ if !expando.is_null() {
indexedGetter = self.descriptor.operations['IndexedGetter'] indexedGetter = self.descriptor.operations['IndexedGetter']
if indexedGetter: if indexedGetter:
getIndexedOrExpando = ("let index = get_array_index_from_id(*cx, id_lt);\n" + getIndexedOrExpando = ("let index = get_array_index_from_id(*cx, id_lt);\n"
"if let Some(index) = index {\n" + + "if let Some(index) = index {\n"
" let this = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n"
" let this = &*this;\n" + + " let this = &*this;\n"
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define()) + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define())
getIndexedOrExpando += """\ getIndexedOrExpando += """\
// Even if we don't have this index, we don't forward the // Even if we don't have this index, we don't forward the
// get on to our expando object. // get on to our expando object.
@ -5648,9 +5649,9 @@ if !expando.is_null() {
# 3. Set ignoreNamedProps to true. # 3. Set ignoreNamedProps to true.
if indexedGetter: if indexedGetter:
condition = "index.is_none() && (%s)" % condition condition = "index.is_none() && (%s)" % condition
getNamed = ("if %s {\n" + getNamed = ("if %s {\n"
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + + CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define()
"}\n") % condition + "}\n") % condition
else: else:
getNamed = "" getNamed = ""
@ -5852,10 +5853,10 @@ class CGInterfaceTrait(CGThing):
def members(): def members():
for m in descriptor.interface.members: for m in descriptor.interface.members:
if (m.isMethod() and not m.isStatic() and if (m.isMethod() and not m.isStatic()
not m.isMaplikeOrSetlikeOrIterableMethod() and and not m.isMaplikeOrSetlikeOrIterableMethod()
(not m.isIdentifierLess() or (m.isStringifier() and not m.underlyingAttr)) and and (not m.isIdentifierLess() or (m.isStringifier() and not m.underlyingAttr))
not m.isDefaultToJSON()): and not m.isDefaultToJSON()):
name = CGSpecializedMethod.makeNativeName(descriptor, m) name = CGSpecializedMethod.makeNativeName(descriptor, m)
infallible = 'infallible' in descriptor.getExtendedAttributes(m) infallible = 'infallible' in descriptor.getExtendedAttributes(m)
for idx, (rettype, arguments) in enumerate(m.signatures()): for idx, (rettype, arguments) in enumerate(m.signatures()):
@ -6254,8 +6255,8 @@ class CGDescriptor(CGThing):
defaultToJSONMethod = None defaultToJSONMethod = None
unscopableNames = [] unscopableNames = []
for m in descriptor.interface.members: for m in descriptor.interface.members:
if (m.isMethod() and if (m.isMethod()
(not m.isIdentifierLess() or m == descriptor.operations["Stringifier"])): and (not m.isIdentifierLess() or m == descriptor.operations["Stringifier"])):
if m.getExtendedAttribute("Unscopable"): if m.getExtendedAttribute("Unscopable"):
assert not m.isStatic() assert not m.isStatic()
unscopableNames.append(m.identifier.name) unscopableNames.append(m.identifier.name)
@ -6506,11 +6507,11 @@ class CGDictionary(CGThing):
return (string.Template( return (string.Template(
"#[derive(${derive})]\n" "#[derive(${derive})]\n"
"${mustRoot}" + + "${mustRoot}"
"pub struct ${selfName} {\n" + + "pub struct ${selfName} {\n"
"${inheritance}" + + "${inheritance}"
"\n".join(memberDecls) + "\n" + + "\n".join(memberDecls) + "\n"
"}").substitute({"selfName": self.makeClassName(d), + "}").substitute({"selfName": self.makeClassName(d),
"inheritance": inheritance, "inheritance": inheritance,
"mustRoot": mustRoot, "mustRoot": mustRoot,
"derive": ', '.join(derive)})) "derive": ', '.join(derive)}))
@ -6769,15 +6770,15 @@ class CGRegisterProxyHandlers(CGThing):
descriptors = config.getDescriptors(proxy=True) descriptors = config.getDescriptors(proxy=True)
self.root = CGList([ self.root = CGList([
CGGeneric( CGGeneric(
"#[allow(non_upper_case_globals)]\n" + "#[allow(non_upper_case_globals)]\n"
"pub mod proxy_handlers {\n" + + "pub mod proxy_handlers {\n"
"".join( + "".join(
" pub static %s: std::sync::atomic::AtomicPtr<libc::c_void> =\n" " pub static %s: std::sync::atomic::AtomicPtr<libc::c_void> =\n"
" std::sync::atomic::AtomicPtr::new(std::ptr::null_mut());\n" " std::sync::atomic::AtomicPtr::new(std::ptr::null_mut());\n"
% desc.name % desc.name
for desc in descriptors for desc in descriptors
) + )
"}\n" + "}\n"
), ),
CGRegisterProxyHandlersMethod(descriptors), CGRegisterProxyHandlersMethod(descriptors),
], "\n") ], "\n")
@ -7004,8 +7005,8 @@ class CGNativeMember(ClassMethod):
static=member.isStatic(), static=member.isStatic(),
# Mark our getters, which are attrs that # Mark our getters, which are attrs that
# have a non-void return type, as const. # have a non-void return type, as const.
const=(not member.isStatic() and member.isAttr() and const=(not member.isStatic() and member.isAttr()
not signature[0].isVoid()), and not signature[0].isVoid()),
breakAfterSelf=breakAfterSelf, breakAfterSelf=breakAfterSelf,
unsafe=unsafe, unsafe=unsafe,
visibility=visibility) visibility=visibility)
@ -7087,8 +7088,8 @@ class CGCallback(CGClass):
setupCall = "let s = CallSetup::new(self, aExceptionHandling);\n" setupCall = "let s = CallSetup::new(self, aExceptionHandling);\n"
bodyWithThis = string.Template( bodyWithThis = string.Template(
setupCall + setupCall
"rooted!(in(*s.get_context()) let mut thisObjJS = ptr::null_mut::<JSObject>());\n" + "rooted!(in(*s.get_context()) let mut thisObjJS = ptr::null_mut::<JSObject>());\n"
"wrap_call_this_object(s.get_context(), thisObj, thisObjJS.handle_mut());\n" "wrap_call_this_object(s.get_context(), thisObj, thisObjJS.handle_mut());\n"
"if thisObjJS.is_null() {\n" "if thisObjJS.is_null() {\n"
" return Err(JSFailed);\n" " return Err(JSFailed);\n"
@ -7098,8 +7099,8 @@ class CGCallback(CGClass):
"methodName": 'self.' + method.name, "methodName": 'self.' + method.name,
}) })
bodyWithoutThis = string.Template( bodyWithoutThis = string.Template(
setupCall + setupCall
"rooted!(in(*s.get_context()) let thisObjJS = ptr::null_mut::<JSObject>());\n" + "rooted!(in(*s.get_context()) let thisObjJS = ptr::null_mut::<JSObject>());\n"
"unsafe { ${methodName}(${callArgs}) }").substitute({ "unsafe { ${methodName}(${callArgs}) }").substitute({
"callArgs": ", ".join(argnamesWithoutThis), "callArgs": ", ".join(argnamesWithoutThis),
"methodName": 'self.' + method.name, "methodName": 'self.' + method.name,
@ -7314,23 +7315,23 @@ class CallbackMember(CGNativeMember):
conversion = wrapForType( conversion = wrapForType(
"argv_root.handle_mut()", result=argval, "argv_root.handle_mut()", result=argval,
successCode=("{\n" + successCode=("{\n"
"let arg = &mut argv[%s];\n" + "let arg = &mut argv[%s];\n"
"*arg = Heap::default();\n" + "*arg = Heap::default();\n"
"arg.set(argv_root.get());\n" + "arg.set(argv_root.get());\n"
"}") % jsvalIndex, "}") % jsvalIndex,
pre="rooted!(in(*cx) let mut argv_root = UndefinedValue());") pre="rooted!(in(*cx) let mut argv_root = UndefinedValue());")
if arg.variadic: if arg.variadic:
conversion = string.Template( conversion = string.Template(
"for idx in 0..${arg}.len() {\n" + "for idx in 0..${arg}.len() {\n"
CGIndenter(CGGeneric(conversion)).define() + "\n" + CGIndenter(CGGeneric(conversion)).define() + "\n"
"}" + "}"
).substitute({"arg": arg.identifier.name}) ).substitute({"arg": arg.identifier.name})
elif arg.optional and not arg.defaultValue: elif arg.optional and not arg.defaultValue:
conversion = ( conversion = (
CGIfWrapper("%s.is_some()" % arg.identifier.name, CGIfWrapper("%s.is_some()" % arg.identifier.name,
CGGeneric(conversion)).define() + CGGeneric(conversion)).define()
" else if argc == %d {\n" + " else if argc == %d {\n"
" // This is our current trailing argument; reduce argc\n" " // This is our current trailing argument; reduce argc\n"
" argc -= 1;\n" " argc -= 1;\n"
"} else {\n" "} else {\n"
@ -7464,8 +7465,8 @@ class CallbackOperationBase(CallbackMethod):
return 'rooted!(in(*cx) let callable =\n' + getCallableFromProp + ');\n' return 'rooted!(in(*cx) let callable =\n' + getCallableFromProp + ');\n'
return ( return (
'let isCallable = IsCallable(self.callback());\n' 'let isCallable = IsCallable(self.callback());\n'
'rooted!(in(*cx) let callable =\n' + 'rooted!(in(*cx) let callable =\n'
CGIndenter( + CGIndenter(
CGIfElseWrapper('isCallable', CGIfElseWrapper('isCallable',
CGGeneric('ObjectValue(self.callback())'), CGGeneric('ObjectValue(self.callback())'),
CGGeneric(getCallableFromProp))).define() + ');\n') CGGeneric(getCallableFromProp))).define() + ');\n')
@ -7676,9 +7677,9 @@ class GlobalGenRoots():
return getModuleFromObject(d).split('::')[-1] return getModuleFromObject(d).split('::')[-1]
descriptors = config.getDescriptors(register=True, isIteratorInterface=False) descriptors = config.getDescriptors(register=True, isIteratorInterface=False)
descriptors = (set(toBindingNamespace(d.name) for d in descriptors) | descriptors = (set(toBindingNamespace(d.name) for d in descriptors)
set(leafModule(d) for d in config.callbacks) | | set(leafModule(d) for d in config.callbacks)
set(leafModule(d) for d in config.getDictionaries())) | set(leafModule(d) for d in config.getDictionaries()))
curr = CGList([CGGeneric("pub mod %s;\n" % name) for name in sorted(descriptors)]) curr = CGList([CGGeneric("pub mod %s;\n" % name) for name in sorted(descriptors)])
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
return curr return curr

View file

@ -63,7 +63,8 @@ class Configuration:
c.isCallback() and not c.isInterface()] c.isCallback() and not c.isInterface()]
# Keep the descriptor list sorted for determinism. # Keep the descriptor list sorted for determinism.
cmp = lambda x, y: (x > y) - (x < y) def cmp(x, y):
return (x > y) - (x < y)
self.descriptors.sort(key=functools.cmp_to_key(lambda x, y: cmp(x.name, y.name))) self.descriptors.sort(key=functools.cmp_to_key(lambda x, y: cmp(x.name, y.name)))
def getInterface(self, ifname): def getInterface(self, ifname):
@ -74,25 +75,35 @@ class Configuration:
curr = self.descriptors curr = self.descriptors
for key, val in filters.iteritems(): for key, val in filters.iteritems():
if key == 'webIDLFile': if key == 'webIDLFile':
getter = lambda x: x.interface.filename() def getter(x):
return x.interface.filename()
elif key == 'hasInterfaceObject': elif key == 'hasInterfaceObject':
getter = lambda x: x.interface.hasInterfaceObject() def getter(x):
return x.interface.hasInterfaceObject()
elif key == 'isCallback': elif key == 'isCallback':
getter = lambda x: x.interface.isCallback() def getter(x):
return x.interface.isCallback()
elif key == 'isNamespace': elif key == 'isNamespace':
getter = lambda x: x.interface.isNamespace() def getter(x):
return x.interface.isNamespace()
elif key == 'isJSImplemented': elif key == 'isJSImplemented':
getter = lambda x: x.interface.isJSImplemented() def getter(x):
return x.interface.isJSImplemented()
elif key == 'isGlobal': elif key == 'isGlobal':
getter = lambda x: x.isGlobal() def getter(x):
return x.isGlobal()
elif key == 'isInline': elif key == 'isInline':
getter = lambda x: x.interface.getExtendedAttribute('Inline') is not None def getter(x):
return x.interface.getExtendedAttribute('Inline') is not None
elif key == 'isExposedConditionally': elif key == 'isExposedConditionally':
getter = lambda x: x.interface.isExposedConditionally() def getter(x):
return x.interface.isExposedConditionally()
elif key == 'isIteratorInterface': elif key == 'isIteratorInterface':
getter = lambda x: x.interface.isIteratorInterface() def getter(x):
return x.interface.isIteratorInterface()
else: else:
getter = lambda x: getattr(x, key) def getter(x):
return getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr) curr = filter(lambda x: getter(x) == val, curr)
return curr return curr
@ -125,8 +136,8 @@ class Configuration:
# We should have exactly one result. # We should have exactly one result.
if len(descriptors) != 1: if len(descriptors) != 1:
raise NoSuchDescriptorError("For " + interfaceName + " found " + raise NoSuchDescriptorError("For " + interfaceName + " found "
str(len(descriptors)) + " matches") + str(len(descriptors)) + " matches")
return descriptors[0] return descriptors[0]
def getDescriptorProvider(self): def getDescriptorProvider(self):
@ -157,10 +168,10 @@ class DescriptorProvider:
def MemberIsUnforgeable(member, descriptor): def MemberIsUnforgeable(member, descriptor):
return ((member.isAttr() or member.isMethod()) and return ((member.isAttr() or member.isMethod())
not member.isStatic() and and not member.isStatic()
(member.isUnforgeable() or and (member.isUnforgeable()
bool(descriptor.interface.getExtendedAttribute("Unforgeable")))) or bool(descriptor.interface.getExtendedAttribute("Unforgeable"))))
class Descriptor(DescriptorProvider): class Descriptor(DescriptorProvider):
@ -228,13 +239,13 @@ class Descriptor(DescriptorProvider):
# If we're concrete, we need to crawl our ancestor interfaces and mark # If we're concrete, we need to crawl our ancestor interfaces and mark
# them as having a concrete descendant. # them as having a concrete descendant.
self.concrete = (not self.interface.isCallback() and self.concrete = (not self.interface.isCallback()
not self.interface.isNamespace() and and not self.interface.isNamespace()
not self.interface.getExtendedAttribute("Abstract") and and not self.interface.getExtendedAttribute("Abstract")
not self.interface.getExtendedAttribute("Inline") and and not self.interface.getExtendedAttribute("Inline")
not spiderMonkeyInterface) and not spiderMonkeyInterface)
self.hasUnforgeableMembers = (self.concrete and self.hasUnforgeableMembers = (self.concrete
any(MemberIsUnforgeable(m, self) for m in and any(MemberIsUnforgeable(m, self) for m in
self.interface.members)) self.interface.members))
self.operations = { self.operations = {
@ -391,8 +402,8 @@ class Descriptor(DescriptorProvider):
return None return None
def hasDescendants(self): def hasDescendants(self):
return (self.interface.getUserData("hasConcreteDescendant", False) or return (self.interface.getUserData("hasConcreteDescendant", False)
self.interface.getUserData("hasProxyDescendant", False)) or self.interface.getUserData("hasProxyDescendant", False))
def hasHTMLConstructor(self): def hasHTMLConstructor(self):
ctor = self.interface.ctor() ctor = self.interface.ctor()
@ -402,8 +413,8 @@ class Descriptor(DescriptorProvider):
assert self.interface.hasInterfaceObject() assert self.interface.hasInterfaceObject()
if self.interface.getExtendedAttribute("Inline"): if self.interface.getExtendedAttribute("Inline"):
return False return False
return (self.interface.isCallback() or self.interface.isNamespace() or return (self.interface.isCallback() or self.interface.isNamespace()
self.hasDescendants() or self.hasHTMLConstructor()) or self.hasDescendants() or self.hasHTMLConstructor())
def shouldCacheConstructor(self): def shouldCacheConstructor(self):
return self.hasDescendants() or self.hasHTMLConstructor() return self.hasDescendants() or self.hasHTMLConstructor()
@ -416,8 +427,8 @@ class Descriptor(DescriptorProvider):
Returns true if this is the primary interface for a global object Returns true if this is the primary interface for a global object
of some sort. of some sort.
""" """
return bool(self.interface.getExtendedAttribute("Global") or return bool(self.interface.getExtendedAttribute("Global")
self.interface.getExtendedAttribute("PrimaryGlobal")) or self.interface.getExtendedAttribute("PrimaryGlobal"))
# Some utility methods # Some utility methods
@ -428,8 +439,8 @@ def MakeNativeName(name):
def getModuleFromObject(object): def getModuleFromObject(object):
return ('crate::dom::bindings::codegen::Bindings::' + return ('crate::dom::bindings::codegen::Bindings::'
os.path.basename(object.location.filename()).split('.webidl')[0] + 'Binding') + os.path.basename(object.location.filename()).split('.webidl')[0] + 'Binding')
def getTypesFromDescriptor(descriptor): def getTypesFromDescriptor(descriptor):

View file

@ -198,11 +198,11 @@ class Longhand(object):
self.gecko_pref = gecko_pref self.gecko_pref = gecko_pref
self.has_effect_on_gecko_scrollbars = has_effect_on_gecko_scrollbars self.has_effect_on_gecko_scrollbars = has_effect_on_gecko_scrollbars
assert ( assert (
has_effect_on_gecko_scrollbars in [None, False, True] and has_effect_on_gecko_scrollbars in [None, False, True]
not style_struct.inherited or and not style_struct.inherited
(gecko_pref is None) == (has_effect_on_gecko_scrollbars is None)), ( or (gecko_pref is None) == (has_effect_on_gecko_scrollbars is None)), (
"Property " + name + ": has_effect_on_gecko_scrollbars must be " + "Property " + name + ": has_effect_on_gecko_scrollbars must be "
"specified, and must have a value of True or False, iff a " + "specified, and must have a value of True or False, iff a "
"property is inherited and is behind a Gecko pref") "property is inherited and is behind a Gecko pref")
# For enabled_in, the setup is as follows: # For enabled_in, the setup is as follows:
# It needs to be one of the four values: ["", "ua", "chrome", "content"] # It needs to be one of the four values: ["", "ua", "chrome", "content"]

View file

@ -14,7 +14,7 @@ import re
import subprocess import subprocess
import sys import sys
symbol_regex = re.compile(b"D \*UND\*\t(.*) (.*)$") symbol_regex = re.compile(br"D \*UND\*\t(.*) (.*)$")
allowed_symbols = frozenset([ allowed_symbols = frozenset([
b'unshare', b'unshare',
b'malloc_usable_size', b'malloc_usable_size',

View file

@ -91,7 +91,7 @@ def run_gecko_test(testcase, url, date, timeout, is_async):
"return JSON.stringify(performance.timing)" "return JSON.stringify(performance.timing)"
) )
)) ))
except: except Exception:
# We need to return a timing object no matter what happened. # We need to return a timing object no matter what happened.
# See the comment in generate_placeholder() for explanation # See the comment in generate_placeholder() for explanation
print("Failed to get a valid timing measurement.") print("Failed to get a valid timing measurement.")

View file

@ -116,7 +116,7 @@ def parse_log(log, testcase, url, date):
for line in block: for line in block:
try: try:
(_, key, value) = line.split(",") (_, key, value) = line.split(",")
except: except ValueError:
print("[DEBUG] failed to parse the following line:") print("[DEBUG] failed to parse the following line:")
print(line) print(line)
print('[DEBUG] log:') print('[DEBUG] log:')
@ -133,10 +133,10 @@ def parse_log(log, testcase, url, date):
return timing return timing
def valid_timing(timing, url=None): def valid_timing(timing, url=None):
if (timing is None or if (timing is None
testcase is None or or testcase is None
timing.get('title') == 'Error loading page' or or timing.get('title') == 'Error loading page'
timing.get('testcase') != url): or timing.get('testcase') != url):
return False return False
else: else:
return True return True

View file

@ -29,6 +29,7 @@ def load_data(filename):
results[key] = round(totals[key] / counts[key]) results[key] = round(totals[key] / counts[key])
return results return results
data1 = load_data(args.file1) data1 = load_data(args.file1)
data2 = load_data(args.file2) data2 = load_data(args.file2)
keys = set(data1.keys()).union(data2.keys()) keys = set(data1.keys()).union(data2.keys())

View file

@ -14,8 +14,8 @@ def test_format_testcase_name():
'http://localhost:8000/page_load_test/163.com/p.mail.163.com/' 'http://localhost:8000/page_load_test/163.com/p.mail.163.com/'
'mailinfo/shownewmsg_www_1222.htm.html'))) 'mailinfo/shownewmsg_www_1222.htm.html')))
assert(('1234567890223456789032345678904234567890' assert(('1234567890223456789032345678904234567890'
'5234567890623456789072345678908234567890') == '5234567890623456789072345678908234567890')
submit_to_perfherder.format_testcase_name(( == submit_to_perfherder.format_testcase_name((
'1234567890223456789032345678904234567890' '1234567890223456789032345678904234567890'
'52345678906234567890723456789082345678909234567890'))) '52345678906234567890723456789082345678909234567890')))
assert('news.ycombinator.com' == submit_to_perfherder.format_testcase_name( assert('news.ycombinator.com' == submit_to_perfherder.format_testcase_name(

View file

@ -10,15 +10,14 @@
""" """
Created on Mon Mar 26 20:08:25 2018 Created on Mon Mar 26 20:08:25 2018
@author: Pranshu Sinha, Abhay Soni, Aayushi Agrawal @author: Pranshu Sinha, Abhay Soni, Aayushi Agrawal
"""
"""
The below program is intended to test rendering mismatches in servo by taking screenshots of rendered html files. The below program is intended to test rendering mismatches in servo by taking screenshots of rendered html files.
Here is the breakdown of how our code works: Here is the breakdown of how our code works:
* A session is started on localhost:7002 * A session is started on localhost:7002
* The randomly generated webpage's (html files) data is sent as JSON to this session * The randomly generated webpage's (html files) data is sent as JSON to this session
* Using curl request, we load the html files for this session ID based on the session we just created. * Using curl request, we load the html files for this session ID based on the session we just created.
""" """
import os import os
import json import json
import requests import requests
@ -72,7 +71,7 @@ def render_html_files(num_of_files, url, file_url, json_string, headers, cwd):
image_file.write(base64.decodebytes(image_data_encoded.encode('utf-8'))) image_file.write(base64.decodebytes(image_data_encoded.encode('utf-8')))
print("################################") print("################################")
print("The screenshot is stored in the location: {0}/screenshots/" print("The screenshot is stored in the location: {0}/screenshots/"
+ " with filename: output_image_{1}.png".format(cwd, str(x))) " with filename: output_image_{1}.png".format(cwd, str(x)))
print("################################") print("################################")
@ -124,6 +123,7 @@ def main(argv): # take inputs from command line by considering the options para
# Render each HTML file and take a screenshot # Render each HTML file and take a screenshot
render_html_files(num_of_files, url, file_url, json_string, headers, cwd) render_html_files(num_of_files, url, file_url, json_string, headers, cwd)
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 8: if len(sys.argv) < 8:
print_help() print_help()

View file

@ -128,6 +128,7 @@ class TestPrinter:
def to_string(self): def to_string(self):
return "[UNKNOWN - type = {0}]".format(str(self.val.type)) return "[UNKNOWN - type = {0}]".format(str(self.val.type))
type_map = [ type_map = [
('struct Au', AuPrinter), ('struct Au', AuPrinter),
('FlowFlags', BitFieldU8Printer), ('FlowFlags', BitFieldU8Printer),

View file

@ -13,11 +13,9 @@
python3 -m coverage run $0 python3 -m coverage run $0
python3 -m coverage report -m --fail-under 100 python3 -m coverage report -m --fail-under 100
exit exit
'''
"""
Run the decision task with fake Taskcluster APIs, to catch Python errors before pushing. Run the decision task with fake Taskcluster APIs, to catch Python errors before pushing.
""" '''
import os import os
import sys import sys
@ -47,7 +45,7 @@ os.environ["GIT_REF"] = "refs/heads/auto"
os.environ["TASKCLUSTER_ROOT_URL"] = "https://community-tc.services.mozilla.com" os.environ["TASKCLUSTER_ROOT_URL"] = "https://community-tc.services.mozilla.com"
os.environ["TASKCLUSTER_PROXY_URL"] = "http://taskcluster" os.environ["TASKCLUSTER_PROXY_URL"] = "http://taskcluster"
os.environ["NEW_AMI_WORKER_TYPE"] = "-" os.environ["NEW_AMI_WORKER_TYPE"] = "-"
import decision_task import decision_task # noqa: E402
decision_task.decisionlib.subprocess = MagicMock() decision_task.decisionlib.subprocess = MagicMock()
print("\n# Push:") print("\n# Push:")

View file

@ -34,13 +34,13 @@ with open(sys.argv[1]) as f:
if "action" in entry and entry["action"] == "test_end": if "action" in entry and entry["action"] == "test_end":
thread = None thread = None
else: else:
if ("action" in entry and if ("action" in entry
entry["action"] == "test_start" and and entry["action"] == "test_start"
entry["test"] == sys.argv[2]): and entry["test"] == sys.argv[2]):
thread = entry["thread"] thread = entry["thread"]
print(json.dumps(entry)) print(json.dumps(entry))
elif (full_search and elif (full_search
"command" in entry and and "command" in entry
sys.argv[2] in entry["command"]): and sys.argv[2] in entry["command"]):
thread = entry["thread"] thread = entry["thread"]
print(json.dumps(entry)) print(json.dumps(entry))

View file

@ -51,6 +51,7 @@ def process_log(data):
return test_results return test_results
test_results = { test_results = {
"SKIP": [], "SKIP": [],
"OK": [], "OK": [],

View file

@ -155,7 +155,6 @@ def wptserve_path(is_firefox, topdir, *paths):
def _activate_virtualenv(topdir, is_firefox): def _activate_virtualenv(topdir, is_firefox):
virtualenv_path = os.path.join(topdir, "python", "_virtualenv%d.%d" % (sys.version_info[0], sys.version_info[1])) virtualenv_path = os.path.join(topdir, "python", "_virtualenv%d.%d" % (sys.version_info[0], sys.version_info[1]))
check_exec_path = lambda path: path.startswith(virtualenv_path)
python = sys.executable # If there was no python, mach wouldn't have run at all! python = sys.executable # If there was no python, mach wouldn't have run at all!
if not python: if not python:
sys.exit('Failed to find python executable for starting virtualenv.') sys.exit('Failed to find python executable for starting virtualenv.')
@ -177,7 +176,8 @@ def _activate_virtualenv(topdir, is_firefox):
exec(compile(open(activate_path).read(), activate_path, 'exec'), dict(__file__=activate_path)) exec(compile(open(activate_path).read(), activate_path, 'exec'), dict(__file__=activate_path))
python = _get_exec_path(PYTHON_NAMES, is_valid_path=check_exec_path) python = _get_exec_path(PYTHON_NAMES,
is_valid_path=lambda path: path.startswith(virtualenv_path))
if not python: if not python:
sys.exit("Python executable in virtualenv failed to activate.") sys.exit("Python executable in virtualenv failed to activate.")

View file

@ -11,9 +11,9 @@ setuptools == 39.0
toml == 0.9.2 toml == 0.9.2
# For Python linting # For Python linting
flake8 == 2.4.1 flake8 == 3.8.3
pep8 == 1.5.7 pep8 == 1.5.7
pyflakes == 0.8.1 pyflakes == 2.2.0
# For buildbot checking # For buildbot checking
voluptuous == 0.10.5 voluptuous == 0.10.5

View file

@ -244,7 +244,7 @@ class MachCommands(CommandBase):
with open(path.join(preload_path, preload_filename), 'w') as fd: with open(path.join(preload_path, preload_filename), 'w') as fd:
json.dump(entries, fd, indent=4) json.dump(entries, fd, indent=4)
except ValueError as e: except ValueError:
print("Unable to parse chromium HSTS preload list, has the format changed?") print("Unable to parse chromium HSTS preload list, has the format changed?")
sys.exit(1) sys.exit(1)
@ -262,8 +262,8 @@ class MachCommands(CommandBase):
print("Unable to download the public suffix list; are you connected to the internet?") print("Unable to download the public suffix list; are you connected to the internet?")
sys.exit(1) sys.exit(1)
lines = [l.strip() for l in content.decode("utf8").split("\n")] lines = [line.strip() for line in content.decode("utf8").split("\n")]
suffixes = [l for l in lines if not l.startswith("//") and not l == ""] suffixes = [line for line in lines if not line.startswith("//") and not line == ""]
with open(dst_filename, "wb") as fo: with open(dst_filename, "wb") as fo:
for suffix in suffixes: for suffix in suffixes:
@ -475,7 +475,7 @@ class MachCommands(CommandBase):
if os.path.exists(crate_path): if os.path.exists(crate_path):
try: try:
delete(crate_path) delete(crate_path)
except: except Exception:
print(traceback.format_exc()) print(traceback.format_exc())
print("Delete %s failed!" % crate_path) print("Delete %s failed!" % crate_path)
else: else:

View file

@ -46,7 +46,7 @@ def notify_linux(title, text):
notify_obj = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") notify_obj = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
method = notify_obj.get_dbus_method("Notify", "org.freedesktop.Notifications") method = notify_obj.get_dbus_method("Notify", "org.freedesktop.Notifications")
method(title, 0, "", text, "", [], {"transient": True}, -1) method(title, 0, "", text, "", [], {"transient": True}, -1)
except: except ImportError:
raise Exception("Optional Python module 'dbus' is not installed.") raise Exception("Optional Python module 'dbus' is not installed.")
@ -55,7 +55,7 @@ def notify_win(title, text):
from servo.win32_toast import WindowsToast from servo.win32_toast import WindowsToast
w = WindowsToast() w = WindowsToast()
w.balloon_tip(title, text) w.balloon_tip(title, text)
except: except WindowsError:
from ctypes import Structure, windll, POINTER, sizeof from ctypes import Structure, windll, POINTER, sizeof
from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
@ -920,7 +920,7 @@ def package_gstreamer_dlls(env, servo_exe_dir, target, uwp):
for gst_lib in gst_dlls: for gst_lib in gst_dlls:
try: try:
shutil.copy(path.join(gst_root, "bin", gst_lib), servo_exe_dir) shutil.copy(path.join(gst_root, "bin", gst_lib), servo_exe_dir)
except: except Exception:
missing += [str(gst_lib)] missing += [str(gst_lib)]
for gst_lib in missing: for gst_lib in missing:
@ -976,7 +976,7 @@ def package_gstreamer_dlls(env, servo_exe_dir, target, uwp):
for gst_lib in gst_dlls: for gst_lib in gst_dlls:
try: try:
shutil.copy(path.join(gst_plugin_path, gst_lib), servo_exe_dir) shutil.copy(path.join(gst_plugin_path, gst_lib), servo_exe_dir)
except: except Exception:
missing += [str(gst_lib)] missing += [str(gst_lib)]
for gst_lib in missing: for gst_lib in missing:

View file

@ -487,7 +487,7 @@ class CommandBase(object):
print("Could not fetch the available nightly versions from the repository : {}".format( print("Could not fetch the available nightly versions from the repository : {}".format(
e.reason)) e.reason))
sys.exit(1) sys.exit(1)
except AttributeError as e: except AttributeError:
print("Could not fetch a nightly version for date {} and platform {}".format( print("Could not fetch a nightly version for date {} and platform {}".format(
nightly_date, os_prefix)) nightly_date, os_prefix))
sys.exit(1) sys.exit(1)
@ -517,8 +517,8 @@ class CommandBase(object):
else: else:
print("The nightly {} does not exist yet, downloading it.".format( print("The nightly {} does not exist yet, downloading it.".format(
destination_file)) destination_file))
download_file(destination_file, NIGHTLY_REPOSITORY_URL + download_file(destination_file, NIGHTLY_REPOSITORY_URL
file_to_download, destination_file) + file_to_download, destination_file)
# Extract the downloaded nightly version # Extract the downloaded nightly version
if os.path.isdir(destination_folder): if os.path.isdir(destination_folder):
@ -537,7 +537,7 @@ class CommandBase(object):
try: try:
if check_gstreamer_lib(): if check_gstreamer_lib():
return False return False
except: except Exception:
# Some systems don't have pkg-config; we can't probe in this case # Some systems don't have pkg-config; we can't probe in this case
# and must hope for the best # and must hope for the best
return False return False
@ -858,9 +858,9 @@ install them, let us know by filing a bug!")
def pick_media_stack(self, media_stack, target): def pick_media_stack(self, media_stack, target):
if not(media_stack): if not(media_stack):
if ( if (
not(target) or not(target)
("armv7" in target and "android" in target) or or ("armv7" in target and "android" in target)
("x86_64" in target) or ("x86_64" in target)
): ):
media_stack = "gstreamer" media_stack = "gstreamer"
else: else:
@ -1032,7 +1032,7 @@ install them, let us know by filing a bug!")
print() print()
sys.exit(1) sys.exit(1)
raise raise
version = tuple(map(int, re.match(b"rustup (\d+)\.(\d+)\.(\d+)", version_line).groups())) version = tuple(map(int, re.match(br"rustup (\d+)\.(\d+)\.(\d+)", version_line).groups()))
version_needed = (1, 21, 0) version_needed = (1, 21, 0)
if version < version_needed: if version < version_needed:
print("rustup is at version %s.%s.%s, Servo requires %s.%s.%s or more recent." % (version + version_needed)) print("rustup is at version %s.%s.%s, Servo requires %s.%s.%s or more recent." % (version + version_needed))
@ -1069,8 +1069,8 @@ install them, let us know by filing a bug!")
def find_highest_msvc_version_ext(): def find_highest_msvc_version_ext():
def vswhere(args): def vswhere(args):
program_files = (os.environ.get('PROGRAMFILES(X86)') or program_files = (os.environ.get('PROGRAMFILES(X86)')
os.environ.get('PROGRAMFILES')) or os.environ.get('PROGRAMFILES'))
if not program_files: if not program_files:
return [] return []
vswhere = os.path.join(program_files, 'Microsoft Visual Studio', vswhere = os.path.join(program_files, 'Microsoft Visual Studio',
@ -1107,8 +1107,8 @@ def find_highest_msvc_version():
versions = sorted(find_highest_msvc_version_ext(), key=lambda tup: float(tup[1])) versions = sorted(find_highest_msvc_version_ext(), key=lambda tup: float(tup[1]))
if not versions: if not versions:
print("Can't find MSBuild.exe installation under %s. Please set the VSINSTALLDIR and VisualStudioVersion" + print("Can't find MSBuild.exe installation under %s. Please set the VSINSTALLDIR and VisualStudioVersion"
" environment variables" % base_vs_path) + " environment variables" % base_vs_path)
sys.exit(1) sys.exit(1)
return versions[0] return versions[0]

View file

@ -93,8 +93,8 @@ class MachCommands(CommandBase):
help='Updates the selected package') help='Updates the selected package')
@CommandArgument( @CommandArgument(
'--all-packages', '-a', action='store_true', '--all-packages', '-a', action='store_true',
help='Updates all packages. NOTE! This is very likely to break your ' + help='Updates all packages. NOTE! This is very likely to break your '
'working copy, making it impossible to build servo. Only do ' + 'working copy, making it impossible to build servo. Only do '
'this if you really know what you are doing.') 'this if you really know what you are doing.')
@CommandArgument( @CommandArgument(
'--dry-run', '-d', action='store_true', '--dry-run', '-d', action='store_true',

View file

@ -138,8 +138,8 @@ class DuplicateLine(Strategy):
plus_equals_statement = r".+?\s\+\=\s.*" plus_equals_statement = r".+?\s\+\=\s.*"
minus_equals_statement = r".+?\s\-\=\s.*" minus_equals_statement = r".+?\s\-\=\s.*"
self._replace_strategy = { self._replace_strategy = {
'regex': (append_statement + '|' + remove_statement + '|' + push_statement + 'regex': (append_statement + '|' + remove_statement + '|' + push_statement
'|' + pop_statement + '|' + plus_equals_statement + '|' + minus_equals_statement), + '|' + pop_statement + '|' + plus_equals_statement + '|' + minus_equals_statement),
'replaceString': r"\g<0>\n\g<0>", 'replaceString': r"\g<0>\n\g<0>",
} }

View file

@ -30,9 +30,6 @@ from mach.decorators import (
Command, Command,
) )
from mach.registrar import Registrar from mach.registrar import Registrar
# Note: mako cannot be imported at the top level because it breaks mach bootstrap
sys.path.append(path.join(path.dirname(__file__), "..", "..",
"components", "style", "properties", "Mako-1.1.2-py2.py3-none-any.whl"))
from servo.command_base import ( from servo.command_base import (
archive_deterministically, archive_deterministically,
@ -44,6 +41,9 @@ from servo.command_base import (
) )
from servo.util import delete from servo.util import delete
# Note: mako cannot be imported at the top level because it breaks mach bootstrap
sys.path.append(path.join(path.dirname(__file__), "..", "..",
"components", "style", "properties", "Mako-1.1.2-py2.py3-none-any.whl"))
PACKAGES = { PACKAGES = {
'android': [ 'android': [
@ -96,18 +96,18 @@ else:
def get_taskcluster_secret(name): def get_taskcluster_secret(name):
url = ( url = (
os.environ.get("TASKCLUSTER_PROXY_URL", "http://taskcluster") + os.environ.get("TASKCLUSTER_PROXY_URL", "http://taskcluster")
"/api/secrets/v1/secret/project/servo/" + + "/api/secrets/v1/secret/project/servo/"
name + name
) )
return json.load(urllib.request.urlopen(url))["secret"] return json.load(urllib.request.urlopen(url))["secret"]
def otool(s): def otool(s):
o = subprocess.Popen(['/usr/bin/otool', '-L', s], stdout=subprocess.PIPE) o = subprocess.Popen(['/usr/bin/otool', '-L', s], stdout=subprocess.PIPE)
for l in o.stdout: for line in o.stdout:
if l[0] == '\t': if line[0] == '\t':
yield l.split(' ', 1)[0][1:] yield line.split(' ', 1)[0][1:]
def listfiles(directory): def listfiles(directory):
@ -781,7 +781,7 @@ def setup_uwp_signing(ms_app_store, publisher):
print("Packaging on TC. Using secret certificate") print("Packaging on TC. Using secret certificate")
pfx = get_taskcluster_secret("windows-codesign-cert/latest")["pfx"] pfx = get_taskcluster_secret("windows-codesign-cert/latest")["pfx"]
open("servo.pfx", "wb").write(base64.b64decode(pfx["base64"])) open("servo.pfx", "wb").write(base64.b64decode(pfx["base64"]))
run_powershell_cmd('Import-PfxCertificate -FilePath .\servo.pfx -CertStoreLocation Cert:\CurrentUser\My') run_powershell_cmd('Import-PfxCertificate -FilePath .\\servo.pfx -CertStoreLocation Cert:\\CurrentUser\\My')
os.remove("servo.pfx") os.remove("servo.pfx")
# Powershell command that lists all certificates for publisher # Powershell command that lists all certificates for publisher
@ -796,7 +796,7 @@ def setup_uwp_signing(ms_app_store, publisher):
# PowerShell command that creates and install signing certificate for publisher # PowerShell command that creates and install signing certificate for publisher
cmd = '(New-SelfSignedCertificate -Type Custom -Subject ' + publisher + \ cmd = '(New-SelfSignedCertificate -Type Custom -Subject ' + publisher + \
' -FriendlyName "Allizom Signing Certificate (temporary)"' + \ ' -FriendlyName "Allizom Signing Certificate (temporary)"' + \
' -KeyUsage DigitalSignature -CertStoreLocation "Cert:\CurrentUser\My"' + \ ' -KeyUsage DigitalSignature -CertStoreLocation "Cert:\\CurrentUser\\My"' + \
' -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")).Thumbprint' ' -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")).Thumbprint'
thumbprint = run_powershell_cmd(cmd) thumbprint = run_powershell_cmd(cmd)
elif len(certs) > 1: elif len(certs) > 1:

View file

@ -161,8 +161,8 @@ class PostBuildCommands(CommandBase):
command = rustCommand command = rustCommand
# Prepend the debugger args. # Prepend the debugger args.
args = ([command] + self.debuggerInfo.args + args = ([command] + self.debuggerInfo.args
args + params) + args + params)
else: else:
args = args + params args = args + params
@ -208,8 +208,8 @@ class PostBuildCommands(CommandBase):
env = self.build_env() env = self.build_env()
env["RUST_BACKTRACE"] = "1" env["RUST_BACKTRACE"] = "1"
servo_cmd = [bin or self.get_nightly_binary_path(nightly) or servo_cmd = [bin or self.get_nightly_binary_path(nightly)
self.get_binary_path(release, dev)] + params or self.get_binary_path(release, dev)] + params
rr_cmd = ['rr', '--fatal-errors', 'record'] rr_cmd = ['rr', '--fatal-errors', 'record']
try: try:
check_call(rr_cmd + servo_cmd) check_call(rr_cmd + servo_cmd)

View file

@ -117,8 +117,8 @@ class MachCommands(CommandBase):
help="Optionally select test based on " help="Optionally select test based on "
"test file directory") "test file directory")
@CommandArgument('--render-mode', '-rm', default=DEFAULT_RENDER_MODE, @CommandArgument('--render-mode', '-rm', default=DEFAULT_RENDER_MODE,
help="The render mode to be used on all tests. " + help="The render mode to be used on all tests. "
HELP_RENDER_MODE) + HELP_RENDER_MODE)
@CommandArgument('--release', default=False, action="store_true", @CommandArgument('--release', default=False, action="store_true",
help="Run with a release build of servo") help="Run with a release build of servo")
@CommandArgument('--tidy-all', default=False, action="store_true", @CommandArgument('--tidy-all', default=False, action="store_true",

View file

@ -33,10 +33,11 @@ wpt = os.path.join(topdir, "tests", "wpt")
def wpt_path(*args): def wpt_path(*args):
return os.path.join(wpt, *args) return os.path.join(wpt, *args)
CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml") CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml")
WPT_MANIFEST_PATH = wpt_path("include.ini") WPT_MANIFEST_PATH = wpt_path("include.ini")
# regex source https://stackoverflow.com/questions/6883049/ # regex source https://stackoverflow.com/questions/6883049/
URL_REGEX = re.compile(b'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+') URL_REGEX = re.compile(br'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+')
# Import wptmanifest only when we do have wpt in tree, i.e. we're not # Import wptmanifest only when we do have wpt in tree, i.e. we're not
# inside a Firefox checkout. # inside a Firefox checkout.
@ -105,8 +106,8 @@ WEBIDL_STANDARDS = [
b"//github.com/immersive-web/webxr-hands-input/", b"//github.com/immersive-web/webxr-hands-input/",
b"//gpuweb.github.io", b"//gpuweb.github.io",
# Not a URL # Not a URL
b"// This interface is entirely internal to Servo, and should not be" + b"// This interface is entirely internal to Servo, and should not be"
b" accessible to\n// web pages." + b" accessible to\n// web pages."
] ]
@ -228,14 +229,14 @@ def check_license(file_name, lines):
max_blank_lines = 2 if lines[0].startswith(b"#!") else 1 max_blank_lines = 2 if lines[0].startswith(b"#!") else 1
license_block = [] license_block = []
for l in lines: for line in lines:
l = l.rstrip(b'\n') line = line.rstrip(b'\n')
if not l.strip(): if not line.strip():
blank_lines += 1 blank_lines += 1
if blank_lines >= max_blank_lines: if blank_lines >= max_blank_lines:
break break
continue continue
line = uncomment(l) line = uncomment(line)
if line is not None: if line is not None:
license_block.append(line) license_block.append(line)
@ -250,7 +251,7 @@ def check_modeline(file_name, lines):
for idx, line in enumerate(lines[:5]): for idx, line in enumerate(lines[:5]):
if re.search(b'^.*[ \t](vi:|vim:|ex:)[ \t]', line): if re.search(b'^.*[ \t](vi:|vim:|ex:)[ \t]', line):
yield (idx + 1, "vi modeline present") yield (idx + 1, "vi modeline present")
elif re.search(b'-\*-.*-\*-', line, re.IGNORECASE): elif re.search(br'-\*-.*-\*-', line, re.IGNORECASE):
yield (idx + 1, "emacs file variables present") yield (idx + 1, "emacs file variables present")
@ -271,10 +272,10 @@ def contains_url(line):
def is_unsplittable(file_name, line): def is_unsplittable(file_name, line):
return ( return (
contains_url(line) or contains_url(line)
file_name.endswith(".rs") and or file_name.endswith(".rs")
line.startswith(b"use ") and and line.startswith(b"use ")
b"{" not in line and b"{" not in line
) )
@ -327,6 +328,7 @@ def check_flake8(file_name, contents):
ignore = { ignore = {
"W291", # trailing whitespace; the standard tidy process will enforce no trailing whitespace "W291", # trailing whitespace; the standard tidy process will enforce no trailing whitespace
"W503", # linebreak before binary operator; replaced by W504 - linebreak after binary operator
"E501", # 80 character line length; the standard tidy process will enforce line length "E501", # 80 character line length; the standard tidy process will enforce line length
} }
@ -478,7 +480,7 @@ def check_shell(file_name, lines):
if " [ " in stripped or stripped.startswith("[ "): if " [ " in stripped or stripped.startswith("[ "):
yield (idx + 1, "script should use `[[` instead of `[` for conditional testing") yield (idx + 1, "script should use `[[` instead of `[` for conditional testing")
for dollar in re.finditer('\$', stripped): for dollar in re.finditer(r'\$', stripped):
next_idx = dollar.end() next_idx = dollar.end()
if next_idx < len(stripped): if next_idx < len(stripped):
next_char = stripped[next_idx] next_char = stripped[next_idx]
@ -598,14 +600,15 @@ def check_rust(file_name, lines):
multi_line_string = True multi_line_string = True
# get rid of comments # get rid of comments
line = re.sub('//.*?$|/\*.*?$|^\*.*?$', '//', line) line = re.sub(r'//.*?$|/\*.*?$|^\*.*?$', '//', line)
# get rid of attributes that do not contain = # get rid of attributes that do not contain =
line = re.sub('^#[A-Za-z0-9\(\)\[\]_]*?$', '#[]', line) line = re.sub(r'^#[A-Za-z0-9\(\)\[\]_]*?$', '#[]', line)
# flag this line if it matches one of the following regular expressions # flag this line if it matches one of the following regular expressions
# tuple format: (pattern, format_message, filter_function(match, line)) # tuple format: (pattern, format_message, filter_function(match, line))
no_filter = lambda match, line: True def no_filter(match, line):
return True
regex_rules = [ regex_rules = [
# There should not be any extra pointer dereferencing # There should not be any extra pointer dereferencing
(r": &Vec<", "use &[T] instead of &Vec<T>", no_filter), (r": &Vec<", "use &[T] instead of &Vec<T>", no_filter),
@ -849,16 +852,16 @@ def check_spec(file_name, lines):
if SPEC_BASE_PATH not in file_name: if SPEC_BASE_PATH not in file_name:
return return
file_name = os.path.relpath(os.path.splitext(file_name)[0], SPEC_BASE_PATH) file_name = os.path.relpath(os.path.splitext(file_name)[0], SPEC_BASE_PATH)
patt = re.compile("^\s*\/\/.+") patt = re.compile(r"^\s*\/\/.+")
# Pattern representing a line with a macro # Pattern representing a line with a macro
macro_patt = re.compile("^\s*\S+!(.*)$") macro_patt = re.compile(r"^\s*\S+!(.*)$")
# Pattern representing a line with comment containing a spec link # Pattern representing a line with comment containing a spec link
link_patt = re.compile("^\s*///? (<https://.+>|https://.+)$") link_patt = re.compile(r"^\s*///? (<https://.+>|https://.+)$")
# Pattern representing a line with comment or attribute # Pattern representing a line with comment or attribute
comment_patt = re.compile("^\s*(///?.+|#\[.+\])$") comment_patt = re.compile(r"^\s*(///?.+|#\[.+\])$")
brace_count = 0 brace_count = 0
in_impl = False in_impl = False
@ -924,7 +927,7 @@ def check_config_file(config_file, print_text=True, no_wpt=False):
continue continue
# Check for invalid tables # Check for invalid tables
if re.match("\[(.*?)\]", line.strip()): if re.match(r"\[(.*?)\]", line.strip()):
table_name = re.findall(r"\[(.*?)\]", line)[0].strip() table_name = re.findall(r"\[(.*?)\]", line)[0].strip()
if table_name not in ("configs", "blocked-packages", "ignore", "check_ext"): if table_name not in ("configs", "blocked-packages", "ignore", "check_ext"):
yield config_file, idx + 1, "invalid config table [%s]" % table_name yield config_file, idx + 1, "invalid config table [%s]" % table_name
@ -954,10 +957,10 @@ def check_config_file(config_file, print_text=True, no_wpt=False):
key = line.split("=")[0].strip() key = line.split("=")[0].strip()
# Check for invalid keys inside [configs] and [ignore] table # Check for invalid keys inside [configs] and [ignore] table
if (current_table == "configs" and key not in config or if (current_table == "configs" and key not in config
current_table == "ignore" and key not in config["ignore"] or or current_table == "ignore" and key not in config["ignore"]
# Any key outside of tables # Any key outside of tables
current_table == ""): or current_table == ""):
yield config_file, idx + 1, "invalid config key '%s'" % key yield config_file, idx + 1, "invalid config key '%s'" % key
# Parse config file # Parse config file

View file

@ -14,7 +14,7 @@ from setuptools import setup, find_packages
VERSION = '0.3.0' VERSION = '0.3.0'
install_requires = [ install_requires = [
"flake8==2.4.1", "flake8==3.8.3",
"toml==0.9.2", "toml==0.9.2",
"colorama==0.3.7", "colorama==0.3.7",
"voluptuous==0.11.5", "voluptuous==0.11.5",
@ -26,13 +26,13 @@ here = os.path.dirname(os.path.abspath(__file__))
try: try:
with open(os.path.join(here, 'README.rst')) as doc: with open(os.path.join(here, 'README.rst')) as doc:
readme = doc.read() readme = doc.read()
except: except Exception:
readme = '' readme = ''
try: try:
with open(os.path.join(here, 'HISTORY.rst')) as doc: with open(os.path.join(here, 'HISTORY.rst')) as doc:
history = doc.read() history = doc.read()
except: except Exception:
history = '' history = ''
long_description = readme + '\n\n' + history long_description = readme + '\n\n' + history

View file

@ -65,15 +65,15 @@ if __name__ == '__main__':
while not server.got_post: while not server.got_post:
server.handle_request() server.handle_request()
data = json.loads(server.post_data[0]) data = json.loads(server.post_data[0])
n = 0 number = 0
l = 0 length = 0
for test in data: for test in data:
n = max(n, len(data[test])) number = max(number, len(data[test]))
l = max(l, len(test)) length = max(length, len(test))
print("\n Test{0} | Time".format(" " * (l - len("Test")))) print("\n Test{0} | Time".format(" " * (length - len("Test"))))
print("-{0}-|-{1}-".format("-" * l, "-" * n)) print("-{0}-|-{1}-".format("-" * length, "-" * number))
for test in data: for test in data:
print(" {0}{1} | {2}".format(test, " " * (l - len(test)), data[test])) print(" {0}{1} | {2}".format(test, " " * (length - len(test)), data[test]))
proc.kill() proc.kill()
else: else:
print_usage() print_usage()

View file

@ -183,7 +183,7 @@ def run_http_server():
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
self.end_headers() self.end_headers()
return f return f
except: except IOError:
f.close() f.close()
raise raise
@ -195,6 +195,7 @@ def run_http_server():
sys.stdout.flush() sys.stdout.flush()
server.handle_request() server.handle_request()
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 4: if len(sys.argv) == 4:
cmd = sys.argv[1] cmd = sys.argv[1]

View file

@ -134,10 +134,10 @@ def PowerParser(OutputDir, LayoutThreads):
TotalPower = PowerGen / float(ExperimentNum - 1) TotalPower = PowerGen / float(ExperimentNum - 1)
TotalTime = TimeGen / float(ExperimentNum - 1) TotalTime = TimeGen / float(ExperimentNum - 1)
ResultFile.write(str(layoutT) + " , " + str(TotalPower) + " , " + ResultFile.write(str(layoutT) + " , " + str(TotalPower) + " , "
str(MaxPower) + " , " + str(MinPower) + " , " + + str(MaxPower) + " , " + str(MinPower) + " , "
str(TotalTime) + " , " + str(MaxTime) + " , " + + str(TotalTime) + " , " + str(MaxTime) + " , "
str(MinTime) + "\n") + str(MinTime) + "\n")
ResultFile.close() ResultFile.close()
Opener = ResultFile = open(ResultTable, "r") Opener = ResultFile = open(ResultTable, "r")
for line in Opener: for line in Opener:
@ -180,5 +180,6 @@ def main():
PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer) PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer)
PowerParser(OutputDir, LayoutThreads) PowerParser(OutputDir, LayoutThreads)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -75,8 +75,8 @@ class ServoFormatter(base.BaseFormatter):
def text_to_erase_display(self): def text_to_erase_display(self):
if not self.interactive or not self.current_display: if not self.interactive or not self.current_display:
return "" return ""
return ((self.move_up + self.clear_eol) * return ((self.move_up + self.clear_eol)
self.current_display.count('\n')) * self.current_display.count('\n'))
def generate_output(self, text=None, new_display=None, unexpected_in_test=None): def generate_output(self, text=None, new_display=None, unexpected_in_test=None):
if not self.interactive: if not self.interactive:

View file

@ -19,6 +19,7 @@ def wpt_path(*args):
def servo_path(*args): def servo_path(*args):
return os.path.join(servo_root, *args) return os.path.join(servo_root, *args)
paths = {"include_manifest": wpt_path("include.ini"), paths = {"include_manifest": wpt_path("include.ini"),
"config": wpt_path("config.ini"), "config": wpt_path("config.ini"),
"ca-cert-path": wpt_path("web-platform-tests/tools/certs/cacert.pem"), "ca-cert-path": wpt_path("web-platform-tests/tools/certs/cacert.pem"),
@ -26,8 +27,8 @@ paths = {"include_manifest": wpt_path("include.ini"),
"host-cert-path": wpt_path("web-platform-tests/tools/certs/web-platform.test.pem")} "host-cert-path": wpt_path("web-platform-tests/tools/certs/web-platform.test.pem")}
# Imports # Imports
sys.path.append(wpt_path("web-platform-tests", "tools")) sys.path.append(wpt_path("web-platform-tests", "tools"))
import localpaths # noqa: flake8 import localpaths # noqa: F401,E402
from wptrunner import wptrunner, wptcommandline from wptrunner import wptrunner, wptcommandline # noqa: E402
def run_tests(**kwargs): def run_tests(**kwargs):
@ -106,5 +107,6 @@ def main():
kwargs = vars(parser.parse_args()) kwargs = vars(parser.parse_args())
return run_tests(**kwargs) return run_tests(**kwargs)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(0 if main() else 1) sys.exit(0 if main() else 1)

View file

@ -5,6 +5,7 @@
import os import os
import sys import sys
from wptrunner import wptcommandline from wptrunner import wptcommandline
from update import updatecommandline
here = os.path.split(__file__)[0] here = os.path.split(__file__)[0]
@ -12,9 +13,6 @@ here = os.path.split(__file__)[0]
def wpt_path(*args): def wpt_path(*args):
return os.path.join(here, *args) return os.path.join(here, *args)
# Imports
from update import updatecommandline
def update_tests(**kwargs): def update_tests(**kwargs):
import update import update
@ -45,5 +43,6 @@ def main():
kwargs = vars(parser.parse_args()) kwargs = vars(parser.parse_args())
return update_tests(**kwargs) return update_tests(**kwargs)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(0 if main() else 1) sys.exit(0 if main() else 1)