From f3fa8fe79ba4c0b9d0a9817957c71f56b7f1a9a2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Aug 2016 18:24:21 +0200 Subject: Add workaround for Windows baseutils /bin search issue --- bpkg/bpkg.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'bpkg/bpkg.cxx') 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 // getenv(), _putenv() +#endif + #include // strcmp() #include @@ -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. -- cgit v1.1