diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-01 16:10:48 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-01 16:41:08 +0300 |
commit | da9cbf29c403d27c2940f9b31199c4648f8ae4a1 (patch) | |
tree | 9732de6f48bdaead2becf32be41b1284e1e83e00 | |
parent | 8e69e09b7ec68377758c63092f9b254e95a0d7be (diff) |
Move version build system module to separate library
-rw-r--r-- | bootstrap-mingw.bat | 2 | ||||
-rw-r--r-- | bootstrap-msvc.bat | 2 | ||||
-rw-r--r-- | bootstrap.gmake | 4 | ||||
-rwxr-xr-x | bootstrap.sh | 2 | ||||
-rw-r--r-- | build2/b.cxx | 5 | ||||
-rw-r--r-- | build2/bash/init.cxx | 2 | ||||
-rw-r--r-- | build2/buildfile | 4 | ||||
-rw-r--r-- | build2/version/init.hxx | 31 | ||||
-rw-r--r-- | libbuild2/buildfile | 2 | ||||
-rw-r--r-- | libbuild2/version/buildfile | 66 | ||||
-rw-r--r-- | libbuild2/version/export.hxx | 34 | ||||
-rw-r--r-- | libbuild2/version/init.cxx (renamed from build2/version/init.cxx) | 29 | ||||
-rw-r--r-- | libbuild2/version/init.hxx | 28 | ||||
-rw-r--r-- | libbuild2/version/module.cxx (renamed from build2/version/module.cxx) | 4 | ||||
-rw-r--r-- | libbuild2/version/module.hxx (renamed from build2/version/module.hxx) | 8 | ||||
-rw-r--r-- | libbuild2/version/rule.cxx (renamed from build2/version/rule.cxx) | 8 | ||||
-rw-r--r-- | libbuild2/version/rule.hxx (renamed from build2/version/rule.hxx) | 8 | ||||
-rw-r--r-- | libbuild2/version/snapshot-git.cxx (renamed from build2/version/snapshot-git.cxx) | 4 | ||||
-rw-r--r-- | libbuild2/version/snapshot.cxx (renamed from build2/version/snapshot.cxx) | 4 | ||||
-rw-r--r-- | libbuild2/version/snapshot.hxx (renamed from build2/version/snapshot.hxx) | 8 | ||||
-rw-r--r-- | libbuild2/version/utility.cxx (renamed from build2/version/utility.cxx) | 4 | ||||
-rw-r--r-- | libbuild2/version/utility.hxx (renamed from build2/version/utility.hxx) | 8 | ||||
-rw-r--r-- | tests/libbuild2/buildfile | 1 | ||||
-rw-r--r-- | tests/libbuild2/driver.cxx | 2 |
24 files changed, 192 insertions, 78 deletions
diff --git a/bootstrap-mingw.bat b/bootstrap-mingw.bat index 5061753..e4caf8e 100644 --- a/bootstrap-mingw.bat +++ b/bootstrap-mingw.bat @@ -65,7 +65,6 @@ set "src=%src% build2\bin" set "src=%src% build2\c" set "src=%src% build2\cc" set "src=%src% build2\cxx" -set "src=%src% build2\version" set "src=%src% libbuild2" set "src=%src% libbuild2\config" @@ -73,6 +72,7 @@ set "src=%src% libbuild2\dist" set "src=%src% libbuild2\test" set "src=%src% libbuild2\test\script" set "src=%src% libbuild2\install" +set "src=%src% libbuild2\version" set "src=%src% libbuild2\in" set "src=%src% %libbutl%\libbutl" diff --git a/bootstrap-msvc.bat b/bootstrap-msvc.bat index e4e2a66..1facca5 100644 --- a/bootstrap-msvc.bat +++ b/bootstrap-msvc.bat @@ -96,7 +96,6 @@ set "src=%src% build2\bin" set "src=%src% build2\c" set "src=%src% build2\cc" set "src=%src% build2\cxx" -set "src=%src% build2\version" set "src=%src% libbuild2" set "src=%src% libbuild2\config" @@ -104,6 +103,7 @@ set "src=%src% libbuild2\dist" set "src=%src% libbuild2\test" set "src=%src% libbuild2\test\script" set "src=%src% libbuild2\install" +set "src=%src% libbuild2\version" set "src=%src% libbuild2\in" set "src=%src% %libbutl%\libbutl" diff --git a/bootstrap.gmake b/bootstrap.gmake index 793f3d0..e4d4b33 100644 --- a/bootstrap.gmake +++ b/bootstrap.gmake @@ -133,8 +133,7 @@ build2_sub := \ bin \ c \ cc \ -cxx \ -version +cxx libbuild2_sub := \ config \ @@ -142,6 +141,7 @@ dist \ test/script \ test \ install \ +version \ in build2_src := $(wildcard $(src_root)/build2/*.cxx) diff --git a/bootstrap.sh b/bootstrap.sh index 7e754b0..8de5e3c 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -122,7 +122,6 @@ src="$src build2/c/*.cxx" src="$src build2/cc/*.cxx" src="$src build2/cxx/*.cxx" src="$src build2/cli/*.cxx" -src="$src build2/version/*.cxx" src="$src build2/bash/*.cxx" src="$src libbuild2/*.cxx" @@ -131,6 +130,7 @@ src="$src libbuild2/dist/*.cxx" src="$src libbuild2/test/*.cxx" src="$src libbuild2/test/script/*.cxx" src="$src libbuild2/install/*.cxx" +src="$src libbuild2/version/*.cxx" src="$src libbuild2/in/*.cxx" src="$src $libbutl/libbutl/*.cxx" diff --git a/build2/b.cxx b/build2/b.cxx index 907784b..a016278 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -52,7 +52,7 @@ #include <libbuild2/install/init.hxx> #include <libbuild2/in/init.hxx> -#include <build2/version/init.hxx> +#include <libbuild2/version/init.hxx> #include <build2/bin/init.hxx> #include <build2/c/init.hxx> @@ -449,8 +449,7 @@ main (int argc, char* argv[]) reg (&test::build2_test_load); reg (&install::build2_install_load); - bm["version"] = mf {"version", &version::boot, &version::init}; - + reg (&version::build2_version_load); reg (&in::build2_in_load); bm["bin.vars"] = mf {"bin.vars", nullptr, &bin::vars_init}; diff --git a/build2/bash/init.cxx b/build2/bash/init.cxx index a23bc61..146e680 100644 --- a/build2/bash/init.cxx +++ b/build2/bash/init.cxx @@ -36,7 +36,7 @@ namespace build2 tracer trace ("bash::init"); l5 ([&]{trace << "for " << bs;}); - // Load in.base (in.* varibales, in{} target type). + // Load in.base (in.* variables, in{} target type). // if (!cast_false<bool> (rs["in.base.loaded"])) load_module (rs, rs, "in.base", l); diff --git a/build2/buildfile b/build2/buildfile index a940793..ea39e87 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -8,9 +8,9 @@ import libs += libpkgconf%lib{pkgconf} include ../libbuild2/ libs += ../libbuild2/lib{build2} -for m: in +for m: version in { - include ../libbuild2/in/ + include ../libbuild2/$m/ libs += ../libbuild2/$m/lib{build2-$m} } diff --git a/build2/version/init.hxx b/build2/version/init.hxx deleted file mode 100644 index ef3688a..0000000 --- a/build2/version/init.hxx +++ /dev/null @@ -1,31 +0,0 @@ -// file : build2/version/init.hxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BUILD2_VERSION_INIT_HXX -#define BUILD2_VERSION_INIT_HXX - -#include <libbuild2/types.hxx> -#include <libbuild2/utility.hxx> - -#include <libbuild2/module.hxx> - -namespace build2 -{ - namespace version - { - bool - boot (scope&, const location&, unique_ptr<module_base>&); - - bool - init (scope&, - scope&, - const location&, - unique_ptr<module_base>&, - bool, - bool, - const variable_map&); - } -} - -#endif // BUILD2_VERSION_INIT_HXX diff --git a/libbuild2/buildfile b/libbuild2/buildfile index b015d21..ab95098 100644 --- a/libbuild2/buildfile +++ b/libbuild2/buildfile @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2014-2019 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -./: lib{build2} in/ +./: lib{build2} version/ in/ import int_libs = libbutl%lib{butl} diff --git a/libbuild2/version/buildfile b/libbuild2/version/buildfile new file mode 100644 index 0000000..e9d4905 --- /dev/null +++ b/libbuild2/version/buildfile @@ -0,0 +1,66 @@ +# file : libbuild2/version/buildfile +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +import int_libs = libbutl%lib{butl} + +include ../ +int_libs += ../lib{build2} + +include ../in/ +int_libs += ../in/lib{build2-in} + +./: lib{build2-version}: libul{build2-version}: \ + {hxx ixx txx cxx}{** -**.test...} \ + $int_libs + +# Unit tests. +# +exe{*.test}: +{ + test = true + install = false +} + +for t: cxx{**.test...} +{ + d = $directory($t) + n = $name($t)... + + ./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n} + $d/exe{$n}: libul{build2-version}: bin.whole = false +} + +# Build options. +# +obja{*}: cxx.poptions += -DLIBBUILD2_VERSION_STATIC_BUILD +objs{*}: cxx.poptions += -DLIBBUILD2_VERSION_SHARED_BUILD + +# Export options. +# +lib{build2-version}: +{ + cxx.export.poptions = "-I$out_root" "-I$src_root" + cxx.export.libs = $int_libs +} + +liba{build2-version}: cxx.export.poptions += -DLIBBUILD2_VERSION_STATIC +libs{build2-version}: cxx.export.poptions += -DLIBBUILD2_VERSION_SHARED + +# For pre-releases use the complete version to make sure they cannot be used +# in place of another pre-release or the final version. See the version module +# for details on the version.* variable values. +# +if $version.pre_release + lib{build2-version}: bin.lib.version = @"-$version.project_id" +else + lib{build2-version}: bin.lib.version = @"-$version.major.$version.minor" + +# Install into the libbuild2/version/ subdirectory of, say, /usr/include/ +# recreating subdirectories. +# +{hxx ixx txx}{*}: +{ + install = include/libbuild2/version/ + install.subdirs = true +} diff --git a/libbuild2/version/export.hxx b/libbuild2/version/export.hxx new file mode 100644 index 0000000..c76cd8a --- /dev/null +++ b/libbuild2/version/export.hxx @@ -0,0 +1,34 @@ +#pragma once + +// Normally we don't export class templates (but do complete specializations), +// inline functions, and classes with only inline member functions. Exporting +// classes that inherit from non-exported/imported bases (e.g., std::string) +// will end up badly. The only known workarounds are to not inherit or to not +// export. Also, MinGW GCC doesn't like seeing non-exported functions being +// used before their inline definition. The workaround is to reorder code. In +// the end it's all trial and error. + +#if defined(LIBBUILD2_VERSION_STATIC) // Using static. +# define LIBBUILD2_VERSION_SYMEXPORT +#elif defined(LIBBUILD2_VERSION_STATIC_BUILD) // Building static. +# define LIBBUILD2_VERSION_SYMEXPORT +#elif defined(LIBBUILD2_VERSION_SHARED) // Using shared. +# ifdef _WIN32 +# define LIBBUILD2_VERSION_SYMEXPORT __declspec(dllimport) +# else +# define LIBBUILD2_VERSION_SYMEXPORT +# endif +#elif defined(LIBBUILD2_VERSION_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define LIBBUILD2_VERSION_SYMEXPORT __declspec(dllexport) +# else +# define LIBBUILD2_VERSION_SYMEXPORT +# endif +#else +// If none of the above macros are defined, then we assume we are being used +// by some third-party build system that cannot/doesn't signal the library +// type. Note that this fallback works for both static and shared but in case +// of shared will be sub-optimal compared to having dllimport. +// +# define LIBBUILD2_VERSION_SYMEXPORT // Using static or shared. +#endif diff --git a/build2/version/init.cxx b/libbuild2/version/init.cxx index 30f0f45..8adbb29 100644 --- a/build2/version/init.cxx +++ b/libbuild2/version/init.cxx @@ -1,8 +1,8 @@ -// file : build2/version/init.cxx -*- C++ -*- +// file : libbuild2/version/init.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/version/init.hxx> +#include <libbuild2/version/init.hxx> #include <libbutl/manifest-parser.mxx> @@ -15,10 +15,10 @@ #include <libbuild2/dist/module.hxx> -#include <build2/version/rule.hxx> -#include <build2/version/module.hxx> -#include <build2/version/utility.hxx> -#include <build2/version/snapshot.hxx> +#include <libbuild2/version/rule.hxx> +#include <libbuild2/version/module.hxx> +#include <libbuild2/version/utility.hxx> +#include <libbuild2/version/snapshot.hxx> using namespace std; using namespace butl; @@ -295,7 +295,7 @@ namespace build2 if (!first) fail (l) << "multiple version module initializations"; - // Load in.base (in.* varibales, in{} target type). + // Load in.base (in.* variables, in{} target type). // if (!cast_false<bool> (rs["in.base.loaded"])) load_module (rs, rs, "in.base", l); @@ -388,5 +388,20 @@ namespace build2 fail << "unable to overwrite " << f << ": " << e; } } + + static const module_functions mod_functions[] = + { + // NOTE: don't forget to also update the documentation in init.hxx if + // changing anything here. + + {"version", boot, init}, + {nullptr, nullptr, nullptr} + }; + + const module_functions* + build2_version_load () + { + return mod_functions; + } } } diff --git a/libbuild2/version/init.hxx b/libbuild2/version/init.hxx new file mode 100644 index 0000000..68e4def --- /dev/null +++ b/libbuild2/version/init.hxx @@ -0,0 +1,28 @@ +// file : libbuild2/version/init.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBUILD2_VERSION_INIT_HXX +#define LIBBUILD2_VERSION_INIT_HXX + +#include <libbuild2/types.hxx> +#include <libbuild2/utility.hxx> + +#include <libbuild2/module.hxx> + +#include <libbuild2/version/export.hxx> + +namespace build2 +{ + namespace version + { + // Module `version` requires bootstrapping. + // + // No submodules. + // + extern "C" LIBBUILD2_VERSION_SYMEXPORT const module_functions* + build2_version_load (); + } +} + +#endif // LIBBUILD2_VERSION_INIT_HXX diff --git a/build2/version/module.cxx b/libbuild2/version/module.cxx index 1811cfc..5ee44f7 100644 --- a/build2/version/module.cxx +++ b/libbuild2/version/module.cxx @@ -1,8 +1,8 @@ -// file : build2/version/module.cxx -*- C++ -*- +// file : libbuild2/version/module.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/version/module.hxx> +#include <libbuild2/version/module.hxx> using namespace std; diff --git a/build2/version/module.hxx b/libbuild2/version/module.hxx index d2b681c..174da7b 100644 --- a/build2/version/module.hxx +++ b/libbuild2/version/module.hxx @@ -1,9 +1,9 @@ -// file : build2/version/module.hxx -*- C++ -*- +// file : libbuild2/version/module.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_VERSION_MODULE_HXX -#define BUILD2_VERSION_MODULE_HXX +#ifndef LIBBUILD2_VERSION_MODULE_HXX +#define LIBBUILD2_VERSION_MODULE_HXX #include <map> @@ -61,4 +61,4 @@ namespace build2 } } -#endif // BUILD2_VERSION_MODULE_HXX +#endif // LIBBUILD2_VERSION_MODULE_HXX diff --git a/build2/version/rule.cxx b/libbuild2/version/rule.cxx index f110e3e..37e6b0f 100644 --- a/build2/version/rule.cxx +++ b/libbuild2/version/rule.cxx @@ -1,8 +1,8 @@ -// file : build2/version/rule.cxx -*- C++ -*- +// file : libbuild2/version/rule.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/version/rule.hxx> +#include <libbuild2/version/rule.hxx> #include <libbuild2/scope.hxx> #include <libbuild2/target.hxx> @@ -10,8 +10,8 @@ #include <libbuild2/in/target.hxx> -#include <build2/version/module.hxx> -#include <build2/version/utility.hxx> +#include <libbuild2/version/module.hxx> +#include <libbuild2/version/utility.hxx> using namespace std; using namespace butl; diff --git a/build2/version/rule.hxx b/libbuild2/version/rule.hxx index 7bfb783..ce21aa4 100644 --- a/build2/version/rule.hxx +++ b/libbuild2/version/rule.hxx @@ -1,9 +1,9 @@ -// file : build2/version/rule.hxx -*- C++ -*- +// file : libbuild2/version/rule.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_VERSION_RULE_HXX -#define BUILD2_VERSION_RULE_HXX +#ifndef LIBBUILD2_VERSION_RULE_HXX +#define LIBBUILD2_VERSION_RULE_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> @@ -49,4 +49,4 @@ namespace build2 } } -#endif // BUILD2_VERSION_RULE_HXX +#endif // LIBBUILD2_VERSION_RULE_HXX diff --git a/build2/version/snapshot-git.cxx b/libbuild2/version/snapshot-git.cxx index f7993d2..b7ca084 100644 --- a/build2/version/snapshot-git.cxx +++ b/libbuild2/version/snapshot-git.cxx @@ -1,4 +1,4 @@ -// file : build2/version/snapshot-git.cxx -*- C++ -*- +// file : libbuild2/version/snapshot-git.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file @@ -6,7 +6,7 @@ #include <libbutl/sha1.mxx> -#include <build2/version/snapshot.hxx> +#include <libbuild2/version/snapshot.hxx> using namespace std; using namespace butl; diff --git a/build2/version/snapshot.cxx b/libbuild2/version/snapshot.cxx index b43e083..46b37f3 100644 --- a/build2/version/snapshot.cxx +++ b/libbuild2/version/snapshot.cxx @@ -1,8 +1,8 @@ -// file : build2/version/snapshot.cxx -*- C++ -*- +// file : libbuild2/version/snapshot.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/version/snapshot.hxx> +#include <libbuild2/version/snapshot.hxx> #include <libbuild2/filesystem.hxx> diff --git a/build2/version/snapshot.hxx b/libbuild2/version/snapshot.hxx index 824ec89..86b6eab 100644 --- a/build2/version/snapshot.hxx +++ b/libbuild2/version/snapshot.hxx @@ -1,9 +1,9 @@ -// file : build2/version/snapshot.hxx -*- C++ -*- +// file : libbuild2/version/snapshot.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_VERSION_SNAPSHOT_HXX -#define BUILD2_VERSION_SNAPSHOT_HXX +#ifndef LIBBUILD2_VERSION_SNAPSHOT_HXX +#define LIBBUILD2_VERSION_SNAPSHOT_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> @@ -31,4 +31,4 @@ namespace build2 } } -#endif // BUILD2_VERSION_SNAPSHOT_HXX +#endif // LIBBUILD2_VERSION_SNAPSHOT_HXX diff --git a/build2/version/utility.cxx b/libbuild2/version/utility.cxx index 8286ff8..c93a251 100644 --- a/build2/version/utility.cxx +++ b/libbuild2/version/utility.cxx @@ -1,8 +1,8 @@ -// file : build2/version/utility.cxx -*- C++ -*- +// file : libbuild2/version/utility.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/version/utility.hxx> +#include <libbuild2/version/utility.hxx> #include <libbutl/manifest-parser.mxx> #include <libbutl/manifest-serializer.mxx> diff --git a/build2/version/utility.hxx b/libbuild2/version/utility.hxx index 83bb91c..16e8c78 100644 --- a/build2/version/utility.hxx +++ b/libbuild2/version/utility.hxx @@ -1,9 +1,9 @@ -// file : build2/version/utility.hxx -*- C++ -*- +// file : libbuild2/version/utility.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_VERSION_UTILITY_HXX -#define BUILD2_VERSION_UTILITY_HXX +#ifndef LIBBUILD2_VERSION_UTILITY_HXX +#define LIBBUILD2_VERSION_UTILITY_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> @@ -22,4 +22,4 @@ namespace build2 } } -#endif // BUILD2_VERSION_UTILITY_HXX +#endif // LIBBUILD2_VERSION_UTILITY_HXX diff --git a/tests/libbuild2/buildfile b/tests/libbuild2/buildfile index 51b2f5b..aa6c17f 100644 --- a/tests/libbuild2/buildfile +++ b/tests/libbuild2/buildfile @@ -4,6 +4,7 @@ import libs = build2%lib{build2} import libs += build2%lib{build2-in} +import libs += build2%lib{build2-version} exe{driver}: {hxx cxx}{*} $libs testscript diff --git a/tests/libbuild2/driver.cxx b/tests/libbuild2/driver.cxx index d9c086a..544d43e 100644 --- a/tests/libbuild2/driver.cxx +++ b/tests/libbuild2/driver.cxx @@ -9,6 +9,7 @@ #include <libbuild2/scheduler.hxx> #include <libbuild2/in/init.hxx> +#include <libbuild2/version/init.hxx> using namespace build2; @@ -20,6 +21,7 @@ main (int, char* argv[]) init_diag (1); init (argv[0]); + version::build2_version_load (); in::build2_in_load (); sched.startup (1); // Serial execution. |