From 9740d9e777c9d19482052a37ad3a6ab25112d6d6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 17 Dec 2016 11:49:34 +0200 Subject: Use PATH search as fallback import mechanism for exe{} targets --- build2/file.cxx | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++------- build2/target | 12 ++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/build2/file.cxx b/build2/file.cxx index b049590..ea646f7 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -7,6 +7,7 @@ #include // cin #include +#include #include #include // exists() #include @@ -1038,21 +1039,65 @@ namespace build2 target& import (const prerequisite_key& pk) { + tracer trace ("import"); + assert (pk.proj != nullptr); const string& p (*pk.proj); + // Target type-specific search. + // + const target_key& tk (pk.tk); + const target_type& tt (*tk.type); + + // Try to find the executable in PATH. + // + if (tt.is_a () && tk.dir->empty ()) + { + process_path pp ( + process::try_path_search ( + tk.ext == nullptr ? *tk.name : *tk.name + '.' + *tk.ext, true)); + + if (!pp.empty ()) + { + path& p (pp.effect); + assert (!p.empty ()); // We searched for a simple name. + + dir_path d (p.directory ()); + const char* e (p.extension ()); + + exe& t ( + targets.insert ( + tt, + move (d), + dir_path (), // No out (out of project). + p.leaf ().base ().string (), + &extension_pool.find (e == nullptr ? "" : e), // Specified. + trace)); + + if (t.path ().empty ()) + t.path (move (p)); + else + assert (t.path () == p); + + return t; + } + } + // @@ We no longer have location. This is especially bad for the // empty case, i.e., where do I need to specify the project // name)? Looks like the only way to do this is to keep location // in name and then in prerequisite. Perhaps one day... // - if (!p.empty ()) - fail << "unable to import target " << pk << - info << "consider explicitly specifying its project out_root via the " - << "config.import." << p << " command line variable" << endf; + diag_record dr; + dr << fail << "unable to import target " << pk; + + if (p.empty ()) + dr << info << "consider adding its installation location" << + info << "or explicitly specify its project name"; else - fail << "unable to import target " << pk << - info << "consider adding its installation location" << - info << "or explicitly specifying its project name" << endf; + dr << info << "use config.import." << p << " command line variable to " + << "specifying its project out_root"; + + dr << endf; } } diff --git a/build2/target b/build2/target index 5c897f1..9b3c679 100644 --- a/build2/target +++ b/build2/target @@ -1013,6 +1013,18 @@ namespace build2 const string* ext, tracer&); + template + T& + insert (const target_type& tt, + dir_path dir, + dir_path out, + string name, + const string* ext, + tracer& t) + { + return static_cast ( + insert (tt, move (dir), move (out), move (name), ext, t).first); + } template T& -- cgit v1.1