blob: 597b9df2eddab0ee24a2d1628fc66b002261d7f3 [file] [log] [blame]
Jack He1817a2a2020-03-18 02:52:54 -07001#!/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
17from distutils import log
Jack He1817a2a2020-03-18 02:52:54 -070018import os
Jack He838422b2020-04-08 22:58:07 -070019from setuptools import find_packages
20from setuptools import setup
Jack He1817a2a2020-03-18 02:52:54 -070021from setuptools.command.install import install
Jack He3a276552020-03-23 17:23:45 -070022import stat
Jack He1817a2a2020-03-18 02:52:54 -070023import subprocess
24import sys
25
Jack Hee9bb55a2022-01-10 09:20:33 -080026reuse_libraries = False
27force_install = False
28
Jack He1817a2a2020-03-18 02:52:54 -070029install_requires = [
30 'grpcio',
Jack Heebd72a92020-04-12 19:02:52 -070031 'psutil',
Jack He0077bd32022-05-26 14:15:02 -070032 'protobuf>=3.14.0, <4.0',
Jack Hee9bb55a2022-01-10 09:20:33 -080033 'mobly',
Jack He1817a2a2020-03-18 02:52:54 -070034]
35
Jack He3a276552020-03-23 17:23:45 -070036host_executables = [
37 'root-canal',
Zach Johnson7796be12020-11-04 15:24:55 -080038 'bluetooth_stack_with_facade', # c++
39 'bluetooth_with_facades', # rust
Hansong Zhang13515a72021-11-11 04:46:10 -080040 'bt_topshim_facade', # topshim
Jack He3a276552020-03-23 17:23:45 -070041]
42
Jack He1817a2a2020-03-18 02:52:54 -070043
Jack He838422b2020-04-08 22:58:07 -070044def set_permissions_for_host_executables(outputs):
Jack He3a276552020-03-23 17:23:45 -070045 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 Johnson764d3b72020-05-18 12:52:26 -070050 log.log(log.INFO, "Changed file mode of %s from %s to %s" % (file, oct(current_mode), oct(new_mode)))
Jack He3a276552020-03-23 17:23:45 -070051
52
Jack He1817a2a2020-03-18 02:52:54 -070053class InstallLocalPackagesForInstallation(install):
54
55 def run(self):
Jack Hee9bb55a2022-01-10 09:20:33 -080056 global reuse_libraries, force_install
Jizheng Chu534cb1d2021-11-18 13:32:48 -080057 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 Hee9bb55a2022-01-10 09:20:33 -080062 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 Chu534cb1d2021-11-18 13:32:48 -080066 self.announce('Dependencies installed.')
67
Jack He1817a2a2020-03-18 02:52:54 -070068 install.run(self)
Jack He838422b2020-04-08 22:58:07 -070069 set_permissions_for_host_executables(self.get_outputs())
Jack He1817a2a2020-03-18 02:52:54 -070070
71
72def main():
Jack Hee9bb55a2022-01-10 09:20:33 -080073 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 He1817a2a2020-03-18 02:52:54 -070079 # 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 Chu534cb1d2021-11-18 13:32:48 -080092 packages=[''] + find_packages(exclude=['llvm_binutils', 'llvm_binutils.*']),
Jack He1817a2a2020-03-18 02:52:54 -070093 install_requires=install_requires,
94 package_data={
Zach Johnson764d3b72020-05-18 12:52:26 -070095 '': host_executables + ['*.so', 'lib64/*.so', 'target/*', 'llvm_binutils/bin/*', 'llvm_binutils/lib64/*'],
Jack He1817a2a2020-03-18 02:52:54 -070096 },
97 cmdclass={
98 'install': InstallLocalPackagesForInstallation,
Jack He1817a2a2020-03-18 02:52:54 -070099 })
100
101
102if __name__ == '__main__':
103 main()