Skip to content

Commit

Permalink
Improve patchExternalProjectGit
Browse files Browse the repository at this point in the history
Add basic support for checking the version if it is assigned to a
variable.
  • Loading branch information
lopsided98 committed Nov 15, 2024
1 parent 5d3c826 commit f556a34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
13 changes: 1 addition & 12 deletions distros/distro-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions distros/rolling/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 1 addition & 2 deletions distros/ros2-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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=";
};

Expand Down
3 changes: 3 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
rev,
originalRev ? rev,
originalUrl ? url,
revVariable ? "",
file ? "CMakeLists.txt",
fetchgitArgs ? {}
}: pkg.overrideAttrs ({
Expand All @@ -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"
Expand All @@ -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}
Expand Down

0 comments on commit f556a34

Please sign in to comment.