fx ide-queryThis document details the self-bootstrapping mechanism used by the fx ide-query tool.
The ide-query tool is implemented in Go but is triggered via a shell script wrapper at //tools/devshell/ide-query. This wrapper handles the compilation of the Go source on-demand, caching the resulting binary for subsequent executions.
This design mirrors the approach taken by other core fx tools like fx set.
The first step is to implement a minimal “Hello World” version of the Go tool. This ensures the bootstrapping logic (compilation, caching, and execution) is functional before any real query logic is added.
go run for complex tools.--dev flag to force recompilation without waiting for a full fx build.The shell script wrapper performs the following steps:
//tools/devshell/lib/vars.sh to define ${FUCHSIA_DIR}, ${FX_CACHE_DIR}, and find the prebuilt Go toolchain.git rev-parse HEAD) with a value stored in ${FX_CACHE_DIR}/ide-query.revision.--dev flag is set, a rebuild is triggered.go.mod, go.sum, vendor) from //third_party/golibs.//tools).go build using the prebuilt Go binary.GOPROXY=off, CGO_ENABLED=0).${FX_CACHE_DIR}/ide-query.bin.${PREBUILT_GO_DIR}.//third_party/golibs.${FX_CACHE_DIR} exists and is writable.To maintain high quality and correctness, the following testing strategies will be used:
All logic inside //scripts/cog/ide_query should be covered by standard Go unit tests (*_test.go).
go test ./scripts/cog/ide_query/....A BUILD.gn will be added to the directory to allow the tool to be tested by Fuchsia's standard infrastructure.
go_test target will be defined to run unit tests as part of fx test.The shell script wrapper's ability to compile and run the tool will be verified by:
fx ide-query --dev and verifying it prints “Hello World”.fx ide-query --dev reflects the change.