nix-ros-overlay/lib/ament_cmake_vendor_packageConfig.cmake
Michal Sojka 0ecce1a1b5 Update patchAmentVendorGit to use automatically extracted information about vendored source
The information is stored in vendored-source.json files in the package
directories. The file can be automatically generated by running
command like this:

    $(nix-build -A rosPackages.jazzy.gz-math-vendor.updateAmentVendor)'

This command executes Cmake for the given package with an alternative
implementation of the ament_vendor Cmake macro, which generates the
file instead of fetching the source code. The above command generates
`distros/jazzy/gz-math-vendor/vendored-source.json` files with this
content:

    {
      "url": "https://github.com/gazebosim/gz-math.git",
      "rev": "gz-math7_7.5.2",
      "hash": "sha256-LwYeyv8nwX06n5ju+ra2uqNMedMSLRumem8qDHXtNns="
    }

patchAmentVendorGit function is updated to pick the information about
patching from that file instead of from its arguments.

patchGzAmentVendorGit is updated similarly and the check for version
mismatch is removed, because it would not work (version information is
not available from function arguments) and more importantly, it
is (hopefully) no longer needed, because the version will always be
updated automatically by CI.
2025-04-13 21:39:02 -04:00

32 lines
1.5 KiB
CMake

# CMake package that defines alternative version of ament_vendor macro
# to extract information about vendored source to
# vendored-source.json. Normally, the ament_vendor macro is defined in
# the ament_cmake_vendor_package and it downloads the vendored source
# code at compile time. This is not possible with Nix, because Nix
# builds packages without network access. Therefore, we inject this
# alternative macro to cmake at update time and it extracts the
# information needed by Nix to download the source code. The main
# entry point to all this functionality is in the patchAmentVendorGit
# function.
if(NOT ament_cmake_vendor_package_FIND_QUIETLY)
message(STATUS "Found ament_cmake_vendor_package: Dummy version for Nix patching (${ament_cmake_vendor_package_DIR})")
endif()
find_program(JQ jq)
find_program(NIX_PREFETCH_GIT nix-prefetch-git)
macro(ament_vendor TARGET_NAME)
cmake_parse_arguments(_ARG "GLOBAL_HOOK;SKIP_INSTALL" "SOURCE_SUBDIR;VCS_TYPE;VCS_URL;VCS_VERSION;SATISFIED" "CMAKE_ARGS;PATCHES" ${ARGN})
if(_ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "ament_vendor() called with unused arguments: "
"${_ARG_UNPARSED_ARGUMENTS}")
endif()
execute_process(
COMMAND ${NIX_PREFETCH_GIT} --url ${_ARG_VCS_URL} --rev ${_ARG_VCS_VERSION}
COMMAND ${JQ} "{url: \"${_ARG_VCS_URL}\", rev: \"${_ARG_VCS_VERSION}\", hash: .hash}"
OUTPUT_FILE ${CMAKE_BINARY_DIR}/vendored-source.json
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY)
endmacro()