Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wslbridge-backend path from command #25

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions frontend/wslbridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,13 @@ static std::wstring getModuleFileName(HMODULE module) {
return std::wstring(path);
}

static std::wstring findBackendProgram() {
std::wstring progDir = dirname(getModuleFileName(getCurrentModule()));
static std::wstring findBackendProgram(std::string backendPath) {
std::wstring progDir = mbsToWcs(backendPath);
std::wstring ret = progDir + (L"\\" BACKEND_PROGRAM);
if (!pathExists(ret)) {
progDir = dirname(getModuleFileName(getCurrentModule()));
ret = progDir + (L"\\" BACKEND_PROGRAM);
}
if (!pathExists(ret)) {
fatal("error: '%s' backend program is missing\n",
wcsToMbs(ret).c_str());
Expand Down Expand Up @@ -616,6 +620,7 @@ static void usage(const char *prog) {
printf("Runs a program within a Windows Subsystem for Linux (WSL) pty\n");
printf("\n");
printf("Options:\n");
printf(" -b path Path of only folder where wslbridge-backend present.\n");
printf(" -C WSLDIR Changes the working directory to WSLDIR first.\n");
printf(" An initial '~' indicates the WSL home directory.\n");
printf(" -e VAR Copies VAR into the WSL environment.\n");
Expand Down Expand Up @@ -980,24 +985,32 @@ int main(int argc, char *argv[]) {
}

Environment env;
std::string backendPath;
std::string spawnCwd;
std::string distroGuid;
enum class TtyRequest { Auto, Yes, No, Force } ttyRequest = TtyRequest::Auto;

int debugFork = 0;
int c = 0;
const struct option kOptionTable[] = {
{ "backend", true, nullptr, 'b' },
{ "help", false, nullptr, 'h' },
{ "debug-fork", false, &debugFork, 1 },
{ "version", false, nullptr, 'v' },
{ "distro-guid", true, nullptr, 'd' },
{ nullptr, false, nullptr, 0 },
};
while ((c = getopt_long(argc, argv, "+e:C:tT", kOptionTable, nullptr)) != -1) {
while ((c = getopt_long(argc, argv, "+b:e:C:tT", kOptionTable, nullptr)) != -1) {
switch (c) {
case 0:
// Ignore long option.
break;
case 'b':
backendPath = optarg;
if (backendPath.empty()) {
fatal("error: the -b option requires a non-empty string argument");
}
break;
case 'e': {
const char *eq = strchr(optarg, '=');
const auto varname = eq ? std::string(optarg, eq - optarg) : std::string(optarg);
Expand Down Expand Up @@ -1083,7 +1096,7 @@ int main(int argc, char *argv[]) {
}

const auto bashPath = findSystemProgram(L"bash.exe");
const auto backendPathInfo = normalizePath(findBackendProgram());
const auto backendPathInfo = normalizePath(findBackendProgram(backendPath));
const auto backendPathWin = backendPathInfo.first;
const auto fsname = backendPathInfo.second;
const auto backendPathWsl = convertPathToWsl(backendPathWin);
Expand Down