blob: 7902f614b7352694a6b9b4d5e0c0d4c3ef1cd6ff [file]
# Copyright 2025 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/python/python_binary.gni")
import("//build/testing/golden_files.gni")
import("//tools/fidl/fidlc/testdata/info.gni")
# TODO(https://fxbug.dev/308723467): In other fidlgen_* implementations, there is an associated
# "goldens" target that depends on each library of bindings generated. However,
# fidlgen_python relies on host test data that includes an IR for each FIDL
# library stored in a shared IR root path. Because many golden libraries have
# duplicate names, there is a conflict to write IRs with the same library name
# to the same IR root path.
#
# If you'd like to update the goldens, edit your `args.gn` to have
# `update_goldens=true` or run `fx set` with `--args="update_goldens=true"`.
# Then make sure to run
#
# `fx build --host //tools/fidl/fidlgen_python:tests`
#
# The tests aren't "run" they're just part of a build step.
golden_files("fidlgen_python_golden_tests") {
testonly = true
formatter = {
script = "//prebuilt/third_party/black/linux-x64/black"
args = [
"--quiet",
"-",
]
inputs = [
"//.gitignore",
"//pyproject.toml",
]
}
deps = []
comparisons = []
foreach(info, fidl_testdata_info) {
if (info.denylist + [ "fidlgen_python" ] - [ "fidlgen_python" ] ==
info.denylist) {
deps += [ "${info.target}_python_generate($fidl_toolchain)" ]
_library_underscore = string_replace(info.library, ".", "_")
comparisons += [
{
golden = "goldens/${info.name}.py.golden"
candidate = "${info.fidl_gen_dir}/${info.target_name}/python/fidl_${_library_underscore}/__init__.py"
},
]
}
}
# Add dynsuite as a golden since we can't otherwise test with it.
dynsuite_label = "//src/tests/fidl/dynsuite/client_suite/fidl:fidl.clientsuite_python_generate($fidl_toolchain)"
deps += [ dynsuite_label ]
comparisons += [
{
golden = "goldens/clientsuite.py.golden"
candidate = get_label_info("${dynsuite_label}", "target_gen_dir") +
"/fidl.clientsuite/python/fidl_fidl_clientsuite/__init__.py"
},
]
}
# [START describe_host_example_build_target]
python_binary("describe_host_example") {
testonly = true
main_source = "examples/describe_host.py"
deps = [
"//sdk/fidl/fuchsia.buildinfo:fuchsia.buildinfo_python",
"//sdk/fidl/fuchsia.developer.remotecontrol:fuchsia.developer.remotecontrol_python",
"//src/developer/ffx:host",
]
}
# [END describe_host_example_build_target]
python_binary("bindings_example") {
testonly = true
main_source = "examples/bindings.py"
deps = [
"//tools/fidl/fidlc/testdata:test.bits_python",
"//tools/fidl/fidlc/testdata:test.struct_python",
"//tools/fidl/fidlc/testdata:test.table_python",
"//tools/fidl/fidlc/testdata:test.union_python",
]
}
group("examples") {
testonly = true
deps = [
":bindings_example",
":describe_host_example",
]
}
group("tests") {
testonly = true
deps = [
":examples($host_toolchain)",
":fidlgen_python_golden_tests($host_toolchain)",
"tests:fidlgen_python_client_test($host_toolchain)",
"tests:fidlgen_python_const_test($host_toolchain)",
"tests:fidlgen_python_external_library_test($host_toolchain)",
"tests:fidlgen_python_protocol_compile_test($host_toolchain)",
"tests:fidlgen_python_reserved_names_test($host_toolchain)",
"tests:fidlgen_python_server_and_event_handler_test($host_toolchain)",
"tests:fidlgen_python_union_test($host_toolchain)",
]
}