diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-01 16:17:09 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-01 16:41:08 +0300 |
commit | 930ae81f85e5ee5ac37311f5e9c89000fbcb59a6 (patch) | |
tree | d14c8a341f16fb6c485bfa4212bc1002fe52ed6b | |
parent | da9cbf29c403d27c2940f9b31199c4648f8ae4a1 (diff) |
Move bash build system module to separate library
-rwxr-xr-x | bootstrap.sh | 2 | ||||
-rw-r--r-- | build2/b.cxx | 13 | ||||
-rw-r--r-- | build2/bash/init.hxx | 28 | ||||
-rw-r--r-- | build2/buildfile | 2 | ||||
-rw-r--r-- | libbuild2/bash/buildfile | 65 | ||||
-rw-r--r-- | libbuild2/bash/export.hxx | 34 | ||||
-rw-r--r-- | libbuild2/bash/init.cxx (renamed from build2/bash/init.cxx) | 25 | ||||
-rw-r--r-- | libbuild2/bash/init.hxx | 28 | ||||
-rw-r--r-- | libbuild2/bash/rule.cxx (renamed from build2/bash/rule.cxx) | 8 | ||||
-rw-r--r-- | libbuild2/bash/rule.hxx (renamed from build2/bash/rule.hxx) | 16 | ||||
-rw-r--r-- | libbuild2/bash/target.cxx (renamed from build2/bash/target.cxx) | 4 | ||||
-rw-r--r-- | libbuild2/bash/target.hxx (renamed from build2/bash/target.hxx) | 12 | ||||
-rw-r--r-- | libbuild2/bash/utility.hxx (renamed from build2/bash/utility.hxx) | 8 | ||||
-rw-r--r-- | libbuild2/buildfile | 2 | ||||
-rw-r--r-- | tests/libbuild2/buildfile | 7 | ||||
-rw-r--r-- | tests/libbuild2/driver.cxx | 4 |
16 files changed, 189 insertions, 69 deletions
diff --git a/bootstrap.sh b/bootstrap.sh index 8de5e3c..6eb570f 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -121,8 +121,6 @@ src="$src build2/bin/*.cxx" src="$src build2/c/*.cxx" src="$src build2/cc/*.cxx" src="$src build2/cxx/*.cxx" -src="$src build2/cli/*.cxx" -src="$src build2/bash/*.cxx" src="$src libbuild2/*.cxx" src="$src libbuild2/config/*.cxx" diff --git a/build2/b.cxx b/build2/b.cxx index a016278..2bb5920 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -54,16 +54,17 @@ #include <libbuild2/in/init.hxx> #include <libbuild2/version/init.hxx> +#ifndef BUILD2_BOOTSTRAP +# include <libbuild2/bash/init.hxx> + +# include <build2/cli/init.hxx> +#endif + #include <build2/bin/init.hxx> #include <build2/c/init.hxx> #include <build2/cc/init.hxx> #include <build2/cxx/init.hxx> -#ifndef BUILD2_BOOTSTRAP -# include <build2/cli/init.hxx> -# include <build2/bash/init.hxx> -#endif - using namespace butl; using namespace std; @@ -481,7 +482,7 @@ main (int argc, char* argv[]) bm["cli.config"] = mf {"cli.config", nullptr, &cli::config_init}; bm["cli"] = mf {"cli", nullptr, &cli::init}; - bm["bash"] = mf {"bash", nullptr, &bash::init}; + reg (&bash::build2_bash_load); #endif } diff --git a/build2/bash/init.hxx b/build2/bash/init.hxx deleted file mode 100644 index 2a7e95c..0000000 --- a/build2/bash/init.hxx +++ /dev/null @@ -1,28 +0,0 @@ -// file : build2/bash/init.hxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BUILD2_BASH_INIT_HXX -#define BUILD2_BASH_INIT_HXX - -#include <libbuild2/types.hxx> -#include <libbuild2/utility.hxx> - -#include <libbuild2/module.hxx> - -namespace build2 -{ - namespace bash - { - bool - init (scope&, - scope&, - const location&, - unique_ptr<module_base>&, - bool, - bool, - const variable_map&); - } -} - -#endif // BUILD2_BASH_INIT_HXX diff --git a/build2/buildfile b/build2/buildfile index ea39e87..57c2561 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -8,7 +8,7 @@ import libs += libpkgconf%lib{pkgconf} include ../libbuild2/ libs += ../libbuild2/lib{build2} -for m: version in +for m: bash in version { include ../libbuild2/$m/ libs += ../libbuild2/$m/lib{build2-$m} diff --git a/libbuild2/bash/buildfile b/libbuild2/bash/buildfile new file mode 100644 index 0000000..e1a9f53 --- /dev/null +++ b/libbuild2/bash/buildfile @@ -0,0 +1,65 @@ +# file : libbuild2/bash/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-bash}: libul{build2-bash}: {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-bash}: bin.whole = false +} + +# Build options. +# +obja{*}: cxx.poptions += -DLIBBUILD2_BASH_STATIC_BUILD +objs{*}: cxx.poptions += -DLIBBUILD2_BASH_SHARED_BUILD + +# Export options. +# +lib{build2-bash}: +{ + cxx.export.poptions = "-I$out_root" "-I$src_root" + cxx.export.libs = $int_libs +} + +liba{build2-bash}: cxx.export.poptions += -DLIBBUILD2_BASH_STATIC +libs{build2-bash}: cxx.export.poptions += -DLIBBUILD2_BASH_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-bash}: bin.lib.version = @"-$version.project_id" +else + lib{build2-bash}: bin.lib.version = @"-$version.major.$version.minor" + +# Install into the libbuild2/bash/ subdirectory of, say, /usr/include/ +# recreating subdirectories. +# +{hxx ixx txx}{*}: +{ + install = include/libbuild2/bash/ + install.subdirs = true +} diff --git a/libbuild2/bash/export.hxx b/libbuild2/bash/export.hxx new file mode 100644 index 0000000..d87e677 --- /dev/null +++ b/libbuild2/bash/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_BASH_STATIC) // Using static. +# define LIBBUILD2_BASH_SYMEXPORT +#elif defined(LIBBUILD2_BASH_STATIC_BUILD) // Building static. +# define LIBBUILD2_BASH_SYMEXPORT +#elif defined(LIBBUILD2_BASH_SHARED) // Using shared. +# ifdef _WIN32 +# define LIBBUILD2_BASH_SYMEXPORT __declspec(dllimport) +# else +# define LIBBUILD2_BASH_SYMEXPORT +# endif +#elif defined(LIBBUILD2_BASH_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define LIBBUILD2_BASH_SYMEXPORT __declspec(dllexport) +# else +# define LIBBUILD2_BASH_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_BASH_SYMEXPORT // Using static or shared. +#endif diff --git a/build2/bash/init.cxx b/libbuild2/bash/init.cxx index 146e680..17c9ddd 100644 --- a/build2/bash/init.cxx +++ b/libbuild2/bash/init.cxx @@ -1,8 +1,8 @@ -// file : build2/bash/init.cxx -*- C++ -*- +// file : libbuild2/bash/init.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/bash/init.hxx> +#include <libbuild2/bash/init.hxx> #include <libbuild2/scope.hxx> #include <libbuild2/context.hxx> @@ -11,9 +11,9 @@ #include <libbuild2/install/utility.hxx> -#include <build2/bash/rule.hxx> -#include <build2/bash/target.hxx> -#include <build2/bash/utility.hxx> +#include <libbuild2/bash/rule.hxx> +#include <libbuild2/bash/target.hxx> +#include <libbuild2/bash/utility.hxx> using namespace std; @@ -85,5 +85,20 @@ namespace build2 return true; } + + static const module_functions mod_functions[] = + { + // NOTE: don't forget to also update the documentation in init.hxx if + // changing anything here. + + {"bash", nullptr, init}, + {nullptr, nullptr, nullptr} + }; + + const module_functions* + build2_bash_load () + { + return mod_functions; + } } } diff --git a/libbuild2/bash/init.hxx b/libbuild2/bash/init.hxx new file mode 100644 index 0000000..4d05f2d --- /dev/null +++ b/libbuild2/bash/init.hxx @@ -0,0 +1,28 @@ +// file : libbuild2/bash/init.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBUILD2_BASH_INIT_HXX +#define LIBBUILD2_BASH_INIT_HXX + +#include <libbuild2/types.hxx> +#include <libbuild2/utility.hxx> + +#include <libbuild2/module.hxx> + +#include <libbuild2/bash/export.hxx> + +namespace build2 +{ + namespace bash + { + // Module `bash` does not require bootstrapping. + // + // No submodules. + // + extern "C" LIBBUILD2_BASH_SYMEXPORT const module_functions* + build2_bash_load (); + } +} + +#endif // LIBBUILD2_BASH_INIT_HXX diff --git a/build2/bash/rule.cxx b/libbuild2/bash/rule.cxx index a612d23..d9bf857 100644 --- a/build2/bash/rule.cxx +++ b/libbuild2/bash/rule.cxx @@ -1,8 +1,8 @@ -// file : build2/bash/rule.cxx -*- C++ -*- +// file : libbuild2/bash/rule.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/bash/rule.hxx> +#include <libbuild2/bash/rule.hxx> #include <cstring> // strlen(), strchr() @@ -13,8 +13,8 @@ #include <libbuild2/in/target.hxx> -#include <build2/bash/target.hxx> -#include <build2/bash/utility.hxx> +#include <libbuild2/bash/target.hxx> +#include <libbuild2/bash/utility.hxx> using namespace std; using namespace butl; diff --git a/build2/bash/rule.hxx b/libbuild2/bash/rule.hxx index c160bb7..665a6c2 100644 --- a/build2/bash/rule.hxx +++ b/libbuild2/bash/rule.hxx @@ -1,9 +1,9 @@ -// file : build2/bash/rule.hxx -*- C++ -*- +// file : libbuild2/bash/rule.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_BASH_RULE_HXX -#define BUILD2_BASH_RULE_HXX +#ifndef LIBBUILD2_BASH_RULE_HXX +#define LIBBUILD2_BASH_RULE_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> @@ -12,6 +12,8 @@ #include <libbuild2/in/rule.hxx> +#include <libbuild2/bash/export.hxx> + namespace build2 { namespace bash @@ -25,7 +27,7 @@ namespace build2 // however, is still able to override both of these choices with the // corresponding in.* variables (e.g., to use '`' and strict mode). // - class in_rule: public in::rule + class LIBBUILD2_BASH_SYMEXPORT in_rule: public in::rule { public: in_rule (): rule ("bash.in 1", "bash.in", '@', false /* strict */) {} @@ -66,7 +68,7 @@ namespace build2 // // 2. Custom filtering of prerequisites. // - class install_rule: public install::file_rule + class LIBBUILD2_BASH_SYMEXPORT install_rule: public install::file_rule { public: install_rule (const in_rule& in): in_ (in) {} @@ -80,10 +82,10 @@ namespace build2 virtual const target* filter (action, const target&, const prerequisite&) const override; - private: + protected: const in_rule& in_; }; } } -#endif // BUILD2_BASH_RULE_HXX +#endif // LIBBUILD2_BASH_RULE_HXX diff --git a/build2/bash/target.cxx b/libbuild2/bash/target.cxx index e843d53..7313316 100644 --- a/build2/bash/target.cxx +++ b/libbuild2/bash/target.cxx @@ -1,8 +1,8 @@ -// file : build2/bash/target.cxx -*- C++ -*- +// file : libbuild2/bash/target.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <build2/bash/target.hxx> +#include <libbuild2/bash/target.hxx> #include <libbuild2/context.hxx> diff --git a/build2/bash/target.hxx b/libbuild2/bash/target.hxx index 6be83c4..af8b32c 100644 --- a/build2/bash/target.hxx +++ b/libbuild2/bash/target.hxx @@ -1,15 +1,17 @@ -// file : build2/bash/target.hxx -*- C++ -*- +// file : libbuild2/bash/target.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_BASH_TARGET_HXX -#define BUILD2_BASH_TARGET_HXX +#ifndef LIBBUILD2_BASH_TARGET_HXX +#define LIBBUILD2_BASH_TARGET_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> #include <libbuild2/target.hxx> +#include <libbuild2/bash/export.hxx> + namespace build2 { namespace bash @@ -17,7 +19,7 @@ namespace build2 // Bash module file to be sourced by a script. The default/standard // extension is .bash. // - class bash: public file + class LIBBUILD2_BASH_SYMEXPORT bash: public file { public: using file::file; @@ -29,4 +31,4 @@ namespace build2 } } -#endif // BUILD2_BASH_TARGET_HXX +#endif // LIBBUILD2_BASH_TARGET_HXX diff --git a/build2/bash/utility.hxx b/libbuild2/bash/utility.hxx index 31a6b99..1f981c2 100644 --- a/build2/bash/utility.hxx +++ b/libbuild2/bash/utility.hxx @@ -1,9 +1,9 @@ -// file : build2/bash/utility.hxx -*- C++ -*- +// file : libbuild2/bash/utility.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_BASH_UTILITY_HXX -#define BUILD2_BASH_UTILITY_HXX +#ifndef LIBBUILD2_BASH_UTILITY_HXX +#define LIBBUILD2_BASH_UTILITY_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> @@ -24,4 +24,4 @@ namespace build2 } } -#endif // BUILD2_BASH_UTILITY_HXX +#endif // LIBBUILD2_BASH_UTILITY_HXX diff --git a/libbuild2/buildfile b/libbuild2/buildfile index ab95098..377ea30 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} version/ in/ +./: lib{build2} bash/ in/ version/ import int_libs = libbutl%lib{butl} diff --git a/tests/libbuild2/buildfile b/tests/libbuild2/buildfile index aa6c17f..bd22b4c 100644 --- a/tests/libbuild2/buildfile +++ b/tests/libbuild2/buildfile @@ -2,9 +2,10 @@ # copyright : Copyright (c) 2014-2019 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -import libs = build2%lib{build2} -import libs += build2%lib{build2-in} -import libs += build2%lib{build2-version} +import libs = build2%lib{build2} + +for m: bash in version + import libs += build2%lib{build2-$m} exe{driver}: {hxx cxx}{*} $libs testscript diff --git a/tests/libbuild2/driver.cxx b/tests/libbuild2/driver.cxx index 544d43e..20c0ec2 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/bash/init.hxx> #include <libbuild2/version/init.hxx> using namespace build2; @@ -21,8 +22,9 @@ main (int, char* argv[]) init_diag (1); init (argv[0]); - version::build2_version_load (); + bash::build2_bash_load (); in::build2_in_load (); + version::build2_version_load (); sched.startup (1); // Serial execution. reset (strings ()); // No command line variables. |