Skip to content

Commit

Permalink
rolling: rviz-ogre-vendor: correctly patch vendor URLs
Browse files Browse the repository at this point in the history
This package requires complex patching. It uses ament_vendor(), which is picky
about what kinds of sources it requires. Additionally, ogre contains its own
vendoring of imgui that needs to be patched.
  • Loading branch information
lopsided98 committed Aug 5, 2023
1 parent d5f6bfe commit 5f92686
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
9 changes: 0 additions & 9 deletions distros/distro-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,6 @@ let
nativeBuildInputs = nativeBuildInputs ++ [ self.qt5.wrapQtAppsHook ];
});

rviz-ogre-vendor = rosSuper.rviz-ogre-vendor.overrideAttrs ({
preFixup ? "", ...
}: {
preFixup = ''
# Prevent /build RPATH references
rm -r ogre_install
'' + preFixup;
});

rxcpp-vendor = patchVendorUrl rosSuper.rxcpp-vendor {
url = "https://github.com/ReactiveX/RxCpp/archive/v4.1.0.tar.gz";
sha256 = "1smxrcm0s6bz05185dx1i2xjgn47rq7m247pblil6p3bmk3lkfyk";
Expand Down
21 changes: 18 additions & 3 deletions distros/rolling/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,24 @@ rosSelf: rosSuper: with rosSelf.lib; {
};
};

rviz-ogre-vendor = patchVendorUrl rosSuper.rviz-ogre-vendor {
url = "https://github.com/OGRECave/ogre/archive/v1.12.10.zip";
sha256 = "sha256-lZDLywgShlWeWah7oTnyKBTqzN505LJKbQbgXRfJXlk=";
rviz-ogre-vendor = patchAmentVendorGit rosSuper.rviz-ogre-vendor {
url = "https://github.com/OGRECave/ogre.git";
rev = "v1.12.10";
fetchgitArgs.hash = "sha256-Z0ixdSmkV93coBBVZ5R3lPLfVMXRfWsFz/RsSyqPWFY=";
tarSourceArgs.hook = let
version = "1.79";
imgui = (self.fetchFromGitHub rec {
name = "${repo}-${version}";
owner = "ocornut";
repo = "imgui";
rev = "v${version}";
hash = "sha256-GIVhZ8Q7WebfHeKeJdVABXrTT26FOS7updncbv2LRnQ=";
});
imguiTar = tarSource { } imgui;
in ''
substituteInPlace Components/Overlay/CMakeLists.txt \
--replace ${escapeShellArg imgui.url} file://${escapeShellArg imguiTar}
'';
};

urdfdom = rosSuper.urdfdom.overrideAttrs ({
Expand Down
59 changes: 54 additions & 5 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,79 @@ with lib;
s = composeManyExtensions overlays s {};
in s;

# Create a tarball of a package source. If the source is already an archive,
# it will be unpacked and repacked as a tarball.
tarSource = {
compress ? false,
hook ? ""
}: src: self.runCommand ("${src.name}.tar" + lib.optionalString compress ".gz") { inherit src; } ''
unpackPhase
pushd "$sourceRoot"
${hook}
popd
tar --sort=name \
--format=gnu \
--owner=0 --group=0 --numeric-owner \
${lib.optionalString compress "-z"} \
-cf "$out" "$sourceRoot"
'';

patchVendorUrl = pkg: {
url, sha256,
url, hash ? "", sha256 ? "",
originalUrl ? url,
file ? "CMakeLists.txt"
}: pkg.overrideAttrs ({
postPatch ? "", ...
}: {
postPatch = ''
substituteInPlace '${file}' \
--replace '${originalUrl}' '${self.fetchurl { inherit url sha256; }}'
substituteInPlace ${escapeShellArg file} \
--replace ${escapeShellArg originalUrl} ${escapeShellArg (self.fetchurl { inherit url hash sha256; })}
'' + postPatch;
});

patchVendorGit = pkg: {
url,
originalUrl ? url,
file ? "CMakeLists.txt",
fetchgitArgs ? {}
}: pkg.overrideAttrs ({
postPatch ? "", ...
}: {
postPatch = ''
sed -i '\|GIT_REPOSITORY\s.*${escapeShellArg url}|c\
sed -i '\|GIT_REPOSITORY\s.*${originalUrl}|c\
URL "${self.fetchgit ({ inherit url; } // fetchgitArgs)}"' \
'${file}'
${escapeShellArg file}
'' + postPatch;
});

# Patch a vendored download that uses ament_vendor() with a Git repo as the
# source.
patchAmentVendorGit = pkg: {
url,
originalUrl ? url,
rev, # Must correspond to the VCS_VERSION argument
file ? "CMakeLists.txt",
fetchgitArgs ? {},
tarSourceArgs ? {}
}: pkg.overrideAttrs ({
nativeBuildInputs ? [],
postPatch ? "", ...
}: let
# ament_vendor doesn't allow patches for path inputs, so we have to pack it
# into a tar first. Additionally, vcstool only accepts tarballs with the
# version number as the root directory name.
vendor = lib.tarSource tarSourceArgs (self.fetchgit (fetchgitArgs // {
name = rev;
inherit url rev;
}));
in {
# CMake ExternalProject patches are applied with git apply
nativeBuildInputs = nativeBuildInputs ++ [ self.git ];
postPatch = ''
sed -i '\|VCS_URL\s*${originalUrl}|c\
VCS_URL "file://${vendor}"\
VCS_TYPE tar' \
${lib.escapeShellArg file}
'' + postPatch;
});

Expand Down

0 comments on commit 5f92686

Please sign in to comment.