14 #include "boost/filesystem/convenience.hpp"
15 #include "boost/filesystem/path.hpp"
21 namespace bf=boost::filesystem;
23 int run_script(
const std::string& shell,
const std::string& script)
30 std::cerr <<
"fork failed, to run " << script << std::endl;;
36 execlp(shell.c_str(),
"sh",
"-c", script.c_str(), (
const char *)(0));
37 std::cerr <<
"child failed becuase '"<<strerror(errno)<<
"'\n";
42 while(waitpid(pid,&status,0)<0)
46 std::cerr <<
"child process failed "<<strerror(errno)<<
"\n";
50 if( WIFSIGNALED(status) ) {
51 std::cerr <<
"child existed because of a signal "<<WTERMSIG(status)<<
"\n";
55 if( WIFSIGNALED(status) ) {
56 std::cerr <<
"child existed because of a signal "<<WTERMSIG(status)<<
"\n";
58 if(WIFEXITED(status)) {
67 int do_work(
int argc,
char* argv[],
char** env)
69 bf::path currentPath(bf::initial_path().
string(), bf::no_check);
73 std::cout <<
"Usage: " << argv[0] <<
" shell subdir script1 script2 ... scriptN\n\n"
74 <<
"where shell is the path+shell (e.g., /bin/bash) intended to run the scripts\n"
75 <<
"and subdir is the subsystem/package/subdir in which the scripts are found\n"
76 <<
"(e.g., FWCore/Utilities/test)\n"
79 std::cout <<
"Current directory is: " << currentPath.native_directory_string() <<
'\n';
82 for (
int i = 0; env[
i] != 0; ++
i)
std::cout << env[
i] <<
'\n';
84 std::cout <<
"Executable name: " << argv[0] <<
'\n';
88 for (
int i = 0;
i < argc; ++
i)
90 std::cout <<
"argument " <<
i <<
": " << argv[
i] <<
'\n';
94 std::string shell(argv[1]);
95 std::cerr <<
"shell is: " << shell <<
'\n';
97 std::cout <<
"Current directory is: " << currentPath.native_directory_string() <<
'\n';
100 const char* topdir = getenv(
"SCRAMRT_LOCALRT");
101 if (!topdir) topdir = getenv(
"LOCALRT");
103 const char*
arch = getenv(
"SCRAM_ARCH");
108 bf::path exepath(argv[0], bf::no_check);
109 std::string maybe_arch = exepath.branch_path().leaf();
110 if (setenv(
"SCRAM_ARCH", maybe_arch.c_str(), 1) != 0)
112 std::cerr <<
"SCRAM_ARCH not set and attempt to set it failed\n";
115 arch = getenv(
"SCRAM_ARCH");
122 std::cout <<
"Neither SCRAMRT_LOCALRT nor LOCALRT is not defined" << std::endl;;
127 std::string testdir(topdir); testdir +=
"/src/"; testdir += argv[2];
128 std::string tmpdir(topdir); tmpdir+=
"/tmp/"; tmpdir+=
arch;
129 std::string testbin(topdir); testbin+=
"/test/"; testbin+=
arch;
131 std::cout <<
"topdir is: " << topdir <<
'\n';
132 std::cout <<
"testdir is: " << testdir <<
'\n';
133 std::cout <<
"tmpdir is: " << tmpdir <<
'\n';
134 std::cout <<
"testbin is: " << testbin <<
'\n';
137 if (setenv(
"LOCAL_TEST_DIR",testdir.c_str(),1)!=0)
139 std::cerr <<
"Could not set LOCAL_TEST_DIR to " << testdir << std::endl;;
142 if (setenv(
"LOCAL_TMP_DIR",tmpdir.c_str(),1)!=0)
144 std::cerr <<
"Could not set LOCAL_TMP_DIR to " << tmpdir << std::endl;;
147 if (setenv(
"LOCAL_TOP_DIR",topdir,1)!=0)
149 std::cerr <<
"Could not set LOCAL_TOP_DIR to " << topdir << std::endl;;
152 if (setenv(
"LOCAL_TEST_BIN",testbin.c_str(),1)!=0)
154 std::cerr <<
"Could not set LOCAL_TEST_BIN to " << testbin << std::endl;;
160 for(
int i=3;
i<argc && rc==0; ++
i)
162 std::string scriptname(testdir);
163 scriptname += argv[
i];
164 std::cout <<
"Running script: " << scriptname << std::endl;
168 std::cout <<
"status = " << rc << std::endl;;
169 return rc == 0 ? 0 : -1;
181 std::cerr <<
"Caught an edm::Exception in "
187 std::cerr <<
"Caught a cms::Exception in "
193 std::cerr <<
"Caught a std::exception in "
199 std::cerr <<
"Caught an unknown exception in "
int run_script(const std::string &shell, const std::string &script)
int do_work(int argc, char *argv[], char **env)
int ptomaine(int argc, char *argv[], char **env)