Improve patchExternalProjectGit

Add basic support for checking the version if it is assigned to a
variable.
This commit is contained in:
Ben Wolsieffer 2024-11-15 13:10:05 -05:00
parent 5d3c82695b
commit f556a34f39
4 changed files with 12 additions and 14 deletions

View file

@ -168,20 +168,8 @@ let
osqp-vendor = pipe rosSuper.osqp-vendor [ osqp-vendor = pipe rosSuper.osqp-vendor [
(pkg: pkg.overrideAttrs ({ (pkg: pkg.overrideAttrs ({
prePatch ? "",
preInstall ? "", ... 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 # osqp installs into both lib/cmake/ and lib64/cmake/ which is
# problematic because moveLib64 doesn't attempt to merge overlapping # problematic because moveLib64 doesn't attempt to merge overlapping
# directories but fails instead. Here we do the merge manually. # directories but fails instead. Here we do the merge manually.
@ -195,6 +183,7 @@ let
(pkg: patchExternalProjectGit pkg { (pkg: patchExternalProjectGit pkg {
url = "https://github.com/osqp/osqp.git"; url = "https://github.com/osqp/osqp.git";
rev = "v0.6.2"; rev = "v0.6.2";
revVariable = "git_tag";
fetchgitArgs = { fetchgitArgs = {
hash = "sha256-0BbUe1J9qzvyKDBLTz+pAEmR3QpRL+hnxZ2re/3mEvs="; hash = "sha256-0BbUe1J9qzvyKDBLTz+pAEmR3QpRL+hnxZ2re/3mEvs=";
leaveDotGit = true; leaveDotGit = true;

View file

@ -184,6 +184,13 @@ in {
hash = "sha256-ZP8+URGfN//Pr53uy9mHp8tNTZA110o/03czlaRw/aE="; 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 { rviz-ogre-vendor = lib.patchAmentVendorGit rosSuper.rviz-ogre-vendor {
url = "https://github.com/OGRECave/ogre.git"; url = "https://github.com/OGRECave/ogre.git";
rev = "v1.12.10"; rev = "v1.12.10";

View file

@ -54,9 +54,8 @@ rosSelf: rosSuper: with rosSelf.lib; {
fmilibrary-vendor = patchExternalProjectGit rosSuper.fmilibrary-vendor { fmilibrary-vendor = patchExternalProjectGit rosSuper.fmilibrary-vendor {
url = "https://github.com/modelon-community/fmi-library.git"; url = "https://github.com/modelon-community/fmi-library.git";
# Uses ${fmilibrary_version}, so can't match
originalRev = "";
rev = "2.2.3"; rev = "2.2.3";
revVariable = "fmilibrary_version";
fetchgitArgs.hash = "sha256-i8EtjPMg39S/3RyoUaXm5A8Nu/NbgAwjxRCdyh2elyU="; fetchgitArgs.hash = "sha256-i8EtjPMg39S/3RyoUaXm5A8Nu/NbgAwjxRCdyh2elyU=";
}; };

View file

@ -48,6 +48,7 @@
rev, rev,
originalRev ? rev, originalRev ? rev,
originalUrl ? url, originalUrl ? url,
revVariable ? "",
file ? "CMakeLists.txt", file ? "CMakeLists.txt",
fetchgitArgs ? {} fetchgitArgs ? {}
}: pkg.overrideAttrs ({ }: pkg.overrideAttrs ({
@ -59,6 +60,7 @@
{ print "URL \"" path "\""; foundUrl=1; next } \ { print "URL \"" path "\""; foundUrl=1; next } \
{ print } { print }
$0 ~ "GIT_TAG[[:blank:]]+" originalRev { print; foundRev=1 } $0 ~ "GIT_TAG[[:blank:]]+" originalRev { print; foundRev=1 }
$0 ~ "set\\(" revVariable "[[:blank:]]+\"?" originalRev "\"?\\)" { print; foundRev=1 }
END { END {
if (!foundUrl) print "patchExternalProjectGit: did not find URL: " originalUrl > "/dev/stderr" if (!foundUrl) print "patchExternalProjectGit: did not find URL: " originalUrl > "/dev/stderr"
if (!foundRev) print "patchExternalProjectGit: did not find revision: " originalRev > "/dev/stderr" if (!foundRev) print "patchExternalProjectGit: did not find revision: " originalRev > "/dev/stderr"
@ -69,6 +71,7 @@
awk -i inplace \ awk -i inplace \
-v originalUrl=${lib.escapeShellArg originalUrl} \ -v originalUrl=${lib.escapeShellArg originalUrl} \
-v originalRev=${lib.escapeShellArg originalRev} \ -v originalRev=${lib.escapeShellArg originalRev} \
-v revVariable=${lib.escapeShellArg revVariable} \
-v path=${lib.escapeShellArg (self.fetchgit ({ inherit url rev; } // fetchgitArgs))} \ -v path=${lib.escapeShellArg (self.fetchgit ({ inherit url rev; } // fetchgitArgs))} \
${lib.escapeShellArg script} \ ${lib.escapeShellArg script} \
${lib.escapeShellArg file} ${lib.escapeShellArg file}