aboutsummaryrefslogtreecommitdiff
path: root/build2/cli/rule.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-04-27 09:49:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-04-27 10:03:50 +0200
commit9e5750ae2e3f837f80860aaab6b01e4d556213ed (patch)
treed3b2e551e444c47b6ce0289969e78360161b6685 /build2/cli/rule.cxx
parent028e10ba787a7dbb46e3fcba6f88f496b76cebc5 (diff)
Rework tool importation along with cli module
Specifically, now config.<tool> (like config.cli) is handled by the import machinery (it is like a shorter alias for config.import.<tool>.<tool>.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)"
Diffstat (limited to 'build2/cli/rule.cxx')
-rw-r--r--build2/cli/rule.cxx25
1 files changed, 13 insertions, 12 deletions
diff --git a/build2/cli/rule.cxx b/build2/cli/rule.cxx
index 9917f1a..3109689 100644
--- a/build2/cli/rule.cxx
+++ b/build2/cli/rule.cxx
@@ -13,9 +13,6 @@
#include <build2/cli/target.hxx>
-using namespace std;
-using namespace butl;
-
namespace build2
{
namespace cli
@@ -166,11 +163,17 @@ namespace build2
//
match_prerequisite_members (a, t);
- //@@ TODO: inject dependency on exe{cli}.
+ // For update inject dependency on the CLI compiler target.
+ //
+ if (a == perform_update_id)
+ inject (a, t, ctgt);
switch (a)
{
- case perform_update_id: return &perform_update;
+ case perform_update_id: return [this] (action a, const target& t)
+ {
+ return perform_update (a, t);
+ };
case perform_clean_id: return &perform_clean_group_depdb;
default: return noop_recipe; // Configure/dist update.
}
@@ -206,7 +209,7 @@ namespace build2
}
target_state compile_rule::
- perform_update (action a, const target& xt)
+ perform_update (action a, const target& xt) const
{
tracer trace ("cli::compile_rule::perform_update");
@@ -215,7 +218,6 @@ namespace build2
// timestamp, depdb, etc.
//
const cli_cxx& t (xt.as<cli_cxx> ());
- const scope& rs (t.root_scope ());
const path& tp (t.h->path ());
// Update prerequisites and determine if any relevant ones render us
@@ -242,7 +244,7 @@ namespace build2
// Then the compiler checksum.
//
- if (dd.expect (cast<string> (rs["cli.checksum"])) != nullptr)
+ if (dd.expect (csum) != nullptr)
l4 ([&]{trace << "compiler mismatch forcing update of " << t;});
// Then the options checksum.
@@ -277,9 +279,8 @@ namespace build2
path relo (relative (t.dir));
path rels (relative (s.path ()));
- const process_path& cli (cast<process_path> (rs["cli.path"]));
-
- cstrings args {cli.recall_string ()};
+ const process_path& pp (ctgt.process_path ());
+ cstrings args {pp.recall_string ()};
// See if we need to pass --output-{prefix,suffix}
//
@@ -323,7 +324,7 @@ namespace build2
if (!t.ctx.dry_run)
{
- run (cli, args);
+ run (pp, args);
dd.check_mtime (tp);
}