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/target.cxx | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 7 deletions(-) (limited to 'build2/target.cxx') diff --git a/build2/target.cxx b/build2/target.cxx index fa8378c..676dc6b 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -659,6 +659,7 @@ namespace build2 nullptr, nullptr, nullptr, + nullptr, &search_target, false }; @@ -670,6 +671,7 @@ namespace build2 nullptr, nullptr, nullptr, + nullptr, &search_target, false }; @@ -681,6 +683,7 @@ namespace build2 nullptr, nullptr, nullptr, + nullptr, &search_target, false }; @@ -714,6 +717,7 @@ namespace build2 &path_target::static_type, &file_factory, &target_extension_var, + &target_pattern_var, &target_print_1_ext_verb, // Print extension even at verbosity level 0. &search_file, false @@ -740,14 +744,15 @@ namespace build2 &target_factory, nullptr, // Extension not used. nullptr, + nullptr, &search_alias, false }; static const target* - search_dir (const prerequisite_key& pk) + dir_target_search (const prerequisite_key& pk) { - tracer trace ("search_dir"); + tracer trace ("dir_target_search"); // The first step is like in search_alias(): looks for an existing target. // @@ -831,14 +836,36 @@ namespace build2 info << "did you forget to include the corresponding buildfile?" << endf; } + static bool + dir_target_pattern (const target_type&, const scope&, string& v, bool r) + { + // Add/strip trailing directory separator unless already there. + // + bool d (path::traits::is_separator (v.back ())); + + if (r) + { + assert (d); + v.resize (v.size () - 1); + } + else if (!d) + { + v += path::traits::directory_separator; + return true; + } + + return false; + } + const target_type dir::static_type { "dir", &alias::static_type, &target_factory, - nullptr, // Extension not used. + nullptr, // Extension not used. + &dir_target_pattern, nullptr, - &search_dir, + &dir_target_search, false }; @@ -847,14 +874,15 @@ namespace build2 "fsdir", &target::static_type, &target_factory, - nullptr, // Extension not used. + nullptr, // Extension not used. + &dir_target_pattern, nullptr, &search_target, false }; static optional - exe_extension (const target_key&, const scope&, bool search) + exe_target_extension (const target_key&, const scope&, bool search) { // If we are searching for an executable that is not a target, then // use the build machine executable extension. Otherwise, if this is @@ -871,12 +899,38 @@ namespace build2 : nullopt; } +#ifdef _WIN32 + static bool + exe_target_pattern (const target_type&, const scope&, string& v, bool r) + { + size_t p (path::traits::find_extension (v)); + + if (r) + { + assert (p != string::npos); + v.resize (p); + } + else if (p == string::npos) + { + v += ".exe"; + return true; + } + + return false; + } +#endif + const target_type exe::static_type { "exe", &file::static_type, &target_factory, - &exe_extension, + &exe_target_extension, +#ifdef _WIN32 + &exe_target_pattern, +#else + nullptr, +#endif nullptr, &search_file, false @@ -904,12 +958,35 @@ namespace build2 return *tk.name == "buildfile" ? string () : "build"; } + static bool + buildfile_target_pattern (const target_type&, + const scope&, + string& v, + bool r) + { + size_t p (path::traits::find_extension (v)); + + if (r) + { + assert (p != string::npos); + v.resize (p); + } + else if (p == string::npos && v != "buildfile") + { + v += ".build"; + return true; + } + + return false; + } + const target_type buildfile::static_type { "build", &file::static_type, &buildfile_factory, &buildfile_target_extension, + &buildfile_target_pattern, nullptr, &search_file, false @@ -921,6 +998,7 @@ namespace build2 &file::static_type, &file_factory, // No extension by default. &target_extension_var, // Same as file. + &target_pattern_var, // Same as file. &target_print_1_ext_verb, // Same as file. &search_file, false @@ -945,6 +1023,7 @@ namespace build2 &doc::static_type, &man_factory, &target_extension_null, // Should be specified explicitly (see factory). + nullptr, &target_print_1_ext_verb, // Print extension even at verbosity level 0. &search_file, false @@ -958,6 +1037,7 @@ namespace build2 &man::static_type, &file_factory, &target_extension_fix, + &target_pattern_fix, &target_print_0_ext_verb, // Fixed extension, no use printing. &search_file, false -- cgit v1.1