From 6362c4e4eda8340eedc73dfdbf6b92b281ccbadd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 10 Mar 2017 11:51:24 +0200 Subject: Implement support for wildcard patterns --- build2/context.cxx | 189 +++++++++++++++++++++++++++-------------------------- 1 file changed, 97 insertions(+), 92 deletions(-) (limited to 'build2/context.cxx') 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 ("extension", variable_visibility::target); + + gs.assign ("build.work") = work; + gs.assign ("build.home") = home; + + // Build system driver process path. + // + gs.assign ("build.path") = + process_path (nullptr, // Will be filled by value assignment. + path (argv0.recall_string ()), + path (argv0.effect)); + + // Build system version. + // + { + gs.assign ("build.version") = uint64_t (BUILD2_VERSION); + gs.assign ("build.version.string") = BUILD2_VERSION_STR; + + // AABBCCDD + // + auto comp = [] (unsigned int d) -> uint64_t + { + return (BUILD2_VERSION / d) % 100; + }; + + gs.assign ("build.version.release") = comp (1); + gs.assign ("build.version.patch") = comp (100); + gs.assign ("build.version.minor") = comp (10000); + gs.assign ("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 (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 ("build.host.cpu") = t.cpu; + gs.assign ("build.host.vendor") = t.vendor; + gs.assign ("build.host.system") = t.system; + gs.assign ("build.host.version") = t.version; + gs.assign ("build.host.class") = t.class_; + + gs.assign ("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 (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + } + // 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 r (p.parse_variable_value (l, gs, var)); + pair 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 ("import.target"); - // Target extension. - // - vp.insert ("extension", variable_visibility::target); - - gs.assign ("build.work") = work; - gs.assign ("build.home") = home; - - // Build system driver process path. - // - gs.assign ("build.path") = - process_path (nullptr, // Will be filled by value assignment. - path (argv0.recall_string ()), - path (argv0.effect)); - - // Build system version. - // - { - gs.assign ("build.version") = uint64_t (BUILD2_VERSION); - gs.assign ("build.version.string") = BUILD2_VERSION_STR; - - // AABBCCDD - // - auto comp = [] (unsigned int d) -> uint64_t - { - return (BUILD2_VERSION / d) % 100; - }; - - gs.assign ("build.version.release") = comp (1); - gs.assign ("build.version.patch") = comp (100); - gs.assign ("build.version.minor") = comp (10000); - gs.assign ("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 (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 ("build.host.cpu") = t.cpu; - gs.assign ("build.host.vendor") = t.vendor; - gs.assign ("build.host.system") = t.system; - gs.assign ("build.host.version") = t.version; - gs.assign ("build.host.class") = t.class_; - - gs.assign ("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 (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - } - // Register builtin rules. // { -- cgit v1.1