Skip to content

Commit 83de9fe

Browse files
committed
support for running standalone
1 parent 7981f84 commit 83de9fe

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

util/worker/worker.cc

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,36 @@ int RunAsWorker(
149149
return 0;
150150
}
151151

152+
int RunStandalone(
153+
const System::StrType& exec_path,
154+
const System::EnvironmentBlock& environment_block,
155+
const System::StrType& param_file_param
156+
) {
157+
if (param_file_param[0] != '@') {
158+
std::cerr << "Param file must start with '@', got \"" << param_file_param << "\"\n";
159+
return -1;
160+
}
161+
162+
std::string param_file = ToUtf8(param_file_param).substr(1);
163+
System::Arguments arguments;
164+
165+
std::ifstream source(param_file);
166+
std::string line;
167+
while (std::getline(source, line)) {
168+
arguments.push_back(line);
169+
}
170+
171+
std::string empty;
172+
173+
return System::Exec(exec_path, arguments, environment_block, empty, empty);
174+
}
175+
152176
using CharType = process_wrapper::System::StrType::value_type;
153177

154178
int PW_MAIN(int argc, const CharType* argv[], const CharType* envp[]) {
155179
System::StrType exec_path;
156180
System::StrType compilation_mode;
181+
System::StrType param_file;
157182
System::EnvironmentBlock environment_block;
158183
// Taking all environment variables from the current process
159184
// and sending them down to the child process
@@ -188,6 +213,8 @@ int PW_MAIN(int argc, const CharType* argv[], const CharType* envp[]) {
188213
return -1;
189214
}
190215
exec_path = argv[i];
216+
} else if (arg[0] == '@') {
217+
param_file = arg;
191218
} else {
192219
std::cerr << "worker wrapper error: unknown argument \"" << ToUtf8(arg)
193220
<< "\"." << '\n';
@@ -196,8 +223,12 @@ int PW_MAIN(int argc, const CharType* argv[], const CharType* envp[]) {
196223
}
197224

198225
if (as_worker) {
199-
return RunAsWorker(exec_path, compilation_mode, environment_block);
226+
if (!param_file.empty()) {
227+
std::cerr << "Param file argument \"" << param_file << "\" not supported in worker mode\n";
228+
return -1;
229+
}
230+
return RunAsWorker(exec_path, compilation_mode, environment_block);
231+
} else {
232+
return RunStandalone(exec_path, environment_block, param_file);
200233
}
201-
std::cerr << "Don't know how to run as non-worker yet\n";
202-
return -1;
203234
}

0 commit comments

Comments
 (0)