diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-05-10T23·03-0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-05-10T23·03-0400 |
commit | 4f7bab7db1d0447e41f858633cddba1dcb2c9ea2 (patch) | |
tree | 818adb7b019671906e2b9016b4c265ebc53cfdf1 /perl/lib/Nix/Store.pm | |
parent | 6a7b24a3f25548fe2b083555cd2117dd66557ab0 (diff) |
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.
Diffstat (limited to 'perl/lib/Nix/Store.pm')
-rw-r--r-- | perl/lib/Nix/Store.pm | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/perl/lib/Nix/Store.pm b/perl/lib/Nix/Store.pm index 1ae3b04b7e6f..8312a732cdea 100644 --- a/perl/lib/Nix/Store.pm +++ b/perl/lib/Nix/Store.pm @@ -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__ |