aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/dist/init.cxx14
-rw-r--r--libbuild2/dist/module.hxx11
-rw-r--r--libbuild2/dist/operation.cxx10
-rw-r--r--libbuild2/dist/rule.cxx20
-rw-r--r--libbuild2/dist/rule.hxx23
-rw-r--r--libbuild2/dist/types.hxx1
6 files changed, 41 insertions, 38 deletions
diff --git a/libbuild2/dist/init.cxx b/libbuild2/dist/init.cxx
index 9de84ce..26ff86d 100644
--- a/libbuild2/dist/init.cxx
+++ b/libbuild2/dist/init.cxx
@@ -21,6 +21,8 @@ namespace build2
{
namespace dist
{
+ static const rule rule_;
+
void
boot (scope& rs, const location&, module_boot_extra& extra)
{
@@ -194,7 +196,7 @@ namespace build2
const location& l,
bool first,
bool,
- module_init_extra& extra)
+ module_init_extra&)
{
tracer trace ("dist::init");
@@ -206,19 +208,13 @@ namespace build2
l5 ([&]{trace << "for " << rs;});
- module& mod (extra.module_as<module> ());
-
auto& vp (rs.var_pool (true /* public */)); // All qualified.
// Register our wildcard rule. Do it explicitly for the alias to prevent
// something like insert<target>(dist_id, test_id) taking precedence.
//
- {
- const rule& r (mod);
-
- rs.insert_rule<target> (dist_id, 0, "dist", r);
- rs.insert_rule<alias> (dist_id, 0, "dist.alias", r);
- }
+ rs.insert_rule<target> (dist_id, 0, "dist", rule_);
+ rs.insert_rule<alias> (dist_id, 0, "dist.alias", rule_);
// We need this rule for out-of-any-project dependencies (for example,
// executables imported from /usr/bin, etc). We are registering it on
diff --git a/libbuild2/dist/module.hxx b/libbuild2/dist/module.hxx
index dbe2a3e..da97939 100644
--- a/libbuild2/dist/module.hxx
+++ b/libbuild2/dist/module.hxx
@@ -11,7 +11,6 @@
#include <libbuild2/variable.hxx>
#include <libbuild2/dist/types.hxx>
-#include <libbuild2/dist/rule.hxx>
#include <libbuild2/export.hxx>
@@ -19,8 +18,7 @@ namespace build2
{
namespace dist
{
- class LIBBUILD2_SYMEXPORT module: public build2::module,
- public rule
+ class LIBBUILD2_SYMEXPORT module: public build2::module
{
public:
static const string name;
@@ -43,9 +41,9 @@ namespace build2
adhoc.push_back (move (f));
}
- // List of postponed prerequisites.
+ // List of postponed prerequisites (see rule for details).
//
- postponed_prerequisites postponed;
+ mutable postponed_prerequisites postponed;
// Distribution post-processing callbacks.
//
@@ -79,8 +77,7 @@ namespace build2
// Implementation details.
//
public:
- module (const variable& v_d_p)
- : rule (postponed), var_dist_package (v_d_p) {}
+ module (const variable& v_d_p): var_dist_package (v_d_p) {}
public:
bool distributed = false; // True if this project is being distributed.
diff --git a/libbuild2/dist/operation.cxx b/libbuild2/dist/operation.cxx
index e5c9307..af7b40b 100644
--- a/libbuild2/dist/operation.cxx
+++ b/libbuild2/dist/operation.cxx
@@ -16,6 +16,7 @@
#include <libbuild2/diagnostics.hxx>
#include <libbuild2/dist/types.hxx>
+#include <libbuild2/dist/rule.hxx>
#include <libbuild2/dist/module.hxx>
using namespace std;
@@ -237,10 +238,7 @@ namespace build2
fail << "unknown distribution package name" <<
info << "did you forget to set dist.package?";
- // Need non-const in order to clear postponed. This is safe since only
- // doing it when running serially.
- //
- module& mod (const_cast<module&> (*rs.find_module<module> (module::name)));
+ const module& mod (*rs.find_module<module> (module::name));
const string& dist_package (cast<string> (l));
const process_path& dist_cmd (cast<process_path> (rs.vars["dist.cmd"]));
@@ -301,9 +299,7 @@ namespace build2
for (auto i (mod.postponed.list.begin ());
i != mod.postponed.list.end ();
++i)
- {
- rule::match_postponed (i->action, i->target, i->prereq);
- }
+ rule::match_postponed (*i);
}
};
diff --git a/libbuild2/dist/rule.cxx b/libbuild2/dist/rule.cxx
index 7233eba..736490e 100644
--- a/libbuild2/dist/rule.cxx
+++ b/libbuild2/dist/rule.cxx
@@ -8,6 +8,9 @@
#include <libbuild2/algorithm.hxx>
#include <libbuild2/diagnostics.hxx>
+#include <libbuild2/dist/types.hxx>
+#include <libbuild2/dist/module.hxx>
+
using namespace std;
namespace build2
@@ -91,8 +94,11 @@ namespace build2
// may be unknown because we haven't matched the lib{} group
// yet. So we postpone this for later (see match_postponed()).
//
- mlock l (postponed_.mutex);
- postponed_.list.push_back (postponed_prerequisite {a, t, p,});
+ const module& mod (*rs.find_module<module> (module::name));
+
+ mlock l (mod.postponed.mutex);
+ mod.postponed.list.push_back (
+ postponed_prerequisite {a, t, p, t.state[a].rule->first});
continue;
}
@@ -112,19 +118,23 @@ namespace build2
}
void rule::
- match_postponed (action a, const target& t, const prerequisite& p)
+ match_postponed (const postponed_prerequisite& pp)
{
+ action a (pp.action);
+ const target& t (pp.target);
+ const prerequisite& p (pp.prereq);
+
const prerequisite_key& k (p.key ());
const target* pt (k.tk.type->search (t, k));
if (pt == nullptr)
{
// Note that we do loose the diag frame that we normally get when
- // failing during match. So let's mention the target manually.
+ // failing during match. So let's mention the target/rule manually.
//
fail << "prerequisite " << k << " is not existing source file nor "
<< "known output target" <<
- info << "while applying rule dist to " << diag_do (a, t);
+ info << "while applying rule " << pp.rule << " to " << diag_do (a, t);
}
search_custom (p, *pt); // Cache.
diff --git a/libbuild2/dist/rule.hxx b/libbuild2/dist/rule.hxx
index ec6c41a..69ab3d9 100644
--- a/libbuild2/dist/rule.hxx
+++ b/libbuild2/dist/rule.hxx
@@ -13,6 +13,8 @@
#include <libbuild2/dist/types.hxx>
+#include <libbuild2/export.hxx>
+
namespace build2
{
namespace dist
@@ -21,27 +23,28 @@ namespace build2
//
// A custom rule (usually the same as perform_update) may be necessary to
// establish group links (so that we see the dist variable set on a group)
- // or to see through non-see-through groups (like lib{}; see the
- // bin::lib_rule for an example). Note that in the latter case the rule
- // should "see" all its members for the dist case.
+ // or to see through non-see-through groups (like lib{}, obj{}; see rule
+ // in the bin module for an example). Note that in the latter case the
+ // rule should "see" all its members for the dist case.
//
- class rule: public simple_rule
+ class LIBBUILD2_SYMEXPORT rule: public simple_rule
{
public:
- explicit
- rule (postponed_prerequisites& p): postponed_ (p) {}
+ rule () {}
+ // Always matches (returns true).
+ //
virtual bool
match (action, target&) const override;
+ // Matches all the prerequisites (including from group) and returns
+ // noop_recipe (which will never be executed).
+ //
virtual recipe
apply (action, target&) const override;
static void
- match_postponed (action, const target&, const prerequisite&);
-
- private:
- postponed_prerequisites& postponed_;
+ match_postponed (const postponed_prerequisite&);
};
}
}
diff --git a/libbuild2/dist/types.hxx b/libbuild2/dist/types.hxx
index f3b1009..b833951 100644
--- a/libbuild2/dist/types.hxx
+++ b/libbuild2/dist/types.hxx
@@ -27,6 +27,7 @@ namespace build2
build2::action action;
reference_wrapper<const build2::target> target;
reference_wrapper<const prerequisite> prereq;
+ string rule;
};
struct postponed_prerequisites