Add builtin constants ‘langVersion’ and ‘nixVersion’

The integer constant ‘langVersion’ denotes the current language
version.  It gets increased every time a language feature is
added/changed/removed.  It's currently 1.

The string constant ‘nixVersion’ contains the current Nix version,
e.g. "1.2pre2980_9de6bc5".
This commit is contained in:
Eelco Dolstra 2012-11-27 13:29:55 +01:00
parent 5943f41b8b
commit 8b8ee53bc7
6 changed files with 18 additions and 2 deletions

View file

@ -1143,6 +1143,16 @@ void EvalState::createBaseEnv()
mkString(v, settings.thisSystem.c_str()); mkString(v, settings.thisSystem.c_str());
addConstant("__currentSystem", v); addConstant("__currentSystem", v);
mkString(v, nixVersion.c_str());
addConstant("__nixVersion", v);
/* Language version. This should be increased every time a new
language feature gets added. It's not necessary to increase it
when primops get added, because you can just use `builtins ?
primOp' to check. */
mkInt(v, 1);
addConstant("__langVersion", v);
// Miscellaneous // Miscellaneous
addPrimOp("import", 1, prim_import); addPrimOp("import", 1, prim_import);
addPrimOp("isNull", 1, prim_isNull); addPrimOp("isNull", 1, prim_isNull);

View file

@ -7,6 +7,5 @@ libmain_la_LIBADD = ../libstore/libstore.la @BDW_GC_LIBS@
pkginclude_HEADERS = shared.hh pkginclude_HEADERS = shared.hh
AM_CXXFLAGS = \ AM_CXXFLAGS = \
-DNIX_VERSION=\"$(VERSION)\" \
-I$(srcdir)/.. -I$(srcdir)/../libutil \ -I$(srcdir)/.. -I$(srcdir)/../libutil \
-I$(srcdir)/../libstore -I$(srcdir)/../libstore

View file

@ -180,7 +180,7 @@ static void initAndRun(int argc, char * * argv)
return; return;
} }
else if (arg == "--version") { else if (arg == "--version") {
std::cout << format("%1% (Nix) %2%") % programId % NIX_VERSION << std::endl; std::cout << format("%1% (Nix) %2%") % programId % nixVersion << std::endl;
return; return;
} }
else if (arg == "--keep-failed" || arg == "-K") else if (arg == "--keep-failed" || arg == "-K")

View file

@ -23,6 +23,7 @@ AM_CXXFLAGS = -Wall \
-DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \ -DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
-DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \ -DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
-DNIX_BIN_DIR=\"$(bindir)\" \ -DNIX_BIN_DIR=\"$(bindir)\" \
-DNIX_VERSION=\"$(VERSION)\" \
-I$(srcdir)/.. -I$(srcdir)/../libutil \ -I$(srcdir)/.. -I$(srcdir)/../libutil \
-I$(srcdir)/../libstore -I$(srcdir)/../libstore

View file

@ -197,4 +197,7 @@ Settings::SettingsMap Settings::getOverrides()
} }
const string nixVersion = NIX_VERSION;
} }

View file

@ -190,4 +190,7 @@ private:
extern Settings settings; extern Settings settings;
extern const string nixVersion;
} }