[Libreoffice-commits] core.git: Branch 'feature/gccwrapper' - solenv/gcc-wrappers
Peter Foley
pefoley2 at verizon.net
Fri Mar 8 13:47:55 PST 2013
solenv/gcc-wrappers/wrapper.cxx | 73 +++++++++++++++++++++++-----------------
1 file changed, 43 insertions(+), 30 deletions(-)
New commits:
commit fa4ef65cc6b949a3bc4b2fbc20dc380dab7cffd8
Author: Peter Foley <pefoley2 at verizon.net>
Date: Thu Mar 7 20:18:17 2013 -0500
more work on enviroment and stdio redirection
Change-Id: I5b855a37a2dd7959d60626af033b3466c920675d
diff --git a/solenv/gcc-wrappers/wrapper.cxx b/solenv/gcc-wrappers/wrapper.cxx
index 43c3d66..e5a6cbb 100644
--- a/solenv/gcc-wrappers/wrapper.cxx
+++ b/solenv/gcc-wrappers/wrapper.cxx
@@ -13,11 +13,11 @@
#include <windows.h>
-using namespace std;
+#define buflen 2048
-vector<char> setupenv() {
- vector<char> enviroment;
+using namespace std;
+void setupenv() {
// Set-up library path
string libpath="LIB=";
char* libbuf;
@@ -25,11 +25,10 @@ vector<char> setupenv() {
_dupenv_s(&libbuf,&liblen,"ILIB");
libpath.append(libbuf);
free(libbuf);
- enviroment.insert(enviroment.end(),libpath.begin(),libpath.end());
- enviroment.push_back('\0');
+ _putenv(libpath.c_str());
// Set-up include path
- string includepath="INCLUDE=.;";
+ string includepath="INCLUDE2=.;";
char* incbuf;
size_t inclen;
_dupenv_s(&incbuf,&inclen,"SOLARINC");
@@ -48,23 +47,17 @@ vector<char> setupenv() {
}
pos=incvar.find(" -I",pos+len);
}
- enviroment.insert(enviroment.end(),includepath.begin(),includepath.end());
- enviroment.push_back('\0');
-
- // CreateProcess requires the enviroment block to be null terminated
- enviroment.push_back('\0');
-
- return enviroment;
+ _putenv(incvar.c_str());
}
string processargs(vector<string> rawargs) {
string args;
- for(vector<string>::iterator i = rawargs.begin(); i != rawargs.end(); i++) {
+ for(vector<string>::iterator i = rawargs.begin(); i != rawargs.end(); ++i) {
args.append(" ");
if(*i == "-o") {
// TODO: handle more than just exe output
args.append("-Fe");
- i++;
+ ++i;
args.append(*i);
}
else if(*i == "-g")
@@ -75,32 +68,40 @@ string processargs(vector<string> rawargs) {
return args;
}
-int startprocess(string command, string args, vector<char> enviroment) {
+int startprocess(string command, string args) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
- DWORD ret;
+ SECURITY_ATTRIBUTES sa;
+
+ HANDLE stdout_read;
+ HANDLE stdout_write;
- HANDLE stdout_handle=GetStdHandle(STD_OUTPUT_HANDLE);
- HANDLE stderr_handle=GetStdHandle(STD_ERROR_HANDLE);
+ memset(&sa,0,sizeof(sa));
+ sa.nLength=sizeof(sa);
+ sa.bInheritHandle=TRUE;
+
+ if(!CreatePipe(&stdout_read,&stdout_write,&sa,0)) {
+ cerr << "Error: could not create sdtout pipe" << endl;
+ exit(1);
+ }
memset(&si,0,sizeof(si));
si.cb=sizeof(si);
si.dwFlags |= STARTF_USESTDHANDLES;
- si.hStdError=stderr_handle;
- si.hStdOutput=stdout_handle;
+ si.hStdOutput=stdout_write;
+ si.hStdError=stdout_write;
memset(&pi,0,sizeof(pi));
- void* env;
- env=&enviroment.front();
+ char* cmdline=_strdup(args.c_str());
if(!CreateProcess(command.c_str(), // Process Name
- (char*)args.c_str(), // Command Line
+ cmdline, // Command Line
NULL, // Process Handle not Inheritable
NULL, // Thread Handle not Inheritable
- FALSE, // Handles are not Inherited
+ TRUE, // Handles are Inherited
0, // No creation flags
- env, // Enviroment for process
+ NULL, // Enviroment for process
NULL, // Use same starting directory
&si, // Startup Info
&pi) // Process Information
@@ -109,7 +110,19 @@ int startprocess(string command, string args, vector<char> enviroment) {
exit(1);
}
- WaitForSingleObject(&pi.hProcess, INFINITE);
+ // Get Process output
+ char buffer[buflen];
+ DWORD readlen, writelen, ret;
+ HANDLE stdouthandle=GetStdHandle(STD_OUTPUT_HANDLE);
+ while(true) {
+ int success=ReadFile(stdout_read,buffer,buflen,&readlen,NULL);
+ DWORD err=GetLastError();
+ if(readlen!=0)
+ WriteFile(stdouthandle,buffer,readlen,&writelen,NULL);
+ if(err==ERROR_BROKEN_PIPE)
+ break;
+ }
+ //WaitForSingleObject(&pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &ret);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
@@ -131,11 +144,11 @@ int main(int argc, char *argv[]) {
string args=processargs(rawargs);
- vector<char> enviroment=setupenv();
+ setupenv();
- cerr << "CC=" << command << "ARGS=" << args << endl;
+ cerr << "CC=" << command << " ARGS=" << args << endl;
- int ret=startprocess(command,args,enviroment);
+ int ret=startprocess(command,args);
return ret;
}
More information about the Libreoffice-commits
mailing list