blob: a508398f48cd450134a1efd8e0f1e6e596ab364a [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 He838422b2020-04-08 22:58:07 -070018from distutils.errors import DistutilsModuleError
Jack He1817a2a2020-03-18 02:52:54 -070019import os
Jack He838422b2020-04-08 22:58:07 -070020from setuptools import find_packages
21from setuptools import setup
Jack He1817a2a2020-03-18 02:52:54 -070022from setuptools.command.install import install
Jack He3a276552020-03-23 17:23:45 -070023import stat
Jack He1817a2a2020-03-18 02:52:54 -070024import subprocess
25import sys
26
27install_requires = [
28 'grpcio',
Jack Heebd72a92020-04-12 19:02:52 -070029 'psutil',
Jack He1817a2a2020-03-18 02:52:54 -070030]
31
Jack He3a276552020-03-23 17:23:45 -070032host_executables = [
33 'root-canal',
34 'bluetooth_stack_with_facade',
35]
36
Jack He1817a2a2020-03-18 02:52:54 -070037
Jack He838422b2020-04-08 22:58:07 -070038# Need to verify acts is importable in a new Python context
39def is_acts_importable():
40 cmd = [sys.executable, '-c', 'import acts']
41 completed_process = subprocess.run(cmd, cwd=os.getcwd())
42 return completed_process.returncode == 0
43
44
Jack He1817a2a2020-03-18 02:52:54 -070045def setup_acts_for_cmd_or_die(cmd_str):
46 acts_framework_dir = os.path.abspath('acts_framework')
47 acts_setup_bin = os.path.join(acts_framework_dir, 'setup.py')
48 cmd = [sys.executable, acts_setup_bin, cmd_str]
Jack He838422b2020-04-08 22:58:07 -070049 subprocess.run(cmd, cwd=acts_framework_dir, check=True)
Jack He1817a2a2020-03-18 02:52:54 -070050
51
Jack He838422b2020-04-08 22:58:07 -070052def set_permissions_for_host_executables(outputs):
Jack He3a276552020-03-23 17:23:45 -070053 for file in outputs:
54 if os.path.basename(file) in host_executables:
55 current_mode = os.stat(file).st_mode
56 new_mode = current_mode | stat.S_IEXEC
57 os.chmod(file, new_mode)
58 log.log(
59 log.INFO, "Changed file mode of %s from %s to %s" %
60 (file, oct(current_mode), oct(new_mode)))
61
62
Jack He1817a2a2020-03-18 02:52:54 -070063class InstallLocalPackagesForInstallation(install):
64
Jack He838422b2020-04-08 22:58:07 -070065 user_options = install.user_options + [
66 ('reuse-acts', None, "Skip ACTS installation if already installed"),
67 ]
68 boolean_options = install.boolean_options + ['reuse-acts']
69
70 def initialize_options(self):
71 install.initialize_options(self)
72 self.reuse_acts = False
73
Jack He1817a2a2020-03-18 02:52:54 -070074 def run(self):
Jack He838422b2020-04-08 22:58:07 -070075 if self.reuse_acts and is_acts_importable():
76 self.announce('Reusing existing ACTS installation', log.WARN)
77 else:
78 self.announce('Installing ACTS for installation', log.WARN)
79 setup_acts_for_cmd_or_die("install")
80 self.announce('ACTS installed for installation.', log.WARN)
81 if not is_acts_importable():
82 raise DistutilsModuleError("Cannot import acts after installation")
Jack He1817a2a2020-03-18 02:52:54 -070083 install.run(self)
Jack He838422b2020-04-08 22:58:07 -070084 set_permissions_for_host_executables(self.get_outputs())
Jack He1817a2a2020-03-18 02:52:54 -070085
86
87def main():
88 # Relative path from calling directory to this file
89 our_dir = os.path.dirname(__file__)
90 # Must cd into this dir for package resolution to work
91 # This won't affect the calling shell
92 os.chdir(our_dir)
93 setup(
94 name='bluetooth_cert_tests',
95 version='1.0',
96 author='Android Open Source Project',
97 license='Apache2.0',
98 description="""Bluetooth Cert Tests Package""",
99 # Include root package so that bluetooth_packets_python3.so can be
100 # included as well
Jack He838422b2020-04-08 22:58:07 -0700101 packages=[''] +
102 find_packages(exclude=['acts_framework', 'acts_framework.*']),
Jack He1817a2a2020-03-18 02:52:54 -0700103 install_requires=install_requires,
104 package_data={
Jack He3a276552020-03-23 17:23:45 -0700105 '': host_executables + ['*.so', 'lib64/*.so', 'target/*'],
Jack He1817a2a2020-03-18 02:52:54 -0700106 'cert': ['all_test_cases'],
107 },
108 cmdclass={
109 'install': InstallLocalPackagesForInstallation,
Jack He1817a2a2020-03-18 02:52:54 -0700110 })
111
112
113if __name__ == '__main__':
114 main()