From f556a34f39d00fa2322300d9e63181714dae2a9c Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Fri, 15 Nov 2024 13:10:05 -0500 Subject: [PATCH] Improve patchExternalProjectGit Add basic support for checking the version if it is assigned to a variable. --- distros/distro-overlay.nix | 13 +------------ distros/rolling/overrides.nix | 7 +++++++ distros/ros2-overlay.nix | 3 +-- lib/default.nix | 3 +++ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/distros/distro-overlay.nix b/distros/distro-overlay.nix index e630668cb2..54b14f1e15 100644 --- a/distros/distro-overlay.nix +++ b/distros/distro-overlay.nix @@ -168,20 +168,8 @@ let osqp-vendor = pipe rosSuper.osqp-vendor [ (pkg: pkg.overrideAttrs ({ - prePatch ? "", preInstall ? "", ... }: { - # Make CMakeLists.txt amenable to automatic patching with - # patchExternalProjectGit - prePatch = prePatch + '' - substituteInPlace CMakeLists.txt --replace-fail \ - 'set(git_tag "v0.6.2")' \ - 'set(git_tag "v0.6.2")' # fail when upstream version changes - substituteInPlace CMakeLists.txt --replace-fail \ - 'GIT_TAG ''${git_tag}' \ - 'GIT_TAG v0.6.2' - ''; - # osqp installs into both lib/cmake/ and lib64/cmake/ which is # problematic because moveLib64 doesn't attempt to merge overlapping # directories but fails instead. Here we do the merge manually. @@ -195,6 +183,7 @@ let (pkg: patchExternalProjectGit pkg { url = "https://github.com/osqp/osqp.git"; rev = "v0.6.2"; + revVariable = "git_tag"; fetchgitArgs = { hash = "sha256-0BbUe1J9qzvyKDBLTz+pAEmR3QpRL+hnxZ2re/3mEvs="; leaveDotGit = true; diff --git a/distros/rolling/overrides.nix b/distros/rolling/overrides.nix index 4ab3c362aa..6bb1e2c406 100644 --- a/distros/rolling/overrides.nix +++ b/distros/rolling/overrides.nix @@ -184,6 +184,13 @@ in { hash = "sha256-ZP8+URGfN//Pr53uy9mHp8tNTZA110o/03czlaRw/aE="; }; + nlohmann-json-schema-validator-vendor = lib.patchExternalProjectGit rosSuper.nlohmann-json-schema-validator-vendor { + url = "https://github.com/pboettch/json-schema-validator.git"; + rev = "5ef4f903af055550e06955973a193e17efded896"; + revVariable = "nlohmann_json_schema_validator_version"; + fetchgitArgs.hash = "sha256-b02OFUx0BxUA6HN6IaacSg1t3RP4o7NND7X0U635W8U="; + }; + rviz-ogre-vendor = lib.patchAmentVendorGit rosSuper.rviz-ogre-vendor { url = "https://github.com/OGRECave/ogre.git"; rev = "v1.12.10"; diff --git a/distros/ros2-overlay.nix b/distros/ros2-overlay.nix index 54f57cb5fe..4f0ba34031 100644 --- a/distros/ros2-overlay.nix +++ b/distros/ros2-overlay.nix @@ -54,9 +54,8 @@ rosSelf: rosSuper: with rosSelf.lib; { fmilibrary-vendor = patchExternalProjectGit rosSuper.fmilibrary-vendor { url = "https://github.com/modelon-community/fmi-library.git"; - # Uses ${fmilibrary_version}, so can't match - originalRev = ""; rev = "2.2.3"; + revVariable = "fmilibrary_version"; fetchgitArgs.hash = "sha256-i8EtjPMg39S/3RyoUaXm5A8Nu/NbgAwjxRCdyh2elyU="; }; diff --git a/lib/default.nix b/lib/default.nix index 59baf7e7a4..c6985b1c82 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -48,6 +48,7 @@ rev, originalRev ? rev, originalUrl ? url, + revVariable ? "", file ? "CMakeLists.txt", fetchgitArgs ? {} }: pkg.overrideAttrs ({ @@ -59,6 +60,7 @@ { print "URL \"" path "\""; foundUrl=1; next } \ { print } $0 ~ "GIT_TAG[[:blank:]]+" originalRev { print; foundRev=1 } + $0 ~ "set\\(" revVariable "[[:blank:]]+\"?" originalRev "\"?\\)" { print; foundRev=1 } END { if (!foundUrl) print "patchExternalProjectGit: did not find URL: " originalUrl > "/dev/stderr" if (!foundRev) print "patchExternalProjectGit: did not find revision: " originalRev > "/dev/stderr" @@ -69,6 +71,7 @@ awk -i inplace \ -v originalUrl=${lib.escapeShellArg originalUrl} \ -v originalRev=${lib.escapeShellArg originalRev} \ + -v revVariable=${lib.escapeShellArg revVariable} \ -v path=${lib.escapeShellArg (self.fetchgit ({ inherit url rev; } // fetchgitArgs))} \ ${lib.escapeShellArg script} \ ${lib.escapeShellArg file}