aboutsummaryrefslogtreecommitdiff
path: root/build2/context.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'build2/context.cxx')
-rw-r--r--build2/context.cxx189
1 files changed, 97 insertions, 92 deletions
diff --git a/build2/context.cxx b/build2/context.cxx
index 62822a3..c055035 100644
--- a/build2/context.cxx
+++ b/build2/context.cxx
@@ -250,6 +250,100 @@ namespace build2
scope& gs (make_global_scope ());
+ // Setup the global scope before parsing any variable overrides since they
+ // may reference these things.
+ //
+
+ // Target extension.
+ //
+ vp.insert<string> ("extension", variable_visibility::target);
+
+ gs.assign<dir_path> ("build.work") = work;
+ gs.assign<dir_path> ("build.home") = home;
+
+ // Build system driver process path.
+ //
+ gs.assign<process_path> ("build.path") =
+ process_path (nullptr, // Will be filled by value assignment.
+ path (argv0.recall_string ()),
+ path (argv0.effect));
+
+ // Build system version.
+ //
+ {
+ gs.assign<uint64_t> ("build.version") = uint64_t (BUILD2_VERSION);
+ gs.assign<string> ("build.version.string") = BUILD2_VERSION_STR;
+
+ // AABBCCDD
+ //
+ auto comp = [] (unsigned int d) -> uint64_t
+ {
+ return (BUILD2_VERSION / d) % 100;
+ };
+
+ gs.assign<uint64_t> ("build.version.release") = comp (1);
+ gs.assign<uint64_t> ("build.version.patch") = comp (100);
+ gs.assign<uint64_t> ("build.version.minor") = comp (10000);
+ gs.assign<uint64_t> ("build.version.major") = comp (1000000);
+ }
+
+ // Enter the host information. Rather than jumping through hoops like
+ // config.guess, for now we are just going to use the compiler target we
+ // were built with. While it is not as precise (for example, a binary
+ // built for i686 might be running on x86_64), it is good enough of an
+ // approximation/fallback since most of the time we are interested in just
+ // the target class (e.g., linux, windows, macosx).
+ //
+ {
+ // Did the user ask us to use config.guess?
+ //
+ string orig (
+ ops.config_guess_specified ()
+ ? run<string> (ops.config_guess (), [] (string& l) {return move (l);})
+ : BUILD2_HOST_TRIPLET);
+
+ l5 ([&]{trace << "original host: '" << orig << "'";});
+
+ try
+ {
+ target_triplet t (orig);
+
+ l5 ([&]{trace << "canonical host: '" << t.string () << "'; "
+ << "class: " << t.class_;});
+
+ // Also enter as build.host.{cpu,vendor,system,version,class} for
+ // convenience of access.
+ //
+ gs.assign<string> ("build.host.cpu") = t.cpu;
+ gs.assign<string> ("build.host.vendor") = t.vendor;
+ gs.assign<string> ("build.host.system") = t.system;
+ gs.assign<string> ("build.host.version") = t.version;
+ gs.assign<string> ("build.host.class") = t.class_;
+
+ gs.assign<target_triplet> ("build.host") = move (t);
+ }
+ catch (const invalid_argument& e)
+ {
+ fail << "unable to parse build host '" << orig << "': " << e <<
+ info << "consider using the --config-guess option";
+ }
+ }
+
+ // Register builtin target types.
+ //
+ {
+ target_type_map& t (gs.target_types);
+
+ t.insert<file> ();
+ t.insert<alias> ();
+ t.insert<dir> ();
+ t.insert<fsdir> ();
+ t.insert<exe> ();
+ t.insert<doc> ();
+ t.insert<man> ();
+ t.insert<man1> ();
+ }
+
// Parse and enter the command line variables. We do it before entering
// any other variables so that all the variables that are overriden are
// marked as such first. Then, as we enter variables, we can verify that
@@ -337,10 +431,11 @@ namespace build2
o = o->override.get ();
// Currently we expand project overrides in the global scope to keep
- // things simple. Pass original variable for diagnostics.
+ // things simple. Pass original variable for diagnostics. Use current
+ // working directory as pattern base.
//
parser p;
- pair<value, token> r (p.parse_variable_value (l, gs, var));
+ pair<value, token> r (p.parse_variable_value (l, gs, &work, var));
if (r.second.type != token_type::eos)
fail << "unexpected " << r.second << " in variable assignment "
@@ -410,96 +505,6 @@ namespace build2
var_import_target = &vp.insert<name> ("import.target");
- // Target extension.
- //
- vp.insert<string> ("extension", variable_visibility::target);
-
- gs.assign<dir_path> ("build.work") = work;
- gs.assign<dir_path> ("build.home") = home;
-
- // Build system driver process path.
- //
- gs.assign<process_path> ("build.path") =
- process_path (nullptr, // Will be filled by value assignment.
- path (argv0.recall_string ()),
- path (argv0.effect));
-
- // Build system version.
- //
- {
- gs.assign<uint64_t> ("build.version") = uint64_t (BUILD2_VERSION);
- gs.assign<string> ("build.version.string") = BUILD2_VERSION_STR;
-
- // AABBCCDD
- //
- auto comp = [] (unsigned int d) -> uint64_t
- {
- return (BUILD2_VERSION / d) % 100;
- };
-
- gs.assign<uint64_t> ("build.version.release") = comp (1);
- gs.assign<uint64_t> ("build.version.patch") = comp (100);
- gs.assign<uint64_t> ("build.version.minor") = comp (10000);
- gs.assign<uint64_t> ("build.version.major") = comp (1000000);
- }
-
- // Enter the host information. Rather than jumping through hoops like
- // config.guess, for now we are just going to use the compiler target we
- // were built with. While it is not as precise (for example, a binary
- // built for i686 might be running on x86_64), it is good enough of an
- // approximation/fallback since most of the time we are interested in just
- // the target class (e.g., linux, windows, macosx).
- //
- {
- // Did the user ask us to use config.guess?
- //
- string orig (
- ops.config_guess_specified ()
- ? run<string> (ops.config_guess (), [] (string& l) {return move (l);})
- : BUILD2_HOST_TRIPLET);
-
- l5 ([&]{trace << "original host: '" << orig << "'";});
-
- try
- {
- target_triplet t (orig);
-
- l5 ([&]{trace << "canonical host: '" << t.string () << "'; "
- << "class: " << t.class_;});
-
- // Also enter as build.host.{cpu,vendor,system,version,class} for
- // convenience of access.
- //
- gs.assign<string> ("build.host.cpu") = t.cpu;
- gs.assign<string> ("build.host.vendor") = t.vendor;
- gs.assign<string> ("build.host.system") = t.system;
- gs.assign<string> ("build.host.version") = t.version;
- gs.assign<string> ("build.host.class") = t.class_;
-
- gs.assign<target_triplet> ("build.host") = move (t);
- }
- catch (const invalid_argument& e)
- {
- fail << "unable to parse build host '" << orig << "': " << e <<
- info << "consider using the --config-guess option";
- }
- }
-
- // Register builtin target types.
- //
- {
- target_type_map& t (gs.target_types);
-
- t.insert<file> ();
- t.insert<alias> ();
- t.insert<dir> ();
- t.insert<fsdir> ();
- t.insert<exe> ();
- t.insert<doc> ();
- t.insert<man> ();
- t.insert<man1> ();
- }
-
// Register builtin rules.
//
{