| # Copyright 2026 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. |
| |
| # Run mypy for a given target, whether binary or library |
| # |
| # Parameters |
| # |
| # target_type (required) |
| # Indicates if this is a binary or a library target |
| # Type: string (valid values: "library", "binary") |
| # |
| # library_infos (required) |
| # The target that generates a json file with all the library dependency info |
| # Type: GN target label |
| # |
| # sources (required) |
| # The list of python source files in the library or binary |
| # Type: list of GN file paths |
| # |
| # Binary-specific parameters: |
| # |
| # data_package_name (optional) |
| # The name of the python package for data files |
| # Type: string |
| # |
| # data_sources (optional) |
| # The source files to add to the data package. Requires 'data_package_name'. |
| # Type: list of GN file paths |
| # |
| # GN usual (optional): |
| # assert_no_deps |
| # deps |
| # testonly |
| # visibility |
| # |
| template("validate_python") { |
| _library_infos_target_outputs = get_target_outputs(invoker.library_infos) |
| _library_infos_file = _library_infos_target_outputs[0] |
| |
| action(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "assert_no_deps", |
| "testonly", |
| "visibility", |
| ]) |
| inputs = [ |
| "//pyproject.toml", |
| "//build/python/package_python_binary.py", |
| _library_infos_file, |
| ] + invoker.sources |
| |
| script = "//build/python/mypy_checker.py" |
| outputs = [ "${target_out_dir}/${target_name}.mypy_checked" ] |
| depfile = "${target_out_dir}/${target_name}.d" |
| mnemonic = "MYPY" |
| args = [ |
| "--target_type", |
| invoker.target_type, |
| "--target_name", |
| target_name, |
| "--library_infos", |
| rebase_path(_library_infos_file, root_build_dir), |
| "--gen_dir", |
| rebase_path(target_gen_dir, root_build_dir), |
| "--depfile", |
| rebase_path(depfile, root_build_dir), |
| "--output", |
| rebase_path(outputs[0], root_build_dir), |
| ] |
| |
| if (invoker.target_type == "binary") { |
| args += [ "--sources" ] |
| args += rebase_path(invoker.sources, root_build_dir) |
| if (defined(invoker.data_package_name)) { |
| args += [ |
| "--data_package_name", |
| invoker.data_package_name, |
| ] |
| } |
| if (defined(invoker.data_sources)) { |
| args += [ "--data_sources" ] |
| args += rebase_path(invoker.data_sources, root_build_dir) |
| } |
| } |
| deps = [ invoker.library_infos ] |
| |
| # Required for generated sources like C extension wrappers. |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| } |
| } |
| |
| # Run mypy for a library |
| # |
| # Parameters |
| # |
| # library_infos (required) |
| # The target that generates a json file with all the library dependency info |
| # Type: GN target label |
| # |
| # sources (required) |
| # The list of python source files in the library or binary |
| # Type: list of GN file paths |
| # |
| # GN usual (optional): |
| # assert_no_deps |
| # deps |
| # testonly |
| # visibility |
| # |
| template("validate_python_library") { |
| validate_python(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "assert_no_deps", |
| "deps", |
| "library_infos", |
| "sources", |
| "testonly", |
| "visibility", |
| ]) |
| target_type = "library" |
| } |
| } |
| |
| # Run mypy for a python binary |
| # |
| # Parameters |
| # |
| # library_infos (required) |
| # The target that generates a json file with all the library dependency info |
| # Type: GN target label |
| # |
| # sources (required) |
| # The list of python source files in the library or binary |
| # Type: list of GN file paths |
| # |
| # data_package_name (optional) |
| # The name of the python package for data files |
| # Type: string |
| # |
| # data_sources (optional) |
| # The source files to add to the data package. Requires 'data_package_name'. |
| # Type: list of GN file paths |
| # |
| # GN usual (optional): |
| # assert_no_deps |
| # deps |
| # testonly |
| # visibility |
| # |
| template("validate_python_binary") { |
| validate_python(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "assert_no_deps", |
| "data_package_name", |
| "data_sources", |
| "deps", |
| "library_infos", |
| "sources", |
| "testonly", |
| "visibility", |
| ]) |
| target_type = "binary" |
| } |
| } |