diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2023-04-13 13:55:00 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2023-04-13 13:55:00 +0200 |
commit | 894813b993963de006d0a8aa7480b0403daaa87a (patch) | |
tree | bfc4f5a57da17089f93da5035e1d156b5adebd54 | |
parent | e9a3804c2ea5972dd84a7d4759d4ea965c2490fb (diff) |
Move cli module to libbuild2-cli library
This is a temporary measure (until we unboundle this module) needed for
in-process configure support in bpkg.
-rw-r--r-- | build2/b.cxx | 5 | ||||
-rw-r--r-- | build2/buildfile | 2 | ||||
-rw-r--r-- | libbuild2/buildfile | 2 | ||||
-rw-r--r-- | libbuild2/cli/buildfile | 71 | ||||
-rw-r--r-- | libbuild2/cli/export.hxx | 37 | ||||
-rw-r--r-- | libbuild2/cli/init.cxx (renamed from build2/cli/init.cxx) | 10 | ||||
-rw-r--r-- | libbuild2/cli/init.hxx (renamed from build2/cli/init.hxx) | 12 | ||||
-rw-r--r-- | libbuild2/cli/module.hxx (renamed from build2/cli/module.hxx) | 10 | ||||
-rw-r--r-- | libbuild2/cli/rule.cxx (renamed from build2/cli/rule.cxx) | 6 | ||||
-rw-r--r-- | libbuild2/cli/rule.hxx (renamed from build2/cli/rule.hxx) | 13 | ||||
-rw-r--r-- | libbuild2/cli/target.cxx (renamed from build2/cli/target.cxx) | 4 | ||||
-rw-r--r-- | libbuild2/cli/target.hxx (renamed from build2/cli/target.hxx) | 15 | ||||
-rw-r--r-- | libbuild2/module.cxx | 1 |
13 files changed, 152 insertions, 36 deletions
diff --git a/build2/b.cxx b/build2/b.cxx index 1cfb019..ee0d58c 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -54,8 +54,7 @@ #ifndef BUILD2_BOOTSTRAP # include <libbuild2/bash/init.hxx> - -# include <build2/cli/init.hxx> +# include <libbuild2/cli/init.hxx> #endif using namespace butl; @@ -384,8 +383,8 @@ main (int argc, char* argv[]) load_builtin_module (&in::build2_in_load); #ifndef BUILD2_BOOTSTRAP - load_builtin_module (&cli::build2_cli_load); load_builtin_module (&bash::build2_bash_load); + load_builtin_module (&cli::build2_cli_load); #endif // Start up the scheduler and allocate lock shards. diff --git a/build2/buildfile b/build2/buildfile index 0c21388..5ae8aa0 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -11,7 +11,7 @@ libs = $libbutl include ../libbuild2/ libs += ../libbuild2/lib{build2} -for m: bash bin c cc cxx in version +for m: bash bin c cc cli cxx in version { include ../libbuild2/$m/ libs += ../libbuild2/$m/lib{build2-$m} diff --git a/libbuild2/buildfile b/libbuild2/buildfile index 6707b05..b3a9c52 100644 --- a/libbuild2/buildfile +++ b/libbuild2/buildfile @@ -4,7 +4,7 @@ # NOTE: remember to update bundled_modules in libbuild2/module.cxx if adding a # new module. # -bundled_modules = bash/ bin/ c/ cc/ cxx/ in/ version/ +bundled_modules = bash/ bin/ c/ cc/ cli/ cxx/ in/ version/ ./: lib{build2} $bundled_modules diff --git a/libbuild2/cli/buildfile b/libbuild2/cli/buildfile new file mode 100644 index 0000000..9b6e4eb --- /dev/null +++ b/libbuild2/cli/buildfile @@ -0,0 +1,71 @@ +# file : libbuild2/cli/buildfile +# license : MIT; see accompanying LICENSE file + +# NOTE: shared imports should go into root.build. +# +include ../ +impl_libs = ../lib{build2} # Implied interface dependency. + +include ../cxx/ +intf_libs = ../cxx/lib{build2-cxx} + +./: lib{build2-cli}: libul{build2-cli}: {hxx ixx txx cxx}{** -**.test...} \ + $intf_libs $impl_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-cli}: bin.whole = false +} + +# Build options. +# +obja{*}: cxx.poptions += -DLIBBUILD2_CLI_STATIC_BUILD +objs{*}: cxx.poptions += -DLIBBUILD2_CLI_SHARED_BUILD + +# Export options. +# +lib{build2-cli}: +{ + cxx.export.poptions = "-I$out_root" "-I$src_root" + cxx.export.libs = $intf_libs +} + +liba{build2-cli}: cxx.export.poptions += -DLIBBUILD2_CLI_STATIC +libs{build2-cli}: cxx.export.poptions += -DLIBBUILD2_CLI_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. +# +# And because this is a build system module, we also embed the same value as +# the interface version (note that we cannot use build.version.interface for +# bundled modules because we could be built with a different version of the +# build system). +# +ver = ($version.pre_release \ + ? "$version.project_id" \ + : "$version.major.$version.minor") + +lib{build2-cli}: bin.lib.version = @"-$ver" +libs{build2-cli}: bin.lib.load_suffix = "-$ver" + +# Install into the libbuild2/cli/ subdirectory of, say, /usr/include/ +# recreating subdirectories. +# +{hxx ixx txx}{*}: +{ + install = include/libbuild2/cli/ + install.subdirs = true +} diff --git a/libbuild2/cli/export.hxx b/libbuild2/cli/export.hxx new file mode 100644 index 0000000..67c1eb9 --- /dev/null +++ b/libbuild2/cli/export.hxx @@ -0,0 +1,37 @@ +// file : libbuild2/cli/export.hxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#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_CLI_STATIC) // Using static. +# define LIBBUILD2_CLI_SYMEXPORT +#elif defined(LIBBUILD2_CLI_STATIC_BUILD) // Building static. +# define LIBBUILD2_CLI_SYMEXPORT +#elif defined(LIBBUILD2_CLI_SHARED) // Using shared. +# ifdef _WIN32 +# define LIBBUILD2_CLI_SYMEXPORT __declspec(dllimport) +# else +# define LIBBUILD2_CLI_SYMEXPORT +# endif +#elif defined(LIBBUILD2_CLI_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define LIBBUILD2_CLI_SYMEXPORT __declspec(dllexport) +# else +# define LIBBUILD2_CLI_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_CLI_SYMEXPORT // Using static or shared. +#endif diff --git a/build2/cli/init.cxx b/libbuild2/cli/init.cxx index d7d8251..581fdaf 100644 --- a/build2/cli/init.cxx +++ b/libbuild2/cli/init.cxx @@ -1,7 +1,7 @@ -// file : build2/cli/init.cxx -*- C++ -*- +// file : libbuild2/cli/init.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#include <build2/cli/init.hxx> +#include <libbuild2/cli/init.hxx> #include <libbuild2/file.hxx> #include <libbuild2/scope.hxx> @@ -13,9 +13,9 @@ #include <libbuild2/cxx/target.hxx> -#include <build2/cli/rule.hxx> -#include <build2/cli/module.hxx> -#include <build2/cli/target.hxx> +#include <libbuild2/cli/rule.hxx> +#include <libbuild2/cli/module.hxx> +#include <libbuild2/cli/target.hxx> namespace build2 { diff --git a/build2/cli/init.hxx b/libbuild2/cli/init.hxx index 1c54316..6d23795 100644 --- a/build2/cli/init.hxx +++ b/libbuild2/cli/init.hxx @@ -1,14 +1,16 @@ -// file : build2/cli/init.hxx -*- C++ -*- +// file : libbuild2/cli/init.hxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_CLI_INIT_HXX -#define BUILD2_CLI_INIT_HXX +#ifndef LIBBUILD2_CLI_INIT_HXX +#define LIBBUILD2_CLI_INIT_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> #include <libbuild2/module.hxx> +#include <libbuild2/cli/export.hxx> + namespace build2 { namespace cli @@ -21,9 +23,9 @@ namespace build2 // `cli.config` -- load `cli.guess` and set the rest of the variables. // `cli` -- load `cli.config` and register targets and rules. // - extern "C" const module_functions* + extern "C" LIBBUILD2_CLI_SYMEXPORT const module_functions* build2_cli_load (); } } -#endif // BUILD2_CLI_INIT_HXX +#endif // LIBBUILD2_CLI_INIT_HXX diff --git a/build2/cli/module.hxx b/libbuild2/cli/module.hxx index 70f6ba8..ba10540 100644 --- a/build2/cli/module.hxx +++ b/libbuild2/cli/module.hxx @@ -1,15 +1,15 @@ -// file : build2/cli/module.hxx -*- C++ -*- +// file : libbuild2/cli/module.hxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_CLI_MODULE_HXX -#define BUILD2_CLI_MODULE_HXX +#ifndef LIBBUILD2_CLI_MODULE_HXX +#define LIBBUILD2_CLI_MODULE_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> #include <libbuild2/module.hxx> -#include <build2/cli/rule.hxx> +#include <libbuild2/cli/rule.hxx> namespace build2 { @@ -27,4 +27,4 @@ namespace build2 } } -#endif // BUILD2_CLI_MODULE_HXX +#endif // LIBBUILD2_CLI_MODULE_HXX diff --git a/build2/cli/rule.cxx b/libbuild2/cli/rule.cxx index 7f610c9..996ca51 100644 --- a/build2/cli/rule.cxx +++ b/libbuild2/cli/rule.cxx @@ -1,7 +1,7 @@ -// file : build2/cli/rule.cxx -*- C++ -*- +// file : libbuild2/cli/rule.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#include <build2/cli/rule.hxx> +#include <libbuild2/cli/rule.hxx> #include <libbuild2/depdb.hxx> #include <libbuild2/scope.hxx> @@ -11,7 +11,7 @@ #include <libbuild2/filesystem.hxx> #include <libbuild2/diagnostics.hxx> -#include <build2/cli/target.hxx> +#include <libbuild2/cli/target.hxx> namespace build2 { diff --git a/build2/cli/rule.hxx b/libbuild2/cli/rule.hxx index 0538c57..0132b44 100644 --- a/build2/cli/rule.hxx +++ b/libbuild2/cli/rule.hxx @@ -1,14 +1,16 @@ -// file : build2/cli/rule.hxx -*- C++ -*- +// file : libbuild2/cli/rule.hxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_CLI_RULE_HXX -#define BUILD2_CLI_RULE_HXX +#ifndef LIBBUILD2_CLI_RULE_HXX +#define LIBBUILD2_CLI_RULE_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> #include <libbuild2/rule.hxx> +#include <libbuild2/cli/export.hxx> + namespace build2 { namespace cli @@ -23,7 +25,8 @@ namespace build2 // @@ Redo as two separate rules? // - class compile_rule: public simple_rule, virtual data + class LIBBUILD2_CLI_SYMEXPORT compile_rule: public simple_rule, + private virtual data { public: compile_rule (data&& d): data (move (d)) {} @@ -40,4 +43,4 @@ namespace build2 } } -#endif // BUILD2_CLI_RULE_HXX +#endif // LIBBUILD2_CLI_RULE_HXX diff --git a/build2/cli/target.cxx b/libbuild2/cli/target.cxx index 37eee97..22ae75c 100644 --- a/build2/cli/target.cxx +++ b/libbuild2/cli/target.cxx @@ -1,7 +1,7 @@ -// file : build2/cli/target.cxx -*- C++ -*- +// file : libbuild2/cli/target.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#include <build2/cli/target.hxx> +#include <libbuild2/cli/target.hxx> #include <libbuild2/context.hxx> diff --git a/build2/cli/target.hxx b/libbuild2/cli/target.hxx index f27ee89..8efb837 100644 --- a/build2/cli/target.hxx +++ b/libbuild2/cli/target.hxx @@ -1,8 +1,8 @@ -// file : build2/cli/target.hxx -*- C++ -*- +// file : libbuild2/cli/target.hxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef BUILD2_CLI_TARGET_HXX -#define BUILD2_CLI_TARGET_HXX +#ifndef LIBBUILD2_CLI_TARGET_HXX +#define LIBBUILD2_CLI_TARGET_HXX #include <libbuild2/types.hxx> #include <libbuild2/utility.hxx> @@ -11,11 +11,13 @@ #include <libbuild2/cxx/target.hxx> +#include <libbuild2/cli/export.hxx> + namespace build2 { namespace cli { - class cli: public file + class LIBBUILD2_CLI_SYMEXPORT cli: public file { public: cli (context& c, dir_path d, dir_path o, string n) @@ -37,7 +39,8 @@ namespace build2 const cxx::ixx* i = nullptr; }; - class cli_cxx: public mtime_target, public cli_cxx_members + class LIBBUILD2_CLI_SYMEXPORT cli_cxx: public mtime_target, + public cli_cxx_members { public: cli_cxx (context& c, dir_path d, dir_path o, string n) @@ -55,4 +58,4 @@ namespace build2 } } -#endif // BUILD2_CLI_TARGET_HXX +#endif // LIBBUILD2_CLI_TARGET_HXX diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx index 0928307..4c1271c 100644 --- a/libbuild2/module.cxx +++ b/libbuild2/module.cxx @@ -50,6 +50,7 @@ namespace build2 "bin", "c", "cc", + "cli", "cxx", "in", "version" |