From 8b8ee53bc73769bb25d967ba259dabc9b23e2e6f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 27 Nov 2012 13:29:55 +0100 Subject: [PATCH] =?UTF-8?q?Add=20builtin=20constants=20=E2=80=98langVersio?= =?UTF-8?q?n=E2=80=99=20and=20=E2=80=98nixVersion=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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". --- src/libexpr/primops.cc | 10 ++++++++++ src/libmain/Makefile.am | 1 - src/libmain/shared.cc | 2 +- src/libstore/Makefile.am | 1 + src/libstore/globals.cc | 3 +++ src/libstore/globals.hh | 3 +++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 509297003..6876b2853 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1143,6 +1143,16 @@ void EvalState::createBaseEnv() mkString(v, settings.thisSystem.c_str()); 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 addPrimOp("import", 1, prim_import); addPrimOp("isNull", 1, prim_isNull); diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am index 404353c62..6a2d7f5f5 100644 --- a/src/libmain/Makefile.am +++ b/src/libmain/Makefile.am @@ -7,6 +7,5 @@ libmain_la_LIBADD = ../libstore/libstore.la @BDW_GC_LIBS@ pkginclude_HEADERS = shared.hh AM_CXXFLAGS = \ - -DNIX_VERSION=\"$(VERSION)\" \ -I$(srcdir)/.. -I$(srcdir)/../libutil \ -I$(srcdir)/../libstore diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 2cf5b08df..ead3fc017 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -180,7 +180,7 @@ static void initAndRun(int argc, char * * argv) return; } 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; } else if (arg == "--keep-failed" || arg == "-K") diff --git a/src/libstore/Makefile.am b/src/libstore/Makefile.am index 46e18be23..3dfb1e0c3 100644 --- a/src/libstore/Makefile.am +++ b/src/libstore/Makefile.am @@ -23,6 +23,7 @@ AM_CXXFLAGS = -Wall \ -DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \ -DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \ -DNIX_BIN_DIR=\"$(bindir)\" \ + -DNIX_VERSION=\"$(VERSION)\" \ -I$(srcdir)/.. -I$(srcdir)/../libutil \ -I$(srcdir)/../libstore diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 7b881d1d2..bb453a451 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -197,4 +197,7 @@ Settings::SettingsMap Settings::getOverrides() } +const string nixVersion = NIX_VERSION; + + } diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index d25ee6adc..953eed9c3 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -190,4 +190,7 @@ private: extern Settings settings; +extern const string nixVersion; + + }