aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/bin/init.cxx4
-rw-r--r--build2/cc/module.cxx6
-rw-r--r--build2/cli/init.cxx2
-rw-r--r--build2/dist/init.cxx2
-rw-r--r--build2/install/init.cxx4
-rw-r--r--build2/rule12
-rw-r--r--build2/rule-map11
-rw-r--r--build2/rule.cxx8
-rw-r--r--build2/test/init.cxx4
9 files changed, 30 insertions, 23 deletions
diff --git a/build2/bin/init.cxx b/build2/bin/init.cxx
index eaded2a..913c887 100644
--- a/build2/bin/init.cxx
+++ b/build2/bin/init.cxx
@@ -24,8 +24,8 @@ namespace build2
{
namespace bin
{
- static obj_rule obj_;
- static lib_rule lib_;
+ static const obj_rule obj_;
+ static const lib_rule lib_;
// Default config.bin.*.lib values.
//
diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx
index e63f740..3e20694 100644
--- a/build2/cc/module.cxx
+++ b/build2/cc/module.cxx
@@ -363,9 +363,9 @@ namespace build2
//
// @@ Should we check if install module was loaded (see bin)?
//
- compile& cr (*this);
- link& lr (*this);
- install& ir (*this);
+ const compile& cr (*this);
+ const link& lr (*this);
+ const install& ir (*this);
r.insert<obje> (perform_update_id, x_compile, cr);
r.insert<obje> (perform_clean_id, x_compile, cr);
diff --git a/build2/cli/init.cxx b/build2/cli/init.cxx
index 45e2655..b34711d 100644
--- a/build2/cli/init.cxx
+++ b/build2/cli/init.cxx
@@ -23,7 +23,7 @@ namespace build2
{
namespace cli
{
- static compile compile_;
+ static const compile compile_;
bool
config_init (scope& rs,
diff --git a/build2/dist/init.cxx b/build2/dist/init.cxx
index f185145..901e9c2 100644
--- a/build2/dist/init.cxx
+++ b/build2/dist/init.cxx
@@ -20,7 +20,7 @@ namespace build2
{
namespace dist
{
- static rule rule_;
+ static const rule rule_;
void
boot (scope& r, const location&, unique_ptr<module_base>&)
diff --git a/build2/install/init.cxx b/build2/install/init.cxx
index 5281d38..8c28dad 100644
--- a/build2/install/init.cxx
+++ b/build2/install/init.cxx
@@ -120,8 +120,8 @@ namespace build2
var_pool.insert<bool> (string ("install.") + n + ".subdirs");
}
- static alias_rule alias_;
- static file_rule file_;
+ static const alias_rule alias_;
+ static const file_rule file_;
void
boot (scope& r, const location&, unique_ptr<module_base>&)
diff --git a/build2/rule b/build2/rule
index 015cf1a..fbf3dcc 100644
--- a/build2/rule
+++ b/build2/rule
@@ -29,6 +29,10 @@ namespace build2
match_result (bool r, action a): result (r), recipe_action (a) {}
};
+ // Once a rule is registered (for a scope), it is treated as immutable. If
+ // you need to modify some state (e.g., counters or some such), then make
+ // sure it is MT-safe.
+ //
class rule
{
public:
@@ -50,7 +54,7 @@ namespace build2
virtual recipe
apply (action, target&) const override;
- static file_rule instance;
+ static const file_rule instance;
};
class alias_rule: public rule
@@ -62,7 +66,7 @@ namespace build2
virtual recipe
apply (action, target&) const override;
- static alias_rule instance;
+ static const alias_rule instance;
};
class fsdir_rule: public rule
@@ -80,7 +84,7 @@ namespace build2
static target_state
perform_clean (action, target&);
- static fsdir_rule instance;
+ static const fsdir_rule instance;
};
// Fallback rule that always matches and does nothing.
@@ -94,7 +98,7 @@ namespace build2
virtual recipe
apply (action, target&) const override {return noop_recipe;}
- static fallback_rule instance;
+ static const fallback_rule instance;
};
}
diff --git a/build2/rule-map b/build2/rule-map
index c1b757b..b7397a0 100644
--- a/build2/rule-map
+++ b/build2/rule-map
@@ -21,7 +21,7 @@ namespace build2
using target_type_rule_map = std::map<
const target_type*,
butl::prefix_map<string, // Rule hint.
- reference_wrapper<rule>, '.'>>;
+ reference_wrapper<const rule>, '.'>>;
// This is an "indexed map" with operation_id being the index. Entry
// with id 0 is a wildcard.
@@ -31,7 +31,7 @@ namespace build2
public:
template <typename T>
void
- insert (operation_id oid, const char* hint, rule& r)
+ insert (operation_id oid, const char* hint, const rule& r)
{
// 3 is the number of builtin operations.
//
@@ -69,14 +69,17 @@ namespace build2
template <typename T>
void
- insert (action_id a, const char* hint, rule& r)
+ insert (action_id a, const char* hint, const rule& r)
{
insert<T> (a >> 4, a & 0x0F, hint, r);
}
template <typename T>
void
- insert (meta_operation_id mid, operation_id oid, const char* hint, rule& r)
+ insert (meta_operation_id mid,
+ operation_id oid,
+ const char* hint,
+ const rule& r)
{
if (mid_ == mid)
map_.insert<T> (oid, hint, r);
diff --git a/build2/rule.cxx b/build2/rule.cxx
index 1c0e08c..42d5eb8 100644
--- a/build2/rule.cxx
+++ b/build2/rule.cxx
@@ -110,7 +110,7 @@ namespace build2
return default_recipe;
}
- file_rule file_rule::instance;
+ const file_rule file_rule::instance;
// alias_rule
//
@@ -132,7 +132,7 @@ namespace build2
return default_recipe;
}
- alias_rule alias_rule::instance;
+ const alias_rule alias_rule::instance;
// fsdir_rule
//
@@ -222,9 +222,9 @@ namespace build2
return ts;
}
- fsdir_rule fsdir_rule::instance;
+ const fsdir_rule fsdir_rule::instance;
// fallback_rule
//
- fallback_rule fallback_rule::instance;
+ const fallback_rule fallback_rule::instance;
}
diff --git a/build2/test/init.cxx b/build2/test/init.cxx
index 4338231..94e4073 100644
--- a/build2/test/init.cxx
+++ b/build2/test/init.cxx
@@ -146,8 +146,8 @@ namespace build2
// Register rules.
//
{
- rule& r (m);
- alias_rule& ar (m);
+ const rule& r (m);
+ const alias_rule& ar (m);
// Register our test running rule.
//