2003-04-08 12:00:51 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
|
2003-04-08 14:05:15 +00:00
|
|
|
#include <sys/types.h>
|
2003-04-08 15:36:54 +00:00
|
|
|
#include <sys/stat.h>
|
2003-04-08 14:05:15 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2003-04-08 12:00:51 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "util.hh"
|
2003-06-15 13:41:32 +00:00
|
|
|
#include "hash.hh"
|
2003-04-08 12:00:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
static string nixDescriptorDir;
|
|
|
|
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
static bool verbose = false;
|
|
|
|
|
|
|
|
|
2003-04-08 15:36:54 +00:00
|
|
|
/* Mapping of Fix file names to the hashes of the resulting Nix
|
|
|
|
descriptors. */
|
2003-06-15 13:41:32 +00:00
|
|
|
typedef map<string, Hash> DescriptorMap;
|
2003-04-08 12:00:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
void registerFile(string filename)
|
|
|
|
{
|
2003-05-26 09:44:18 +00:00
|
|
|
int res = system(("nix regfile " + filename).c_str());
|
|
|
|
/* !!! escape */
|
2003-04-08 12:00:51 +00:00
|
|
|
if (WEXITSTATUS(res) != 0)
|
|
|
|
throw Error("cannot register " + filename + " with Nix");
|
|
|
|
}
|
|
|
|
|
2003-05-26 09:44:18 +00:00
|
|
|
|
2003-06-15 13:41:32 +00:00
|
|
|
void registerURL(Hash hash, string url)
|
2003-05-26 09:44:18 +00:00
|
|
|
{
|
2003-06-15 13:41:32 +00:00
|
|
|
int res = system(("nix regurl " + (string) hash + " " + url).c_str());
|
2003-05-26 09:44:18 +00:00
|
|
|
/* !!! escape */
|
|
|
|
if (WEXITSTATUS(res) != 0)
|
2003-06-15 13:41:32 +00:00
|
|
|
throw Error("cannot register " +
|
|
|
|
(string) hash + " -> " + url + " with Nix");
|
2003-05-26 09:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
Error badTerm(const string & msg, ATerm e)
|
2003-04-08 12:00:51 +00:00
|
|
|
{
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
char * s = ATwriteToString(e);
|
|
|
|
return Error(msg + ", in `" + s + "'");
|
2003-04-08 12:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
/* Term evaluation. */
|
|
|
|
|
|
|
|
typedef map<string, ATerm> BindingsMap;
|
|
|
|
|
|
|
|
struct EvalContext
|
2003-04-08 12:00:51 +00:00
|
|
|
{
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
string dir;
|
|
|
|
DescriptorMap * done;
|
|
|
|
BindingsMap * vars;
|
|
|
|
};
|
|
|
|
|
2003-04-08 12:00:51 +00:00
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
ATerm evaluate(ATerm e, EvalContext ctx);
|
2003-06-15 13:41:32 +00:00
|
|
|
Hash instantiateDescriptor(string filename, EvalContext ctx);
|
2003-04-08 12:00:51 +00:00
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
|
|
|
|
string evaluateStr(ATerm e, EvalContext ctx)
|
2003-04-08 12:00:51 +00:00
|
|
|
{
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
e = evaluate(e, ctx);
|
2003-04-08 12:00:51 +00:00
|
|
|
char * s;
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
if (ATmatch(e, "Str(<str>)", &s))
|
2003-04-08 12:00:51 +00:00
|
|
|
return s;
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
else throw badTerm("string value expected", e);
|
2003-04-08 12:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
bool evaluateBool(ATerm e, EvalContext ctx)
|
2003-04-08 12:00:51 +00:00
|
|
|
{
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
e = evaluate(e, ctx);
|
|
|
|
if (ATmatch(e, "Bool(True)"))
|
|
|
|
return true;
|
|
|
|
else if (ATmatch(e, "Bool(False)"))
|
|
|
|
return false;
|
|
|
|
else throw badTerm("boolean value expected", e);
|
2003-04-08 12:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
ATerm evaluate(ATerm e, EvalContext ctx)
|
2003-04-08 12:00:51 +00:00
|
|
|
{
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
char * s;
|
2003-05-25 22:42:19 +00:00
|
|
|
ATerm e2, e3;
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
ATerm eCond, eTrue, eFalse;
|
2003-04-08 12:00:51 +00:00
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
/* Check for normal forms first. */
|
2003-04-08 12:00:51 +00:00
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
if (ATmatch(e, "Str(<str>)", &s) ||
|
|
|
|
ATmatch(e, "Bool(True)") || ATmatch(e, "Bool(False)"))
|
|
|
|
return e;
|
|
|
|
|
|
|
|
else if (
|
|
|
|
ATmatch(e, "Pkg(<str>)", &s) ||
|
|
|
|
ATmatch(e, "File(<str>)", &s))
|
|
|
|
{
|
2003-06-15 13:41:32 +00:00
|
|
|
parseHash(s);
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Short-hands. */
|
|
|
|
|
|
|
|
else if (ATmatch(e, "<str>", &s))
|
|
|
|
return ATmake("Str(<str>)", s);
|
|
|
|
|
|
|
|
else if (ATmatch(e, "True", &s))
|
|
|
|
return ATmake("Bool(True)", s);
|
|
|
|
|
|
|
|
else if (ATmatch(e, "False", &s))
|
|
|
|
return ATmake("Bool(False)", s);
|
|
|
|
|
|
|
|
/* Functions. */
|
|
|
|
|
|
|
|
/* `Var' looks up a variable. */
|
|
|
|
else if (ATmatch(e, "Var(<str>)", &s)) {
|
|
|
|
string name(s);
|
|
|
|
ATerm e2 = (*ctx.vars)[name];
|
|
|
|
if (!e2) throw Error("undefined variable " + name);
|
|
|
|
return evaluate(e2, ctx); /* !!! update binding */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* `Fix' recursively instantiates a Fix descriptor, returning the
|
|
|
|
hash of the generated Nix descriptor. */
|
|
|
|
else if (ATmatch(e, "Fix(<term>)", &e2)) {
|
|
|
|
string filename = absPath(evaluateStr(e2, ctx), ctx.dir); /* !!! */
|
|
|
|
return ATmake("Pkg(<str>)",
|
2003-06-15 13:41:32 +00:00
|
|
|
((string) instantiateDescriptor(filename, ctx)).c_str());
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
}
|
|
|
|
|
2003-05-25 22:42:19 +00:00
|
|
|
#if 0
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
/* `Source' copies the specified file to nixSourcesDir, registers
|
|
|
|
it with Nix, and returns the hash of the file. */
|
|
|
|
else if (ATmatch(e, "Source(<term>)", &e2)) {
|
|
|
|
string source = absPath(evaluateStr(e2, ctx), ctx.dir); /* !!! */
|
|
|
|
string target = nixSourcesDir + "/" + baseNameOf(source);
|
|
|
|
|
|
|
|
// Don't copy if filename is already in nixSourcesDir.
|
|
|
|
if (source != target) {
|
|
|
|
if (verbose)
|
|
|
|
cerr << "copying source " << source << endl;
|
|
|
|
string cmd = "cp -p " + source + " " + target;
|
|
|
|
int res = system(cmd.c_str());
|
|
|
|
if (WEXITSTATUS(res) != 0)
|
|
|
|
throw Error("cannot copy " + source + " to " + target);
|
|
|
|
}
|
|
|
|
|
|
|
|
registerFile(target);
|
|
|
|
return ATmake("File(<str>)", hashFile(target).c_str());
|
|
|
|
}
|
2003-05-25 22:42:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* `Local' registers a file with Nix, and returns the file's
|
|
|
|
hash. */
|
|
|
|
else if (ATmatch(e, "Local(<term>)", &e2)) {
|
|
|
|
string filename = absPath(evaluateStr(e2, ctx), ctx.dir); /* !!! */
|
2003-06-15 13:41:32 +00:00
|
|
|
Hash hash = hashFile(filename);
|
2003-05-26 09:44:18 +00:00
|
|
|
registerFile(filename); /* !!! */
|
2003-06-15 13:41:32 +00:00
|
|
|
return ATmake("File(<str>)", ((string) hash).c_str());
|
2003-05-25 22:42:19 +00:00
|
|
|
}
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
|
2003-05-25 22:42:19 +00:00
|
|
|
/* `Url' registers a mapping from a hash to an url with Nix, and
|
|
|
|
returns the hash. */
|
|
|
|
else if (ATmatch(e, "Url(<term>, <term>)", &e2, &e3)) {
|
2003-06-15 13:41:32 +00:00
|
|
|
Hash hash = parseHash(evaluateStr(e2, ctx));
|
2003-05-25 22:42:19 +00:00
|
|
|
string url = evaluateStr(e3, ctx);
|
2003-05-26 09:44:18 +00:00
|
|
|
registerURL(hash, url);
|
2003-06-15 13:41:32 +00:00
|
|
|
return ATmake("File(<str>)", ((string) hash).c_str());
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* `If' provides conditional evaluation. */
|
|
|
|
else if (ATmatch(e, "If(<term>, <term>, <term>)",
|
|
|
|
&eCond, &eTrue, &eFalse))
|
|
|
|
return evaluate(evaluateBool(eCond, ctx) ? eTrue : eFalse, ctx);
|
|
|
|
|
|
|
|
else throw badTerm("invalid expression", e);
|
|
|
|
}
|
2003-04-08 12:00:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
string getStringFromMap(BindingsMap & bindingsMap,
|
|
|
|
const string & name)
|
|
|
|
{
|
|
|
|
ATerm e = bindingsMap[name];
|
|
|
|
if (!e) throw Error("binding " + name + " is not set");
|
|
|
|
char * s;
|
|
|
|
if (ATmatch(e, "Str(<str>)", &s))
|
|
|
|
return s;
|
|
|
|
else
|
|
|
|
throw Error("binding " + name + " is not a string");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Instantiate a Fix descriptors into a Nix descriptor, recursively
|
|
|
|
instantiating referenced descriptors as well. */
|
2003-06-15 13:41:32 +00:00
|
|
|
Hash instantiateDescriptor(string filename, EvalContext ctx)
|
2003-04-08 12:00:51 +00:00
|
|
|
{
|
|
|
|
/* Already done? */
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
DescriptorMap::iterator isInMap = ctx.done->find(filename);
|
|
|
|
if (isInMap != ctx.done->end()) return isInMap->second;
|
2003-04-08 12:00:51 +00:00
|
|
|
|
|
|
|
/* No. */
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
ctx.dir = dirOf(filename);
|
2003-04-08 12:00:51 +00:00
|
|
|
|
|
|
|
/* Read the Fix descriptor as an ATerm. */
|
|
|
|
ATerm inTerm = ATreadFromNamedFile(filename.c_str());
|
|
|
|
if (!inTerm) throw Error("cannot read aterm " + filename);
|
|
|
|
|
|
|
|
ATerm bindings;
|
|
|
|
if (!ATmatch(inTerm, "Descr(<term>)", &bindings))
|
|
|
|
throw Error("invalid term in " + filename);
|
|
|
|
|
|
|
|
/* Iterate over the bindings and evaluate them to normal form. */
|
|
|
|
BindingsMap bindingsMap; /* the normal forms */
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
ctx.vars = &bindingsMap;
|
2003-04-08 12:00:51 +00:00
|
|
|
|
|
|
|
char * cname;
|
|
|
|
ATerm value;
|
|
|
|
while (ATmatch(bindings, "[Bind(<str>, <term>), <list>]",
|
|
|
|
&cname, &value, &bindings))
|
|
|
|
{
|
|
|
|
string name(cname);
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
ATerm e = evaluate(value, ctx);
|
2003-04-08 12:00:51 +00:00
|
|
|
bindingsMap[name] = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct a descriptor identifier by concatenating the package
|
|
|
|
and release ids. */
|
|
|
|
string pkgId = getStringFromMap(bindingsMap, "pkgId");
|
|
|
|
string releaseId = getStringFromMap(bindingsMap, "releaseId");
|
|
|
|
string id = pkgId + "-" + releaseId;
|
|
|
|
bindingsMap["id"] = ATmake("Str(<str>)", id.c_str());
|
|
|
|
|
|
|
|
/* Add a system name. */
|
|
|
|
bindingsMap["system"] = ATmake("Str(<str>)", thisSystem.c_str());
|
|
|
|
|
|
|
|
/* Construct the resulting ATerm. Note that iterating over the
|
|
|
|
map yields the bindings in sorted order, which is exactly the
|
|
|
|
canonical form for Nix descriptors. */
|
|
|
|
ATermList bindingsList = ATempty;
|
|
|
|
for (BindingsMap::iterator it = bindingsMap.begin();
|
|
|
|
it != bindingsMap.end(); it++)
|
|
|
|
/* !!! O(n^2) */
|
|
|
|
bindingsList = ATappend(bindingsList,
|
|
|
|
ATmake("Bind(<str>, <term>)", it->first.c_str(), it->second));
|
|
|
|
ATerm outTerm = ATmake("Descr(<term>)", bindingsList);
|
|
|
|
|
|
|
|
/* Write out the resulting ATerm. */
|
|
|
|
string tmpFilename = nixDescriptorDir + "/tmp";
|
|
|
|
if (!ATwriteToNamedTextFile(outTerm, tmpFilename.c_str()))
|
|
|
|
throw Error("cannot write aterm to " + tmpFilename);
|
|
|
|
|
2003-06-15 13:41:32 +00:00
|
|
|
Hash outHash = hashFile(tmpFilename);
|
|
|
|
string outFilename = nixDescriptorDir + "/" +
|
|
|
|
id + "-" + (string) outHash + ".nix";
|
2003-04-08 12:00:51 +00:00
|
|
|
if (rename(tmpFilename.c_str(), outFilename.c_str()))
|
|
|
|
throw Error("cannot rename " + tmpFilename + " to " + outFilename);
|
|
|
|
|
|
|
|
/* Register it with Nix. */
|
|
|
|
registerFile(outFilename);
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
if (verbose)
|
2003-06-15 13:41:32 +00:00
|
|
|
cerr << "instantiated " << (string) outHash
|
|
|
|
<< " from " << filename << endl;
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
|
|
|
|
(*ctx.done)[filename] = outHash;
|
2003-04-08 15:36:54 +00:00
|
|
|
return outHash;
|
2003-04-08 12:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Instantiate a set of Fix descriptors into Nix descriptors. */
|
|
|
|
void instantiateDescriptors(Strings filenames)
|
|
|
|
{
|
|
|
|
DescriptorMap done;
|
|
|
|
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
EvalContext ctx;
|
|
|
|
ctx.done = &done;
|
|
|
|
|
2003-04-08 12:00:51 +00:00
|
|
|
for (Strings::iterator it = filenames.begin();
|
|
|
|
it != filenames.end(); it++)
|
|
|
|
{
|
|
|
|
string filename = absPath(*it);
|
2003-06-15 13:41:32 +00:00
|
|
|
cout << (string) instantiateDescriptor(filename, ctx) << endl;
|
2003-04-08 12:00:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Print help. */
|
|
|
|
void printUsage()
|
|
|
|
{
|
|
|
|
cerr <<
|
2003-06-15 13:41:32 +00:00
|
|
|
"Usage: fix ...\n\
|
2003-04-08 12:00:51 +00:00
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Parse the command-line arguments, call the right operation. */
|
|
|
|
void run(Strings::iterator argCur, Strings::iterator argEnd)
|
|
|
|
{
|
2003-05-30 20:53:36 +00:00
|
|
|
umask(0022);
|
|
|
|
|
2003-04-08 12:00:51 +00:00
|
|
|
Strings extraArgs;
|
|
|
|
enum { cmdUnknown, cmdInstantiate } command = cmdUnknown;
|
|
|
|
|
|
|
|
char * homeDir = getenv(nixHomeDirEnvVar.c_str());
|
|
|
|
if (homeDir) nixHomeDir = homeDir;
|
|
|
|
|
|
|
|
nixDescriptorDir = nixHomeDir + "/var/nix/descriptors";
|
|
|
|
|
|
|
|
for ( ; argCur != argEnd; argCur++) {
|
|
|
|
string arg(*argCur);
|
|
|
|
if (arg == "-h" || arg == "--help") {
|
|
|
|
printUsage();
|
|
|
|
return;
|
* Cleaned up the semantics of Fix expressions.
* Conditionals and variables in Fix expressions. This allows, e.g.,
Descr(
[ Bind("pkgId", "subversion-0.21.0")
, Bind("httpsClient", Bool(True))
, Bind("httpServer", Bool(True))
, Bind("ssl", If(Var("httpsClient"), Fix("./openssl-0.9.7b.fix"), ""))
, Bind("httpd", If(Var("httpServer"), Fix("./httpd-2.0.45.fix"), ""))
...
])
which introduces domain feature variables httpsClient and httpServer
(i.e., whether Subversion is built with https client and webdav
server support); the values of the variables influences package
dependencies and the build scripts.
The next step is to allow that packages can express constraints on
each other. E.g., StrategoXT is dependent on an ATerm library with
the "gcc" variant enabled. In fact, this may cause several
Nix instantiations to be created from a single Fix descriptor. If
possible, Fix should try to find the least set of instantiations
that obeys the constraints.
2003-04-25 15:33:50 +00:00
|
|
|
} else if (arg == "-v" || arg == "--verbose") {
|
|
|
|
verbose = true;
|
|
|
|
} else if (arg == "--instantiate" || arg == "-i") {
|
2003-04-08 12:00:51 +00:00
|
|
|
command = cmdInstantiate;
|
|
|
|
} else if (arg[0] == '-')
|
|
|
|
throw UsageError("invalid option `" + arg + "'");
|
|
|
|
else
|
|
|
|
extraArgs.push_back(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
|
|
|
|
case cmdInstantiate:
|
|
|
|
instantiateDescriptors(extraArgs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw UsageError("no operation specified");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char * * argv)
|
|
|
|
{
|
|
|
|
ATerm bottomOfStack;
|
|
|
|
ATinit(argc, argv, &bottomOfStack);
|
|
|
|
|
|
|
|
/* Put the arguments in a vector. */
|
|
|
|
Strings args;
|
|
|
|
while (argc--) args.push_back(*argv++);
|
|
|
|
Strings::iterator argCur = args.begin(), argEnd = args.end();
|
|
|
|
|
|
|
|
argCur++;
|
|
|
|
|
|
|
|
try {
|
|
|
|
run(argCur, argEnd);
|
|
|
|
} catch (UsageError & e) {
|
|
|
|
cerr << "error: " << e.what() << endl
|
|
|
|
<< "Try `fix -h' for more information.\n";
|
|
|
|
return 1;
|
|
|
|
} catch (exception & e) {
|
|
|
|
cerr << "error: " << e.what() << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|