Commit 908d29ec authored by Wez's avatar Wez Committed by Commit Bot

[fuchsia] Generate FIDL package targets with fully qualified names.

Chromium's GN rules generator previous generated GN targets with names
based on the last part of FIDL library names. This could lead to target
name clashes, so switch to using fully-qualified target names.

To allow soft migration of [public_]deps targets are also emitted for
most of the old names, for now.

Bug: fuchsia:42135
Change-Id: Ic63f423bbe934ff346fda625eff1b060450f573b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1937767
Commit-Queue: Wez <wez@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719385}
parent 88e8166c
...@@ -18,7 +18,7 @@ fidl_library("cast_fidl") { ...@@ -18,7 +18,7 @@ fidl_library("cast_fidl") {
] ]
public_deps = [ public_deps = [
"//third_party/fuchsia-sdk/sdk:web", "//third_party/fuchsia-sdk/sdk:fuchsia-web",
] ]
} }
......
...@@ -27,11 +27,15 @@ def SerializeListOfStrings(strings): ...@@ -27,11 +27,15 @@ def SerializeListOfStrings(strings):
return '[' + ','.join(['"{}"'.format(s) for s in strings]) + ']' return '[' + ','.join(['"{}"'.format(s) for s in strings]) + ']'
def ReformatTargetName(dep_name): def ReformatTargetName(dep_name):
"""Removes the namespace from |target| and substitutes invalid target """"Substitutes characters in |dep_name| which are not valid in GN target
characters with valid ones (e.g. hyphens become underscores).""" names (e.g. dots become hyphens)."""
assert not '.' in dep_name, "Invalid target name: %s" % dep_name # TODO(fxb/42135): Remove this rewriting and use names already containing
# hyphens as-is.
reformatted_name = dep_name.replace('-','_') reformatted_name = dep_name.replace('-','_')
reformatted_name = reformatted_name.replace('.','-')
return reformatted_name return reformatted_name
def ConvertCommonFields(json): def ConvertCommonFields(json):
...@@ -40,7 +44,8 @@ def ConvertCommonFields(json): ...@@ -40,7 +44,8 @@ def ConvertCommonFields(json):
return { return {
'target_name': ReformatTargetName(json['name']), 'target_name': ReformatTargetName(json['name']),
'public_deps': [':' + ReformatTargetName(dep) for dep in json['deps']] 'public_deps': [':' + ReformatTargetName(dep) for dep in (
json['deps'] + json.get('fidl_deps', []))]
} }
def FormatGNTarget(fields): def FormatGNTarget(fields):
...@@ -73,19 +78,6 @@ def FormatGNTarget(fields): ...@@ -73,19 +78,6 @@ def FormatGNTarget(fields):
return output 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): def ConvertFidlLibrary(json):
"""Converts a fidl_library manifest entry to a GN target. """Converts a fidl_library manifest entry to a GN target.
...@@ -94,13 +86,9 @@ def ConvertFidlLibrary(json): ...@@ -94,13 +86,9 @@ def ConvertFidlLibrary(json):
Returns: Returns:
The GN target definition, represented as a string.""" The GN target definition, represented as a string."""
converted = { converted = ConvertCommonFields(json)
'public_deps': [ converted['type'] = 'fuchsia_sdk_fidl_pkg'
':' + ReformatFidlTargetName(dep) for dep in json['deps']], converted['sources'] = json['sources']
'sources': json['sources'],
'target_name': ReformatFidlTargetName(json['name']),
'type': 'fuchsia_sdk_fidl_pkg'
}
# Override the package name & namespace, otherwise the rule will generate # Override the package name & namespace, otherwise the rule will generate
# a top-level package with |target_name| as its directory name. # a top-level package with |target_name| as its directory name.
...@@ -151,8 +139,6 @@ def ConvertCcSourceLibrary(json): ...@@ -151,8 +139,6 @@ def ConvertCcSourceLibrary(json):
converted['sources'] = list(set(converted['sources'])) converted['sources'] = list(set(converted['sources']))
converted['include_dirs'] = [json['root'] + '/include'] converted['include_dirs'] = [json['root'] + '/include']
converted['public_deps'] += \
[':' + ReformatFidlTargetName(dep) for dep in json['fidl_deps']]
return converted return converted
...@@ -194,12 +180,32 @@ def ConvertSdkManifests(): ...@@ -194,12 +180,32 @@ def ConvertSdkManifests():
convert_function = _CONVERSION_FUNCTION_MAP.get(part['type']) convert_function = _CONVERSION_FUNCTION_MAP.get(part['type'])
if convert_function is None: if convert_function is None:
raise Exception('Unexpected SDK artifact type %s in %s.' % raise Exception('Unexpected SDK artifact type %s in %s.' %
(parsed['type'], part['meta'])) (part['type'], part['meta']))
converted = convert_function(parsed) converted = convert_function(parsed)
if converted: if converted:
buildfile.write(FormatGNTarget(converted) + '\n\n') buildfile.write(FormatGNTarget(converted) + '\n\n')
# TODO(fxb/42135): Remove this hack once dependencies have been updated.
# Create dummy targets using the old short names, which depend on the
# new fully-qualified names, to allow old dependencies to work.
if part['type'] == 'fidl_library':
target_name = ReformatTargetName(parsed['name'])
# Generate an old-style FIDL library target name, by stripping the
# "fuchsia-" prefix and replacing hyphens with underscores.
short_target_name = target_name[8:].replace('-', '_')
# fuchsia.inspect's short name clashes with the inspect source library.
if short_target_name == 'inspect':
continue
fields = {
'target_name' : short_target_name,
'type': 'group',
'public_deps': [ ':' + target_name]
}
buildfile.write(FormatGNTarget(fields) + '\n\n')
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(ConvertSdkManifests()) sys.exit(ConvertSdkManifests())
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