Commit 3d9e71e4 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Add FIDL namespaces support

Lack of namespace support in FIDL was breaking some libraries when
using them in chromium due to name conflicts. fidlgen now supports
namespaces. That change requires some updates in GN files because
fidlgen now assumes a different location for generated headers
(<namespace>/<name>/cpp/fidl.h instead of fuchsia/cpp/<name>.h).

1. Updated FIDL GN templates to support FIDL files with namespaces.
2. Updated existing FIDL deps in //base and //net.
3. Removed fuchsia/cpp from global include_rules.
4. Added SDK packages for Scenic in //third_party/fuchsia-sdk/BUILD.gn
5. Marked base::ServicesDirectory::GetDefault() static (was omitted
   initially by mistake).

Bug: 831384
Change-Id: Iabae4887733b4a78e3de6781069cf029bdcc8c92
Reviewed-on: https://chromium-review.googlesource.com/1068203
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560899}
parent 1e181731
...@@ -1305,9 +1305,6 @@ include_rules = [ ...@@ -1305,9 +1305,6 @@ include_rules = [
'+build', '+build',
'+ipc', '+ipc',
# FIDL (Fuchsia IDL) generates headers under fuchsia/cpp.
"+fuchsia/cpp",
# Everybody can use headers generated by tools/generate_library_loader. # Everybody can use headers generated by tools/generate_library_loader.
'+library_loaders', '+library_loaders',
......
...@@ -2125,6 +2125,9 @@ if (is_ios || is_mac) { ...@@ -2125,6 +2125,9 @@ if (is_ios || is_mac) {
if (is_fuchsia) { if (is_fuchsia) {
fidl_library("test_fidl") { fidl_library("test_fidl") {
namespace = "base.fuchsia"
namespace_path = "base/fuchsia"
sources = [ sources = [
"fuchsia/test.fidl", "fuchsia/test.fidl",
] ]
......
...@@ -42,7 +42,7 @@ class BASE_EXPORT ServicesDirectory { ...@@ -42,7 +42,7 @@ class BASE_EXPORT ServicesDirectory {
// Returns default ServiceDirectory instance for the current process. It // Returns default ServiceDirectory instance for the current process. It
// publishes services to the directory provided by the process creator. // publishes services to the directory provided by the process creator.
ServicesDirectory* GetDefault(); static ServicesDirectory* GetDefault();
void AddService(StringPiece name, ConnectServiceCallback connect_callback); void AddService(StringPiece name, ConnectServiceCallback connect_callback);
void RemoveService(StringPiece name); void RemoveService(StringPiece name);
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/fuchsia/component_context.h" #include "base/fuchsia/component_context.h"
#include "base/fuchsia/scoped_service_binding.h" #include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/test_fidl/cpp/fidl.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "fuchsia/cpp/test_fidl.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace base { namespace base {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
library test_fidl; library base.fuchsia.test_fidl;
[Discoverable] [Discoverable]
interface TestInterface { interface TestInterface {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "net/base/network_interfaces.h" #include "net/base/network_interfaces.h"
#include <fuchsia/cpp/netstack.h> #include <netstack/cpp/fidl.h>
#include "base/fuchsia/component_context.h" #include "base/fuchsia/component_context.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
......
...@@ -25,60 +25,40 @@ fuchsia_sdk_pkg("async") { ...@@ -25,60 +25,40 @@ fuchsia_sdk_pkg("async") {
# async-default keep a per-thread dispatcher for async. # async-default keep a per-thread dispatcher for async.
fuchsia_sdk_lib_pkg("async_default") { fuchsia_sdk_lib_pkg("async_default") {
name = "async-default" package_name = "async-default"
sources = [ sources = [
"include/lib/async/default.h", "include/lib/async/default.h",
] ]
} }
fuchsia_sdk_pkg("zx") { fuchsia_sdk_pkg("component") {
sources = [ fidl_files = [
"channel.cpp", "application_controller.fidl",
"event.cpp", "application_environment.fidl",
"eventpair.cpp", "application_environment_controller.fidl",
"fifo.cpp", "application_launcher.fidl",
"guest.cpp", "application_runner.fidl",
"include/lib/zx/bti.h", "flat_namespace.fidl",
"include/lib/zx/channel.h", "loader.fidl",
"include/lib/zx/event.h", "service_provider.fidl",
"include/lib/zx/eventpair.h",
"include/lib/zx/fifo.h",
"include/lib/zx/guest.h",
"include/lib/zx/handle.h",
"include/lib/zx/interrupt.h",
"include/lib/zx/job.h",
"include/lib/zx/log.h",
"include/lib/zx/object.h",
"include/lib/zx/object_traits.h",
"include/lib/zx/pmt.h",
"include/lib/zx/port.h",
"include/lib/zx/process.h",
"include/lib/zx/resource.h",
"include/lib/zx/socket.h",
"include/lib/zx/task.h",
"include/lib/zx/thread.h",
"include/lib/zx/time.h",
"include/lib/zx/timer.h",
"include/lib/zx/vmar.h",
"include/lib/zx/vmo.h",
"interrupt.cpp",
"job.cpp",
"log.cpp",
"port.cpp",
"process.cpp",
"resource.cpp",
"socket.cpp",
"thread.cpp",
"timer.cpp",
"vmar.cpp",
"vmo.cpp",
] ]
fidl_deps = [ ":mem" ]
} }
fuchsia_sdk_lib_pkg("launchpad") { fuchsia_sdk_lib_pkg("fdio") {
sources = [ sources = [
"include/launchpad/launchpad.h", "include/fdio/debug.h",
"include/launchpad/vmo.h", "include/fdio/io.fidl.h",
"include/fdio/io.h",
"include/fdio/limits.h",
"include/fdio/module.modulemap",
"include/fdio/namespace.h",
"include/fdio/private.h",
"include/fdio/remoteio.h",
"include/fdio/socket.h",
"include/fdio/util.h",
"include/fdio/vfs.h",
"include/fdio/watcher.h",
] ]
} }
...@@ -167,23 +147,79 @@ fuchsia_sdk_pkg("fidl_cpp") { ...@@ -167,23 +147,79 @@ fuchsia_sdk_pkg("fidl_cpp") {
] ]
} }
fuchsia_sdk_lib_pkg("fdio") { fuchsia_sdk_pkg("geometry") {
fidl_files = [ "geometry.fidl" ]
}
fuchsia_sdk_pkg("gfx") {
fidl_files = [
"commands.fidl",
"display_info.fidl",
"events.fidl",
"hit.fidl",
"nodes.fidl",
"renderer.fidl",
"resources.fidl",
"shapes.fidl",
"types.fidl",
]
fidl_deps = [ ":images" ]
}
fuchsia_sdk_pkg("images") {
fidl_files = [
"encoded_image.fidl",
"image_info.fidl",
"image_pipe.fidl",
"memory_type.fidl",
"presentation_info.fidl",
]
}
fuchsia_sdk_pkg("input") {
fidl_files = [
"ime_service.fidl",
"input_connection.fidl",
"input_device_registry.fidl",
"input_dispatcher.fidl",
"input_event_constants.fidl",
"input_events.fidl",
"input_reports.fidl",
"text_editing.fidl",
"text_input.fidl",
"usages.fidl",
]
}
fuchsia_sdk_lib_pkg("launchpad") {
sources = [ sources = [
"include/fdio/debug.h", "include/launchpad/launchpad.h",
"include/fdio/io.fidl.h", "include/launchpad/vmo.h",
"include/fdio/io.h", ]
"include/fdio/limits.h", }
"include/fdio/module.modulemap",
"include/fdio/namespace.h", fuchsia_sdk_pkg("media") {
"include/fdio/private.h", fidl_files = [
"include/fdio/remoteio.h", "audio_capturer.fidl",
"include/fdio/socket.h", "audio_renderer.fidl",
"include/fdio/util.h", "audio_server.fidl",
"include/fdio/vfs.h", "media_capturer.fidl",
"include/fdio/watcher.h", "media_renderer.fidl",
"media_result.fidl",
"media_transport.fidl",
"media_types.fidl",
"timeline_controller.fidl",
"timelines.fidl",
] ]
} }
fuchsia_sdk_pkg("mem") {
fidl_namespace = "fuchsia"
fidl_namespace_path = "fuchsia"
fidl_files = [ "buffer.fidl" ]
}
fuchsia_sdk_pkg("netstack") { fuchsia_sdk_pkg("netstack") {
fidl_files = [ fidl_files = [
"net_address.fidl", "net_address.fidl",
...@@ -191,8 +227,110 @@ fuchsia_sdk_pkg("netstack") { ...@@ -191,8 +227,110 @@ fuchsia_sdk_pkg("netstack") {
] ]
} }
fuchsia_sdk_pkg("presentation") {
fidl_files = [
"display_usage.fidl",
"presentation.fidl",
"presenter.fidl",
]
fidl_deps = [ ":views_v1" ]
}
fuchsia_sdk_lib_pkg("svc") { fuchsia_sdk_lib_pkg("svc") {
sources = [ sources = [
"include/lib/svc/dir.h", "include/lib/svc/dir.h",
] ]
} }
fuchsia_sdk_pkg("ui") {
fidl_files = [
"commands.fidl",
"events.fidl",
"scenic.fidl",
"session.fidl",
]
fidl_deps = [
":component",
":gfx",
":input",
":views",
]
}
fuchsia_sdk_pkg("views") {
fidl_files = [
"commands.fidl",
"events.fidl",
]
fidl_deps = [
":gfx",
":images",
]
}
fuchsia_sdk_pkg("views_v1") {
fidl_files = [
"view_containers.fidl",
"view_properties.fidl",
"views.fidl",
"view_tree_token.fidl",
"view_manager.fidl",
"view_provider.fidl",
"view_trees.fidl",
]
fidl_deps = [
":geometry",
":gfx",
":ui",
":images",
":views_v1_token",
]
}
fuchsia_sdk_pkg("views_v1_token") {
fidl_files = [ "view_token.fidl" ]
}
fuchsia_sdk_pkg("zx") {
sources = [
"channel.cpp",
"event.cpp",
"eventpair.cpp",
"fifo.cpp",
"guest.cpp",
"include/lib/zx/bti.h",
"include/lib/zx/channel.h",
"include/lib/zx/event.h",
"include/lib/zx/eventpair.h",
"include/lib/zx/fifo.h",
"include/lib/zx/guest.h",
"include/lib/zx/handle.h",
"include/lib/zx/interrupt.h",
"include/lib/zx/job.h",
"include/lib/zx/log.h",
"include/lib/zx/object.h",
"include/lib/zx/object_traits.h",
"include/lib/zx/pmt.h",
"include/lib/zx/port.h",
"include/lib/zx/process.h",
"include/lib/zx/resource.h",
"include/lib/zx/socket.h",
"include/lib/zx/task.h",
"include/lib/zx/thread.h",
"include/lib/zx/time.h",
"include/lib/zx/timer.h",
"include/lib/zx/vmar.h",
"include/lib/zx/vmo.h",
"interrupt.cpp",
"job.cpp",
"log.cpp",
"port.cpp",
"process.cpp",
"resource.cpp",
"socket.cpp",
"thread.cpp",
"timer.cpp",
"vmar.cpp",
"vmo.cpp",
]
}
...@@ -4,19 +4,52 @@ ...@@ -4,19 +4,52 @@
assert(is_fuchsia) assert(is_fuchsia)
# Template for FIDL libraries. Following parameters can be passed when
# instantiating this template:
# sources - List of .fidl files.
# library_name - (optional) Name of the library. target_name is used if name
# is not specified explicitly.
# namespace - (optional) Namespace for the library.
# namespace_path - (optional) namespace with '.' are replaced with '/', e.g.
# if namespace is "fuchsia.foo", then namespace_path must be
# set to "fuchsia/foo". This parameter must be specified when
# namespace is specified.
# TODO(sergeyu): In theory namespace_path can be generated
# from name, but GN doesn't provide any tools to perform this
# conversion without invoking a python script.
# deps - (optional) List of other fidl_library() targets that this
# FIDL library depends on.
#
# $namespace.$library_name must match the the library name specified in the FIDL
# files.
template("fidl_library") { template("fidl_library") {
pkg_name = target_name forward_variables_from(invoker,
[
"namespace",
"namespace_path",
])
_library_basename = target_name
if (defined(invoker.library_name)) {
_library_basename = invoker.library_name
}
pkg_name = target_name if (defined(namespace)) {
if (defined(invoker.name)) { assert(defined(namespace_path),
pkg_name = invoker.name "FIDL libraries with namespace must specify namespace_path")
_library_name = "${namespace}.${_library_basename}"
_library_path = "${namespace_path}/${_library_basename}"
} else {
_library_name = _library_basename
_library_path = _library_basename
} }
response_file = "$target_gen_dir/$target_name.rsp" _response_file = "$target_gen_dir/$target_name.rsp"
json_representation = "$target_gen_dir/$pkg_name.fidl.json" _json_representation = "$target_gen_dir/${_library_name}.fidl.json"
output_gen_base = "$target_gen_dir/fidl" _output_gen_dir = "$target_gen_dir/fidl"
output_gen_dir = "$output_gen_base/fuchsia/cpp" _output_base = "$_output_gen_dir/${_library_path}/cpp/fidl"
tables_file = "$output_gen_base/$pkg_name.fidl-tables.cc" _tables_file = "$_output_gen_dir/${_library_name}.fidl-tables.cc"
action("${target_name}_response_file") { action("${target_name}_response_file") {
visibility = [ ":*" ] visibility = [ ":*" ]
...@@ -31,24 +64,24 @@ template("fidl_library") { ...@@ -31,24 +64,24 @@ template("fidl_library") {
"testonly", "testonly",
]) ])
libraries_file = "$target_gen_dir/${invoker.target_name}.fidl_libraries" _libraries_file = "$target_gen_dir/${invoker.target_name}.fidl_libraries"
outputs = [ outputs = [
response_file, _response_file,
libraries_file, _libraries_file,
] ]
args = [ args = [
"--out-response-file", "--out-response-file",
rebase_path(response_file, root_build_dir), rebase_path(_response_file, root_build_dir),
"--out-libraries", "--out-libraries",
rebase_path(libraries_file, root_build_dir), rebase_path(_libraries_file, root_build_dir),
"--tables", "--tables",
rebase_path(tables_file, root_build_dir), rebase_path(_tables_file, root_build_dir),
"--json", "--json",
rebase_path(json_representation, root_build_dir), rebase_path(_json_representation, root_build_dir),
"--name", "--name",
pkg_name, _library_name,
"--sources", "--sources",
] + rebase_path(sources, root_build_dir) ] + rebase_path(sources, root_build_dir)
...@@ -91,15 +124,15 @@ template("fidl_library") { ...@@ -91,15 +124,15 @@ template("fidl_library") {
script = "//build/gn_run_binary.py" script = "//build/gn_run_binary.py"
inputs = [ inputs = [
response_file, _response_file,
] ]
outputs = [ outputs = [
json_representation, _json_representation,
tables_file, _tables_file,
] ]
rebased_response_file = rebase_path(response_file, root_build_dir) rebased_response_file = rebase_path(_response_file, root_build_dir)
args = [ args = [
rebase_path("//third_party/fuchsia-sdk/sdk/tools/fidlc", root_build_dir), rebase_path("//third_party/fuchsia-sdk/sdk/tools/fidlc", root_build_dir),
"@$rebased_response_file", "@$rebased_response_file",
...@@ -114,12 +147,12 @@ template("fidl_library") { ...@@ -114,12 +147,12 @@ template("fidl_library") {
] ]
inputs = [ inputs = [
json_representation, _json_representation,
] ]
outputs = [ outputs = [
"$output_gen_dir/$pkg_name.h", "${_output_base}.h",
"$output_gen_dir/$pkg_name.cc", "${_output_base}.cc",
] ]
script = "//build/gn_run_binary.py" script = "//build/gn_run_binary.py"
...@@ -129,17 +162,17 @@ template("fidl_library") { ...@@ -129,17 +162,17 @@ template("fidl_library") {
"-generators", "-generators",
"cpp", "cpp",
"-json", "-json",
rebase_path("$json_representation"), rebase_path(_json_representation),
"-include-base", "-include-base",
rebase_path("$output_gen_base"), rebase_path(_output_gen_dir),
"-output-base", "-output-base",
rebase_path("$output_gen_dir/$pkg_name"), rebase_path("${_output_base}"),
] ]
} }
config("${target_name}_config") { config("${target_name}_config") {
visibility = [ ":${invoker.target_name}" ] visibility = [ ":${invoker.target_name}" ]
include_dirs = [ output_gen_base ] include_dirs = [ _output_gen_dir ]
} }
source_set("${target_name}") { source_set("${target_name}") {
...@@ -152,9 +185,9 @@ template("fidl_library") { ...@@ -152,9 +185,9 @@ template("fidl_library") {
]) ])
sources = [ sources = [
"$output_gen_dir/$pkg_name.cc", "${_output_base}.cc",
"$output_gen_dir/$pkg_name.h", "${_output_base}.h",
tables_file, _tables_file,
] ]
if (!defined(deps)) { if (!defined(deps)) {
......
...@@ -6,19 +6,32 @@ assert(is_fuchsia) ...@@ -6,19 +6,32 @@ assert(is_fuchsia)
import("fidl_library.gni") import("fidl_library.gni")
template("fuchsia_sdk_pkg") { # Template for Fuchsia SDK packages. Each package may contain a mix of C++ files
pkg_name = target_name # and FIDL interfaces. The following parameters can be specified when
# instantiating this template:
# package_name - Name of the library. target_name is used if name
# is not specified explicitly.
# fidl_namespace, fidl_namespace_path - FIDL namespace. See fidl_library.gni
# for details.
# sources - List of sources relative to sdk/pkg/${name}.
# fidl_sources - List of .fidl files relative to
# sdk/fidl/${fidl_namespace}.${name}.
# public_deps - List of public dependencies which are propagated to
# dependents.
# deps - List of dependencies.
# fidl_deps - List of FIDL dependencies for this package (must be other
# fuchsia_sdk_pkg).
pkg_name = target_name template("fuchsia_sdk_pkg") {
if (defined(invoker.name)) { _package_name = target_name
pkg_name = invoker.name if (defined(invoker.package_name)) {
_package_name = invoker.package_name
} }
have_fidl = defined(invoker.fidl_files) _has_fidl_files = defined(invoker.fidl_files)
if (have_fidl) { if (_has_fidl_files) {
fidl_library("${target_name}_fidl") { fidl_library("${target_name}_fidl") {
name = pkg_name
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"public_deps", "public_deps",
...@@ -26,9 +39,23 @@ template("fuchsia_sdk_pkg") { ...@@ -26,9 +39,23 @@ template("fuchsia_sdk_pkg") {
"visibility", "visibility",
]) ])
library_name = _package_name
if (defined(invoker.fidl_namespace)) {
assert(
defined(invoker.fidl_namespace_path),
"SDK packages with fidl_namespace must specify fidl_namespace_path")
namespace = invoker.fidl_namespace
namespace_path = invoker.fidl_namespace_path
_library_name = "${namespace}.${_package_name}"
} else {
_library_name = _package_name
}
sources = [] sources = []
foreach(file, invoker.fidl_files) { foreach(file, invoker.fidl_files) {
sources += [ "sdk/fidl/${pkg_name}/${file}" ] sources += [ "sdk/fidl/${_library_name}/${file}" ]
} }
if (defined(invoker.fidl_deps)) { if (defined(invoker.fidl_deps)) {
...@@ -42,7 +69,7 @@ template("fuchsia_sdk_pkg") { ...@@ -42,7 +69,7 @@ template("fuchsia_sdk_pkg") {
config("${target_name}_config") { config("${target_name}_config") {
visibility = [ ":${invoker.target_name}" ] visibility = [ ":${invoker.target_name}" ]
include_dirs = [ "sdk/pkg/${pkg_name}/include" ] include_dirs = [ "sdk/pkg/${_package_name}/include" ]
} }
static_library("${target_name}") { static_library("${target_name}") {
...@@ -58,11 +85,11 @@ template("fuchsia_sdk_pkg") { ...@@ -58,11 +85,11 @@ template("fuchsia_sdk_pkg") {
sources = [] sources = []
if (defined(invoker.sources)) { if (defined(invoker.sources)) {
foreach(src, invoker.sources) { foreach(src, invoker.sources) {
sources += [ "sdk/pkg/${pkg_name}/${src}" ] sources += [ "sdk/pkg/${_package_name}/${src}" ]
} }
} }
if (have_fidl) { if (_has_fidl_files) {
public_deps = [ public_deps = [
":${invoker.target_name}_fidl", ":${invoker.target_name}_fidl",
] ]
...@@ -80,8 +107,8 @@ template("fuchsia_sdk_pkg") { ...@@ -80,8 +107,8 @@ template("fuchsia_sdk_pkg") {
template("fuchsia_sdk_lib_pkg") { template("fuchsia_sdk_lib_pkg") {
fuchsia_sdk_pkg(target_name) { fuchsia_sdk_pkg(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
if (defined(invoker.name)) { if (defined(invoker.package_name)) {
libs = [ invoker.name ] libs = [ invoker.package_name ]
} else { } else {
libs = [ target_name ] libs = [ target_name ]
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment