Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2020 - 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 | from distutils import log |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 18 | import os |
Jack He | 838422b | 2020-04-08 22:58:07 -0700 | [diff] [blame] | 19 | from setuptools import find_packages |
| 20 | from setuptools import setup |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 21 | from setuptools.command.install import install |
Jack He | 3a27655 | 2020-03-23 17:23:45 -0700 | [diff] [blame] | 22 | import stat |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 23 | import subprocess |
| 24 | import sys |
| 25 | |
Jack He | e9bb55a | 2022-01-10 09:20:33 -0800 | [diff] [blame] | 26 | reuse_libraries = False |
| 27 | force_install = False |
| 28 | |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 29 | install_requires = [ |
| 30 | 'grpcio', |
Jack He | ebd72a9 | 2020-04-12 19:02:52 -0700 | [diff] [blame] | 31 | 'psutil', |
Jack He | 0077bd3 | 2022-05-26 14:15:02 -0700 | [diff] [blame] | 32 | 'protobuf>=3.14.0, <4.0', |
Jack He | e9bb55a | 2022-01-10 09:20:33 -0800 | [diff] [blame] | 33 | 'mobly', |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 34 | ] |
| 35 | |
Jack He | 3a27655 | 2020-03-23 17:23:45 -0700 | [diff] [blame] | 36 | host_executables = [ |
| 37 | 'root-canal', |
Zach Johnson | 7796be1 | 2020-11-04 15:24:55 -0800 | [diff] [blame] | 38 | 'bluetooth_stack_with_facade', # c++ |
| 39 | 'bluetooth_with_facades', # rust |
Hansong Zhang | 13515a7 | 2021-11-11 04:46:10 -0800 | [diff] [blame] | 40 | 'bt_topshim_facade', # topshim |
Jack He | 3a27655 | 2020-03-23 17:23:45 -0700 | [diff] [blame] | 41 | ] |
| 42 | |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 43 | |
Jack He | 838422b | 2020-04-08 22:58:07 -0700 | [diff] [blame] | 44 | def set_permissions_for_host_executables(outputs): |
Jack He | 3a27655 | 2020-03-23 17:23:45 -0700 | [diff] [blame] | 45 | for file in outputs: |
| 46 | if os.path.basename(file) in host_executables: |
| 47 | current_mode = os.stat(file).st_mode |
| 48 | new_mode = current_mode | stat.S_IEXEC |
| 49 | os.chmod(file, new_mode) |
Zach Johnson | 764d3b7 | 2020-05-18 12:52:26 -0700 | [diff] [blame] | 50 | log.log(log.INFO, "Changed file mode of %s from %s to %s" % (file, oct(current_mode), oct(new_mode))) |
Jack He | 3a27655 | 2020-03-23 17:23:45 -0700 | [diff] [blame] | 51 | |
| 52 | |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 53 | class InstallLocalPackagesForInstallation(install): |
| 54 | |
| 55 | def run(self): |
Jack He | e9bb55a | 2022-01-10 09:20:33 -0800 | [diff] [blame] | 56 | global reuse_libraries, force_install |
Jizheng Chu | 534cb1d | 2021-11-18 13:32:48 -0800 | [diff] [blame] | 57 | install_args = [sys.executable, '-m', 'pip', 'install'] |
| 58 | subprocess.check_call(install_args + ['--upgrade', 'pip']) |
| 59 | |
| 60 | for package in install_requires: |
| 61 | self.announce('Installing %s...' % package, log.INFO) |
Jack He | e9bb55a | 2022-01-10 09:20:33 -0800 | [diff] [blame] | 62 | cmd = install_args + ['-v', '--no-cache-dir', package] |
| 63 | if force_install and not reuse_libraries: |
| 64 | cmd.append("--force-reinstall") |
| 65 | subprocess.check_call(cmd) |
Jizheng Chu | 534cb1d | 2021-11-18 13:32:48 -0800 | [diff] [blame] | 66 | self.announce('Dependencies installed.') |
| 67 | |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 68 | install.run(self) |
Jack He | 838422b | 2020-04-08 22:58:07 -0700 | [diff] [blame] | 69 | set_permissions_for_host_executables(self.get_outputs()) |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 70 | |
| 71 | |
| 72 | def main(): |
Jack He | e9bb55a | 2022-01-10 09:20:33 -0800 | [diff] [blame] | 73 | global reuse_libraries, force_install |
| 74 | if sys.argv[-1] == "--reuse-libraries": |
| 75 | reuse_libraries = True |
| 76 | sys.argv = sys.argv[:-1] |
| 77 | if "--force" in sys.argv: |
| 78 | force_install = True |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 79 | # Relative path from calling directory to this file |
| 80 | our_dir = os.path.dirname(__file__) |
| 81 | # Must cd into this dir for package resolution to work |
| 82 | # This won't affect the calling shell |
| 83 | os.chdir(our_dir) |
| 84 | setup( |
| 85 | name='bluetooth_cert_tests', |
| 86 | version='1.0', |
| 87 | author='Android Open Source Project', |
| 88 | license='Apache2.0', |
| 89 | description="""Bluetooth Cert Tests Package""", |
| 90 | # Include root package so that bluetooth_packets_python3.so can be |
| 91 | # included as well |
Jizheng Chu | 534cb1d | 2021-11-18 13:32:48 -0800 | [diff] [blame] | 92 | packages=[''] + find_packages(exclude=['llvm_binutils', 'llvm_binutils.*']), |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 93 | install_requires=install_requires, |
| 94 | package_data={ |
Zach Johnson | 764d3b7 | 2020-05-18 12:52:26 -0700 | [diff] [blame] | 95 | '': host_executables + ['*.so', 'lib64/*.so', 'target/*', 'llvm_binutils/bin/*', 'llvm_binutils/lib64/*'], |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 96 | }, |
| 97 | cmdclass={ |
| 98 | 'install': InstallLocalPackagesForInstallation, |
Jack He | 1817a2a | 2020-03-18 02:52:54 -0700 | [diff] [blame] | 99 | }) |
| 100 | |
| 101 | |
| 102 | if __name__ == '__main__': |
| 103 | main() |