diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2014-07-11 12:57:48 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2014-07-11 12:57:48 +0100 |
commit | 8cf004e28ad81fac242a43ec6e9cd5c00d61c7ee (patch) | |
tree | 3c54e89fe222748eccbe68d08292f073ceeb4448 | |
parent | 11d9ae61033c7f8895b820879d8670599f64e528 (diff) | |
parent | 44a76e542fc7c07dfb874b3f9e6d1fdbb1609665 (diff) | |
download | servo-8cf004e28ad81fac242a43ec6e9cd5c00d61c7ee.tar.gz servo-8cf004e28ad81fac242a43ec6e9cd5c00d61c7ee.zip |
Merge pull request #2806 from Ms2ger/tidy
Improve and extend tidy.py, and run it on Travis.
-rw-r--r-- | src/components/compositing/compositor_task.rs | 2 | ||||
-rw-r--r-- | src/components/gfx/font_template.rs | 4 | ||||
-rw-r--r-- | src/components/net/resource_task.rs | 4 | ||||
-rw-r--r-- | src/components/script/dom/bindings/str.rs | 2 | ||||
-rw-r--r-- | src/components/script/dom/file.rs | 2 | ||||
-rw-r--r-- | src/components/script/dom/htmlpreelement.rs | 2 | ||||
-rw-r--r-- | src/components/script/dom/urlsearchparams.rs | 2 | ||||
-rw-r--r-- | src/components/util/opts.rs | 2 | ||||
-rw-r--r-- | src/etc/licenseck.py | 18 | ||||
-rw-r--r-- | src/etc/servo_gdb.py | 158 | ||||
-rw-r--r-- | src/etc/tidy.py | 70 | ||||
-rw-r--r-- | src/test/wpt/run.py | 4 | ||||
-rwxr-xr-x | travis.linux.script.sh | 2 | ||||
-rwxr-xr-x | travis.osx.script.sh | 2 |
14 files changed, 138 insertions, 136 deletions
diff --git a/src/components/compositing/compositor_task.rs b/src/components/compositing/compositor_task.rs index b4ffaa6ba81..4f803413e7c 100644 --- a/src/components/compositing/compositor_task.rs +++ b/src/components/compositing/compositor_task.rs @@ -47,7 +47,7 @@ impl ScriptListener for CompositorChan { pipeline_id: PipelineId, layer_id: LayerId, point: Point2D<f32>) { - self.chan.send(ScrollFragmentPoint(pipeline_id, layer_id, point)); + self.chan.send(ScrollFragmentPoint(pipeline_id, layer_id, point)); } fn close(&self) { diff --git a/src/components/gfx/font_template.rs b/src/components/gfx/font_template.rs index 2bd6a1270d2..12753da68a1 100644 --- a/src/components/gfx/font_template.rs +++ b/src/components/gfx/font_template.rs @@ -37,7 +37,7 @@ impl PartialEq for FontTemplateDescriptor { } /// This describes all the information needed to create -/// font instance handles. It contains a unique +/// font instance handles. It contains a unique /// FontTemplateData structure that is platform specific. pub struct FontTemplate { identifier: String, @@ -112,4 +112,4 @@ impl FontTemplate { } } } -}
\ No newline at end of file +} diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index 2316c099151..6489ff65128 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -234,10 +234,10 @@ impl ResourceManager { for scheme_loader in self.loaders.iter() { match *scheme_loader { (ref scheme, ref loader_factory) => { - if (*scheme) == load_data.url.scheme { + if (*scheme) == load_data.url.scheme { return Some((*loader_factory)()); } - } + } } } return None; diff --git a/src/components/script/dom/bindings/str.rs b/src/components/script/dom/bindings/str.rs index 09b327dafa1..b42845b6e77 100644 --- a/src/components/script/dom/bindings/str.rs +++ b/src/components/script/dom/bindings/str.rs @@ -139,4 +139,4 @@ impl FromStr for ByteString { fn from_str(s: &str) -> Option<ByteString> { Some(ByteString::new(s.container_into_owned_bytes())) } -}
\ No newline at end of file +} diff --git a/src/components/script/dom/file.rs b/src/components/script/dom/file.rs index ecaee0976f9..731f76770be 100644 --- a/src/components/script/dom/file.rs +++ b/src/components/script/dom/file.rs @@ -50,4 +50,4 @@ impl Reflectable for File { fn reflector<'a>(&'a self) -> &'a Reflector { self.blob.reflector() } -}
\ No newline at end of file +} diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index fa0e0a612b0..41b518271b5 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -20,7 +20,7 @@ pub struct HTMLPreElement { impl HTMLPreElementDerived for EventTarget { fn is_htmlpreelement(&self) -> bool { - self.type_id == NodeTargetTypeId(ElementNodeTypeId(HTMLPreElementTypeId)) + self.type_id == NodeTargetTypeId(ElementNodeTypeId(HTMLPreElementTypeId)) } } diff --git a/src/components/script/dom/urlsearchparams.rs b/src/components/script/dom/urlsearchparams.rs index 0455cc673a7..862945c1e03 100644 --- a/src/components/script/dom/urlsearchparams.rs +++ b/src/components/script/dom/urlsearchparams.rs @@ -151,4 +151,4 @@ impl URLSearchParamsHelpers for URLSearchParams { // XXXManishearth Implement this when the URL interface is implemented // http://url.spec.whatwg.org/#concept-uq-update } -}
\ No newline at end of file +} diff --git a/src/components/util/opts.rs b/src/components/util/opts.rs index 0fa3a79ed7c..bdd1d2d4347 100644 --- a/src/components/util/opts.rs +++ b/src/components/util/opts.rs @@ -45,7 +45,7 @@ pub struct Opts { /// cause it to produce output on that interval (`-p`). pub time_profiler_period: Option<f64>, - /// `None` to disable the memory profiler or `Some` with an interval in seconds to enable it + /// `None` to disable the memory profiler or `Some` with an interval in seconds to enable it /// and cause it to produce output on that interval (`-m`). pub memory_profiler_period: Option<f64>, diff --git a/src/etc/licenseck.py b/src/etc/licenseck.py index 017fb3f24bd..af7ecae9dc7 100644 --- a/src/etc/licenseck.py +++ b/src/etc/licenseck.py @@ -14,24 +14,18 @@ license0="""\ """ license1="""\ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ -""" - -license2="""\ # This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. """ -license3="""\ +license2="""\ // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. """ -license4 = """\ +license3 = """\ // Copyright 2013 The Servo Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution. // @@ -42,7 +36,7 @@ license4 = """\ // except according to those terms. """ -license5 = """\ +license4 = """\ # Copyright 2013 The Servo Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution. # @@ -53,7 +47,7 @@ license5 = """\ # except according to those terms. """ -licenses = [license0, license1, license2, license3, license4, license5] +licenses = [license0, license1, license2, license3, license4] exceptions = [ "rust-http-client/http_parser.c", # BSD, Joyent diff --git a/src/etc/servo_gdb.py b/src/etc/servo_gdb.py index 188f317fb70..98d9639e7f3 100644 --- a/src/etc/servo_gdb.py +++ b/src/etc/servo_gdb.py @@ -12,7 +12,7 @@ # To load these, you need to add something like the following # to your .gdbinit file. #python -#import sys +#import sys #sys.path.insert(0, '/home/<path to git checkout>/servo/src/etc') #import servo_gdb #servo_gdb.register_printers(None) @@ -22,120 +22,120 @@ import gdb # Print Au in both raw value and CSS pixels class AuPrinter: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def to_string(self): - i32_type = gdb.lookup_type("i32") - au = self.val.cast(i32_type); - return "{0}px ({1} au)".format(au / 60.0, au) + def to_string(self): + i32_type = gdb.lookup_type("i32") + au = self.val.cast(i32_type); + return "{0}px ({1} au)".format(au / 60.0, au) # Print a U8 bitfield as binary class BitFieldU8Printer: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def to_string(self): - u8_type = gdb.lookup_type("u8") - value = self.val.cast(u8_type); - return "[{0:#010b}]".format(int(value)) + def to_string(self): + u8_type = gdb.lookup_type("u8") + value = self.val.cast(u8_type); + return "[{0:#010b}]".format(int(value)) # Print a struct with fields as children class ChildPrinter: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def children(self): - children = [] - for f in self.val.type.fields(): - children.append( (f.name, self.val[f.name]) ) - return children + def children(self): + children = [] + for f in self.val.type.fields(): + children.append( (f.name, self.val[f.name]) ) + return children - def to_string(self): - return None + def to_string(self): + return None # Allow a trusted node to be dereferenced in the debugger class TrustedNodeAddressPrinter: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def children(self): - node_type = gdb.lookup_type("struct script::dom::node::Node").pointer() - value = self.val.cast(node_type) - return [('Node', value)] + def children(self): + node_type = gdb.lookup_type("struct script::dom::node::Node").pointer() + value = self.val.cast(node_type) + return [('Node', value)] - def to_string(self): - return self.val.address + def to_string(self): + return self.val.address # Extract a node type ID from enum class NodeTypeIdPrinter: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def to_string(self): - u8_ptr_type = gdb.lookup_type("u8").pointer() - enum_0 = self.val.address.cast(u8_ptr_type).dereference() - enum_type = self.val.type.fields()[int(enum_0)].type; - return str(enum_type).lstrip('struct ') + def to_string(self): + u8_ptr_type = gdb.lookup_type("u8").pointer() + enum_0 = self.val.address.cast(u8_ptr_type).dereference() + enum_type = self.val.type.fields()[int(enum_0)].type; + return str(enum_type).lstrip('struct ') # Printer for std::Option<> class OptionPrinter: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def is_some(self): - # Get size of discriminator - d_size = self.val.type.fields()[0].type.sizeof + def is_some(self): + # Get size of discriminator + d_size = self.val.type.fields()[0].type.sizeof - if d_size > 0 and d_size <= 8: - # Read first byte to check if None or Some - ptr = self.val.address.cast(gdb.lookup_type("unsigned char").pointer()) - discriminator = int(ptr.dereference()) - return discriminator != 0 + if d_size > 0 and d_size <= 8: + # Read first byte to check if None or Some + ptr = self.val.address.cast(gdb.lookup_type("unsigned char").pointer()) + discriminator = int(ptr.dereference()) + return discriminator != 0 - raise "unhandled discriminator size" + raise "unhandled discriminator size" - def children(self): - if self.is_some(): - option_type = self.val.type + def children(self): + if self.is_some(): + option_type = self.val.type - # Get total size and size of value - ptr = self.val.address.cast(gdb.lookup_type("unsigned char").pointer()) - t_size = option_type.sizeof - value_type = option_type.fields()[1].type.fields()[1].type - v_size = value_type.sizeof - data_ptr = (ptr + t_size - v_size).cast(value_type.pointer()).dereference() - return [('Some', data_ptr)] - return [('None', None)] + # Get total size and size of value + ptr = self.val.address.cast(gdb.lookup_type("unsigned char").pointer()) + t_size = option_type.sizeof + value_type = option_type.fields()[1].type.fields()[1].type + v_size = value_type.sizeof + data_ptr = (ptr + t_size - v_size).cast(value_type.pointer()).dereference() + return [('Some', data_ptr)] + return [('None', None)] - def to_string(self): - return None + def to_string(self): + return None # Useful for debugging when type is unknown class TestPrinter: - def __init__(self, val): - self.val = val + def __init__(self, val): + self.val = val - def to_string(self): - return "[UNKNOWN - type = {0}]".format(str(self.val.type)) + def to_string(self): + return "[UNKNOWN - type = {0}]".format(str(self.val.type)) type_map = [ - ('Au', AuPrinter), - ('FlowFlags', BitFieldU8Printer), - ('IntrinsicWidths', ChildPrinter), - ('PlacementInfo', ChildPrinter), - ('TrustedNodeAddress', TrustedNodeAddressPrinter), - ('NodeTypeId', NodeTypeIdPrinter), - ('Option', OptionPrinter), + ('Au', AuPrinter), + ('FlowFlags', BitFieldU8Printer), + ('IntrinsicWidths', ChildPrinter), + ('PlacementInfo', ChildPrinter), + ('TrustedNodeAddress', TrustedNodeAddressPrinter), + ('NodeTypeId', NodeTypeIdPrinter), + ('Option', OptionPrinter), ] def lookup_servo_type (val): - val_type = str(val.type) - for (type_name, printer) in type_map: - if val_type == type_name or val_type.endswith("::"+type_name): - return printer(val) - return None - #return TestPrinter(val) + val_type = str(val.type) + for (type_name, printer) in type_map: + if val_type == type_name or val_type.endswith("::"+type_name): + return printer(val) + return None + #return TestPrinter(val) def register_printers(obj): - gdb.pretty_printers.append(lookup_servo_type) + gdb.pretty_printers.append(lookup_servo_type) diff --git a/src/etc/tidy.py b/src/etc/tidy.py index 9e9c25b25de..d529bfd5f8b 100644 --- a/src/etc/tidy.py +++ b/src/etc/tidy.py @@ -9,37 +9,54 @@ #!/usr/bin/env python -import fileinput, sys, os -from licenseck import * +import os +import sys +from licenseck import check_license err = 0 + def report_error_name_no(name, no, s): global err print("%s:%d: %s" % (name, no, s)) - err=1 - -def report_err(s): - report_error_name_no(fileinput.filename(), fileinput.filelineno(), s) + err = 1 -def report_warn(s): - print("%s:%d: %s" % (fileinput.filename(), - fileinput.filelineno(), - s)) def do_license_check(name, contents): if not check_license(name, contents): report_error_name_no(name, 1, "incorrect license") + +def do_whitespace_check(name, contents): + for idx, line in enumerate(contents): + if line[-1] == "\n": + line = line[:-1] + else: + report_error_name_no(name, idx + 1, "No newline at EOF") + + if line.endswith(' '): + report_error_name_no(name, idx + 1, "trailing whitespace") + + if '\t' in line: + report_error_name_no(name, idx + 1, "tab on line") + + if '\r' in line: + report_error_name_no(name, idx + 1, "CR on line") + + exceptions = [ - "src/support", # Upstream - "src/platform", # Upstream - "src/compiler", # Upstream - "src/components/main/dom/bindings/codegen", # Generated and upstream code combined with our own. Could use cleanup - "src/components/script/dom/bindings/codegen", # Generated and upstream code combined with our own. Could use cleanup - "src/test/wpt/web-platform-tests", # Upstream + # Upstream + "src/support", + "src/platform", + "src/compiler", + "src/test/wpt/web-platform-tests", + + # Generated and upstream code combined with our own. Could use cleanup + "src/components/script/dom/bindings/codegen", + "src/components/style/properties/mod.rs", ] + def should_check(name): if ".#" in name: return False @@ -55,6 +72,7 @@ def should_check(name): return False return True + file_names = [] for root, dirs, files in os.walk(sys.argv[1]): for myfile in files: @@ -62,20 +80,10 @@ for root, dirs, files in os.walk(sys.argv[1]): if should_check(file_name): file_names.append(file_name) -current_name = "" -current_contents = "" - -for line in fileinput.input(file_names): - if fileinput.isfirstline() and current_name != "": - do_license_check(current_name, current_contents) - - if fileinput.isfirstline(): - current_name = fileinput.filename() - current_contents = "" - - current_contents += line - -if current_name != "": - do_license_check(current_name, current_contents) +for path in file_names: + with open(path, "r") as fp: + lines = fp.readlines() + do_license_check(path, "".join(lines)) + do_whitespace_check(path, lines) sys.exit(err) diff --git a/src/test/wpt/run.py b/src/test/wpt/run.py index 8b7ff7d7104..661fc9dd32c 100644 --- a/src/test/wpt/run.py +++ b/src/test/wpt/run.py @@ -1,6 +1,6 @@ # This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. import sys, os, argparse diff --git a/travis.linux.script.sh b/travis.linux.script.sh index e8e8205a4bd..c8c5b2fd089 100755 --- a/travis.linux.script.sh +++ b/travis.linux.script.sh @@ -1,3 +1,3 @@ cd build ../configure -make -j2 && make check-servo +make tidy && make -j2 && make check-servo diff --git a/travis.osx.script.sh b/travis.osx.script.sh index 6eaa0885116..5058acb8d20 100755 --- a/travis.osx.script.sh +++ b/travis.osx.script.sh @@ -1,3 +1,3 @@ cd build ../configure -make -j2 && make check-servo && make check-content && make check-ref-cpu +make tidy && make -j2 && make check-servo && make check-content && make check-ref-cpu |