diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-01 13:39:09 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-01 13:42:10 +0200 |
commit | 7996c2bfc2d7e998e2f9f1236d457ec7bea8ad8a (patch) | |
tree | dca79d3657bec47d4cd5db85899a70d3d49c079e /build/target | |
parent | f355a4379f035df61a7702f5ff805eefb004fb20 (diff) |
Implement support for definition target type aliases
For example:
define cli=file
Currently, the semantics is that of a real alias with only name differences
that are used for display. See tests/define/buildfile for more use cases.
Diffstat (limited to 'build/target')
-rw-r--r-- | build/target | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/build/target b/build/target index a866c98..a1c7880 100644 --- a/build/target +++ b/build/target @@ -22,6 +22,8 @@ #include <butl/multi-index> // map_iterator_adapter #include <build/types> +#include <build/utility> + #include <build/scope> #include <build/variable> #include <build/operation> @@ -352,7 +354,18 @@ namespace build const T* is_a () const {return dynamic_cast<const T*> (this);} - virtual const target_type& type () const = 0; + // An alias target type should be the same as its target type except + // for the name. + // + const target_type* alias_type = nullptr; + + const target_type& + type () const + { + return alias_type != nullptr ? *alias_type : dynamic_type (); + } + + virtual const target_type& dynamic_type () const = 0; static const target_type static_type; private: @@ -897,8 +910,8 @@ namespace build load_mtime () const final; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; // Alias target. It represents a list of targets (its prerequisites) @@ -910,8 +923,8 @@ namespace build using target::target; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; // Directory target. Note that this is not a filesystem directory @@ -924,8 +937,8 @@ namespace build using alias::alias; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; // While a filesystem directory is mtime-based, the semantics is @@ -941,8 +954,8 @@ namespace build using target::target; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; class buildfile: public file @@ -951,8 +964,8 @@ namespace build using file::file; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; // Common documentation file targets. @@ -965,8 +978,8 @@ namespace build using file::file; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; // The problem with man pages is this: different platforms have @@ -1009,8 +1022,8 @@ namespace build using doc::doc; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; class man1: public man @@ -1019,8 +1032,8 @@ namespace build using man::man; public: - virtual const target_type& type () const {return static_type;} static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} }; // Common implementation of the target factory, extension, and @@ -1028,9 +1041,9 @@ namespace build // template <typename T> target* - target_factory (dir_path d, std::string n, const std::string* e) + target_factory (const target_type&, dir_path d, string n, const string* e) { - return new T (std::move (d), std::move (n), e); + return new T (move (d), move (n), e); } // Return fixed target extension. |