chiark / gitweb /
nailing-cargo: Work around cargo annoyance with workspaces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Jul 2020 15:53:46 +0000 (16:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Jul 2020 16:16:47 +0000 (17:16 +0100)
When the invocation $subdir is a workspace, with -u, cargo complains
that the packages in the linkfarm are different to the ones in the
source area.

Fix this by, in this case, adjusting those path references to point
into the linkfarm.

cargo seems to use realpath on one of these paths, so we must do so
too, or cargo complains that two things are different which are
literally two different paths to the very same symlink.

With this change I am able to build lexpr-rs, both in its own right,
and as a dependency.  Closes #1.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
nailing-cargo

index 354f1e779d0609eedb117250d4832f65f8fcf85a..f015b894ce70ebf9ecb98bd4aafdea58866f8e5d 100755 (executable)
@@ -8,6 +8,7 @@ use strict;
 use POSIX;
 use Types::Serialiser;
 use File::Glob qw(bsd_glob GLOB_ERR GLOB_BRACE GLOB_NOMAGIC);
+use Cwd qw(realpath);
 
 our %archmap = (
     RPI => 'arm-unknown-linux-gnueabihf',
@@ -430,7 +431,15 @@ sub calculate () {
        next unless defined $info;
        $deps->{$p} = $info = { } unless ref $info;
        delete $info->{version};
-       $info->{path} = $worksphere.'/'.$packagemap{$p};
+       my $newpath = $worksphere.'/'.$packagemap{$p};
+       if ($cargo_lock_update and defined $oot_dir and
+           $newpath =~ m{^\Q$src_absdir\E(?=$|/)}) {
+         our $oot_subdir_realpath;
+         $oot_subdir_realpath //= Cwd::realpath "$oot_absdir/$subdir"
+           // die "$self: cannot resolve $oot_absdir/$subdir: $!";
+         $newpath = $oot_subdir_realpath.$';
+       }
+       $info->{path} = $newpath;
       }
     }
     my $nailing = "$mf.nailing~";