Skip to content

Commit

Permalink
Linux: Dynamically load libudev.
Browse files Browse the repository at this point in the history
Funnel all libudev access through a wrapper for the udev library loader.

BUG=415212

Review URL: https://codereview.chromium.org/674703002

Cr-Commit-Position: refs/heads/master@{#305348}
  • Loading branch information
leizleiz authored and Commit bot committed Nov 22, 2014
1 parent 727ab04 commit ee816c2
Show file tree
Hide file tree
Showing 53 changed files with 1,388 additions and 261 deletions.
72 changes: 37 additions & 35 deletions build/config/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import("//build/config/sysroot.gni")
import("//build/config/ui.gni")
import("//tools/generate_library_loader/generate_library_loader.gni")

gypi_values = exec_script(
"//build/gypi_to_gn.py",
[ rebase_path("../../linux/system.gyp") ],
"scope",
[ "../../linux/system.gyp" ])

config("sdk") {
if (sysroot != "") {
cflags = [ "--sysroot=" + sysroot ]
Expand Down Expand Up @@ -47,10 +53,6 @@ pkg_config("pangoft2") {
packages = [ "pangoft2" ]
}

pkg_config("udev") {
packages = [ "libudev" ]
}

# Note: if your target also depends on //dbus, you don't need to add this
# config (it will get added automatically if you depend on //dbus).
pkg_config("dbus") {
Expand Down Expand Up @@ -140,19 +142,7 @@ if (use_brlapi) {
header = "<brlapi.h>"
config = ":brlapi_config"

functions = [
"brlapi_getHandleSize",
"brlapi_error_location",
"brlapi_strerror",
"brlapi__acceptKeys",
"brlapi__openConnection",
"brlapi__closeConnection",
"brlapi__getDisplaySize",
"brlapi__enterTtyModeWithPath",
"brlapi__leaveTtyMode",
"brlapi__writeDots",
"brlapi__readKey",
]
functions = gypi_values.libbrlapi_functions
}
}

Expand All @@ -166,7 +156,7 @@ pkg_config("gio_config") {
# (saucy) and earlier. Update the code to use
# g_settings_schema_source_list_schemas instead.
defines = [ "USE_GIO", "GLIB_DISABLE_DEPRECATION_WARNINGS" ]

# TODO(brettw) Theoretically I think ignore_libs should be set so that we
# don't link directly to GIO and use the loader generated below. But the gio
# target in GYP doesn't make any sense to me and appears to link directly to
Expand All @@ -183,15 +173,7 @@ generate_library_loader("gio") {
header = "<gio/gio.h>"
config = ":gio_config"

functions = [
"g_settings_new",
"g_settings_get_child",
"g_settings_get_string",
"g_settings_get_boolean",
"g_settings_get_int",
"g_settings_get_strv",
"g_settings_list_schemas",
]
functions = gypi_values.libgio_functions
}

# This generates a target named "libpci".
Expand All @@ -201,14 +183,34 @@ generate_library_loader("libpci") {
output_cc = "libpci_loader.cc"
header = "<pci/pci.h>"

functions = [
"pci_alloc",
"pci_init",
"pci_cleanup",
"pci_scan_bus",
"pci_fill_info",
"pci_lookup_name",
]
functions = gypi_values.libpci_functions
}

# Looking for libspeechd? Use //third_party/speech-dispatcher

# This generates a target named "udev0_loader".
generate_library_loader("udev0_loader") {
name = "LibUdev0Loader"
output_h = "libudev0.h"
output_cc = "libudev0_loader.cc"
header = "\"third_party/libudev/libudev0.h\""

functions = gypi_values.libudev_functions
}

# This generates a target named "udev1_loader".
generate_library_loader("udev1_loader") {
name = "LibUdev1Loader"
output_h = "libudev1.h"
output_cc = "libudev1_loader.cc"
header = "\"third_party/libudev/libudev1.h\""

functions = gypi_values.libudev_functions
}

group("udev") {
deps = [
":udev0_loader",
":udev1_loader",
]
}
163 changes: 125 additions & 38 deletions build/linux/system.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,69 @@
'linux_link_libpci%': 0,
'linux_link_libspeechd%': 0,
'linux_link_libbrlapi%': 0,

# Used below for the various libraries. In this scope for sharing with GN.
'libbrlapi_functions': [
'brlapi_getHandleSize',
'brlapi_error_location',
'brlapi_strerror',
'brlapi__acceptKeys',
'brlapi__openConnection',
'brlapi__closeConnection',
'brlapi__getDisplaySize',
'brlapi__enterTtyModeWithPath',
'brlapi__leaveTtyMode',
'brlapi__writeDots',
'brlapi__readKey',
],
'libgio_functions': [
'g_settings_new',
'g_settings_get_child',
'g_settings_get_string',
'g_settings_get_boolean',
'g_settings_get_int',
'g_settings_get_strv',
'g_settings_list_schemas',
],
'libpci_functions': [
'pci_alloc',
'pci_init',
'pci_cleanup',
'pci_scan_bus',
'pci_fill_info',
'pci_lookup_name',
],
'libudev_functions': [
'udev_device_get_action',
'udev_device_get_devnode',
'udev_device_get_parent',
'udev_device_get_parent_with_subsystem_devtype',
'udev_device_get_property_value',
'udev_device_get_subsystem',
'udev_device_get_sysattr_value',
'udev_device_get_sysname',
'udev_device_get_syspath',
'udev_device_new_from_devnum',
'udev_device_new_from_syspath',
'udev_device_unref',
'udev_enumerate_add_match_subsystem',
'udev_enumerate_get_list_entry',
'udev_enumerate_new',
'udev_enumerate_scan_devices',
'udev_enumerate_unref',
'udev_list_entry_get_next',
'udev_list_entry_get_name',
'udev_monitor_enable_receiving',
'udev_monitor_filter_add_match_subsystem_devtype',
'udev_monitor_get_fd',
'udev_monitor_new_from_netlink',
'udev_monitor_receive_device',
'udev_monitor_unref',
'udev_new',
'udev_set_log_fn',
'udev_set_log_priority',
'udev_unref',
],
},
'conditions': [
[ 'chromeos==0 and use_ozone==0', {
Expand Down Expand Up @@ -445,22 +508,67 @@
'targets': [
{
'target_name': 'udev',
'type': 'none',
'type': 'static_library',
'conditions': [
['_toolset=="target"', {
'direct_dependent_settings': {
'cflags': [
'<!@(<(pkg-config) --cflags libudev)'
],
},
'link_settings': {
'ldflags': [
'<!@(<(pkg-config) --libs-only-L --libs-only-other libudev)',
],
'libraries': [
'<!@(<(pkg-config) --libs-only-l libudev)',
],
},
'include_dirs': [
'../..',
],
'hard_dependency': 1,
'actions': [
{
'variables': {
'output_h': '<(SHARED_INTERMEDIATE_DIR)/library_loaders/libudev0.h',
'output_cc': '<(INTERMEDIATE_DIR)/libudev0_loader.cc',
'generator': '../../tools/generate_library_loader/generate_library_loader.py',
},
'action_name': 'generate_libudev0_loader',
'inputs': [
'<(generator)',
],
'outputs': [
'<(output_h)',
'<(output_cc)',
],
'action': ['python',
'<(generator)',
'--name', 'LibUdev0Loader',
'--output-h', '<(output_h)',
'--output-cc', '<(output_cc)',
'--header', '"third_party/libudev/libudev0.h"',
'--link-directly=0',
'<@(libudev_functions)',
],
'message': 'Generating libudev0 library loader',
'process_outputs_as_sources': 1,
},
{
'variables': {
'output_h': '<(SHARED_INTERMEDIATE_DIR)/library_loaders/libudev1.h',
'output_cc': '<(INTERMEDIATE_DIR)/libudev1_loader.cc',
'generator': '../../tools/generate_library_loader/generate_library_loader.py',
},
'action_name': 'generate_libudev1_loader',
'inputs': [
'<(generator)',
],
'outputs': [
'<(output_h)',
'<(output_cc)',
],
'action': ['python',
'<(generator)',
'--name', 'LibUdev1Loader',
'--output-h', '<(output_h)',
'--output-cc', '<(output_cc)',
'--header', '"third_party/libudev/libudev1.h"',
'--link-directly=0',
'<@(libudev_functions)',
],
'message': 'Generating libudev1 library loader',
'process_outputs_as_sources': 1,
},
],
}],
],
},
Expand Down Expand Up @@ -520,12 +628,7 @@
# and get it fixed so that we don't need --use-extern-c.
'--use-extern-c',
'--link-directly=<(linux_link_libpci)',
'pci_alloc',
'pci_init',
'pci_cleanup',
'pci_scan_bus',
'pci_fill_info',
'pci_lookup_name',
'<@(libpci_functions)',
],
'message': 'Generating libpci library loader',
'process_outputs_as_sources': 1,
Expand Down Expand Up @@ -706,13 +809,7 @@
'--output-cc', '<(output_cc)',
'--header', '<gio/gio.h>',
'--link-directly=<(linux_link_gsettings)',
'g_settings_new',
'g_settings_get_child',
'g_settings_get_string',
'g_settings_get_boolean',
'g_settings_get_int',
'g_settings_get_strv',
'g_settings_list_schemas',
'<@(libgio_functions)',
],
'message': 'Generating libgio library loader',
'process_outputs_as_sources': 1,
Expand Down Expand Up @@ -882,17 +979,7 @@
'--output-cc', '<(output_cc)',
'--header', '<brlapi.h>',
'--link-directly=<(linux_link_libbrlapi)',
'brlapi_getHandleSize',
'brlapi_error_location',
'brlapi_strerror',
'brlapi__acceptKeys',
'brlapi__openConnection',
'brlapi__closeConnection',
'brlapi__getDisplaySize',
'brlapi__enterTtyModeWithPath',
'brlapi__leaveTtyMode',
'brlapi__writeDots',
'brlapi__readKey',
'<@(libbrlapi_functions)',
],
'message': 'Generating libbrlapi library loader',
'process_outputs_as_sources': 1,
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,10 @@ static_library("browser") {
}

if (is_linux) {
configs += [ "//build/config/linux:udev" ]
deps += [ "//device/media_transfer_protocol" ]
deps += [
"//device/media_transfer_protocol",
"//device/udev_linux"
]
}
if (is_linux && !is_chromeos) {
deps += [ "//third_party/speech-dispatcher" ]
Expand Down
Loading

0 comments on commit ee816c2

Please sign in to comment.