Remove cruft from gen_blueprints.py, fix pylint.

Test: pylint gen_blueprints.py
Test: ./gen_blueprints.py
Test: make checkbuild
Bug: None
Change-Id: I7c7f442497a825d009057e153f950da7d85a77b3
diff --git a/Android.bp b/Android.bp
index 5984f84..dad4e70 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,86 +1,6 @@
 // THIS FILE IS AUTOGENERATED BY gen-blueprints.py
 // DO NOT EDIT
 
-cc_defaults {
-    name: "ndk_9_defaults",
-    sdk_version: "9",
-}
-
-cc_defaults {
-    name: "ndk_10_defaults",
-    sdk_version: "10",
-}
-
-cc_defaults {
-    name: "ndk_11_defaults",
-    sdk_version: "11",
-}
-
-cc_defaults {
-    name: "ndk_12_defaults",
-    sdk_version: "12",
-}
-
-cc_defaults {
-    name: "ndk_13_defaults",
-    sdk_version: "13",
-}
-
-cc_defaults {
-    name: "ndk_14_defaults",
-    sdk_version: "14",
-}
-
-cc_defaults {
-    name: "ndk_15_defaults",
-    sdk_version: "15",
-}
-
-cc_defaults {
-    name: "ndk_16_defaults",
-    sdk_version: "16",
-}
-
-cc_defaults {
-    name: "ndk_17_defaults",
-    sdk_version: "17",
-}
-
-cc_defaults {
-    name: "ndk_18_defaults",
-    sdk_version: "18",
-}
-
-cc_defaults {
-    name: "ndk_19_defaults",
-    sdk_version: "19",
-}
-
-cc_defaults {
-    name: "ndk_20_defaults",
-    sdk_version: "20",
-}
-
-cc_defaults {
-    name: "ndk_21_defaults",
-    sdk_version: "21",
-}
-
-cc_defaults {
-    name: "ndk_22_defaults",
-    sdk_version: "22",
-}
-
-cc_defaults {
-    name: "ndk_23_defaults",
-    sdk_version: "23",
-}
-
-cc_defaults {
-    name: "ndk_24_defaults",
-    sdk_version: "24",
-}
-
 ndk_prebuilt_object {
     name: "ndk_crtbegin_dynamic.9",
     sdk_version: "9",
@@ -406,4 +326,4 @@
     sdk_version: "24",
 }
 
