* FreeBSD / gcc 2.95 compatibility fixes.

* A script to generate prebuilt registration scripts.
This commit is contained in:
Eelco Dolstra 2003-04-08 14:05:15 +00:00
parent f7ef88df1f
commit cc6eafb3d0
4 changed files with 50 additions and 36 deletions

20
scripts/nix-generate-regscript Executable file
View file

@ -0,0 +1,20 @@
#! /usr/bin/perl -w
my $dir = shift @ARGV;
$dir || die "missing directory";
my $url = shift @ARGV;
$url || die "missing base url";
chdir $dir || die "cannot chdir to $dir";
foreach my $prebuilt (glob("*.tar.bz2")) {
$prebuilt =~ /-([a-z0-9]+)-([a-z0-9]+).tar.bz2$/
|| die "invalid file name: $prebuilt";
my $pkgHash = $1;
my $prebuiltHash = $2;
print "regprebuilt $pkgHash $prebuiltHash\n";
print "regurl $prebuiltHash $url/$prebuilt\n";
}

View file

@ -1,6 +1,9 @@
#include <iostream>
#include <map>
#include <sys/types.h>
#include <sys/wait.h>
extern "C" {
#include <aterm2.h>
}
@ -23,13 +26,31 @@ void registerFile(string filename)
}
/* Return the directory part of the given path, i.e., everything
before the final `/'. */
string dirOf(string s)
{
unsigned int pos = s.rfind('/');
if (pos == string::npos) throw Error("invalid file name");
return string(s, 0, pos);
}
/* Return the base name of the given path, i.e., everything following
the final `/'. */
string baseNameOf(string s)
{
unsigned int pos = s.rfind('/');
if (pos == string::npos) throw Error("invalid file name");
return string(s, pos + 1);
}
/* Download object referenced by the given URL into the sources
directory. Return the file name it was downloaded to. */
string fetchURL(string url)
{
unsigned int pos = url.rfind('/');
if (pos == string::npos) throw Error("invalid url");
string filename(url, pos + 1);
string filename = baseNameOf(url);
string fullname = nixSourcesDir + "/" + filename;
/* !!! quoting */
string shellCmd =
@ -41,16 +62,6 @@ string fetchURL(string url)
}
/* Return the directory part of the given path, i.e., everything
before the final `/'. */
string dirOf(string s)
{
unsigned int pos = s.rfind('/');
if (pos == string::npos) throw Error("invalid file name");
return string(s, 0, pos);
}
/* Term evaluation functions. */
string evaluateStr(ATerm e)
@ -88,12 +99,13 @@ string evaluateFile(ATerm e, string dir)
int res = system(cmd.c_str());
if (WEXITSTATUS(res) != 0)
throw Error("cannot copy " + filename);
registerFile(nixSourcesDir + "/" + baseNameOf(filename));
return hashFile(filename);
} else throw Error("invalid hash expression");
}
ATerm evaluatePkg(ATerm e, DescriptorMap & done)
string evaluatePkg(ATerm e, DescriptorMap & done)
{
char * s;
if (ATmatch(e, "<str>", &s)) {
@ -113,7 +125,7 @@ ATerm evaluate(ATerm e, string dir, DescriptorMap & done)
else if (ATmatch(e, "File(<term>)", &t))
return ATmake("File(<str>)", evaluateFile(t, dir).c_str());
else if (ATmatch(e, "Pkg(<term>)", &t))
return ATmake("Pkg(<term>)", evaluatePkg(t, done));
return ATmake("Pkg(<str>)", evaluatePkg(t, done).c_str());
else throw Error("invalid expression type");
}

View file

@ -1,17 +0,0 @@
#! /usr/bin/perl -w
my $dir = $ARGV[0];
foreach my $prebuilt (glob("$dir/*.tar.bz2")) {
$prebuilt =~ /-([a-z0-9]+)-([a-z0-9]+).tar.bz2$/
|| die "invalid file name: $prebuilt";
my $pkgHash = $1;
my $prebuiltHash = $2;
print "$pkgHash -> $prebuiltHash\n";
system "nix regprebuilt $pkgHash $prebuiltHash";
system "nix regfile $prebuilt";
}

View file

@ -6,11 +6,12 @@
#include <map>
#include <cstdio>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <db4/db_cxx.h>
#include <db_cxx.h>
extern "C" {
#include <aterm1.h>
@ -48,9 +49,7 @@ public:
auto_ptr<Db2> openDB(const string & dbname, bool readonly)
{
auto_ptr<Db2> db;
db = auto_ptr<Db2>(new Db2(0, 0));
auto_ptr<Db2> db(new Db2(0, 0));
db->open((nixHomeDir + "/var/nix/pkginfo.db").c_str(), dbname.c_str(),
DB_HASH, readonly ? DB_RDONLY : DB_CREATE, 0666);