1
1
#include " runner_common.h"
2
2
3
+ #include < toml++/toml.h>
4
+
5
+ #include < algorithm>
3
6
#include < boost/algorithm/string.hpp>
4
7
#include < boost/asio.hpp>
5
8
#include < boost/process.hpp>
@@ -119,6 +122,48 @@ int IntegrationBase::exit_code(Proc &proc) {
119
122
return proc.proc .exit_code ();
120
123
}
121
124
125
+ fs::path IntegrationBase::createCustomConfig (const std::string &extraConfig) {
126
+ // If no extra config provided, return the config path unaltered.
127
+ if (extraConfig.empty ()) {
128
+ return configFile;
129
+ }
130
+
131
+ auto customConfigFile = workingDir / " oid.config.toml" ;
132
+ auto config = toml::parse_file (configFile);
133
+
134
+ // As relative paths are allowed, we must canonicalise the paths before
135
+ // moving the file to the temporary directory.
136
+ fs::path configDirectory = fs::path (configFile).remove_filename ();
137
+
138
+ if (toml::table *types = config[" types" ].as_table ()) {
139
+ if (toml::array *arr = (*types)[" containers" ].as_array ()) {
140
+ arr->for_each ([&](auto &&el) {
141
+ if constexpr (toml::is_string<decltype (el)>) {
142
+ el = configDirectory / el.get ();
143
+ }
144
+ });
145
+ }
146
+ }
147
+ if (toml::table *headers = config[" headers" ].as_table ()) {
148
+ for (auto &path : {" user_paths" , " system_paths" }) {
149
+ if (toml::array *arr = (*headers)[path].as_array ()) {
150
+ arr->for_each ([&](auto &&el) {
151
+ if constexpr (toml::is_string<decltype (el)>) {
152
+ el = configDirectory / el.get ();
153
+ }
154
+ });
155
+ }
156
+ }
157
+ }
158
+
159
+ std::ofstream customConfig (customConfigFile, std::ios_base::app);
160
+ customConfig << config;
161
+ customConfig << " \n\n # Test custom config\n\n " ;
162
+ customConfig << extraConfig;
163
+
164
+ return customConfigFile;
165
+ }
166
+
122
167
std::string OidIntegration::TmpDirStr () {
123
168
return std::string (" /tmp/oid-integration-XXXXXX" );
124
169
}
@@ -149,18 +194,7 @@ OidProc OidIntegration::runOidOnProcess(OidOpts opts,
149
194
std::ofstream touch (segconfigPath);
150
195
}
151
196
152
- // Only create a new custom config if we've been provided an extra_config
153
- boost::trim (extra_config);
154
-
155
- fs::path customConfigFile = configFile;
156
- if (!extra_config.empty ()) {
157
- customConfigFile = workingDir / " oid.config.toml" ;
158
- fs::copy_file (configFile, customConfigFile);
159
-
160
- std::ofstream customConfig (customConfigFile, std::ios_base::app);
161
- customConfig << " \n\n # Test custom config\n\n " ;
162
- customConfig << extra_config;
163
- }
197
+ fs::path thisConfig = createCustomConfig (extra_config);
164
198
165
199
// Keep PID as the last argument to make it easier for users to directly copy
166
200
// and modify the command from the verbose mode output.
@@ -169,7 +203,7 @@ OidProc OidIntegration::runOidOnProcess(OidOpts opts,
169
203
" --debug-level=3" s,
170
204
" --timeout=20" s,
171
205
" --dump-json" s,
172
- " --config-file" s, customConfigFile .string (),
206
+ " --config-file" s, thisConfig .string (),
173
207
" --script-source" s, opts.scriptSource ,
174
208
" --pid" s, std::to_string (targetProcess.id ()),
175
209
};
@@ -302,7 +336,7 @@ std::string OilIntegration::TmpDirStr() {
302
336
return std::string (" /tmp/oil-integration-XXXXXX" );
303
337
}
304
338
305
- Proc OilIntegration::runOilTarget (OidOpts opts) {
339
+ Proc OilIntegration::runOilTarget (OidOpts opts, std::string extra_config ) {
306
340
std::string targetExe = std::string (TARGET_EXE_PATH) + " " + opts.targetArgs ;
307
341
308
342
if (verbose) {
@@ -341,6 +375,8 @@ Proc OilIntegration::runOilTarget(OidOpts opts) {
341
375
// clang-format on
342
376
}
343
377
378
+ fs::path thisConfig = createCustomConfig (extra_config);
379
+
344
380
/* Spawn target with tracing on and IOs redirected in custom pipes to be read
345
381
* later */
346
382
// clang-format off
@@ -349,7 +385,7 @@ Proc OilIntegration::runOilTarget(OidOpts opts) {
349
385
bp::std_in < bp::null,
350
386
bp::std_out > std_out_pipe,
351
387
bp::std_err > std_err_pipe,
352
- bp::env[" CONFIG_FILE_PATH" ] = configFile ,
388
+ bp::env[" CONFIG_FILE_PATH" ] = thisConfig. string () ,
353
389
opts.ctx );
354
390
// clang-format on
355
391
0 commit comments