aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-08-21 15:38:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-08-21 15:38:28 +0200
commit91734f1772aeca9795040d2db03b4f29051fa922 (patch)
tree410fcab8d47a58ea57ce3f27d91c9ea7ede44a9b /libbuild2
parentd64ae97f6865bc25d496485622530e2a090c2eb4 (diff)
Cleanup context.hxx and its usage
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/algorithm.ixx1
-rw-r--r--libbuild2/bash/init.cxx10
-rw-r--r--libbuild2/config/utility.txx2
-rw-r--r--libbuild2/context.cxx215
-rw-r--r--libbuild2/context.hxx104
-rw-r--r--libbuild2/context.ixx32
-rw-r--r--libbuild2/diagnostics.cxx158
-rw-r--r--libbuild2/diagnostics.hxx68
-rw-r--r--libbuild2/dump.cxx1
-rw-r--r--libbuild2/filesystem.txx2
-rw-r--r--libbuild2/function.test.cxx1
-rw-r--r--libbuild2/in/init.cxx1
-rw-r--r--libbuild2/install/rule.cxx1
-rw-r--r--libbuild2/operation.cxx1
-rw-r--r--libbuild2/parser.cxx1
-rw-r--r--libbuild2/scope.hxx27
-rw-r--r--libbuild2/scope.ixx37
-rw-r--r--libbuild2/search.cxx1
-rw-r--r--libbuild2/spec.cxx1
-rw-r--r--libbuild2/target.hxx6
-rw-r--r--libbuild2/test/rule.cxx1
-rw-r--r--libbuild2/utility.cxx1
-rw-r--r--libbuild2/variable.cxx1
-rw-r--r--libbuild2/version/init.cxx1
-rw-r--r--libbuild2/version/utility.cxx1
25 files changed, 341 insertions, 334 deletions
diff --git a/libbuild2/algorithm.ixx b/libbuild2/algorithm.ixx
index a3fa906..6bc771e 100644
--- a/libbuild2/algorithm.ixx
+++ b/libbuild2/algorithm.ixx
@@ -4,6 +4,7 @@
#include <libbuild2/rule.hxx>
#include <libbuild2/context.hxx>
+#include <libbuild2/scheduler.hxx>
#include <libbuild2/export.hxx>
diff --git a/libbuild2/bash/init.cxx b/libbuild2/bash/init.cxx
index 17c9ddd..bd0e34b 100644
--- a/libbuild2/bash/init.cxx
+++ b/libbuild2/bash/init.cxx
@@ -5,7 +5,6 @@
#include <libbuild2/bash/init.hxx>
#include <libbuild2/scope.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/diagnostics.hxx>
@@ -54,10 +53,13 @@ namespace build2
// Install into bin/<project>/ by default stripping the .bash
// extension from <project> if present.
//
- const project_name& p (cast<project_name> (rs.vars[var_project]));
+ const project_name& p (project (rs));
- install_path<bash> (bs, dir_path ("bin") /= project_base (p));
- install_mode<bash> (bs, "644");
+ if (!p.empty ())
+ {
+ install_path<bash> (bs, dir_path ("bin") /= project_base (p));
+ install_mode<bash> (bs, "644");
+ }
}
// Register rules.
diff --git a/libbuild2/config/utility.txx b/libbuild2/config/utility.txx
index b422ff4..841c408 100644
--- a/libbuild2/config/utility.txx
+++ b/libbuild2/config/utility.txx
@@ -3,7 +3,7 @@
// license : MIT; see accompanying LICENSE file
#include <libbuild2/scope.hxx>
-#include <libbuild2/context.hxx>
+#include <libbuild2/context.hxx> // current_mif
namespace build2
{
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx
index 2f5e2af..1cc8bbc 100644
--- a/libbuild2/context.cxx
+++ b/libbuild2/context.cxx
@@ -341,6 +341,38 @@ namespace build2
bool keep_going = false;
bool dry_run = false;
+ void
+ set_current_mif (const meta_operation_info& mif)
+ {
+ if (current_mname != mif.name)
+ {
+ current_mname = mif.name;
+ global_scope->rw ().assign (var_build_meta_operation) = mif.name;
+ }
+
+ current_mif = &mif;
+ current_on = 0; // Reset.
+ }
+
+ void
+ set_current_oif (const operation_info& inner_oif,
+ const operation_info* outer_oif,
+ bool diag_noise)
+ {
+ current_oname = (outer_oif == nullptr ? inner_oif : *outer_oif).name;
+ current_inner_oif = &inner_oif;
+ current_outer_oif = outer_oif;
+ current_on++;
+ current_mode = inner_oif.mode;
+ current_diag_noise = diag_noise;
+
+ // Reset counters (serial execution).
+ //
+ dependency_count.store (0, memory_order_relaxed);
+ target_count.store (0, memory_order_relaxed);
+ skip_count.store (0, memory_order_relaxed);
+ }
+
variable_overrides
reset (const strings& cmd_vars)
{
@@ -850,187 +882,4 @@ namespace build2
const char var_extension[10] = "extension";
const variable* var_build_meta_operation;
-
- dir_path
- src_out (const dir_path& out, const scope& r)
- {
- assert (r.root ());
- return src_out (out, r.out_path (), r.src_path ());
- }
-
- dir_path
- out_src (const dir_path& src, const scope& r)
- {
- assert (r.root ());
- return out_src (src, r.out_path (), r.src_path ());
- }
-
- dir_path
- src_out (const dir_path& o,
- const dir_path& out_root, const dir_path& src_root)
- {
- assert (o.sub (out_root));
- return src_root / o.leaf (out_root);
- }
-
- dir_path
- out_src (const dir_path& s,
- const dir_path& out_root, const dir_path& src_root)
- {
- assert (s.sub (src_root));
- return out_root / s.leaf (src_root);
- }
-
- // diag_do(), etc.
- //
- string
- diag_do (const action&)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- string r;
-
- // perform(update(x)) -> "update x"
- // configure(update(x)) -> "configure updating x"
- //
- if (m.name_do.empty ())
- r = io.name_do;
- else
- {
- r = m.name_do;
-
- if (io.name_doing[0] != '\0')
- {
- r += ' ';
- r += io.name_doing;
- }
- }
-
- if (oo != nullptr)
- {
- r += " (for ";
- r += oo->name;
- r += ')';
- }
-
- return r;
- }
-
- void
- diag_do (ostream& os, const action& a, const target& t)
- {
- os << diag_do (a) << ' ' << t;
- }
-
- string
- diag_doing (const action&)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- string r;
-
- // perform(update(x)) -> "updating x"
- // configure(update(x)) -> "configuring updating x"
- //
- if (!m.name_doing.empty ())
- r = m.name_doing;
-
- if (io.name_doing[0] != '\0')
- {
- if (!r.empty ()) r += ' ';
- r += io.name_doing;
- }
-
- if (oo != nullptr)
- {
- r += " (for ";
- r += oo->name;
- r += ')';
- }
-
- return r;
- }
-
- void
- diag_doing (ostream& os, const action& a, const target& t)
- {
- os << diag_doing (a) << ' ' << t;
- }
-
- string
- diag_did (const action&)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- string r;
-
- // perform(update(x)) -> "updated x"
- // configure(update(x)) -> "configured updating x"
- //
- if (!m.name_did.empty ())
- {
- r = m.name_did;
-
- if (io.name_doing[0] != '\0')
- {
- r += ' ';
- r += io.name_doing;
- }
- }
- else
- r += io.name_did;
-
- if (oo != nullptr)
- {
- r += " (for ";
- r += oo->name;
- r += ')';
- }
-
- return r;
- }
-
- void
- diag_did (ostream& os, const action& a, const target& t)
- {
- os << diag_did (a) << ' ' << t;
- }
-
- void
- diag_done (ostream& os, const action&, const target& t)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- // perform(update(x)) -> "x is up to date"
- // configure(update(x)) -> "updating x is configured"
- //
- if (m.name_done.empty ())
- {
- os << t;
-
- if (io.name_done[0] != '\0')
- os << ' ' << io.name_done;
-
- if (oo != nullptr)
- os << " (for " << oo->name << ')';
- }
- else
- {
- if (io.name_doing[0] != '\0')
- os << io.name_doing << ' ';
-
- if (oo != nullptr)
- os << "(for " << oo->name << ") ";
-
- os << t << ' ' << m.name_done;
- }
- }
}
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx
index 86867a1..ce9a996 100644
--- a/libbuild2/context.hxx
+++ b/libbuild2/context.hxx
@@ -8,7 +8,6 @@
#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>
-#include <libbuild2/scope.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/operation.hxx>
#include <libbuild2/scheduler.hxx>
@@ -17,7 +16,9 @@
namespace build2
{
- // Main (and only) scheduler. Started up and shut down in main().
+ class scope;
+
+ // Main scheduler. Started up and shut down in main().
//
LIBBUILD2_SYMEXPORT extern scheduler sched;
@@ -302,10 +303,10 @@ namespace build2
LIBBUILD2_SYMEXPORT extern atomic_count target_count;
LIBBUILD2_SYMEXPORT extern atomic_count skip_count;
- void
+ LIBBUILD2_SYMEXPORT void
set_current_mif (const meta_operation_info&);
- void
+ LIBBUILD2_SYMEXPORT void
set_current_oif (const operation_info& inner,
const operation_info* outer = nullptr,
bool diag_noise = true);
@@ -450,101 +451,6 @@ namespace build2
// .meta_operation
//
LIBBUILD2_SYMEXPORT extern const variable* var_build_meta_operation;
-
- // Utility.
- //
-
- // Return the project name or empty string if unnamed.
- //
- inline const project_name&
- project (const scope& root)
- {
- auto l (root[var_project]);
- return l ? cast<project_name> (l) : empty_project_name;
- }
-
- // Return the src/out directory corresponding to the given out/src. The
- // passed directory should be a sub-directory of out/src_root.
- //
- LIBBUILD2_SYMEXPORT dir_path
- src_out (const dir_path& out, const scope& root);
-
- LIBBUILD2_SYMEXPORT dir_path
- src_out (const dir_path& out,
- const dir_path& out_root, const dir_path& src_root);
-
- LIBBUILD2_SYMEXPORT dir_path
- out_src (const dir_path& src, const scope& root);
-
- LIBBUILD2_SYMEXPORT dir_path
- out_src (const dir_path& src,
- const dir_path& out_root, const dir_path& src_root);
-
- // Action phrases, e.g., "configure update exe{foo}", "updating exe{foo}",
- // and "updating exe{foo} is configured". Use like this:
- //
- // info << "while " << diag_doing (a, t);
- //
- class target;
-
- struct diag_phrase
- {
- const action& a;
- const target& t;
- void (*f) (ostream&, const action&, const target&);
- };
-
- inline ostream&
- operator<< (ostream& os, const diag_phrase& p)
- {
- p.f (os, p.a, p.t);
- return os;
- }
-
- LIBBUILD2_SYMEXPORT string
- diag_do (const action&);
-
- LIBBUILD2_SYMEXPORT void
- diag_do (ostream&, const action&, const target&);
-
- inline diag_phrase
- diag_do (const action& a, const target& t)
- {
- return diag_phrase {a, t, &diag_do};
- }
-
- LIBBUILD2_SYMEXPORT string
- diag_doing (const action&);
-
- LIBBUILD2_SYMEXPORT void
- diag_doing (ostream&, const action&, const target&);
-
- inline diag_phrase
- diag_doing (const action& a, const target& t)
- {
- return diag_phrase {a, t, &diag_doing};
- }
-
- LIBBUILD2_SYMEXPORT string
- diag_did (const action&);
-
- LIBBUILD2_SYMEXPORT void
- diag_did (ostream&, const action&, const target&);
-
- inline diag_phrase
- diag_did (const action& a, const target& t)
- {
- return diag_phrase {a, t, &diag_did};
- }
-
- LIBBUILD2_SYMEXPORT void
- diag_done (ostream&, const action&, const target&);
-
- inline diag_phrase
- diag_done (const action& a, const target& t)
- {
- return diag_phrase {a, t, &diag_done};
- }
}
#include <libbuild2/context.ixx>
diff --git a/libbuild2/context.ixx b/libbuild2/context.ixx
index 1364eb8..f947bd7 100644
--- a/libbuild2/context.ixx
+++ b/libbuild2/context.ixx
@@ -57,36 +57,4 @@ namespace build2
sched.wait (start_count, *task_count);
task_count = nullptr;
}
-
- inline void
- set_current_mif (const meta_operation_info& mif)
- {
- if (current_mname != mif.name)
- {
- current_mname = mif.name;
- global_scope->rw ().assign (var_build_meta_operation) = mif.name;
- }
-
- current_mif = &mif;
- current_on = 0; // Reset.
- }
-
- inline void
- set_current_oif (const operation_info& inner_oif,
- const operation_info* outer_oif,
- bool diag_noise)
- {
- current_oname = (outer_oif == nullptr ? inner_oif : *outer_oif).name;
- current_inner_oif = &inner_oif;
- current_outer_oif = outer_oif;
- current_on++;
- current_mode = inner_oif.mode;
- current_diag_noise = diag_noise;
-
- // Reset counters (serial execution).
- //
- dependency_count.store (0, memory_order_relaxed);
- target_count.store (0, memory_order_relaxed);
- skip_count.store (0, memory_order_relaxed);
- }
}
diff --git a/libbuild2/diagnostics.cxx b/libbuild2/diagnostics.cxx
index eab3b78..3375e00 100644
--- a/libbuild2/diagnostics.cxx
+++ b/libbuild2/diagnostics.cxx
@@ -8,6 +8,11 @@
#include <libbutl/process-io.mxx>
+#include <libbuild2/scope.hxx>
+#include <libbuild2/action.hxx>
+#include <libbuild2/target.hxx>
+#include <libbuild2/context.hxx>
+
using namespace std;
namespace build2
@@ -135,4 +140,157 @@ namespace build2
const basic_mark text (nullptr, nullptr, nullptr); // No type/data/frame.
const fail_mark fail ("error");
const fail_end endf;
+
+ // diag_do(), etc.
+ //
+ string
+ diag_do (const action&)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ string r;
+
+ // perform(update(x)) -> "update x"
+ // configure(update(x)) -> "configure updating x"
+ //
+ if (m.name_do.empty ())
+ r = io.name_do;
+ else
+ {
+ r = m.name_do;
+
+ if (io.name_doing[0] != '\0')
+ {
+ r += ' ';
+ r += io.name_doing;
+ }
+ }
+
+ if (oo != nullptr)
+ {
+ r += " (for ";
+ r += oo->name;
+ r += ')';
+ }
+
+ return r;
+ }
+
+ void
+ diag_do (ostream& os, const action& a, const target& t)
+ {
+ os << diag_do (a) << ' ' << t;
+ }
+
+ string
+ diag_doing (const action&)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ string r;
+
+ // perform(update(x)) -> "updating x"
+ // configure(update(x)) -> "configuring updating x"
+ //
+ if (!m.name_doing.empty ())
+ r = m.name_doing;
+
+ if (io.name_doing[0] != '\0')
+ {
+ if (!r.empty ()) r += ' ';
+ r += io.name_doing;
+ }
+
+ if (oo != nullptr)
+ {
+ r += " (for ";
+ r += oo->name;
+ r += ')';
+ }
+
+ return r;
+ }
+
+ void
+ diag_doing (ostream& os, const action& a, const target& t)
+ {
+ os << diag_doing (a) << ' ' << t;
+ }
+
+ string
+ diag_did (const action&)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ string r;
+
+ // perform(update(x)) -> "updated x"
+ // configure(update(x)) -> "configured updating x"
+ //
+ if (!m.name_did.empty ())
+ {
+ r = m.name_did;
+
+ if (io.name_doing[0] != '\0')
+ {
+ r += ' ';
+ r += io.name_doing;
+ }
+ }
+ else
+ r += io.name_did;
+
+ if (oo != nullptr)
+ {
+ r += " (for ";
+ r += oo->name;
+ r += ')';
+ }
+
+ return r;
+ }
+
+ void
+ diag_did (ostream& os, const action& a, const target& t)
+ {
+ os << diag_did (a) << ' ' << t;
+ }
+
+ void
+ diag_done (ostream& os, const action&, const target& t)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ // perform(update(x)) -> "x is up to date"
+ // configure(update(x)) -> "updating x is configured"
+ //
+ if (m.name_done.empty ())
+ {
+ os << t;
+
+ if (io.name_done[0] != '\0')
+ os << ' ' << io.name_done;
+
+ if (oo != nullptr)
+ os << " (for " << oo->name << ')';
+ }
+ else
+ {
+ if (io.name_doing[0] != '\0')
+ os << io.name_doing << ' ';
+
+ if (oo != nullptr)
+ os << "(for " << oo->name << ") ";
+
+ os << t << ' ' << m.name_done;
+ }
+ }
}
diff --git a/libbuild2/diagnostics.hxx b/libbuild2/diagnostics.hxx
index 802cd3c..dbc8351 100644
--- a/libbuild2/diagnostics.hxx
+++ b/libbuild2/diagnostics.hxx
@@ -431,6 +431,74 @@ namespace build2
LIBBUILD2_SYMEXPORT extern const fail_mark fail;
LIBBUILD2_SYMEXPORT extern const fail_end endf;
+
+ // Action phrases, e.g., "configure update exe{foo}", "updating exe{foo}",
+ // and "updating exe{foo} is configured". Use like this:
+ //
+ // info << "while " << diag_doing (a, t);
+ //
+ class scope;
+ class target;
+ struct action;
+
+ struct diag_phrase
+ {
+ const action& a;
+ const target& t;
+ void (*f) (ostream&, const action&, const target&);
+ };
+
+ inline ostream&
+ operator<< (ostream& os, const diag_phrase& p)
+ {
+ p.f (os, p.a, p.t);
+ return os;
+ }
+
+ LIBBUILD2_SYMEXPORT string
+ diag_do (const action&);
+
+ LIBBUILD2_SYMEXPORT void
+ diag_do (ostream&, const action&, const target&);
+
+ inline diag_phrase
+ diag_do (const action& a, const target& t)
+ {
+ return diag_phrase {a, t, &diag_do};
+ }
+
+ LIBBUILD2_SYMEXPORT string
+ diag_doing (const action&);
+
+ LIBBUILD2_SYMEXPORT void
+ diag_doing (ostream&, const action&, const target&);
+
+ inline diag_phrase
+ diag_doing (const action& a, const target& t)
+ {
+ return diag_phrase {a, t, &diag_doing};
+ }
+
+ LIBBUILD2_SYMEXPORT string
+ diag_did (const action&);
+
+ LIBBUILD2_SYMEXPORT void
+ diag_did (ostream&, const action&, const target&);
+
+ inline diag_phrase
+ diag_did (const action& a, const target& t)
+ {
+ return diag_phrase {a, t, &diag_did};
+ }
+
+ LIBBUILD2_SYMEXPORT void
+ diag_done (ostream&, const action&, const target&);
+
+ inline diag_phrase
+ diag_done (const action& a, const target& t)
+ {
+ return diag_phrase {a, t, &diag_done};
+ }
}
#endif // LIBBUILD2_DIAGNOSTICS_HXX
diff --git a/libbuild2/dump.cxx b/libbuild2/dump.cxx
index a866fe3..7d59891 100644
--- a/libbuild2/dump.cxx
+++ b/libbuild2/dump.cxx
@@ -7,7 +7,6 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/target.hxx>
#include <libbuild2/variable.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/diagnostics.hxx>
using namespace std;
diff --git a/libbuild2/filesystem.txx b/libbuild2/filesystem.txx
index 6166082..057975a 100644
--- a/libbuild2/filesystem.txx
+++ b/libbuild2/filesystem.txx
@@ -4,7 +4,7 @@
#include <type_traits> // is_base_of
-#include <libbuild2/context.hxx>
+#include <libbuild2/context.hxx> // dry_run
#include <libbuild2/diagnostics.hxx>
namespace build2
diff --git a/libbuild2/function.test.cxx b/libbuild2/function.test.cxx
index a9326f4..2380987 100644
--- a/libbuild2/function.test.cxx
+++ b/libbuild2/function.test.cxx
@@ -7,6 +7,7 @@
#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>
+#include <libbuild2/scope.hxx>
#include <libbuild2/parser.hxx>
#include <libbuild2/context.hxx>
#include <libbuild2/function.hxx>
diff --git a/libbuild2/in/init.cxx b/libbuild2/in/init.cxx
index 6ef996b..a067ec3 100644
--- a/libbuild2/in/init.cxx
+++ b/libbuild2/in/init.cxx
@@ -5,7 +5,6 @@
#include <libbuild2/in/init.hxx>
#include <libbuild2/scope.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/install/rule.cxx b/libbuild2/install/rule.cxx
index afb5b29..48a404b 100644
--- a/libbuild2/install/rule.cxx
+++ b/libbuild2/install/rule.cxx
@@ -9,6 +9,7 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/target.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/algorithm.hxx>
#include <libbuild2/filesystem.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/operation.cxx b/libbuild2/operation.cxx
index 9d84cc2..168ed5c 100644
--- a/libbuild2/operation.cxx
+++ b/libbuild2/operation.cxx
@@ -9,6 +9,7 @@
#include <libbuild2/file.hxx>
#include <libbuild2/scope.hxx>
#include <libbuild2/target.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/algorithm.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index 4c48440..c55d434 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -14,7 +14,6 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/module.hxx>
#include <libbuild2/target.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/function.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/filesystem.hxx>
diff --git a/libbuild2/scope.hxx b/libbuild2/scope.hxx
index f69e822..0c4094b 100644
--- a/libbuild2/scope.hxx
+++ b/libbuild2/scope.hxx
@@ -12,12 +12,13 @@
#include <libbuild2/utility.hxx>
#include <libbuild2/module.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
+#include <libbuild2/rule-map.hxx>
+#include <libbuild2/operation.hxx>
#include <libbuild2/target-key.hxx>
#include <libbuild2/target-type.hxx>
#include <libbuild2/target-state.hxx>
-#include <libbuild2/rule-map.hxx>
-#include <libbuild2/operation.hxx>
#include <libbuild2/export.hxx>
@@ -370,6 +371,28 @@ namespace build2
return os << s.out_path ().representation (); // Always absolute.
}
+ // Return the src/out directory corresponding to the given out/src. The
+ // passed directory should be a sub-directory of out/src_root.
+ //
+ dir_path
+ src_out (const dir_path& out, const scope& root);
+
+ dir_path
+ src_out (const dir_path& out,
+ const dir_path& out_root, const dir_path& src_root);
+
+ dir_path
+ out_src (const dir_path& src, const scope& root);
+
+ dir_path
+ out_src (const dir_path& src,
+ const dir_path& out_root, const dir_path& src_root);
+
+ // Return the project name or empty string if unnamed.
+ //
+ const project_name&
+ project (const scope& root);
+
// Temporary scope. The idea is to be able to create a temporary scope in
// order not to change the variables in the current scope. Such a scope is
// not entered in to the scope map. As a result it can only be used as a
diff --git a/libbuild2/scope.ixx b/libbuild2/scope.ixx
index 3498ae0..aa1247f 100644
--- a/libbuild2/scope.ixx
+++ b/libbuild2/scope.ixx
@@ -51,4 +51,41 @@ namespace build2
return false;
}
+
+ inline dir_path
+ src_out (const dir_path& out, const scope& r)
+ {
+ assert (r.root ());
+ return src_out (out, r.out_path (), r.src_path ());
+ }
+
+ inline dir_path
+ out_src (const dir_path& src, const scope& r)
+ {
+ assert (r.root ());
+ return out_src (src, r.out_path (), r.src_path ());
+ }
+
+ inline dir_path
+ src_out (const dir_path& o,
+ const dir_path& out_root, const dir_path& src_root)
+ {
+ assert (o.sub (out_root));
+ return src_root / o.leaf (out_root);
+ }
+
+ inline dir_path
+ out_src (const dir_path& s,
+ const dir_path& out_root, const dir_path& src_root)
+ {
+ assert (s.sub (src_root));
+ return out_root / s.leaf (src_root);
+ }
+
+ inline const project_name&
+ project (const scope& root)
+ {
+ auto l (root[var_project]);
+ return l ? cast<project_name> (l) : empty_project_name;
+ }
}
diff --git a/libbuild2/search.cxx b/libbuild2/search.cxx
index 1ff9c73..917d750 100644
--- a/libbuild2/search.cxx
+++ b/libbuild2/search.cxx
@@ -6,7 +6,6 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/target.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/filesystem.hxx> // mtime()
#include <libbuild2/prerequisite.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/spec.cxx b/libbuild2/spec.cxx
index 3ad6b7d..58b4541 100644
--- a/libbuild2/spec.cxx
+++ b/libbuild2/spec.cxx
@@ -4,7 +4,6 @@
#include <libbuild2/spec.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/diagnostics.hxx>
using namespace std;
diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx
index 6d320d4..4bd11fe 100644
--- a/libbuild2/target.hxx
+++ b/libbuild2/target.hxx
@@ -16,6 +16,7 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/action.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/target-key.hxx>
#include <libbuild2/target-type.hxx>
@@ -27,13 +28,8 @@
namespace build2
{
class rule;
- class scope;
class target;
- // From <libbuild2/context.hxx>.
- //
- LIBBUILD2_SYMEXPORT extern size_t current_on;
-
// From <libbuild2/algorithm.hxx>.
//
LIBBUILD2_SYMEXPORT const target&
diff --git a/libbuild2/test/rule.cxx b/libbuild2/test/rule.cxx
index a6796b4..1d11063 100644
--- a/libbuild2/test/rule.cxx
+++ b/libbuild2/test/rule.cxx
@@ -6,6 +6,7 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/target.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/algorithm.hxx>
#include <libbuild2/filesystem.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/utility.cxx b/libbuild2/utility.cxx
index cacb464..63fa609 100644
--- a/libbuild2/utility.cxx
+++ b/libbuild2/utility.cxx
@@ -10,6 +10,7 @@
#include <iostream> // cerr
#include <libbuild2/target.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx
index beb169e..c921bbd 100644
--- a/libbuild2/variable.cxx
+++ b/libbuild2/variable.cxx
@@ -8,7 +8,6 @@
#include <libbutl/filesystem.mxx> // path_match()
-#include <libbuild2/context.hxx>
#include <libbuild2/diagnostics.hxx>
using namespace std;
diff --git a/libbuild2/version/init.cxx b/libbuild2/version/init.cxx
index 8adbb29..a4e41d6 100644
--- a/libbuild2/version/init.cxx
+++ b/libbuild2/version/init.cxx
@@ -7,7 +7,6 @@
#include <libbutl/manifest-parser.mxx>
#include <libbuild2/scope.hxx>
-#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/diagnostics.hxx>
diff --git a/libbuild2/version/utility.cxx b/libbuild2/version/utility.cxx
index c93a251..70daab1 100644
--- a/libbuild2/version/utility.cxx
+++ b/libbuild2/version/utility.cxx
@@ -7,6 +7,7 @@
#include <libbutl/manifest-parser.mxx>
#include <libbutl/manifest-serializer.mxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/diagnostics.hxx>
using namespace butl;