Commit 441ccbcb authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Make namespace parameter in fidl_library GN template optional

Previously fidl_library GN template required namespace parameter. It was
separate from library_name mainly to workaround the lack of
string_replace() function in GN. But that's not a problem anymore. This
change updates fidl_library template to make namespace parameter
optional. Now library_name can contain complete name of a FIDL library,
e.g. "fuchsia.ui.gfx". namespace is still supported and works as before.

Also updated all FIDL targets to specify namespace as part of
library_name.

Bug: 1050252
Change-Id: I3de83e244b3ef32449e170f06933beb58198aa0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2045000
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740475}
parent 1c445a88
......@@ -2433,7 +2433,7 @@ if (is_ios || is_mac) {
if (is_fuchsia) {
fidl_library("testfidl") {
namespace = "base.fuchsia"
library_name = "base.fuchsia.testfidl"
sources = [ "fuchsia/test.fidl" ]
}
......
......@@ -11,7 +11,8 @@ assert(is_fuchsia)
# 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 - (optional) Namespace that should be prepended to
# |library_name|.
# deps - (optional) List of other fidl_library() targets that this
# FIDL library depends on.
# languages - Generate bindings for the given languages, defaults to
......@@ -21,26 +22,19 @@ assert(is_fuchsia)
# files.
template("fidl_library") {
forward_variables_from(invoker,
[
"languages",
"namespace",
])
forward_variables_from(invoker, [ "languages" ])
_library_basename = target_name
_library_name = target_name
if (defined(invoker.library_name)) {
_library_basename = invoker.library_name
_library_name = invoker.library_name
}
if (defined(namespace)) {
_library_name = "${namespace}.${_library_basename}"
_namespace_path = string_replace(namespace, ".", "/")
_library_path = "${_namespace_path}/${_library_basename}"
} else {
_library_name = _library_basename
_library_path = _library_basename
if (defined(invoker.namespace)) {
_library_name = "${invoker.namespace}.${_library_name}"
}
_library_path = string_replace(_library_name, ".", "/")
if (!defined(invoker.languages)) {
languages = [ "cpp" ]
}
......
......@@ -9,8 +9,7 @@ import("//build/config/fuchsia/fidl_library.gni")
import("//fuchsia/release_channel.gni")
fidl_library("cast_fidl") {
library_name = "cast"
namespace = "chromium"
library_name = "chromium.cast"
sources = [
"fidl/cast/api_bindings.fidl",
......
......@@ -5,7 +5,6 @@
assert(is_fuchsia)
import("//build/buildflag_header.gni")
import("//build/config/fuchsia/fidl_library.gni")
import("//build/config/fuchsia/generate_runner_scripts.gni")
import("//fuchsia/release_channel.gni")
import("//testing/test.gni")
......
......@@ -4,7 +4,6 @@
assert(is_fuchsia)
import("//build/config/fuchsia/fidl_library.gni")
import("//build/config/fuchsia/generate_runner_scripts.gni")
import("//build/config/fuchsia/symbol_archive.gni")
import("//build/util/process_version.gni")
......
......@@ -12,32 +12,20 @@ import("//build/toolchain/toolchain.gni")
# Declares a package specifying FIDL files and its dependencies.
#
# Parameters:
# package_name - Name of the library. target_name is used if name
# is not specified explicitly.
# namespace - FIDL namespace.
# library_name - FIDL library name.
# sources - List of sources relative to sdk/fidl/${name}.
# deps - List of dependencies.
template("fuchsia_sdk_fidl_pkg") {
_package_name = target_name
if (defined(invoker.package_name)) {
_package_name = invoker.package_name
}
fidl_library(target_name) {
forward_variables_from(invoker,
[
"deps",
"library_name",
"public_deps",
"testonly",
"visibility",
])
library_name = _package_name
if (defined(invoker.namespace)) {
namespace = invoker.namespace
}
sources = invoker.sources
}
}
......
......@@ -84,12 +84,7 @@ def ConvertFidlLibrary(json):
converted = ConvertCommonFields(json)
converted['type'] = 'fuchsia_sdk_fidl_pkg'
converted['sources'] = json['sources']
# Override the package name & namespace, otherwise the rule will generate
# a top-level package with |target_name| as its directory name.
name_parts = json['name'].split('.')
converted['package_name'] = name_parts[-1]
converted['namespace'] = '.'.join(name_parts[:-1])
converted['library_name'] = json['name']
return converted
......
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