aboutsummaryrefslogtreecommitdiff
path: root/bpkg/bpkg.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-22 18:24:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-22 18:24:21 +0200
commitf3fa8fe79ba4c0b9d0a9817957c71f56b7f1a9a2 (patch)
tree23352cf4f00306dbe45ed170ee2f7f9fd5eeb663 /bpkg/bpkg.cxx
parentec0f0db8821366f3240c4f922bd29620396bd7cd (diff)
Add workaround for Windows baseutils /bin search issue
Diffstat (limited to 'bpkg/bpkg.cxx')
-rw-r--r--bpkg/bpkg.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index d6f6924..8a270fd 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -2,6 +2,10 @@
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
+#ifdef _WIN32
+# include <stdlib.h> // getenv(), _putenv()
+#endif
+
#include <cstring> // strcmp()
#include <iostream>
@@ -100,6 +104,30 @@ try
exec_dir = path (argv[0]).directory ();
+ // This is a little hack to make out baseutils for Windows work when called
+ // with absolute path. In a nutshell, MSYS2's exec*p() doesn't search in the
+ // parent's executable directory, only in PATH. And since we are running
+ // without a shell (that would read /etc/profile which sets PATH to some
+ // sensible values), we are only getting Win32 PATH values. And MSYS2 /bin
+ // is not one of them. So what we are going to do is add /bin at the end of
+ // PATH (which will be passed as is by the MSYS2 machinery). This will make
+ // MSYS2 search in /bin (where our baseutils live). And for everyone else
+ // this should be harmless since it is not a valid Win32 path.
+ //
+#ifdef _WIN32
+ {
+ string mp ("PATH=");
+ if (const char* p = getenv ("PATH"))
+ {
+ mp += p;
+ mp += ';';
+ }
+ mp += "/bin";
+
+ _putenv (mp.c_str ());
+ }
+#endif
+
argv_file_scanner scan (argc, argv, "--options-file");
// First parse common options and --version/--help.