From 70e095024ab33404ba0cf20c184a7a9560bca5f0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 18 Jan 2022 10:54:23 +0200 Subject: Add dynamic prerequisites to $< unless --adhoc is specified Also add a few tests for depdb-dyndep. --- libbuild2/build/script/parser.cxx | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'libbuild2/build/script/parser.cxx') diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx index 6f3c300..dd6fa2d 100644 --- a/libbuild2/build/script/parser.cxx +++ b/libbuild2/build/script/parser.cxx @@ -1604,6 +1604,14 @@ namespace build2 else def_pt = &file::static_type; + // --adhoc + // + if (ops.adhoc ()) + { + if (byprod) + fail (ll) << "depdb dyndep: --adhoc specified with --byproduct"; + } + // Update prerequisite targets. // using dyndep = dyndep_rule; @@ -1858,10 +1866,6 @@ namespace build2 // Enter as a target, update, and add to the list of prerequisite // targets a file. // - // Note that these targets don't end up in $< (which is the right - // thing) because that variable has already been initialized (in the - // environment ctor). - // size_t skip_count (0); auto add = [this, &trace, what, @@ -1959,10 +1963,19 @@ namespace build2 trace, what, a, t, *ft, mt, - false /* fail */, - false /* adhoc */, - 1 /* data */)) + false /* fail */, + ops.adhoc () /* adhoc */)) { + prerequisite_target& pt (pts.back ()); + + if (pt.adhoc) + { + pt.data = reinterpret_cast (pt.target); + pt.target = nullptr; + } + else + pt.data = 1; // Already updated. + if (!cache) dd.expect (ft->path ()); // @@ Use fp (or verify match)? @@ -2221,6 +2234,12 @@ namespace build2 // Add the terminating blank line (we are updating depdb). // dd.expect (""); + + // Reload $< and $> to make sure they contain the newly discovered + // prerequisites and targets. + // + if (update) + environment_->set_special_variables (a); } // When add a special variable don't forget to update lexer::word(). -- cgit v1.1