diff --git a/tools/ndk/.gitignore b/tools/ndk/.gitignore new file mode 100644 index 000000000..a81c8ee12 --- /dev/null +++ b/tools/ndk/.gitignore @@ -0,0 +1,138 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/tools/ndk/OWNERS b/tools/ndk/OWNERS new file mode 100644 index 000000000..7310b199a --- /dev/null +++ b/tools/ndk/OWNERS @@ -0,0 +1,4 @@ +danalbert@google.com +enh@google.com +hhb@google.com +rprichard@google.com diff --git a/tools/ndk/build_ndk_docs.py b/tools/ndk/build_ndk_docs.py new file mode 100755 index 000000000..9a36362b3 --- /dev/null +++ b/tools/ndk/build_ndk_docs.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 The Android Open Source Project +# +# 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 NDK API docs for local viewing. + +Note that the local docs will not exactly match the docs that are uploaded to +devsite. The theming is different and the per-file view is not available. +Ensure that your documentation is accessible from the module view or it will +not be discoverable on devsite. +""" +import argparse +import os +from pathlib import Path +import shutil +import subprocess +import sys + +THIS_DIR = Path(__file__).resolve().parent +ANDROID_TOP = THIS_DIR.parents[2] + + +def check_environment() -> None: + """Validates that we have everything we need from the environment.""" + if shutil.which('doxygen') is None: + sys.exit('Doxygen not found. Run `sudo apt install doxygen`.') + + if 'ANDROID_PRODUCT_OUT' not in os.environ: + sys.exit('Could not find ANDROID_PRODUCT_OUT. Run lunch.') + + +def build_ndk() -> None: + """Builds the NDK sysroot.""" + subprocess.run(["build/soong/soong_ui.bash", "--make-mode", "ndk"], + cwd=ANDROID_TOP, + check=True) + + +def generate_docs() -> None: + """Generates the NDK API reference.""" + product_out = Path(os.environ['ANDROID_PRODUCT_OUT']) + out_dir = product_out.parents[1] / 'common/ndk-docs' + html_dir = out_dir / 'html' + input_dir = product_out.parents[2] / 'soong/ndk/sysroot/usr/include' + doxyfile_template = ANDROID_TOP / 'frameworks/native/docs/Doxyfile' + doxyfile = out_dir / 'Doxyfile' + + doxyfile_contents = doxyfile_template.read_text() + doxyfile_contents += f'\nINPUT={input_dir}\nHTML_OUTPUT={html_dir}' + doxyfile.write_text(doxyfile_contents) + + subprocess.run(['doxygen', str(doxyfile)], cwd=ANDROID_TOP, check=True) + index = html_dir / 'index.html' + print(f'Generated NDK API documentation to {index.as_uri()}') + + +def parse_args() -> argparse.Namespace: + """Parses command line arguments.""" + parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__) + return parser.parse_args() + + +def main() -> None: + """Program entry point.""" + _ = parse_args() + check_environment() + build_ndk() + generate_docs() + + +if __name__ == '__main__': + main()