diff --git a/llvm/tools/bugpoint/ToolRunner.h b/llvm/tools/bugpoint/ToolRunner.h --- a/llvm/tools/bugpoint/ToolRunner.h +++ b/llvm/tools/bugpoint/ToolRunner.h @@ -37,10 +37,12 @@ class CC { std::string CCPath; // The path to the cc executable. std::string RemoteClientPath; // The path to the rsh / ssh executable. + std::string RemoteCopyPath; // The path to the scp executable. std::vector ccArgs; // CC-specific arguments. - CC(StringRef ccPath, StringRef RemotePath, + CC(StringRef ccPath, StringRef RemotePath, StringRef CopyPath, const std::vector *CCArgs) - : CCPath(std::string(ccPath)), RemoteClientPath(std::string(RemotePath)) { + : CCPath(std::string(ccPath)), RemoteClientPath(std::string(RemotePath)), + RemoteCopyPath(std::string(CopyPath)) { if (CCArgs) ccArgs = *CCArgs; } diff --git a/llvm/tools/bugpoint/ToolRunner.cpp b/llvm/tools/bugpoint/ToolRunner.cpp --- a/llvm/tools/bugpoint/ToolRunner.cpp +++ b/llvm/tools/bugpoint/ToolRunner.cpp @@ -44,9 +44,16 @@ cl::opt RemoteUser("remote-user", cl::desc("Remote execution (rsh/ssh) user id")); +cl::opt RemoteDir("remote-directory", + cl::desc("Remote execution (rsh/ssh) directory")); + cl::opt RemoteExtra("remote-extra-options", cl::desc("Remote execution (rsh/ssh) extra options")); + +cl::opt + RemoteCopy("remote-copy", + cl::desc("Remote execution copy client (scp)")); } /// RunProgramWithTimeout - This function provides an alternate interface @@ -691,6 +698,8 @@ if (RunProgramWithTimeout(CCPath, CCArgs, "", "", "")) return ProcessFailure(CCPath, CCArgs); + FileRemover OutputBinaryRemover(OutputBinary.str(), !SaveTemps); + std::vector ProgramArgs; // Declared here so that the destructor only runs after @@ -700,6 +709,47 @@ if (RemoteClientPath.empty()) ProgramArgs.push_back(OutputBinary); else { + const char *Dir = getenv("PWD"); + + if (!RemoteCopy.empty()) { + // Declared here so that the destructor only runs after + // RemoteCopyArgs is used. + std::string CopyTarget; + std::vector RemoteCopyArgs; + RemoteCopyArgs.push_back(RemoteCopyPath); + + if (!RemotePort.empty()) { + ProgramArgs.push_back("-P"); + ProgramArgs.push_back(RemotePort); + } + + RemoteCopyArgs.push_back(OutputBinary); + + CopyTarget = ""; + if (!RemoteUser.empty()) { + CopyTarget += RemoteUser; + CopyTarget += "@"; + } + CopyTarget += RemoteHost; + CopyTarget += ":"; + CopyTarget += RemoteDir; + Dir = RemoteDir.c_str(); + CopyTarget += "/"; + RemoteCopyArgs.push_back(CopyTarget); + + outs() << ""; + outs().flush(); + LLVM_DEBUG( + errs() << "\nAbout to run:\t"; + for (unsigned i = 0, e = RemoteCopyArgs.size(); i != e; ++i) errs() + << " " << RemoteCopyArgs[i]; + errs() << "\n";); + + if (RunProgramWithTimeout(RemoteCopyPath, RemoteCopyArgs, "", "", "")) + return ProcessFailure(RemoteCopyPath, RemoteCopyArgs); + } else if (!RemoteDir.empty()) + Dir = RemoteDir.c_str(); + ProgramArgs.push_back(RemoteClientPath); ProgramArgs.push_back(RemoteHost); if (!RemoteUser.empty()) { @@ -716,9 +766,8 @@ // Full path to the binary. We need to cd to the exec directory because // there is a dylib there that the exec expects to find in the CWD - char *env_pwd = getenv("PWD"); Exec = "cd "; - Exec += env_pwd; + Exec += Dir; Exec += "; ./"; Exec += OutputBinary.c_str(); ProgramArgs.push_back(Exec); @@ -737,8 +786,6 @@ << " " << ProgramArgs[i]; errs() << "\n";); - FileRemover OutputBinaryRemover(OutputBinary.str(), !SaveTemps); - if (RemoteClientPath.empty()) { LLVM_DEBUG(errs() << ""); std::string Error; @@ -860,6 +907,17 @@ RemoteClientPath = *Path; } + std::string RemoteCopyPath; + if (!RemoteCopy.empty()) { + auto Path = sys::findProgramByName(RemoteCopy); + if (!Path) { + Message = "Cannot find `" + RemoteCopy + "' in PATH: " + + Path.getError().message() + "\n"; + return nullptr; + } + RemoteCopyPath = *Path; + } + Message = "Found CC: " + *CCPath + "\n"; - return new CC(*CCPath, RemoteClientPath, Args); + return new CC(*CCPath, RemoteClientPath, RemoteCopyPath, Args); }