]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - tools/patman/checkpatch.py
patman: Allow use outside of u-boot tree
[karo-tx-uboot.git] / tools / patman / checkpatch.py
index a234277177866f58d75df0d0048f691beeba8c00..d3a0477bbf1c905078b486d4242e375d4902c9bf 100644 (file)
@@ -23,13 +23,16 @@ import command
 import gitutil
 import os
 import re
+import sys
 import terminal
 
 def FindCheckPatch():
+    top_level = gitutil.GetTopLevel()
     try_list = [
         os.getcwd(),
         os.path.join(os.getcwd(), '..', '..'),
-        os.path.join(gitutil.GetTopLevel(), 'tools'),
+        os.path.join(top_level, 'tools'),
+        os.path.join(top_level, 'scripts'),
         '%s/bin' % os.getenv('HOME'),
         ]
     # Look in current dir
@@ -45,8 +48,10 @@ def FindCheckPatch():
         if os.path.isfile(fname):
             return fname
         path = os.path.dirname(path)
-    print 'Could not find checkpatch.pl'
-    return None
+
+    print >> sys.stderr, ('Cannot find checkpatch.pl - please put it in your ' +
+                '~/bin directory or use --no-check')
+    sys.exit(1)
 
 def CheckPatch(fname, verbose=False):
     """Run checkpatch.pl on a file.
@@ -65,9 +70,6 @@ def CheckPatch(fname, verbose=False):
     error_count, warning_count, lines = 0, 0, 0
     problems = []
     chk = FindCheckPatch()
-    if not chk:
-        raise OSError, ('Cannot find checkpatch.pl - please put it in your ' +
-                '~/bin directory')
     item = {}
     stdout = command.Output(chk, '--no-tree', fname)
     #pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -145,8 +147,9 @@ def CheckPatches(verbose, args):
             if len(problems) != error_count + warning_count:
                 print "Internal error: some problems lost"
             for item in problems:
-                print GetWarningMsg(col, item['type'], item['file'],
-                        item['line'], item['msg'])
+                print GetWarningMsg(col, item['type'],
+                        item.get('file', '<unknown>'),
+                        item.get('line', 0), item['msg'])
             #print stdout
     if error_count != 0 or warning_count != 0:
         str = 'checkpatch.pl found %d error(s), %d warning(s)' % (