diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-12-17 11:49:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-12-17 11:49:34 +0200 |
commit | 9740d9e777c9d19482052a37ad3a6ab25112d6d6 (patch) | |
tree | 91cb7a0485f0207e01c4bb886c4d654026b9bc84 /build2/file.cxx | |
parent | 747ff339c4be7d271a33996638b3b026a166d805 (diff) |
Use PATH search as fallback import mechanism for exe{} targets
Diffstat (limited to 'build2/file.cxx')
-rw-r--r-- | build2/file.cxx | 59 |
1 files changed, 52 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 <iostream> // cin #include <build2/scope> +#include <build2/target> #include <build2/context> #include <build2/filesystem> // exists() #include <build2/prerequisite> @@ -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<exe> () && 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<exe> ( + 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; } } |