Skip to content

Commit 9bd8242

Browse files
committed
Build support and abstractions for Linux build
This has a large number of fixes to build on Linux/ChromeOS. In general, it is making sure the BUILD.gn and Android.bp for a directory structure match and it has all the configs + deps needed to build. Besides a number of simple fixups (missing headers), there are also a few abstractions that need to be noted: * All of audio HAL is stubbed out (using the host implementation) * Parameter provider and system_properties (under gd/os) now have a linux variant that changes where configuration files are kept. The current location for linux is now /etc/systembt. This implementation was copied from the host versions (which seems to be used for host testing). Bug: 176847256 Tag: #floss Test: atest --host bluetooth_test_gd Change-Id: I1a6b3b362cedbe5f675794a115a330cc7f85f9c1
1 parent b3fe88b commit 9bd8242

File tree

35 files changed

+822
-114
lines changed

35 files changed

+822
-114
lines changed

BUILD.gn

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@
2121
# file to your new one or GN won't know about it.
2222

2323
group("all") {
24-
deps = [
25-
":bluetooth",
26-
]
24+
deps = [ ":bluetooth" ]
2725

2826
if (use.test) {
29-
deps += [
30-
":bluetooth_tests"
31-
]
27+
deps += [ ":bluetooth_tests" ]
3228
}
3329
}
3430

