2011-10-10 20:12:40 +02:00
|
|
|
#include "EXTERN.h"
|
|
|
|
#include "perl.h"
|
|
|
|
#include "XSUB.h"
|
|
|
|
|
|
|
|
/* Prevent a clash between some Perl and libstdc++ macros. */
|
|
|
|
#undef do_open
|
|
|
|
#undef do_close
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
#include "derivations.hh"
|
|
|
|
#include "globals.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "util.hh"
|
2016-02-16 16:38:44 +01:00
|
|
|
#include "crypto.hh"
|
2011-10-10 20:12:40 +02:00
|
|
|
|
2015-02-10 11:54:06 +01:00
|
|
|
#if HAVE_SODIUM
|
2015-02-04 16:43:32 +01:00
|
|
|
#include <sodium.h>
|
2015-02-10 11:54:06 +01:00
|
|
|
#endif
|
2015-02-04 16:43:32 +01:00
|
|
|
|
2011-10-10 20:12:40 +02:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
2016-02-04 14:48:42 +01:00
|
|
|
static ref<Store> store()
|
2011-10-10 20:12:40 +02:00
|
|
|
{
|
2016-02-04 14:48:42 +01:00
|
|
|
static std::shared_ptr<Store> _store;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
if (!_store) {
|
2011-10-10 20:12:40 +02:00
|
|
|
try {
|
2012-07-31 01:55:41 +02:00
|
|
|
settings.processEnvironment();
|
2013-11-24 21:22:23 +01:00
|
|
|
settings.loadConfFile();
|
|
|
|
settings.update();
|
2013-09-06 16:36:56 +02:00
|
|
|
settings.lockCPU = false;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
_store = openStore();
|
2011-10-10 20:12:40 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
}
|
2016-02-04 14:48:42 +01:00
|
|
|
return ref<Store>(_store);
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MODULE = Nix::Store PACKAGE = Nix::Store
|
|
|
|
PROTOTYPES: ENABLE
|
|
|
|
|
|
|
|
|
2014-01-21 16:38:03 +01:00
|
|
|
#undef dNOOP // Hack to work around "error: declaration of 'Perl___notused' has a different language linkage" error message on clang.
|
|
|
|
#define dNOOP
|
|
|
|
|
|
|
|
|
2011-10-10 20:12:40 +02:00
|
|
|
void init()
|
|
|
|
CODE:
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
store();
|
2011-10-10 20:12:40 +02:00
|
|
|
|
|
|
|
|
2015-03-04 16:27:42 +01:00
|
|
|
void setVerbosity(int level)
|
|
|
|
CODE:
|
|
|
|
verbosity = (Verbosity) level;
|
|
|
|
|
|
|
|
|
2011-10-11 17:41:13 +02:00
|
|
|
int isValidPath(char * path)
|
2011-10-10 20:12:40 +02:00
|
|
|
CODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
RETVAL = store()->isValidPath(path);
|
2011-10-10 20:12:40 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
|
2011-10-11 17:41:13 +02:00
|
|
|
SV * queryReferences(char * path)
|
2011-10-10 20:12:40 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
PathSet paths;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
store()->queryReferences(path, paths);
|
2011-10-10 20:12:40 +02:00
|
|
|
for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i)
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(i->c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-11 17:41:13 +02:00
|
|
|
SV * queryPathHash(char * path)
|
2011-10-10 20:12:40 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
Hash hash = store()->queryPathHash(path);
|
2011-11-29 13:32:55 +01:00
|
|
|
string s = "sha256:" + printHash32(hash);
|
2011-10-10 20:12:40 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-11 17:41:13 +02:00
|
|
|
SV * queryDeriver(char * path)
|
2011-10-10 20:12:40 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
Path deriver = store()->queryDeriver(path);
|
2011-10-10 20:12:40 +02:00
|
|
|
if (deriver == "") XSRETURN_UNDEF;
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(deriver.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 22:55:45 +02:00
|
|
|
SV * queryPathInfo(char * path, int base32)
|
2011-10-10 20:12:40 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
ValidPathInfo info = store()->queryPathInfo(path);
|
2011-10-10 20:12:40 +02:00
|
|
|
if (info.deriver == "")
|
|
|
|
XPUSHs(&PL_sv_undef);
|
|
|
|
else
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(info.deriver.c_str(), 0)));
|
2016-02-16 11:49:12 +01:00
|
|
|
string s = "sha256:" + (base32 ? printHash32(info.narHash) : printHash(info.narHash));
|
2011-10-10 20:12:40 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
mXPUSHi(info.registrationTime);
|
|
|
|
mXPUSHi(info.narSize);
|
|
|
|
AV * arr = newAV();
|
|
|
|
for (PathSet::iterator i = info.references.begin(); i != info.references.end(); ++i)
|
|
|
|
av_push(arr, newSVpv(i->c_str(), 0));
|
|
|
|
XPUSHs(sv_2mortal(newRV((SV *) arr)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-18 00:55:39 +02:00
|
|
|
SV * queryPathFromHashPart(char * hashPart)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
Path path = store()->queryPathFromHashPart(hashPart);
|
2012-07-18 00:55:39 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(path.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2012-07-18 00:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-10 20:12:40 +02:00
|
|
|
SV * computeFSClosure(int flipDirection, int includeOutputs, ...)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
PathSet paths;
|
|
|
|
for (int n = 2; n < items; ++n)
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
store()->computeFSClosure(SvPV_nolen(ST(n)), paths, flipDirection, includeOutputs);
|
2011-10-10 20:12:40 +02:00
|
|
|
for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i)
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(i->c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-10 20:12:40 +02:00
|
|
|
}
|
2011-10-11 17:41:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
SV * topoSortPaths(...)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
PathSet paths;
|
|
|
|
for (int n = 0; n < items; ++n) paths.insert(SvPV_nolen(ST(n)));
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
Paths sorted = store()->topoSortPaths(paths);
|
2011-10-11 17:41:13 +02:00
|
|
|
for (Paths::iterator i = sorted.begin(); i != sorted.end(); ++i)
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(i->c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-11 17:41:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SV * followLinksToStorePath(char * path)
|
|
|
|
CODE:
|
|
|
|
try {
|
2016-02-15 20:09:30 +01:00
|
|
|
store();
|
2011-10-11 17:41:13 +02:00
|
|
|
RETVAL = newSVpv(followLinksToStorePath(path).c_str(), 0);
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-10-11 17:41:13 +02:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
2011-11-23 16:13:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
void exportPaths(int fd, int sign, ...)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
Paths paths;
|
|
|
|
for (int n = 2; n < items; ++n) paths.push_back(SvPV_nolen(ST(n)));
|
|
|
|
FdSink sink(fd);
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
store()->exportPaths(paths, sign, sink);
|
2011-11-23 16:13:37 +01:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-11-23 16:13:37 +01:00
|
|
|
}
|
2011-11-29 14:01:24 +01:00
|
|
|
|
|
|
|
|
2014-07-11 16:02:19 +02:00
|
|
|
void importPaths(int fd)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
FdSource source(fd);
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
store()->importPaths(false, source);
|
2014-07-11 16:02:19 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2014-07-11 16:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-29 14:01:24 +01:00
|
|
|
SV * hashPath(char * algo, int base32, char * path)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
Hash h = hashPath(parseHashType(algo), path).first;
|
|
|
|
string s = base32 ? printHash32(h) : printHash(h);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-11-29 14:01:24 +01:00
|
|
|
}
|
2011-12-02 13:09:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
SV * hashFile(char * algo, int base32, char * path)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
Hash h = hashFile(parseHashType(algo), path);
|
|
|
|
string s = base32 ? printHash32(h) : printHash(h);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-12-02 13:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SV * hashString(char * algo, int base32, char * s)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
Hash h = hashString(parseHashType(algo), s);
|
|
|
|
string s = base32 ? printHash32(h) : printHash(h);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-12-02 13:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-03 15:33:17 +02:00
|
|
|
SV * convertHash(char * algo, char * s, int toBase32)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
Hash h = parseHash16or32(parseHashType(algo), s);
|
|
|
|
string s = toBase32 ? printHash32(h) : printHash(h);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2015-06-03 15:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-16 16:38:44 +01:00
|
|
|
SV * signString(char * secretKey_, char * msg)
|
2015-02-04 16:43:32 +01:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2015-02-10 11:54:06 +01:00
|
|
|
#if HAVE_SODIUM
|
2016-02-16 16:38:44 +01:00
|
|
|
auto sig = SecretKey(secretKey_).signDetached(msg);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(sig.c_str(), sig.size())));
|
2015-02-10 11:54:06 +01:00
|
|
|
#else
|
|
|
|
throw Error("Nix was not compiled with libsodium, required for signed binary cache support");
|
|
|
|
#endif
|
2015-02-04 16:43:32 +01:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2015-02-04 16:43:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int checkSignature(SV * publicKey_, SV * sig_, char * msg)
|
|
|
|
CODE:
|
|
|
|
try {
|
2015-02-10 11:54:06 +01:00
|
|
|
#if HAVE_SODIUM
|
2015-02-04 16:43:32 +01:00
|
|
|
STRLEN publicKeyLen;
|
|
|
|
unsigned char * publicKey = (unsigned char *) SvPV(publicKey_, publicKeyLen);
|
|
|
|
if (publicKeyLen != crypto_sign_PUBLICKEYBYTES)
|
|
|
|
throw Error("public key is not valid");
|
|
|
|
|
|
|
|
STRLEN sigLen;
|
|
|
|
unsigned char * sig = (unsigned char *) SvPV(sig_, sigLen);
|
|
|
|
if (sigLen != crypto_sign_BYTES)
|
|
|
|
throw Error("signature is not valid");
|
|
|
|
|
|
|
|
RETVAL = crypto_sign_verify_detached(sig, (unsigned char *) msg, strlen(msg), publicKey) == 0;
|
2015-02-10 11:54:06 +01:00
|
|
|
#else
|
|
|
|
throw Error("Nix was not compiled with libsodium, required for signed binary cache support");
|
|
|
|
#endif
|
2015-02-04 16:43:32 +01:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2015-02-04 16:43:32 +01:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
|
2011-12-02 13:09:24 +01:00
|
|
|
SV * addToStore(char * srcPath, int recursive, char * algo)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
Path path = store()->addToStore(baseNameOf(srcPath), srcPath, recursive, parseHashType(algo));
|
2011-12-02 13:09:24 +01:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(path.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-12-02 13:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SV * makeFixedOutputPath(int recursive, char * algo, char * hash, char * name)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
HashType ht = parseHashType(algo);
|
|
|
|
Path path = makeFixedOutputPath(recursive, ht,
|
|
|
|
parseHash16or32(ht, hash), name);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(path.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2011-12-02 13:09:24 +01:00
|
|
|
}
|
2012-03-19 04:14:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
SV * derivationFromPath(char * drvPath)
|
|
|
|
PREINIT:
|
|
|
|
HV *hash;
|
|
|
|
CODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
Derivation drv = store()->derivationFromPath(drvPath);
|
2012-03-19 04:14:21 +01:00
|
|
|
hash = newHV();
|
2013-03-08 01:24:59 +01:00
|
|
|
|
|
|
|
HV * outputs = newHV();
|
|
|
|
for (DerivationOutputs::iterator i = drv.outputs.begin(); i != drv.outputs.end(); ++i)
|
|
|
|
hv_store(outputs, i->first.c_str(), i->first.size(), newSVpv(i->second.path.c_str(), 0), 0);
|
|
|
|
hv_stores(hash, "outputs", newRV((SV *) outputs));
|
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
AV * inputDrvs = newAV();
|
|
|
|
for (DerivationInputs::iterator i = drv.inputDrvs.begin(); i != drv.inputDrvs.end(); ++i)
|
|
|
|
av_push(inputDrvs, newSVpv(i->first.c_str(), 0)); // !!! ignores i->second
|
|
|
|
hv_stores(hash, "inputDrvs", newRV((SV *) inputDrvs));
|
2013-03-08 01:24:59 +01:00
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
AV * inputSrcs = newAV();
|
|
|
|
for (PathSet::iterator i = drv.inputSrcs.begin(); i != drv.inputSrcs.end(); ++i)
|
|
|
|
av_push(inputSrcs, newSVpv(i->c_str(), 0));
|
|
|
|
hv_stores(hash, "inputSrcs", newRV((SV *) inputSrcs));
|
2013-03-08 01:24:59 +01:00
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
hv_stores(hash, "platform", newSVpv(drv.platform.c_str(), 0));
|
|
|
|
hv_stores(hash, "builder", newSVpv(drv.builder.c_str(), 0));
|
2013-03-08 01:24:59 +01:00
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
AV * args = newAV();
|
|
|
|
for (Strings::iterator i = drv.args.begin(); i != drv.args.end(); ++i)
|
|
|
|
av_push(args, newSVpv(i->c_str(), 0));
|
|
|
|
hv_stores(hash, "args", newRV((SV *) args));
|
2013-03-08 01:24:59 +01:00
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
HV * env = newHV();
|
|
|
|
for (StringPairs::iterator i = drv.env.begin(); i != drv.env.end(); ++i)
|
|
|
|
hv_store(env, i->first.c_str(), i->first.size(), newSVpv(i->second.c_str(), 0), 0);
|
|
|
|
hv_stores(hash, "env", newRV((SV *) env));
|
2013-03-08 01:24:59 +01:00
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
RETVAL = newRV_noinc((SV *)hash);
|
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2012-03-19 04:14:21 +01:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
2015-10-09 12:49:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
void addTempRoot(char * storePath)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
store()->addTempRoot(storePath);
|
2015-10-09 12:49:47 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 14:33:13 +01:00
|
|
|
croak("%s", e.what());
|
2015-10-09 12:49:47 +02:00
|
|
|
}
|