From a5592d2ddbce898766dd103ae9a4fe6887ab5209 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Mar 2016 15:26:01 +0200 Subject: Set build.host.* variables --- build2/buildfile | 4 ++++ build2/context.cxx | 53 ++++++++++++++++++++++++++++++++++++++++++++------- build2/cxx/module.cxx | 2 +- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/build2/buildfile b/build2/buildfile index 9f2f19e..6c5f773 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -60,6 +60,10 @@ install/{hxx }{ utility } \ test/{hxx cxx}{ rule } \ $libs +# Pass our compiler target to be used as build2 host. +# +obj{context}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\" + # Load the cli module but only if it's available. This way a distribution # that includes pre-generated files can be built without installing cli. # This is also the reason why above we explicitly spelled out individual diff --git a/build2/context.cxx b/build2/context.cxx index 2abe2f0..5b2b761 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -4,6 +4,8 @@ #include +#include + #include #include #include @@ -29,6 +31,8 @@ namespace build2 void reset () { + tracer trace ("reset"); + extension_pool.clear (); project_name_pool.clear (); @@ -57,9 +61,6 @@ namespace build2 { auto& v (var_pool); - v.find ("build.work", dir_path_type); - v.find ("build.home", dir_path_type); - v.find ("src_root", dir_path_type); v.find ("out_root", dir_path_type); v.find ("src_base", dir_path_type); @@ -82,13 +83,51 @@ namespace build2 global_scope = scopes.insert ( dir_path ("/"), nullptr, true, false)->second; - global_scope->assign ("build.work") = work; - global_scope->assign ("build.home") = home; + scope& gs (*global_scope); + + gs.assign ("build.work", dir_path_type) = work; + gs.assign ("build.home", dir_path_type) = home; + + // 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). + // +#ifndef BUILD2_HOST_TRIPLET +#error BUILD2_HOST_TRIPLET is not defined +#endif + try + { + string canon; + triplet t (BUILD2_HOST_TRIPLET, canon); + + l5 ([&]{trace << "canonical host: '" << canon << "'; " + << "class: " << t.class_;}); + + // Enter as build.host.{cpu,vendor,system,version,class}. + // + gs.assign ("build.host", string_type) = move (canon); + gs.assign ("build.host.cpu", string_type) = move (t.cpu); + gs.assign ("build.host.vendor", string_type) = move (t.vendor); + gs.assign ("build.host.system", string_type) = move (t.system); + gs.assign ("build.host.version", string_type) = move (t.version); + gs.assign ("build.host.class", string_type) = move (t.class_); + } + catch (const invalid_argument& e) + { + // This is where we could suggest that the user specifies --config-guess + // to help us out. + // + fail << "unable to parse build host '" << BUILD2_HOST_TRIPLET << "': " + << e.what (); + } // Register builtin target types. // { - target_type_map& t (global_scope->target_types); + target_type_map& t (gs.target_types); t.insert (); t.insert (); @@ -102,7 +141,7 @@ namespace build2 // Register builtin rules. // { - rule_map& r (global_scope->rules); + rule_map& r (gs.rules); r.insert (perform_id, 0, "alias", alias_rule::instance); diff --git a/build2/cxx/module.cxx b/build2/cxx/module.cxx index 364b801..9ebcc52 100644 --- a/build2/cxx/module.cxx +++ b/build2/cxx/module.cxx @@ -221,7 +221,7 @@ namespace build2 l5 ([&]{trace << "canonical target: '" << canon << "'; " << "class: " << t.class_;}); - // Enter as cxx.target.{cpu,vendor,system,version}. + // Enter as cxx.target.{cpu,vendor,system,version,class}. // r.assign ("cxx.target", string_type) = move (canon); r.assign ("cxx.target.cpu", string_type) = move (t.cpu); -- cgit v1.1