@@ -85,15 +85,9 @@ namespace
8585 INTERNAL_RUNCPP2_SAFE_START ();
8686 ssLOG_FUNC_DEBUG ();
8787
88- std::error_code _;
89- std::string interpretedRunPath = runcpp2::ProcessPath (scriptPath);
90- std::vector<const char *> args = { interpretedRunPath.c_str () };
91-
92- if (!runArgs.empty ())
93- {
94- for (int i = 0 ; i < runArgs.size (); ++i)
95- args.push_back (runArgs[i].c_str ());
96- }
88+ std::vector<const char *> args;
89+ for (size_t i = 0 ; i < runArgs.size (); ++i)
90+ args.push_back (runArgs[i].c_str ());
9791
9892 System2CommandInfo runCommandInfo = {};
9993 SYSTEM2_RESULT result = System2RunSubprocess ( executable.c_str (),
@@ -102,7 +96,7 @@ namespace
10296 &runCommandInfo);
10397
10498 ssLOG_INFO (" Running: " << executable.string ());
105- for (int i = 0 ; i < runArgs.size (); ++i)
99+ for (size_t i = 0 ; i < runArgs.size (); ++i)
106100 ssLOG_INFO (" - " << runArgs[i]);
107101
108102 if (result != SYSTEM2_RESULT_SUCCESS)
@@ -172,12 +166,12 @@ namespace
172166 return false ;
173167 }
174168
175- int (*scriptFullMain)(int , char **) = nullptr ;
169+ int (*scriptFullMain)(int , const char **) = nullptr ;
176170 int (*scriptMain)() = nullptr ;
177171
178172 try
179173 {
180- scriptFullMain = sharedLib->get_function <int (int , char **)>(" main" );
174+ scriptFullMain = sharedLib->get_function <int (int , const char **)>(" main" );
181175 }
182176 catch (const dylib::exception& ex)
183177 {
@@ -217,13 +211,9 @@ namespace
217211 {
218212 if (scriptFullMain != nullptr )
219213 {
220- std::vector<std::string> runArgsCopy = runArgs;
221- runArgsCopy.insert ( runArgsCopy.begin (),
222- runcpp2::ProcessPath (compiledSharedLibPath.string ()));
223-
224- std::vector<char *> runArgsCStr (runArgsCopy.size ());
225- for (int i = 0 ; i < runArgsCopy.size (); ++i)
226- runArgsCStr.at (i) = &runArgsCopy.at (i).at (0 );
214+ std::vector<const char *> runArgsCStr (runArgs.size ());
215+ for (size_t i = 0 ; i < runArgs.size (); ++i)
216+ runArgsCStr.at (i) = &runArgs.at (i).at (0 );
227217
228218 returnStatus = scriptFullMain (runArgsCStr.size (), runArgsCStr.data ());
229219 }
@@ -636,6 +626,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
636626
637627 // Parsing the script, setting up dependencies, compiling and linking
638628 std::vector<std::string> filesToCopyPaths;
629+ Data::ScriptInfo scriptInfo;
639630 {
640631 // Check if there's script info as yaml file instead
641632 std::error_code e;
@@ -672,7 +663,6 @@ runcpp2::StartPipeline( const std::string& scriptPath,
672663 }
673664
674665 // Try to parse the runcpp2 info
675- Data::ScriptInfo scriptInfo;
676666 if (!ParseScriptInfo (parsableInfo, scriptInfo))
677667 {
678668 ssLOG_ERROR (" Failed to parse info" );
@@ -1037,21 +1027,31 @@ runcpp2::StartPipeline( const std::string& scriptPath,
10371027 return PipelineResult::UNEXPECTED_FAILURE;
10381028 }
10391029
1030+ // Prepare run arguments
1031+ std::vector<std::string> finalRunArgs;
1032+ finalRunArgs.push_back (target.string ());
1033+ if (scriptInfo.PassScriptPath )
1034+ finalRunArgs.push_back (absoluteScriptPath);
1035+
1036+ // Add user provided arguments
1037+ for (size_t i = 0 ; i < runArgs.size (); ++i)
1038+ finalRunArgs.push_back (runArgs[i]);
1039+
10401040 if (currentOptions.count (CmdOptions::EXECUTABLE) > 0 )
10411041 {
1042- // Running the script
1043- if (!RunCompiledScript (target, absoluteScriptPath, runArgs , returnStatus))
1042+ // Running the script with modified args
1043+ if (!RunCompiledScript (target, absoluteScriptPath, finalRunArgs , returnStatus))
10441044 {
10451045 ssLOG_ERROR (" Failed to run script" );
10461046 return PipelineResult::RUN_SCRIPT_FAILED;
10471047 }
10481048
10491049 return PipelineResult::SUCCESS;
10501050 }
1051- // Load the shared library and run it
1051+ // Load the shared library and run it with modified args
10521052 else
10531053 {
1054- if (!RunCompiledSharedLib (absoluteScriptPath, target, runArgs , returnStatus))
1054+ if (!RunCompiledSharedLib (absoluteScriptPath, target, finalRunArgs , returnStatus))
10551055 {
10561056 ssLOG_ERROR (" Failed to run script" );
10571057 return PipelineResult::RUN_SCRIPT_FAILED;
0 commit comments