summaryrefslogtreecommitdiff
path: root/gen_blueprints.py
diff options
context:
space:
mode:
Diffstat (limited to 'gen_blueprints.py')
-rwxr-xr-xgen_blueprints.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/gen_blueprints.py b/gen_blueprints.py
new file mode 100755
index 000000000..bbdd6786b
--- /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()