1#!/usr/bin/env python3 2# 3# Copyright 2019 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Usage: 18# 1. Run envsetup and lunch first in an Android checkout 19# 2. Make target bluetooth_packets_python3 that will generate C++ sources for the 20# Extension 21# 3. Build only: 22# python3 bluetooth_packets_python3_setup.py build_ext 23# Then Find the .so file in build/lib.linux-x86_64-3.X 24# 4. Install: 25# python3 bluetooth_packets_python3_setup.py install --user 26 27import os 28import glob 29from setuptools import setup, Extension 30 31ANDROID_BUILD_TOP = os.getenv("ANDROID_BUILD_TOP") 32PYBIND11_INCLUDE_DIR = os.path.join(ANDROID_BUILD_TOP, "external/python/pybind11/include") 33GD_DIR = os.path.join(ANDROID_BUILD_TOP, "packages/modules/Bluetooth/system/gd") 34BT_PACKETS_GEN_DIR = os.path.join(ANDROID_BUILD_TOP, 35 "out/soong/.intermediates/packages/modules/Bluetooth/system/gd/BluetoothGeneratedPackets_h/gen") 36BT_PACKETS_PY3_GEN_DIR = os.path.join(ANDROID_BUILD_TOP, 37 "out/soong/.intermediates/packages/modules/Bluetooth/system/gd/BluetoothGeneratedPackets_python3_cc/gen") 38 39BT_PACKETS_BASE_SRCS = [ 40 os.path.join(GD_DIR, "l2cap/fcs.cc"), 41 os.path.join(GD_DIR, "packet/bit_inserter.cc"), 42 os.path.join(GD_DIR, "packet/byte_inserter.cc"), 43 os.path.join(GD_DIR, "packet/byte_observer.cc"), 44 os.path.join(GD_DIR, "packet/iterator.cc"), 45 os.path.join(GD_DIR, "packet/fragmenting_inserter.cc"), 46 os.path.join(GD_DIR, "packet/packet_view.cc"), 47 os.path.join(GD_DIR, "packet/raw_builder.cc"), 48 os.path.join(GD_DIR, "packet/view.cc"), 49] 50 51BT_PACKETS_PY3_SRCs = \ 52 [os.path.join(GD_DIR, "packet/python3_module.cc")] \ 53 + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "hci", "*.cc")) \ 54 + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "l2cap", "*.cc")) \ 55 + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "security", "*.cc")) 56 57bluetooth_packets_python3_module = Extension( 58 'bluetooth_packets_python3', 59 sources=BT_PACKETS_BASE_SRCS + BT_PACKETS_PY3_SRCs, 60 include_dirs=[GD_DIR, BT_PACKETS_GEN_DIR, BT_PACKETS_PY3_GEN_DIR, PYBIND11_INCLUDE_DIR], 61 extra_compile_args=['-std=c++17']) 62 63setup( 64 name='bluetooth_packets_python3', 65 version='1.0', 66 author="Android Open Source Project", 67 description="""Bluetooth Packet Library""", 68 ext_modules=[bluetooth_packets_python3_module], 69 py_modules=["bluetooth_packets_python3"], 70) 71