Skip to content

Commit d801b12

Browse files
committed
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
1 parent 800130a commit d801b12

File tree

16 files changed

+78
-21
lines changed

16 files changed

+78
-21
lines changed

BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ config("target_defaults") {
104104
"-Wno-final-dtor-non-final-class",
105105
]
106106

107-
cflags_cc = [ "-std=c++17" ]
107+
cflags_cc = [
108+
"-std=c++17",
109+
]
108110

109111
defines = [
110112
"HAS_NO_BDROID_BUILDCFG",
@@ -116,7 +118,7 @@ config("target_defaults") {
116118

117119
# If not configured as a dynamic library, default to static library
118120
if (!(defined(use.bt_dynlib) && use.bt_dynlib)) {
119-
defines = [
121+
defines += [
120122
"STATIC_LIBBLUETOOTH",
121123
]
122124
}

build.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,21 @@
6161
'tools', # Build the host tools (i.e. packetgen)
6262
'rust', # Build only the rust components + copy artifacts to output dir
6363
'main', # Build the main C++ codebase
64-
'test', # Build and run the unit tests
64+
'test', # Run the unit tests
6565
'clean', # Clean up output directory
6666
'all', # All targets except test and clean
6767
]
6868

69+
HOST_TESTS = [
70+
'bluetooth_test_common',
71+
'bluetoothtbd_test',
72+
'net_test_avrcp',
73+
'net_test_btcore',
74+
'net_test_types',
75+
'net_test_btm_iso',
76+
'net_test_btpackets',
77+
]
78+
6979

7080
class UseFlags():
7181

@@ -110,6 +120,7 @@ def __init__(self, args):
110120
self.jobs = self.args.jobs
111121
if not self.jobs:
112122
self.jobs = multiprocessing.cpu_count()
123+
print("Number of jobs = {}".format(self.jobs))
113124

114125
# Normalize all directories
115126
self.output_dir = os.path.abspath(self.args.output)
@@ -123,7 +134,13 @@ def __init__(self, args):
123134
if hasattr(self.args, 'target') and self.args.target:
124135
self.target = self.args.target
125136

126-
self.use = UseFlags(self.args.use if self.args.use else [])
137+
target_use = self.args.use if self.args.use else []
138+
139+
# Unless set, always build test code
140+
if not self.args.notest:
141+
target_use.append('test')
142+
143+
self.use = UseFlags(target_use)
127144

128145
# Validate platform directory
129146
assert os.path.isdir(self.platform_dir), 'Platform dir does not exist'
@@ -137,6 +154,18 @@ def __init__(self, args):
137154

138155
self.configure_environ()
139156

157+
def _generate_rustflags(self):
158+
""" Rustflags to include for the build.
159+
"""
160+
rust_flags = [
161+
'-L',
162+
'{}/out/Default/'.format(self.output_dir),
163+
'-C',
164+
'link-arg=-Wl,--allow-multiple-definition',
165+
]
166+
167+
return ' '.join(rust_flags)
168+
140169
def configure_environ(self):
141170
""" Configure environment variables for GN and Cargo.
142171
"""
@@ -150,6 +179,7 @@ def configure_environ(self):
150179
# Configure Rust env variables
151180
self.env['CARGO_TARGET_DIR'] = self.output_dir
152181
self.env['CARGO_HOME'] = os.path.join(self.output_dir, 'cargo_home')
182+
self.env['RUSTFLAGS'] = self._generate_rustflags()
153183

154184
# Configure some GN variables
155185
if self.use_board:
@@ -364,7 +394,15 @@ def _target_main(self):
364394
def _target_test(self):
365395
""" Runs the host tests.
366396
"""
367-
raise Exception('Not yet implemented')
397+
# Rust tests first
398+
self.run_command('test', ['cargo', 'test'], cwd=os.path.join(self.platform_dir, 'bt'), env=self.env)
399+
400+
# Host tests second based on host test list
401+
for t in HOST_TESTS:
402+
self.run_command(
403+
'test', [os.path.join(self.output_dir, 'out/Default', t)],
404+
cwd=os.path.join(self.output_dir),
405+
env=self.env)
368406

369407
def _target_clean(self):
370408
""" Delete the output directory entirely.
@@ -393,8 +431,6 @@ def build(self):
393431
elif self.target == 'main':
394432
self._target_main()
395433
elif self.target == 'test':
396-
self.use.set_flag('test')
397-
self._target_all()
398434
self._target_test()
399435
elif self.target == 'clean':
400436
self._target_clean()
@@ -406,14 +442,15 @@ def build(self):
406442
parser = argparse.ArgumentParser(description='Simple build for host.')
407443
parser.add_argument('--output', help='Output directory for the build.', required=True)
408444
parser.add_argument('--platform-dir', help='Directory where platform2 is staged.', required=True)
409-
parser.add_argument('--clang', help='Use clang compiler.', default=False, action="store_true")
445+
parser.add_argument('--clang', help='Use clang compiler.', default=False, action='store_true')
410446
parser.add_argument('--use', help='Set a specific use flag.')
447+
parser.add_argument('--notest', help="Don't compile test code.", default=False, action='store_true')
411448
parser.add_argument('--target', help='Run specific build target')
412449
parser.add_argument('--sysroot', help='Set a specific sysroot path', default='/')
413450
parser.add_argument('--libdir', help='Libdir - default = usr/lib64', default='usr/lib64')
414451
parser.add_argument('--use-board', help='Use a built x86 board for dependencies. Provide path.')
415452
parser.add_argument('--jobs', help='Number of jobs to run', default=0, type=int)
416-
parser.add_argument('--vendored-rust', help='Use vendored rust crates', default=False, action="store_true")
453+
parser.add_argument('--vendored-rust', help='Use vendored rust crates', default=False, action='store_true')
417454
parser.add_argument('--verbose', help='Verbose logs for build.')
418455

419456
args = parser.parse_args()

system/btif/src/btif_bqr.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include <base/logging.h>
1818
#include <errno.h>
1919
#include <fcntl.h>
20+
#ifdef OS_ANDROID
2021
#include <statslog.h>
22+
#endif
2123
#include <stdio.h>
2224
#include <sys/stat.h>
2325

@@ -395,6 +397,7 @@ void AddLinkQualityEventToQueue(uint8_t length, uint8_t* p_link_quality_event) {
395397
p_bqr_event->bqr_link_quality_event_.no_rx_count,
396398
p_bqr_event->bqr_link_quality_event_.nak_count);
397399

400+
#ifdef OS_ANDROID
398401
int ret = android::util::stats_write(
399402
android::util::BLUETOOTH_QUALITY_REPORT_REPORTED,
400403
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) {
420423
LOG(WARNING) << __func__ << ": failed to log BQR event to statsd, error "
421424
<< ret;
422425
}
426+
#else
427+
// TODO(abps) Metrics for non-Android build
428+
#endif
423429
kpBqrEventQueue->Enqueue(p_bqr_event.release());
424430
}
425431

system/gd/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static_library("libbluetooth_gd") {
6767
"//bt/gd/crypto_toolbox:BluetoothCryptoToolboxSources",
6868
"//bt/gd/dumpsys:BluetoothDumpsysSources",
6969
"//bt/gd/hal:BluetoothHalSources",
70-
"//bt/gd/hal:BluetoothHalSources_hci_rootcanal",
70+
"//bt/gd/hal:BluetoothHalSources_hci_host",
7171
"//bt/gd/l2cap:BluetoothL2capSources",
7272
"//bt/gd/neighbor:BluetoothNeighborSources",
7373
"//bt/gd/rust/shim:libbluetooth_rust_interop",

system/gd/common/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
source_set("BluetoothCommonSources") {
1818
sources = [
1919
"init_flags.cc",
20-
"metric_id_manager.cc"
20+
"metric_id_manager.cc",
2121
"stop_watch.cc",
2222
"strings.cc",
2323
]
2424

2525
configs += [ "//bt/gd:gd_defaults" ]
2626
deps = [
2727
"//bt/gd:gd_default_deps",
28-
"//bt/third_party/proto_logging/stats:libbt-platform-protos"
28+
"//bt:libbt-platform-protos-lite",
2929
]
3030
}

system/gd/common/circular_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <cstddef>
2020
#include <iterator>
21+
#include <memory>
2122
#include <mutex>
2223
#include <queue>
2324

system/gd/common/strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include <limits.h>
1920
#include <string.h>
2021
#include <charconv>
2122
#include <iomanip>

system/gd/hal/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ source_set("BluetoothHalSources") {
2121
deps = [ "//bt/gd:gd_default_deps" ]
2222
}
2323

24-
source_set("BluetoothHalSources_hci_rootcanal") {
25-
sources = [ "hci_hal_host_rootcanal.cc" ]
24+
source_set("BluetoothHalSources_hci_host") {
25+
sources = [ "hci_hal_host.cc" ]
2626

2727
configs += [ "//bt/gd:gd_defaults" ]
2828
deps = [ "//bt/gd:gd_default_deps" ]

system/gd/os/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ source_set("BluetoothOsSources_linux") {
2020
]
2121

2222
configs += [ "//bt/gd:gd_defaults" ]
23+
deps = [ "//bt:libbt-platform-protos-lite" ]
2324
}
2425

2526
source_set("BluetoothOsSources_linux_generic") {

system/gd/security/ecdh_keys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
******************************************************************************/
1818
#pragma once
1919

20+
#include <stdint.h>
2021
#include <array>
2122

2223
namespace bluetooth {

0 commit comments

Comments
 (0)