This directory contains fx
subcommands written in Python.
These tools are automatically included in builds.
See fxrev.dev/1080462 for an example of following these instructions.
The following instructions assume you are creating a tool called my-new-fx-tool
, which you can replace with the real name of your tool.
//tools/devshell/python/my-new-fx-tool
. The rest of the instructions are relative to that directory unless otherwise specified.tests
directory for your test code.# Copyright 2024 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/host.gni") import("//build/python/python_host_test.gni")
python_binary
to your BUILD.gn file:python_binary("my-new-fx-tool") { main_source = "main.py" # Reference main source here sources = [ "main.py" ] # Sources here deps = [] # Deps here }
if (is_host) { python_host_test("my-new-fx-tool-test") { main_source = "tests/test_my_new_fx_tool.py" # Test path here sources = [ "main.py", # Allow import main. "tests/test_my_new_fx_tool.py", ] } }
install_python_tool("install") { name = "my-new-fx-tool" binary = ":my-new-fx-tool" } group("tests") { testonly = true deps = [ ":my-new-fx-tool-test($host_toolchain)" ] }
//tools/devshell/python
:group("tests") { testonly = true deps = [ # ... "my-new-fx-tool:tests", ] } group("install") { deps = [ # ... "my-new-fx-tool:tests", ] }
//tools/devshell/my-new-fx-tool.fx
, replacing values in <>
:# Copyright 2024 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. #### CATEGORY=Other <replace with correct category> #### EXECUTABLE=${HOST_TOOLS_DIR}/my-new-fx-tool ### <Short description> ## 'fx my-new-fx-tool --help' for instructions.
You can now run your tool with fx my-new-fx-tool
.
Add the correct labels and execute tests:
fx set minimal.x64 --with-test //tools/devshell:tests fx test --host //tools/devshell