aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/parser.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-02-12 09:34:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-02-12 09:34:50 +0200
commit20e49b4e63779abc0e25bec4c74399a83ec8a83c (patch)
tree9f2f01ff0b6a40142fa8ee04a1a394c5b98c9a57 /libbuild2/parser.hxx
parentf0cfe78cb306532518d42e3d2b8e59405d006717 (diff)
Add ability to specify recipes in separate files
This can now be achieved with the new `recipe` directive: recipe <language> <file> Note that similar to the use of if-else and switch directives with recipes, this directive requires explicit % recipe header. For example, instead of: file{foo.output}: {{ echo 'hello' >$path($>) }} We can now write: file{foo.output}: % recipe buildscript hello.buildscript With hello.buildscript containing: echo 'hello' >$path($>) Similarly, for C++ recipes (this time for a pattern), instead of: [rule_name=hello] file{~'/(.+)\.output/'}: % update clean {{ c++ 1 -- -- ... }} We can now write: [rule_name=hello] file{~'/(.+)\.output/'}: % update clean recipe c++ hello.cxx With hello.cxx containing: // c++ 1 -- -- ... Relative <file> paths are resolved using the buildfile directory that contains the `recipe` directive as a base. Note also that this mechanism can be used in exported buildfiles with recipe files placed into build/export/ together with buildfiles.
Diffstat (limited to 'libbuild2/parser.hxx')
-rw-r--r--libbuild2/parser.hxx15
1 files changed, 11 insertions, 4 deletions
diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx
index b756984..0645b5a 100644
--- a/libbuild2/parser.hxx
+++ b/libbuild2/parser.hxx
@@ -265,7 +265,9 @@ namespace build2
parse_if_else (token&, token_type&,
bool,
const function<void (
- token&, token_type&, bool, const string&)>&);
+ token&, token_type&, bool, const string&)>&,
+ const function<void (
+ token&, token_type&, const string&)>&);
void
parse_switch (token&, token_type&);
@@ -274,7 +276,9 @@ namespace build2
parse_switch (token&, token_type&,
bool,
const function<void (
- token&, token_type&, bool, const string&)>&);
+ token&, token_type&, bool, const string&)>&,
+ const function<void (
+ token&, token_type&, const string&)>&);
void
parse_for (token&, token_type&);
@@ -617,9 +621,12 @@ namespace build2
void
process_default_target (token&, const buildfile*);
- // Enter buildfile as a target.
+ private:
+ // Enter buildfile or buildfile-file like file (e.g., a recipe file) as a
+ // target.
//
- const buildfile&
+ template <typename T>
+ const T&
enter_buildfile (const path&, optional<dir_path> out = nullopt);
// Lexer.