Bug 1064316 - Rewrite check_spidermonkey_style.py to use os.walk instead of looking at the repo data. r=njn
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 18 Apr 2018 09:42:24 +0200
changeset 467759 4a4a8ad2c4af575a73b140fc566304419a54ba35
parent 467758 61b3c0c87bb5ce6601616450146aff14642f5826
child 467760 f5f4089f457e85f1f485bd0411bd4cf1d30d487e
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1064316
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1064316 - Rewrite check_spidermonkey_style.py to use os.walk instead of looking at the repo data. r=njn
config/check_spidermonkey_style.py
js/src/Makefile.in
--- a/config/check_spidermonkey_style.py
+++ b/config/check_spidermonkey_style.py
@@ -37,19 +37,16 @@
 
 from __future__ import print_function
 
 import difflib
 import os
 import re
 import sys
 
-from mozversioncontrol import get_repository_from_env
-
-
 # We don't bother checking files in these directories, because they're (a) auxiliary or (b)
 # imported code that doesn't follow our coding style.
 ignored_js_src_dirs = [
    'js/src/config/',            # auxiliary stuff
    'js/src/ctypes/libffi/',     # imported code
    'js/src/devtools/',          # auxiliary stuff
    'js/src/editline/',          # imported code
    'js/src/gdb/',               # auxiliary stuff
@@ -253,33 +250,52 @@ def check_style(enable_fixup):
     # - "js/src/vm/String.h"        -> "vm/String.h"
 
     non_js_dirnames = ('mfbt/',
                        'memory/mozalloc/',
                        'mozglue/')  # type: tuple(str)
     non_js_inclnames = set()        # type: set(inclname)
     js_names = dict()               # type: dict(filename, inclname)
 
-    with get_repository_from_env() as repo:
-        # Select the appropriate files.
-        for filename in repo.get_files_in_working_directory():
-            for non_js_dir in non_js_dirnames:
-                if filename.startswith(non_js_dir) and filename.endswith('.h'):
-                    inclname = 'mozilla/' + filename.split('/')[-1]
+    # Process files in js/src.
+    js_src_root = os.path.join('js', 'src')
+    for dirpath, dirnames, filenames in os.walk(js_src_root):
+        if dirpath == js_src_root:
+            # Skip any subdirectories that contain a config.status file
+            # (likely objdirs).
+            builddirs = []
+            for dirname in dirnames:
+                path = os.path.join(dirpath, dirname, 'config.status')
+                if os.path.isfile(path):
+                    builddirs.append(dirname)
+            for dirname in builddirs:
+                dirnames.remove(dirname)
+        for filename in filenames:
+            filepath = os.path.join(dirpath, filename).replace('\\', '/')
+            if not filepath.startswith(tuple(ignored_js_src_dirs)) and \
+               filepath.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')):
+                inclname = filepath[len('js/src/'):]
+                js_names[filepath] = inclname
+
+    # Look for header files in directories in non_js_dirnames.
+    for non_js_dir in non_js_dirnames:
+        for dirpath, dirnames, filenames in os.walk(non_js_dir):
+            for filename in filenames:
+                if filename.endswith('.h'):
+                    inclname = 'mozilla/' + filename
                     non_js_inclnames.add(inclname)
 
-            if filename.startswith('js/public/') and filename.endswith('.h'):
-                inclname = 'js/' + filename[len('js/public/'):]
-                js_names[filename] = inclname
-
-            if filename.startswith('js/src/') and \
-               not filename.startswith(tuple(ignored_js_src_dirs)) and \
-               filename.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')):
-                inclname = filename[len('js/src/'):]
-                js_names[filename] = inclname
+    # Look for header files in js/public.
+    js_public_root = os.path.join('js', 'public')
+    for dirpath, dirnames, filenames in os.walk(js_public_root):
+        for filename in filenames:
+            if filename.endswith('.h'):
+                filepath = os.path.join(dirpath, filename).replace('\\', '/')
+                inclname = 'js/' + filepath[len('js/public/'):]
+                js_names[filepath] = inclname
 
     all_inclnames = non_js_inclnames | set(js_names.values())
 
     edges = dict()      # type: dict(inclname, set(inclname))
 
     # We don't care what's inside the MFBT and MOZALLOC files, but because they
     # are #included from JS files we have to add them to the inclusion graph.
     for inclname in non_js_inclnames:
@@ -288,25 +304,22 @@ def check_style(enable_fixup):
     # Process all the JS files.
     for filename in js_names.keys():
         inclname = js_names[filename]
         file_kind = FileKind.get(filename)
         if file_kind == FileKind.C or file_kind == FileKind.CPP or \
            file_kind == FileKind.H or file_kind == FileKind.INL_H:
             included_h_inclnames = set()    # type: set(inclname)
 
-            # This script is run in js/src/, so prepend '../../' to get to the root of the Mozilla
-            # source tree.
-            filepath = os.path.join(repo.path, filename)
-            with open(filepath) as f:
+            with open(filename) as f:
                 code = read_file(f)
 
             if enable_fixup:
                 code = code.sorted(inclname)
-                with open(filepath, 'w') as f:
+                with open(filename, 'w') as f:
                     f.write(code.to_source())
 
             check_file(filename, inclname, file_kind, code, all_inclnames, included_h_inclnames)
 
         edges[inclname] = included_h_inclnames
 
     find_cycles(all_inclnames, edges)
 
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -45,17 +45,17 @@ ifdef MOZ_TSAN
 JITTEST_SANITIZER_ENV=TSAN_OPTIONS="external_symbolizer_path=$(LLVM_SYMBOLIZER) $$TSAN_OPTIONS"
 endif
 ifdef MOZ_MSAN
 JITTEST_SANITIZER_ENV=MSAN_SYMBOLIZER_PATH='$(LLVM_SYMBOLIZER)'
 endif
 endif
 
 check-style::
-	(cd $(srcdir) && $(PYTHON) $(topsrcdir)/config/check_spidermonkey_style.py);
+	(cd $(topsrcdir) && $(PYTHON) $(topsrcdir)/config/check_spidermonkey_style.py);
 
 check-masm::
 	(cd $(srcdir) && $(PYTHON) $(topsrcdir)/config/check_macroassembler_style.py);
 
 check-js-msg::
 	(cd $(topsrcdir) && $(PYTHON) $(topsrcdir)/config/check_js_msg_encoding.py);
 
 check-opcode::