From 7996c2bfc2d7e998e2f9f1236d457ec7bea8ad8a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 1 Dec 2015 13:39:09 +0200 Subject: 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. --- build/target | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'build/target') diff --git a/build/target b/build/target index a866c98..a1c7880 100644 --- a/build/target +++ b/build/target @@ -22,6 +22,8 @@ #include // map_iterator_adapter #include +#include + #include #include #include @@ -352,7 +354,18 @@ namespace build const T* is_a () const {return dynamic_cast (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 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. -- cgit v1.1