#!/usr/bin/env vpython3 # Copyright 2023 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # # Generates a single BUILD.gn file with build targets generated using the # manifest files in the SDK.
# TODO(b/40935282): Likely this file should belong to the # //third_party/fuchsia-gn-sdk/ instead of //build/fuchsia/.
# Inserted at the top of the generated BUILD.gn file.
_GENERATED_PREAMBLE = f"""# DO NOT EDIT! This file was generated by # //build/fuchsia/gen_build_def.py. # Any changes made to this file will be discarded.
def ReformatTargetName(dep_name): """"Substitutes characters in |dep_name| which are not valid in GN target
names (e.g. dots become hyphens).""" return dep_name
def FormatGNTarget(fields): """Returns a GN target definition as a string.
|fields|: The GN fields to include in the target body. 'target_name'and'type' are mandatory."""
output = '%s("%s") {\n' % (fields['type'], fields['target_name']) del fields['target_name'] del fields['type']
# Ensure that fields with no ordering requirement are sorted. for field in ['sources', 'public_deps']: if field in fields:
fields[field].sort()
for key, val in fields.items(): if isinstance(val, str):
val_serialized = '\"%s\"' % val elif isinstance(val, list): # Serialize a list of strings in the prettiest possible manner. if len(val) == 0:
val_serialized = '[]' elif len(val) == 1:
val_serialized = '[ \"%s\" ]' % val[0] else:
val_serialized = '[\n ' + ',\n '.join(['\"%s\"' % x for x in val]) + '\n ]' else: raise Exception('Could not serialize %r' % val)
def MetaRootRelativePaths(sdk_relative_paths, meta_root): return [os.path.relpath(path, meta_root) for path in sdk_relative_paths]
def ConvertCommonFields(json): """Extracts fields from JSON manifest data which are used across all
target types. Note that FIDL packages do their own processing."""
# FIDL bindings dependencies are relative to the "fidl" sub-directory. if'fidl_binding_deps'in json: for entry in json['fidl_binding_deps']:
converted['public_deps'] += MetaRootRelativePaths([ 'fidl/' + dep + ':' + os.path.basename(dep) + '_' +
entry['binding_type'] for dep in entry['deps']
], meta_root)
return converted
def ConvertFidlLibrary(json): """Converts a fidl_library manifest entry to a GN target.
Arguments:
json: The parsed manifest JSON.
Returns:
The GN target definition, represented as a string."""
# Headers and source file paths can be scattered across "sources", "headers", # and "files". Merge them together into one source list.
converted['sources'] = MetaRootRelativePaths(json['sources'], meta_root) if'headers'in json:
converted['sources'] += MetaRootRelativePaths(json['headers'], meta_root) if'files'in json:
converted['sources'] += MetaRootRelativePaths(json['files'], meta_root)
converted['sources'] = list(set(converted['sources']))
# Pair each json resource with its corresponding binary. Each such pair # is a "layer". We only need to check one arch because each arch has the # same list of binaries.
arch = next(iter(binaries))
binary_names = binaries[arch]
local_pkg = json['root']
vulkan_targets = []
for res in resources:
layer_name = _filename_no_ext(res)
# Filter binaries for a matching name.
filtered = [n for n in binary_names if _filename_no_ext(n) == layer_name]
ifnot filtered: # If the binary could not be found then do not generate a # target for this layer. The missing targets will cause a # mismatch with the "golden" outputs. continue
# Replace hardcoded arch in the found binary filename.
binary = filtered[0].replace('/' + arch + '/', '/${target_cpu}/')
# Extrapolate the manifest_file's path from the first variant, assuming that # they all follow the same format.
variant = json['variants'][0]
replace_pattern = '/%s-api-%s/' % (variant['arch'], variant['api_level'])
segments = variant['manifest_file'].split(replace_pattern) if len(segments) != 2: raise RuntimeError('Unsupported pattern: %s' % variant['manifest_file'])
converted['manifest_file'] = \ '/${target_cpu}-api-${fuchsia_target_api_level}/'.join(segments)
return converted
def ConvertNoOp(*_): """Null implementation of a conversion function. No output is generated."""
for part in toplevel_meta['parts']:
meta_path = os.path.join(SDK_ROOT, part['meta'])
ConvertMeta(meta_path)
def main():
# Exit if there's no Fuchsia support for this platform. try:
get_host_os() except:
logging.warning('Fuchsia SDK is not supported on this platform.') return0
# TODO(crbug.com/42050591): Remove this when links to these files inside the # sdk directory have been redirected.
build_path = os.path.join(SDK_ROOT, 'build')
os.makedirs(build_path, exist_ok=True) for gn_file in ['component.gni', 'package.gni']:
open(os.path.join(build_path, gn_file), 'w').write("""# DO NOT EDIT! This file was generated by # //build/fuchsia/gen_build_def.py. # Any changes made to this file will be discarded.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.