@@ -43,24 +39,34 @@ group("bluetooth") {
4339
if (use.test) {
4440
group("bluetooth_tests") {
4541
deps = [
42+
"//bt/btcore:net_test_btcore",
4643
"//bt/common:bluetooth_test_common",
47-
"//bt/service:bluetoothtbd_test",
4844
"//bt/profile/avrcp:net_test_avrcp",
49-
"//bt/btcore:net_test_btcore",
50-
"//bt/types:net_test_types",
45+
"//bt/service:bluetoothtbd_test",
5146
"//bt/stack:net_test_btm_iso",
47+
"//bt/types:net_test_types",
48+
5249
#"//bt/packet:net_test_btpackets",
5350
]
5451
}
5552
}
5653

54+
if (host_cpu == target_cpu && host_os == target_os) {
55+
group("tools") {
56+
deps = [
57+
"//bt/gd/dumpsys/bundler:bluetooth_flatbuffer_bundler",
58+
"//bt/gd/packet/parser:bluetooth_packetgen",
59+
]
60+
}
61+
}
62+
5763
if (defined(use.android) && use.android) {
5864
group("android_bluetooth_tests") {
5965
deps = [
60-
"//bt/test/suite:net_test_bluetooth",
66+
"//bt/device:net_test_device",
6167
"//bt/hci:net_test_hci",
6268
"//bt/osi:net_test_osi",
63-
"//bt/device:net_test_device",
69+
"//bt/test/suite:net_test_bluetooth",
6470
]
6571
}
6672
}
@@ -71,11 +77,13 @@ config("target_defaults") {
7177
"//bt/linux_include",
7278
"//bt/types",
7379
"//bt/include",
80+
81+
# For flatbuffer generated headers
82+
"${root_gen_dir}/bt/gd/",
83+
"${root_gen_dir}/bt/gd/dumpsys/bundler",
7484
]
7585

7686
cflags = [
77-
"-DEXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
78-
"-DFALLTHROUGH_INTENDED=[[clang::fallthrough]]",
7987
"-fPIC",
8088
"-Wno-non-c-typedef-for-linkage",
8189
"-Wno-unreachable-code-return",
@@ -91,20 +99,26 @@ config("target_defaults") {
9199
"-Wno-unused-variable",
92100
"-Wno-unused-const-variable",
93101
"-Wno-format",
102+
"-Wno-pessimizing-move",
103+
"-Wno-unknown-warning-option",
104+
"-Wno-final-dtor-non-final-class",
94105
]
95106

96-
cflags_cc = [
97-
"-std=c++17",
98-
]
107+
cflags_cc = [ "-std=c++17" ]
99108

100109
defines = [
101110
"HAS_NO_BDROID_BUILDCFG",
102111
"OS_GENERIC",
112+
"OS_LINUX_GENERIC",
113+
"EXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
114+
"FALLTHROUGH_INTENDED=[[clang::fallthrough]]",
103115
]
104116

105-
configs = [
106-
":external_libchrome",
107-
]
117+
if (!(defined(use.bt_nonstandard_codecs) && use.bt_nonstandard_codecs)) {
118+
defines += [ "EXCLUDE_NONSTANDARD_CODECS" ]
119+
}
120+
121+
configs = [ ":external_libchrome" ]
108122
}
109123

110124
# Configurations to use as dependencies for GN build
@@ -135,6 +149,12 @@ config("external_tinyxml2") {
135149
configs = [ ":pkg_tinyxml2" ]
136150
}
137151

152+
config("external_flatbuffers") {
153+
lib_dirs = [ "${libdir}" ]
154+
155+
libs = [ "flatbuffers" ]
156+
}
157+
138158
# Package configurations to extract dependencies from env
139159
pkg_config("pkg_gtest") {
140160
pkg_deps = [ "gtest" ]
@@ -184,10 +204,10 @@ if (defined(use.bt_nonstandard_codecs) && use.bt_nonstandard_codecs) {
184204
}
185205

186206
pkg_config("pkg_libldacBT_enc") {
187-
pkg_deps = [ "ldacBT-enc", ]
207+
pkg_deps = [ "ldacBT-enc" ]
188208
}
189209

190210
pkg_config("pkg_libldacBT_abr") {
191-
pkg_deps = [ "ldacBT-abr", ]
211+
pkg_deps = [ "ldacBT-abr" ]
192212
}
193213
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Copyright 2021 Google, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at:
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
static_library("audio_hal_interface") {
18+
sources = [
19+
"a2dp_encoding_host.cc",
20+
"hearing_aid_software_encoding_host.cc",
21+
]
22+
23+
include_dirs = [
24+
"//bt/bta/include",
25+
"//bt/btif/include",
26+
"//bt/stack/include",
27+
"//bt/gd/rust/shim",
28+
]
29+
30+
configs += [ "//bt:target_defaults" ]
31+
32+
deps = [
33+
"//bt/common",
34+
"//bt/osi:osi",
35+
]
36+
}

system/bta/include/bta_hearing_aid_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <hardware/bt_hearing_aid.h>
2323
#include <cstdint>
2424
#include <deque>
25+
#include <functional>
2526
#include <vector>
2627

2728
constexpr uint16_t HEARINGAID_MAX_NUM_UUIDS = 1;

system/btcore/BUILD.gn

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ static_library("btcore") {
1919
"src/device_class.cc",
2020
"src/hal_util.cc",
2121
"src/module.cc",
22-
"src/property.cc",
2322
"src/osi_module.cc",
23+
"src/property.cc",
2424
]
2525

2626
include_dirs = [
2727
"include",
2828
"//bt",
2929
]
3030

31-
configs += [
32-
"//bt:target_defaults",
33-
]
31+
configs += [ "//bt:target_defaults" ]
3432

3533
deps = [
3634
"//bt/gd/rust/shim:init_flags_bridge_header",
@@ -41,9 +39,9 @@ static_library("btcore") {
4139
if (use.test) {
4240
executable("net_test_btcore") {
4341
sources = [
42+
"//bt/osi/test/AllocationTestHarness.cc",
4443
"test/device_class_test.cc",
4544
"test/property_test.cc",
46-
"//bt/osi/test/AllocationTestHarness.cc",
4745
]
4846

4947
include_dirs = [

system/btif/BUILD.gn

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,36 @@
1616

1717
static_library("btif") {
1818
sources = [
19+
# TODO(abps) - Do we need this?
1920
"//bt/audio_a2dp_hw/src/audio_a2dp_hw_utils.cc",
2021
"//bt/audio_hearing_aid_hw/src/audio_hearing_aid_hw_utils.cc",
22+
23+
# AVRCP Target Service
2124
"avrcp/avrcp_service.cc",
25+
"co/bta_av_co.cc",
26+
27+
# Callouts
28+
"co/bta_dm_co.cc",
29+
"co/bta_gatts_co.cc",
30+
"co/bta_hh_co.cc",
31+
"co/bta_pan_co.cc",
32+
33+
# HAL layer
34+
"src/bluetooth.cc",
35+
36+
# BTIF implementation
2237
"src/btif_a2dp.cc",
38+
39+
# "TODO(abps) - Move this abstraction elsewhere
40+
# "src/btif_a2dp_audio_interface.cc",
2341
"src/btif_a2dp_audio_interface_linux.cc",
2442
"src/btif_a2dp_control.cc",
2543
"src/btif_a2dp_sink.cc",
26-
# "src/btif_a2dp_source.cc",
44+
"src/btif_a2dp_source.cc",
2745
"src/btif_av.cc",
2846

29-
#TODO(jpawlowski): heavily depends on Android,
30-
# "src/btif_avrcp_audio_track.cc",
47+
# TODO(abps) - Move this abstraction elsewhere
48+
# "src/btif_avrcp_audio_track.cc",
3149
"src/btif_avrcp_audio_track_linux.cc",
3250
"src/btif_ble_advertiser.cc",
3351
"src/btif_ble_scanner.cc",
@@ -70,15 +88,6 @@ static_library("btif") {
7088
"src/stack_manager.cc",
7189
]
7290

73-
# BTIF callouts
74-
sources += [
75-
"co/bta_av_co.cc",
76-
"co/bta_dm_co.cc",
77-
"co/bta_gatts_co.cc",
78-
"co/bta_hh_co.cc",
79-
"co/bta_pan_co.cc",
80-
]
81-
8291
include_dirs = [
8392
"include",
8493
"//bt/",

system/common/BUILD.gn

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
static_library("common") {
1818
sources = [
1919
"address_obfuscator.cc",
20-
"once_timer.cc",
2120
"message_loop_thread.cc",
2221
"metric_id_allocator.cc",
2322
"metrics_linux.cc",
23+
"once_timer.cc",
24+
"os_utils.cc",
2425
"repeating_timer.cc",
2526
"time_util.cc",
2627
]
@@ -37,9 +38,7 @@ static_library("common") {
3738
"//bt/third_party/proto_logging/stats:libbt-platform-protos",
3839
]
3940

40-
configs += [
41-
"//bt:target_defaults",
42-
]
41+
configs += [ "//bt:target_defaults" ]
4342
}
4443

4544
if (use.test) {
@@ -55,9 +54,7 @@ if (use.test) {
5554
"//bt/common",
5655
]
5756

58-
deps = [
59-
"//bt/common",
60-
]
57+
deps = [ "//bt/common" ]
6158

6259
configs += [
6360
"//bt:external_gtest_main",

system/embdrv/g722/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ static_library("g722") {
1919
"g722_decode.cc",
2020
"g722_encode.cc",
2121
]
22+
23+
defines = [ "G722_SUPPORT_MALLOC" ]
24+
configs += [ "//bt:target_defaults" ]
2225
}

system/gd/Android.bp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ cc_defaults {
2323
},
2424
host: {
2525
cflags: [
26-
"-DOS_LINUX",
2726
"-DOS_LINUX_GENERIC",
2827
],
2928
},

0 commit comments

Comments
 (0)