Commit 0ed2b6ca authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Generate more complete GN target names for FIDL packages.

FIDL package names consist of multiple dot-delimited segments, to allow
scoping of packages to avoid clashes. Our GN generator script was using
only the final segment of each package's name, resulting in clashes,
e.g. between fuchsia.auth and fuchsia.modular.auth, if both were
present in the SDK.

We continue to generate targets under the //third_party/fuchsia-sdk/sdk
namespace, but use the full name rather than only the final segment,
e.g. custom.modular.auth would become custom_modular_auth.

We also special-case the top-level "fuchsia" namespace to be ignored,
e.g. fuchsia.modular_auth becomes just modular_auth.

Bug: 910670
Change-Id: I675d894c72b5d43b6d8b20fb026075573a5a3380
Reviewed-on: https://chromium-review.googlesource.com/c/1372892
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615763}
parent e918a7d9
......@@ -21,6 +21,16 @@ import("//third_party/fuchsia-sdk/fuchsia_sdk_pkg.gni")
"""
# TODO(910670): Clean up Chromium fidl_deps and remove this.
_PROVIDE_LEGACY_FIDL_TARGET_NAMES = [
"fuchsia.ui.gfx",
"fuchsia.ui.input",
"fuchsia.ui.policy",
"fuchsia.ui.scenic",
"fuchsia.ui.viewsv1",
"fuchsia.ui.viewsv1token",
"zircon.ethernet",
]
def SerializeListOfStrings(strings):
"""Outputs a list of strings in GN-friendly, double-quoted format."""
......@@ -31,11 +41,13 @@ def ReformatTargetName(dep_name):
"""Removes the namespace from |target| and substitutes invalid target
characters with valid ones (e.g. hyphens become underscores)."""
return dep_name.split('.')[-1].replace('-','_')
assert not '.' in dep_name, "Invalid target name: %s" % dep_name
reformatted_name = dep_name.replace('-','_')
return reformatted_name
def ConvertCommonFields(json):
"""Extracts fields from JSON manifest data which are used across all
target types."""
target types. Note that FIDL packages do their own processing."""
return {
'target_name': ReformatTargetName(json['name']),
......@@ -72,6 +84,19 @@ def FormatGNTarget(fields):
return output
def ReformatFidlTargetName(dep_name):
"""Converts a FIDL |dep_name| consisting of dot-delimited namespaces, and
package name, to a single underscore delimited name."""
assert not '-' in dep_name, "Invalid FIDL target name: %s" % dep_name
# For convenience, treat "fuchsia.*" namespace as top-level.
if dep_name[:8] == 'fuchsia.':
dep_name = dep_name[8:]
reformatted_name = dep_name.replace('.','_')
return reformatted_name
def ConvertFidlLibrary(json):
"""Converts a fidl_library manifest entry to a GN target.
......@@ -80,14 +105,18 @@ def ConvertFidlLibrary(json):
Returns:
The GN target definition, represented as a string."""
converted = ConvertCommonFields(json)
converted['type'] = 'fuchsia_sdk_fidl_pkg'
converted['sources'] = json['sources']
converted = {
'public_deps': [
':' + ReformatFidlTargetName(dep) for dep in json['deps']],
'sources': json['sources'],
'target_name': ReformatFidlTargetName(json['name']),
'type': 'fuchsia_sdk_fidl_pkg'
}
# FIDL names require special handling, because the namespace needs to be
# extracted and used elsewhere.
# 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['target_name'] = name_parts[-1]
converted['package_name'] = name_parts[-1]
converted['namespace'] = '.'.join(name_parts[:-1])
return converted
......@@ -130,7 +159,7 @@ def ConvertCcSourceLibrary(json):
converted['include_dirs'] = [json['root'] + '/include']
converted['public_deps'] += \
[':' + ReformatTargetName(dep) for dep in json['fidl_deps']]
[':' + ReformatFidlTargetName(dep) for dep in json['fidl_deps']]
return converted
......@@ -147,6 +176,7 @@ _CONVERSION_FUNCTION_MAP = {
'cc_prebuilt_library': ConvertCcPrebuiltLibrary,
# No need to build targets for these types yet.
'dart_library': ConvertNoOp,
'host_tool': ConvertNoOp,
'image': ConvertNoOp,
'loadable_module': ConvertNoOp,
......@@ -164,6 +194,16 @@ def ConvertSdkManifests():
with open(build_output_path, 'w') as buildfile:
buildfile.write(_GENERATED_PREAMBLE)
# TODO(910670): Clean up Chromium fidl_deps and remove this.
for fidl_name in _PROVIDE_LEGACY_FIDL_TARGET_NAMES:
new_target_name = ReformatFidlTargetName(fidl_name)
old_target_name = fidl_name.split('.')[-1]
buildfile.write("""
group("%s") {
public_deps = [ ":%s" ]
}
""" % (old_target_name, new_target_name))
for next_part in toplevel_meta['parts']:
parsed = json.load(open(os.path.join(sdk_base_dir, next_part)))
if 'type' not in parsed:
......
......@@ -103,8 +103,8 @@ source_set("webrunner_common") {
deps = [
":web_fidl",
"//base",
"//third_party/fuchsia-sdk/sdk:app",
"//third_party/fuchsia-sdk/sdk:viewsv1",
"//third_party/fuchsia-sdk/sdk:ui_app",
"//third_party/fuchsia-sdk/sdk:ui_viewsv1",
"//url",
]
public_deps = [
......@@ -342,9 +342,9 @@ fidl_library("web_fidl") {
]
public_deps = [
"//third_party/fuchsia-sdk/sdk:gfx",
"//third_party/fuchsia-sdk/sdk:sys",
"//third_party/fuchsia-sdk/sdk:viewsv1token",
"//third_party/fuchsia-sdk/sdk:ui_gfx",
"//third_party/fuchsia-sdk/sdk:ui_viewsv1token",
]
}
......
......@@ -20,7 +20,7 @@ source_set("http_lib") {
public_deps = [
"//base:base",
"//net:net",
"//third_party/fuchsia-sdk/sdk:oldhttp",
"//third_party/fuchsia-sdk/sdk:net_oldhttp",
"//third_party/fuchsia-sdk/sdk:sys",
]
}
......
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