| # Copyright 2021 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. |
| |
| # Defines a python library |
| # |
| # NOTE: Currently does NOT support depending on other python_libraries. |
| # TODO(https://fxbug.dev/73542): Enable other python_libraries as deps when use |
| # case show up. |
| # |
| # Example |
| # |
| # ``` |
| # python_library("lib") { |
| # library_name = "lib" |
| # sources = [ |
| # "__init__.py", |
| # "lib.py", |
| # ] |
| # } |
| # ``` |
| # |
| # Parameters |
| # |
| # library_name (optional) |
| # Name of the library, Python scripts can import this library by this name. |
| # Type: string |
| # Default: ${target_name} |
| # |
| # source_root (optional) |
| # Path to root of the package, where __init__.py is. |
| # Type: path |
| # Default: current directory |
| # |
| # sources (required) |
| # List of sources for this python library, relative to source_root. |
| # Type: list(path) |
| # |
| # Metadata |
| # |
| # library_info |
| # Exactly one scope including name of this library, path to its root and all |
| # of its sources (relative to root). |
| # |
| # library_info_barrier |
| # Empty for stopping metadata walks. |
| template("python_library") { |
| assert(defined(invoker.sources), "sources is required") |
| |
| group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| library_name = target_name |
| if (defined(invoker.library_name)) { |
| library_name = invoker.library_name |
| } |
| |
| source_root = "." |
| if (defined(invoker.source_root)) { |
| source_root = invoker.source_root |
| } |
| metadata = { |
| library_info = [ |
| { |
| library_name = library_name |
| source_root = rebase_path(source_root, root_build_dir) |
| sources = invoker.sources |
| }, |
| ] |
| library_info_barrier = [] |
| } |
| } |
| } |