Skip to content
ocx
install

Run workspace tools from ocx.toml

Use ocx_project to turn a committed ocx.toml and ocx.lock into command lists that run your tools in custom targets, tests and groups.

Put tools in [tools] and rarely used tools in a group.

ocx.toml
[tools]
jq = "ocx.sh/jqlang/jq:latest"
[group.lint.tools]
shellcheck = "ocx.sh/shellcheck/shellcheck:latest"

Call ocx_project with the tools you want as per-tool variables.

examples/project/CMakeLists.txt
ocx_project(NAME TOOLS BINS jq)

NAME TOOLS gives OCX_TOOLS_RUN and OCX_TOOLS_RUN_JQ. Without NAME, the variables are OCX_PROJECT_RUN and OCX_PROJECT_RUN_JQ.

The ocx.toml is found by the upward search, the lock is verified, and nothing is fetched yet.

OCX_TOOLS_RUN is a plain CMake command list, so generator expressions such as $<CONFIG> work and you need no wrapper script.

CMakeLists.txt
add_custom_target(validate ALL
COMMAND ${OCX_TOOLS_RUN} jq -n -e --arg config "$<CONFIG>"
[[$config | length >= 0]]
VERBATIM
)

A group costs nothing until someone builds a target that uses it.

CMakeLists.txt
ocx_project(NAME LINT GROUPS lint)
add_custom_target(lint
COMMAND ${OCX_LINT_RUN} shellcheck "${CMAKE_CURRENT_SOURCE_DIR}/hello.sh"
VERBATIM
)

Use the per-tool variable as the test command.

CMakeLists.txt
add_test(NAME data_valid
COMMAND ${OCX_TOOLS_RUN_JQ} -e ".greeting == \"hello\""
"${CMAKE_CURRENT_SOURCE_DIR}/data.json")
Terminal window
cd examples/project
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure

For the full signatures, see ocx_project. Needs addressed: problems 1 and 2 of the use-case research.