From 9e5750ae2e3f837f80860aaab6b01e4d556213ed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Apr 2020 09:49:45 +0200 Subject: Rework tool importation along with cli module Specifically, now config. (like config.cli) is handled by the import machinery (it is like a shorter alias for config.import...exe that we already had). And the cli module now uses that instead of custom logic. This also adds support for uniform tool metadata extraction that is handled by the import machinery. As a result, a tool that follows the "build2 way" can be imported with metadata by the buildfile and/or corresponding module without any tool-specific code or brittleness associated with parsing --version or similar outputs. See the cli tool/module for details. Finally, two new flavors of the import directive are now supported: import! triggers immediate importation skipping any rule-specific logic while import? is optional import (analogous to using?). Note that optional import is always immediate. There is also the import-specific metadata attribute which can be specified for these two import flavors in order to trigger metadata importation. For example: import? [metadata] cli = cli%exe{cli} if ($cli != [null]) info "cli version $($cli:cli.version)" --- libbuild2/parser.hxx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'libbuild2/parser.hxx') diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx index 6552114..c55e14f 100644 --- a/libbuild2/parser.hxx +++ b/libbuild2/parser.hxx @@ -33,11 +33,17 @@ namespace build2 void parse_buildfile (istream&, const path_name&, - scope& root, - scope& base); + scope* root, + scope& base, + target* = nullptr, + prerequisite* = nullptr); void - parse_buildfile (lexer&, scope& root, scope& base); + parse_buildfile (lexer&, + scope* root, + scope& base, + target* = nullptr, + prerequisite* = nullptr); buildspec parse_buildspec (istream&, const path_name&); @@ -51,7 +57,7 @@ namespace build2 names parse_export_stub (istream& is, const path_name& name, scope& r, scope& b) { - parse_buildfile (is, name, r, b); + parse_buildfile (is, name, &r, b); return move (export_value); } @@ -99,7 +105,9 @@ namespace build2 parse_clause (token&, token_type&, bool one = false); void - parse_variable_block (token&, token_type&, const target_type*, string); + parse_variable_block (token&, token_type&, + const target_type* = nullptr, + string = string ()); // Ad hoc target names inside < ... >. // @@ -270,14 +278,14 @@ namespace build2 attributes& attributes_top () {return attributes_.back ();} - // Source a stream optionnaly entering it as a buildfile and performing - // the default target processing. + // Source a stream optionnaly performing the default target processing. + // If the specified path name has a real path, then also enter it as a + // buildfile. // void source (istream&, const path_name&, const location&, - bool enter, bool default_target); // The what argument is used in diagnostics (e.g., "expected @@ -494,7 +502,7 @@ namespace build2 // Enter buildfile as a target. // void - enter_buildfile (const path_name&); + enter_buildfile (const path&); // Lexer. // -- cgit v1.1