From: Abhishek Pandit-Subedi Date: Sat, 10 Apr 2021 00:41:07 +0000 (+0000) Subject: Additional changes for Linux build X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9956a0aa06e0cd550a35a7d635fc431e55224f9e;p=android-x86%2Fsystem-bt.git Additional changes for Linux build While building for Linux on cloudtop, a few more problems were identified in the build. There were a couple of missing #include and some incomplete struct definitions in btm_int_types.h. Also put statslog.h behind an #ifdef OS_ANDROID. Bug: 184975659 Tag: #floss Test: atest --host bluetooth_test_gd Change-Id: Ic2272a3acfa66259e692db280b48b4ddadff2171 --- diff --git a/BUILD.gn b/BUILD.gn index 109bf7167..9d2f4c7ad 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -104,7 +104,9 @@ config("target_defaults") { "-Wno-final-dtor-non-final-class", ] - cflags_cc = [ "-std=c++17" ] + cflags_cc = [ + "-std=c++17", + ] defines = [ "HAS_NO_BDROID_BUILDCFG", @@ -116,7 +118,7 @@ config("target_defaults") { # If not configured as a dynamic library, default to static library if (!(defined(use.bt_dynlib) && use.bt_dynlib)) { - defines = [ + defines += [ "STATIC_LIBBLUETOOTH", ] } diff --git a/btif/src/btif_bqr.cc b/btif/src/btif_bqr.cc index 7896ea225..c437b2c1b 100644 --- a/btif/src/btif_bqr.cc +++ b/btif/src/btif_bqr.cc @@ -17,7 +17,9 @@ #include #include #include +#ifdef OS_ANDROID #include +#endif #include #include @@ -395,6 +397,7 @@ void AddLinkQualityEventToQueue(uint8_t length, uint8_t* p_link_quality_event) { p_bqr_event->bqr_link_quality_event_.no_rx_count, p_bqr_event->bqr_link_quality_event_.nak_count); +#ifdef OS_ANDROID int ret = android::util::stats_write( android::util::BLUETOOTH_QUALITY_REPORT_REPORTED, p_bqr_event->bqr_link_quality_event_.quality_report_id, @@ -420,6 +423,9 @@ void AddLinkQualityEventToQueue(uint8_t length, uint8_t* p_link_quality_event) { LOG(WARNING) << __func__ << ": failed to log BQR event to statsd, error " << ret; } +#else + // TODO(abps) Metrics for non-Android build +#endif kpBqrEventQueue->Enqueue(p_bqr_event.release()); } diff --git a/build.py b/build.py index 131cbb299..3e79bff55 100755 --- a/build.py +++ b/build.py @@ -61,11 +61,21 @@ VALID_TARGETS = [ 'tools', # Build the host tools (i.e. packetgen) 'rust', # Build only the rust components + copy artifacts to output dir 'main', # Build the main C++ codebase - 'test', # Build and run the unit tests + 'test', # Run the unit tests 'clean', # Clean up output directory 'all', # All targets except test and clean ] +HOST_TESTS = [ + 'bluetooth_test_common', + 'bluetoothtbd_test', + 'net_test_avrcp', + 'net_test_btcore', + 'net_test_types', + 'net_test_btm_iso', + 'net_test_btpackets', +] + class UseFlags(): @@ -110,6 +120,7 @@ class HostBuild(): self.jobs = self.args.jobs if not self.jobs: self.jobs = multiprocessing.cpu_count() + print("Number of jobs = {}".format(self.jobs)) # Normalize all directories self.output_dir = os.path.abspath(self.args.output) @@ -123,7 +134,13 @@ class HostBuild(): if hasattr(self.args, 'target') and self.args.target: self.target = self.args.target - self.use = UseFlags(self.args.use if self.args.use else []) + target_use = self.args.use if self.args.use else [] + + # Unless set, always build test code + if not self.args.notest: + target_use.append('test') + + self.use = UseFlags(target_use) # Validate platform directory assert os.path.isdir(self.platform_dir), 'Platform dir does not exist' @@ -137,6 +154,18 @@ class HostBuild(): self.configure_environ() + def _generate_rustflags(self): + """ Rustflags to include for the build. + """ + rust_flags = [ + '-L', + '{}/out/Default/'.format(self.output_dir), + '-C', + 'link-arg=-Wl,--allow-multiple-definition', + ] + + return ' '.join(rust_flags) + def configure_environ(self): """ Configure environment variables for GN and Cargo. """ @@ -150,6 +179,7 @@ class HostBuild(): # Configure Rust env variables self.env['CARGO_TARGET_DIR'] = self.output_dir self.env['CARGO_HOME'] = os.path.join(self.output_dir, 'cargo_home') + self.env['RUSTFLAGS'] = self._generate_rustflags() # Configure some GN variables if self.use_board: @@ -364,7 +394,15 @@ class HostBuild(): def _target_test(self): """ Runs the host tests. """ - raise Exception('Not yet implemented') + # Rust tests first + self.run_command('test', ['cargo', 'test'], cwd=os.path.join(self.platform_dir, 'bt'), env=self.env) + + # Host tests second based on host test list + for t in HOST_TESTS: + self.run_command( + 'test', [os.path.join(self.output_dir, 'out/Default', t)], + cwd=os.path.join(self.output_dir), + env=self.env) def _target_clean(self): """ Delete the output directory entirely. @@ -393,8 +431,6 @@ class HostBuild(): elif self.target == 'main': self._target_main() elif self.target == 'test': - self.use.set_flag('test') - self._target_all() self._target_test() elif self.target == 'clean': self._target_clean() @@ -406,14 +442,15 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='Simple build for host.') parser.add_argument('--output', help='Output directory for the build.', required=True) parser.add_argument('--platform-dir', help='Directory where platform2 is staged.', required=True) - parser.add_argument('--clang', help='Use clang compiler.', default=False, action="store_true") + parser.add_argument('--clang', help='Use clang compiler.', default=False, action='store_true') parser.add_argument('--use', help='Set a specific use flag.') + parser.add_argument('--notest', help="Don't compile test code.", default=False, action='store_true') parser.add_argument('--target', help='Run specific build target') parser.add_argument('--sysroot', help='Set a specific sysroot path', default='/') parser.add_argument('--libdir', help='Libdir - default = usr/lib64', default='usr/lib64') parser.add_argument('--use-board', help='Use a built x86 board for dependencies. Provide path.') parser.add_argument('--jobs', help='Number of jobs to run', default=0, type=int) - parser.add_argument('--vendored-rust', help='Use vendored rust crates', default=False, action="store_true") + parser.add_argument('--vendored-rust', help='Use vendored rust crates', default=False, action='store_true') parser.add_argument('--verbose', help='Verbose logs for build.') args = parser.parse_args() diff --git a/gd/BUILD.gn b/gd/BUILD.gn index 6abddb1f8..cd48264d0 100644 --- a/gd/BUILD.gn +++ b/gd/BUILD.gn @@ -67,7 +67,7 @@ static_library("libbluetooth_gd") { "//bt/gd/crypto_toolbox:BluetoothCryptoToolboxSources", "//bt/gd/dumpsys:BluetoothDumpsysSources", "//bt/gd/hal:BluetoothHalSources", - "//bt/gd/hal:BluetoothHalSources_hci_rootcanal", + "//bt/gd/hal:BluetoothHalSources_hci_host", "//bt/gd/l2cap:BluetoothL2capSources", "//bt/gd/neighbor:BluetoothNeighborSources", "//bt/gd/rust/shim:libbluetooth_rust_interop", diff --git a/gd/common/BUILD.gn b/gd/common/BUILD.gn index 536bfb74a..fb4dad973 100644 --- a/gd/common/BUILD.gn +++ b/gd/common/BUILD.gn @@ -17,7 +17,7 @@ source_set("BluetoothCommonSources") { sources = [ "init_flags.cc", - "metric_id_manager.cc" + "metric_id_manager.cc", "stop_watch.cc", "strings.cc", ] @@ -25,6 +25,6 @@ source_set("BluetoothCommonSources") { configs += [ "//bt/gd:gd_defaults" ] deps = [ "//bt/gd:gd_default_deps", - "//bt/third_party/proto_logging/stats:libbt-platform-protos" + "//bt:libbt-platform-protos-lite", ] } diff --git a/gd/common/circular_buffer.h b/gd/common/circular_buffer.h index 1914fa097..46d6972fe 100644 --- a/gd/common/circular_buffer.h +++ b/gd/common/circular_buffer.h @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/gd/common/strings.h b/gd/common/strings.h index a110cf45c..c80d01eff 100644 --- a/gd/common/strings.h +++ b/gd/common/strings.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include #include diff --git a/gd/hal/BUILD.gn b/gd/hal/BUILD.gn index 1752241d3..9ed814a7c 100644 --- a/gd/hal/BUILD.gn +++ b/gd/hal/BUILD.gn @@ -21,8 +21,8 @@ source_set("BluetoothHalSources") { deps = [ "//bt/gd:gd_default_deps" ] } -source_set("BluetoothHalSources_hci_rootcanal") { - sources = [ "hci_hal_host_rootcanal.cc" ] +source_set("BluetoothHalSources_hci_host") { + sources = [ "hci_hal_host.cc" ] configs += [ "//bt/gd:gd_defaults" ] deps = [ "//bt/gd:gd_default_deps" ] diff --git a/gd/os/BUILD.gn b/gd/os/BUILD.gn index 84c906921..56ddc598c 100644 --- a/gd/os/BUILD.gn +++ b/gd/os/BUILD.gn @@ -20,6 +20,7 @@ source_set("BluetoothOsSources_linux") { ] configs += [ "//bt/gd:gd_defaults" ] + deps = [ "//bt:libbt-platform-protos-lite" ] } source_set("BluetoothOsSources_linux_generic") { diff --git a/gd/security/ecdh_keys.h b/gd/security/ecdh_keys.h index 8ec25a890..f9c43023b 100644 --- a/gd/security/ecdh_keys.h +++ b/gd/security/ecdh_keys.h @@ -17,6 +17,7 @@ ******************************************************************************/ #pragma once +#include #include namespace bluetooth { diff --git a/main/shim/hci_layer.cc b/main/shim/hci_layer.cc index b273ddc6b..85612cb02 100644 --- a/main/shim/hci_layer.cc +++ b/main/shim/hci_layer.cc @@ -344,7 +344,7 @@ void OnTransmitPacketCommandComplete(command_complete_cb complete_callback, bluetooth::hci::CommandCompleteView view) { LOG_DEBUG("Received cmd complete for %s", bluetooth::hci::OpCodeText(view.GetCommandOpCode()).c_str()); - std::vector data(view.begin(), view.end()); + std::vector data(view.begin(), view.end()); BT_HDR* response = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT, &view); complete_callback(response, context); } diff --git a/osi/include/compat.h b/osi/include/compat.h index 95fe0373e..1d19a590d 100644 --- a/osi/include/compat.h +++ b/osi/include/compat.h @@ -26,7 +26,7 @@ #include /* Get thread identification. */ -pid_t gettid(void); +pid_t gettid(void) throw(); /* Copy src to string dst of size siz. */ size_t strlcpy(char* dst, const char* src, size_t siz); diff --git a/osi/src/compat.cc b/osi/src/compat.cc index 069964c22..e5b41a528 100644 --- a/osi/src/compat.cc +++ b/osi/src/compat.cc @@ -35,7 +35,7 @@ #include "osi/include/osi.h" #if __GLIBC__ -pid_t gettid(void) { return syscall(SYS_gettid); } +pid_t gettid(void) throw() { return syscall(SYS_gettid); } #endif /* These functions from bionic diff --git a/service/BUILD.gn b/service/BUILD.gn index f4b4f09d7..64d084422 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -63,6 +63,8 @@ source_set("service_linux_src") { sources = [ "ipc/ipc_handler_linux.cc", "ipc/linux_ipc_host.cc", + "ipc/dbus/ipc_handler_dbus.cc", + "ipc/dbus/bluetooth_adapter.cc", ] deps = [ @@ -91,8 +93,6 @@ source_set("service") { "common/bluetooth/scan_settings.cc", "common/bluetooth/service.cc", "common/bluetooth/util/atomic_string.cc", - "ipc/dbus/bluetooth_adapter.cc", - "ipc/dbus/ipc_handler_dbus.cc", ] deps = [ @@ -155,6 +155,7 @@ if (use.test) { deps = [ ":service_base_test_src", ":service_daemon_src", + ":service_linux_src", "//bt/service/common:libbluetooth_common", ] diff --git a/stack/btm/btm_int_types.h b/stack/btm/btm_int_types.h index 6a6da3f3e..0622ddd51 100644 --- a/stack/btm/btm_int_types.h +++ b/stack/btm/btm_int_types.h @@ -126,7 +126,7 @@ typedef void(tBTM_BT_QUALITY_REPORT_RECEIVER)(uint8_t len, uint8_t* p_stream); /* Define the Device Management control structure */ -typedef struct { +typedef struct tBTM_DEVCB { tBTM_VS_EVT_CB* p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS]; /* Register for vendor specific events */ @@ -202,7 +202,7 @@ typedef struct { } } tBTM_DEVCB; -typedef struct { +typedef struct tBTM_CB { tBTM_CFG cfg; /* Device configuration */ /***************************************************** diff --git a/types/BUILD.gn b/types/BUILD.gn index 47604a9f4..08a47b648 100644 --- a/types/BUILD.gn +++ b/types/BUILD.gn @@ -54,6 +54,13 @@ if (use.test) { "z", ] + # For some reason, this is required for host build. Otherwise, I get + # a complaint from gmock: + # undefined reference to symbol 'pthread_getspecific@@GLIBC_2.2.5' + ldflags = [ + "-lpthread" + ] + deps = [ ":types", ]