-build = ["stl.bp"]
+build = ["stl.bp"]
\ No newline at end of file
diff --git a/gen-blueprints.py b/gen-blueprints.py
deleted file mode 100755
index 8b16a2f..0000000
--- a/gen-blueprints.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2015 Google Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-
-
-def local_path(path):
-    return os.path.normpath(os.path.join(os.path.dirname(__file__), path))
-
-
-def find(path, names):
-    found = []
-    for root, _, files in os.walk(path):
-        for file_name in sorted(files):
-            if file_name in names:
-                abspath = os.path.abspath(os.path.join(root, file_name))
-                rel_to_root = abspath.replace(os.path.abspath(path), '')
-                found.append(rel_to_root[1:])  # strip leading /
-    return found
-
-
-def sdk_version_from_path(path):
-    return int(path.split('/')[0].split('-')[1])
-
-
-def sdk_versions():
-    versions = []
-    for sdk in os.listdir(local_path('current/platforms')):
-        if sdk.startswith('android-'):
-            versions.append(sdk_version_from_path(sdk))
-    return sorted(versions)
-
-
-def gen_defaults():
-    defaults = []
-    for sdk in sdk_versions():
-        default = []
-        arch_flags = []
-
-        for arch in ['arm', 'arm64', 'mips', 'mips64', 'x86', 'x86_64']:
-            arch_path = local_path(
-                'current/platforms/android-{sdk}/arch-{arch}/usr/include'.format(sdk=sdk, arch=arch))
-            if os.path.exists(arch_path):
-                arch_flags.append(
-                    '        {arch}: {{\n'
-                    '            export_include_dirs: ["{includes}"],\n'
-                    '        }},'.format(arch=arch, includes=arch_path))
-
-        default.append('cc_defaults {{\n'
-                       '    name: "ndk_{version}_defaults",\n'
-                       '    sdk_version: "{version}",'.format(version=sdk))
-        if len(arch_flags) > 0:
-            default.append('    arch: {{\n{arch_flags}\n'
-                           '    }},'.format(arch_flags='\n'.join(arch_flags)))
-        default.append('}')
-        defaults.append('\n'.join(default))
-    return defaults
-
-
-def get_prebuilts(names):
-    prebuilts_path = local_path('current/platforms')
-    prebuilts = find(prebuilts_path, names)
-    prebuilts = [p for p in prebuilts if 'arch-arm/' in p]
-    prebuilts.sort(key=sdk_version_from_path)
-    return prebuilts
-
-
-def gen_lib_prebuilt(prebuilt, name, version):
-    return ('ndk_prebuilt_library {{\n'
-            '    name: "{name}.ndk.{version}",\n'
-            '    defaults: ["ndk_{version}_defaults"],\n'
-            '}}'.format(name=name, version=version))
-
-
-def gen_crt_prebuilt(_, name, version):
-    return ('ndk_prebuilt_object {{\n'
-            '    name: "ndk_{name}.{version}",\n'
-            '    sdk_version: "{version}",\n'
-            '}}'.format(name=name, version=version))
-
-
-def gen_prebuilts(fn, names):
-    prebuilts = []
-    for prebuilt in get_prebuilts(names):
-        name = os.path.splitext(os.path.basename(prebuilt))[0]
-        version = sdk_version_from_path(prebuilt)
-        if version < 9:
-            # We don't support anything before Gingerbread any more.
-            continue
-        prebuilts.append(fn(prebuilt, name, version))
-    return prebuilts
-
-
-def main():
-    blueprints = gen_defaults()
-    blueprints.extend(gen_prebuilts(gen_crt_prebuilt, (
-        'crtbegin_so.o',
-        'crtend_so.o',
-        'crtbegin_dynamic.o',
-        'crtbegin_static.o',
-        'crtend_android.o')))
-
-    with open(local_path('Android.bp'), 'w') as f:
-        f.write('// THIS FILE IS AUTOGENERATED BY gen-blueprints.py\n')
-        f.write('// DO NOT EDIT\n')
-        f.write('\n')
-        f.write('\n\n'.join(blueprints))
-        f.write('\n\n')
-        f.write('build = ["stl.bp"]\n')
-
-
-if __name__ == '__main__':
-    main()
diff --git a/gen_blueprints.py b/gen_blueprints.py
new file mode 100755
index 0000000..bbdd678
--- /dev/null
+++ b/gen_blueprints.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+# Copyright 2015 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Generates the Android.bp file for prebuilts/ndk."""
+import os
+
+
+def local_path(path):
+    """Returns an abspath to the given path from this file's directory."""
+    return os.path.normpath(os.path.join(os.path.dirname(__file__), path))
+
+
+def find(path, names):
+    """Finds a list of files in a directory that match the given names."""
+    found = []
+    for root, _, files in os.walk(path):
+        for file_name in sorted(files):
+            if file_name in names:
+                abspath = os.path.abspath(os.path.join(root, file_name))
+                rel_to_root = abspath.replace(os.path.abspath(path), '')
+                found.append(rel_to_root[1:])  # strip leading /
+    return found
+
+
+def sdk_version_from_path(path):
+    """Returns the integer SDK version for the given path."""
+    return int(path.split('/')[0].split('-')[1])
+
+
+def get_prebuilts(names):
+    """Returns a list of prebuilt objects that match the given names."""
+    prebuilts_path = local_path('current/platforms')
+    prebuilts = find(prebuilts_path, names)
+    prebuilts = [p for p in prebuilts if 'arch-arm/' in p]
+    prebuilts.sort(key=sdk_version_from_path)
+    return prebuilts
+
+
+def gen_crt_prebuilt(_, name, version):
+    """Generate a module for a CRT prebuilt object."""
+    return ('ndk_prebuilt_object {{\n'
+            '    name: "ndk_{name}.{version}",\n'
+            '    sdk_version: "{version}",\n'
+            '}}'.format(name=name, version=version))
+
+
+def gen_prebuilts(module_generator, names):
+    """Generate blueprints for the given modules."""
+    prebuilts = []
+    for prebuilt in get_prebuilts(names):
+        name = os.path.splitext(os.path.basename(prebuilt))[0]
+        version = sdk_version_from_path(prebuilt)
+        if version < 9:
+            # We don't support anything before Gingerbread any more.
+            continue
+        prebuilts.append(module_generator(prebuilt, name, version))
+    return prebuilts
+
+
+def main():
+    """Program entry point."""
+    blueprints = gen_prebuilts(gen_crt_prebuilt, (
+        'crtbegin_so.o',
+        'crtend_so.o',
+        'crtbegin_dynamic.o',
+        'crtbegin_static.o',
+        'crtend_android.o'))
+
+    with open(local_path('Android.bp'), 'w') as bpfile:
+        bpfile.write('// THIS FILE IS AUTOGENERATED BY gen-blueprints.py\n')
+        bpfile.write('// DO NOT EDIT\n')
+        bpfile.write('\n')
+        bpfile.write('\n\n'.join(blueprints))
+        bpfile.write('\n\n')
+        bpfile.write('build = ["stl.bp"]')
+
+
+if __name__ == '__main__':
+    main()