aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-21 13:26:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-21 13:26:28 +0200
commit0f9ce1c7022e5fa572886c9a9bda3a7e5c466314 (patch)
tree30a871a1bbf9d0f0e09f3953bf61bea16b540c71
parentc8459c886bab3a68631491059d1a5f300a3861cb (diff)
Implement searching for b in bpkg's exec directory as last resort
This way if we run /opt/build2/bin/bpkg it will be able to find b in /opt/build2/bin/ without PATH.
-rw-r--r--bpkg/bpkg.cxx2
-rw-r--r--bpkg/utility15
-rw-r--r--bpkg/utility.cxx22
3 files changed, 31 insertions, 8 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index 561e32e..d6f6924 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -98,6 +98,8 @@ try
{
using namespace cli;
+ exec_dir = path (argv[0]).directory ();
+
argv_file_scanner scan (argc, argv, "--options-file");
// First parse common options and --version/--help.
diff --git a/bpkg/utility b/bpkg/utility
index 85cf1ca..a09cac5 100644
--- a/bpkg/utility
+++ b/bpkg/utility
@@ -78,11 +78,22 @@ namespace bpkg
// The process command line is printed for verbosity >= 2 (essential
// command lines).
//
+ // If fallback is specified, then this directory is searched for the
+ // executable as a last resort.
+ //
void
- run (const char* args[]);
+ run (const char* args[], const dir_path& fallback = dir_path ());
inline void
- run (cstrings& args) {run (args.data ());}
+ run (cstrings& args, const dir_path& fallback = dir_path ())
+ {
+ run (args.data (), fallback);
+ }
+
+ // Directory extracted from argv[0] (i.e., this process' recall directory)
+ // or empty if there is none. Can be used as a search fallback.
+ //
+ extern dir_path exec_dir;
// Run build2, mapping verbosity levels. If quiet is true, then run build2
// quiet if our verbosity level is 1. Common vars (cvars) are set on the
diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx
index 12ef220..002d316 100644
--- a/bpkg/utility.cxx
+++ b/bpkg/utility.cxx
@@ -167,15 +167,19 @@ namespace bpkg
}
}
+ dir_path exec_dir;
+
void
- run (const char* args[])
+ run (const char* args[], const dir_path& fallback)
{
- if (verb >= 2)
- print_process (args);
-
try
{
- process pr (args);
+ process_path pp (process::path_search (args[0], fallback));
+
+ if (verb >= 2)
+ print_process (args);
+
+ process pr (pp, args);
if (!pr.wait ())
throw failed (); // Assume the child issued diagnostics.
@@ -253,7 +257,13 @@ namespace bpkg
args.push_back (bspec.c_str ());
args.push_back (nullptr);
- run (args);
+
+ // Use our executable directory as a fallback search since normally the
+ // entire toolchain is installed into one directory. This way, for
+ // example, if we installed into /opt/build2 and run bpkg with absolute
+ // path (and without PATH), then bpkg will be able to find "its" b.
+ //
+ run (args, exec_dir);
}
bool exception_unwinding_dtor = false;