1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Support building with the Perl XS bindings disabled

Since the Perl bindings require shared libraries, this is required on
platforms such as Cygwin where we do a static build.
This commit is contained in:
Eelco Dolstra 2012-05-10 19:03:23 -04:00
parent 6a7b24a3f2
commit 4f7bab7db1
5 changed files with 92 additions and 12 deletions

View file

@ -2,9 +2,12 @@ PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm l
all: $(PERL_MODULES:.in=)
install-exec-local: $(PERL_MODULES:.in=)
install-exec-local: $(PERL_MODULES:.in=) install-perl-xs
$(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix
$(INSTALL_DATA) $(PERL_MODULES:.in=) $(DESTDIR)$(perllibdir)/Nix
if PERL_BINDINGS
install-perl-xs:
$(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store
ln -sfn $(pkglibdir)/libNixStore$(dynlib_suffix) $(DESTDIR)$(perllibdir)/auto/Nix/Store/Store$(dynlib_suffix)
@ -25,6 +28,10 @@ AM_CXXFLAGS = \
lib/Nix/Store.cc: lib/Nix/Store.xs
xsubpp $^ -output $@
else
install-perl-xs:
endif
EXTRA_DIST = $(PERL_MODULES) lib/Nix/Store.xs
include ../substitute.mk

View file

@ -10,6 +10,8 @@ $confDir = $ENV{"NIX_CONF_DIR"} || "@sysconfdir@/nix";
$bzip2 = $ENV{"NIX_BZIP2"} || "@bzip2@";
$curl = "@curl@";
$useBindings = "@perlbindings@" eq "yes";
sub readConfig {
my %config;
my $config = "@sysconfdir@/nix/nix.conf";

View file

@ -2,6 +2,7 @@ package Nix::Store;
use strict;
use warnings;
use Nix::Config;
require Exporter;
@ -21,8 +22,70 @@ our @EXPORT = qw(
our $VERSION = '0.15';
require XSLoader;
XSLoader::load('Nix::Store', $VERSION);
sub backtick {
open(RES, "-|", @_) or die;
local $/;
my $res = <RES> || "";
close RES or die;
return $res;
}
if ($Nix::Config::useBindings) {
require XSLoader;
XSLoader::load('Nix::Store', $VERSION);
} else {
# Provide slow fallbacks of some functions on platforms that don't
# support the Perl bindings.
use File::Temp;
use Fcntl qw/F_SETFD/;
sub hashFile {
my ($algo, $base32, $path) = @_;
my $res = backtick("$Nix::Config::binDir/nix-hash", "--flat", $path, "--type", $algo, $base32 ? "--base32" : ());
chomp $res;
return $res;
}
sub hashPath {
my ($algo, $base32, $path) = @_;
my $res = backtick("$Nix::Config::binDir/nix-hash", $path, "--type", $algo, $base32 ? "--base32" : ());
chomp $res;
return $res;
}
sub hashString {
my ($algo, $base32, $s) = @_;
my $fh = File::Temp->new();
print $fh $s;
my $res = backtick("$Nix::Config::binDir/nix-hash", $fh->filename, "--type", $algo, $base32 ? "--base32" : ());
chomp $res;
return $res;
}
sub addToStore {
my ($srcPath, $recursive, $algo) = @_;
die "not implemented" if $recursive || $algo ne "sha256";
my $res = backtick("$Nix::Config::binDir/nix-store", "--add", $srcPath);
chomp $res;
return $res;
}
sub isValidPath {
my ($path) = @_;
my $res = backtick("$Nix::Config::binDir/nix-store", "--check-validity", "--print-invalid", $path);
chomp $res;
return $res ne $path;
}
sub queryPathHash {
my ($path) = @_;
my $res = backtick("$Nix::Config::binDir/nix-store", "--query", "--hash", $path);
chomp $res;
return $res;
}
}
1;
__END__