chiark / gitweb /
Integrate scanning into build
authorCiaran Gultnieks <ciaran@ciarang.com>
Thu, 2 Feb 2012 22:13:31 +0000 (22:13 +0000)
committerCiaran Gultnieks <ciaran@ciarang.com>
Thu, 2 Feb 2012 22:13:31 +0000 (22:13 +0000)
build.py
common.py
scanner.py

index 4e07ceb9fa88152bc1783715946d975e5b3aa8c9..ef02ca364452ce84e1dd7971a997d212189edef8 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -127,6 +127,15 @@ for app in apps:
                             javacc_path, not refreshed_source)
                     refreshed_source = True
 
+                    # Scan before building...
+                    buildprobs = common.scan_source(build_dir)
+                    if len(buildprobs) > 0:
+                        print 'Scanner found ' + str(len(buildprobs)) + ' problems:'
+                        for problem in buildprobs:
+                            print '...' + problem
+                        raise BuildException("Can't build due to " +
+                                str(len(buildprobs)) + " scanned problems")
+
                     # Build the source tarball right before we build the release...
                     tarname = app['id'] + '_' + thisbuild['vercode'] + '_src'
                     tarball = tarfile.open(os.path.join(tmp_dir,
index 4477e0bae00d5425daee80fb67d65dad56c44cb1..96086c6af7afb39083a03e9f2d7e16218f2690c2 100644 (file)
--- a/common.py
+++ b/common.py
@@ -890,6 +890,45 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
     return root_dir
 
 
+# Scan the source code in the given directory (and all subdirectories)
+# and return a list of potential problems.
+def scan_source(source_dir):
+
+    problems = []
+
+    # Scan for common known non-free blobs:
+    usual_suspects = ['flurryagent',
+                      'paypal_mpl',
+                      'libgoogleanalytics',
+                      'admob-sdk-android',
+                      'googleadview',
+                      'googleadmobadssdk']
+    for r,d,f in os.walk(build_dir):
+        for curfile in f:
+            for suspect in usual_suspects:
+                if curfile.lower().find(suspect) != -1:
+                    msg = 'Found probable non-free blob ' + os.path.join(r, curfile)
+                    problems.append(msg)
+
+    # Presence of a jni directory without buildjni=yes might
+    # indicate a problem...
+    if (os.path.exists(os.path.join(root_dir, 'jni')) and 
+            thisbuild.get('buildjni', 'no') != 'yes'):
+        msg = 'Found jni directory, but buildjni is not enabled'
+        problems.append(msg)
+
+    # Presence of these is not a problem as such, but they
+    # shouldn't be there and mess up our source tarballs...
+    if os.path.exists(os.path.join(root_dir, 'bin')):
+        msg = "There shouldn't be a bin directory"
+        problems.append(msg)
+    if os.path.exists(os.path.join(root_dir, 'gen')):
+        msg = "There shouldn't be a gen directory"
+        problems.append(msg)
+
+    return problems
+
+
 class KnownApks:
 
     def __init__(self):
index 7c241f481deb643aab294831b8ae8884810bcf52..045d57b4179abb9a2eea90cf558f1fb09a62d5a0 100755 (executable)
@@ -92,39 +92,11 @@ for app in apps:
                             not refreshed_source)
                     refreshed_source = True
 
-                    # Scan for common known non-free blobs:
-                    usual_suspects = ['flurryagent',
-                                      'paypal_mpl',
-                                      'libgoogleanalytics',
-                                      'admob-sdk-android',
-                                      'googleadview',
-                                      'googleadmobadssdk']
-                    for r,d,f in os.walk(build_dir):
-                        for curfile in f:
-                            for suspect in usual_suspects:
-                                if curfile.lower().find(suspect) != -1:
-                                    msg = 'Found probable non-free blob ' + os.path.join(r, curfile)
-                                    msg += ' in ' + app['id'] + ' ' + thisbuild['version']
-                                    problems.append(msg)
-
-                    # Presence of a jni directory without buildjni=yes might
-                    # indicate a problem...
-                    if (os.path.exists(os.path.join(root_dir, 'jni')) and 
-                            thisbuild.get('buildjni', 'no') != 'yes'):
-                        msg = 'Found jni directory, but buildjni is not enabled'
-                        msg += ' in ' + app['id'] + ' ' + thisbuild['version']
-                        problems.append(msg)
-
-                    # Presence of these is not a problem as such, but they
-                    # shouldn't be there and mess up our source tarballs...
-                    if os.path.exists(os.path.join(root_dir, 'bin')):
-                        msg = "There shouldn't be a bin directory"
-                        msg += ' in ' + app['id'] + ' ' + thisbuild['version']
-                        problems.append(msg)
-                    if os.path.exists(os.path.join(root_dir, 'gen')):
-                        msg = "There shouldn't be a gen directory"
-                        msg += ' in ' + app['id'] + ' ' + thisbuild['version']
-                        problems.append(msg)
+                    # Do the scan...
+                    buildprobs = common.scan_source(build_dir)
+                    for problem in buildprobs:
+                        problems.append(problem + 
+                            ' in ' + app['id'] + ' ' + thisbuild['version'])
 
         except BuildException as be:
             msg = "Could not scan app %s due to BuildException: %s" % (app['id'], be)