@@ -78,7 +78,8 @@ namespace
7878 runcpp2::TrimRight (inOutFlags);
7979 }
8080
81- bool CompileScript ( const std::string& scriptPath,
81+ bool CompileScript ( const ghc::filesystem::path& buildDir,
82+ const std::string& scriptPath,
8283 const runcpp2::Data::ScriptInfo& scriptInfo,
8384 const std::vector<runcpp2::Data::DependencyInfo*>& availableDependencies,
8485 const runcpp2::Data::Profile& profile,
@@ -122,10 +123,10 @@ namespace
122123 }
123124 }
124125
126+ // TODO: Maybe do ProcessPath on all the .string()?
125127 std::string scriptDirectory = ghc::filesystem::path (scriptPath).parent_path ().string ();
126128 std::string scriptName = ghc::filesystem::path (scriptPath).stem ().string ();
127129 std::string scriptExt = ghc::filesystem::path (scriptPath).extension ().string ();
128- std::string runcpp2ScriptDir = runcpp2::ProcessPath (scriptDirectory + " /.runcpp2" );
129130 // Input File
130131 {
131132 substitutionMap[" {InputFileName}" ] = {scriptName};
@@ -142,11 +143,11 @@ namespace
142143 ssLOG_WARNING (" Object file extension is empty" );
143144
144145 const std::string outputFilePath =
145- runcpp2::ProcessPath (runcpp2ScriptDir + " / " + scriptName + objectFileExt);
146+ runcpp2::ProcessPath ( (buildDir / scriptName). concat ( objectFileExt). string () );
146147
147148 substitutionMap[" {OutputFileName}" ] = {scriptName};
148149 substitutionMap[" {OutputFileExtension}" ] = {objectFileExt};
149- substitutionMap[" {OutputFileDirectory}" ] = {runcpp2ScriptDir };
150+ substitutionMap[" {OutputFileDirectory}" ] = {runcpp2::ProcessPath (buildDir. string ()) };
150151 substitutionMap[" {OutputFilePath}" ] = {outputFilePath};
151152 outScriptObjectFilePath = outputFilePath;
152153 }
@@ -177,7 +178,7 @@ namespace
177178 if ( !runcpp2::RunCommandAndGetOutput ( setupStep,
178179 setupOutput,
179180 setupResult,
180- runcpp2ScriptDir ) ||
181+ buildDir. string () ) ||
181182 setupResult != 0 )
182183 {
183184 ssLOG_ERROR (" Setup command \" " << setupStep << " \" failed" );
@@ -205,14 +206,14 @@ namespace
205206 compileCommand = runPartSubstitutedCommand;
206207
207208 ssLOG_INFO ( " running compile command: " << compileCommand <<
208- " in " << runcpp2ScriptDir );
209+ " in " << buildDir. string () );
209210
210211 std::string commandOutput;
211212 int resultCode = 0 ;
212213 if ( !runcpp2::RunCommandAndGetOutput ( compileCommand,
213214 commandOutput,
214215 resultCode,
215- runcpp2ScriptDir ) ||
216+ buildDir. string () ) ||
216217 resultCode != 0 )
217218 {
218219 ssLOG_ERROR (" Compile command failed with result " << resultCode);
@@ -241,7 +242,7 @@ namespace
241242 if ( !runcpp2::RunCommandAndGetOutput ( cleanupStep,
242243 cleanupOutput,
243244 cleanupResult,
244- runcpp2ScriptDir ) ||
245+ buildDir. string () ) ||
245246 cleanupResult != 0 )
246247 {
247248 ssLOG_ERROR (" Cleanup command \" " << cleanupStep << " \" failed" );
@@ -255,7 +256,8 @@ namespace
255256 return true ;
256257 }
257258
258- bool LinkScript (const std::string& scriptPath,
259+ bool LinkScript (const ghc::filesystem::path& buildDir,
260+ const std::string& scriptPath,
259261 const runcpp2::Data::ScriptInfo& scriptInfo,
260262 const std::vector<runcpp2::Data::DependencyInfo*>& availableDependencies,
261263 const runcpp2::Data::Profile& profile,
@@ -318,30 +320,32 @@ namespace
318320 substitutionMap[" {LinkFlags}" ] = {linkFlags};
319321 }
320322
321- std::string runcpp2ScriptDir;
322323 // Output File
323324 {
324325 const std::string scriptName = ghc::filesystem::path (scriptPath).stem ().string ();
325326 const std::string sharedLibPrefix =
326327 *runcpp2::GetValueFromPlatformMap (profile.FilesTypes .SharedLinkFile .Prefix );
327328 const std::string sharedLibExtension =
328- *runcpp2::GetValueFromPlatformMap (profile.FilesTypes .SharedLibraryFile .Extension );
329+ *runcpp2::GetValueFromPlatformMap (profile .FilesTypes
330+ .SharedLibraryFile
331+ .Extension );
332+
329333 const std::string scriptDirectory =
330334 ghc::filesystem::path (scriptPath).parent_path ().string ();
331335
332- runcpp2ScriptDir = runcpp2::ProcessPath (scriptDirectory + " /.runcpp2 " );
336+
333337 std::string outputFile = linkAsExecutable ?
334338 scriptName + exeExt :
335339 sharedLibPrefix + scriptName + sharedLibExtension;
336340
337- outputFile = runcpp2::ProcessPath (runcpp2ScriptDir + " / " + outputFile);
341+ outputFile = runcpp2::ProcessPath ( (buildDir / outputFile). string () );
338342
339343 substitutionMap[" {OutputFileName}" ] = {scriptName};
340344 substitutionMap[" {OutputFileExtension}" ] =
341345 {
342346 (linkAsExecutable ? exeExt : sharedLibExtension)
343347 };
344- substitutionMap[" {OutputFileDirectory}" ] = {runcpp2ScriptDir };
348+ substitutionMap[" {OutputFileDirectory}" ] = {buildDir. string () };
345349 substitutionMap[" {OutputFilePath}" ] = {outputFile};
346350 }
347351 // Link Files
@@ -448,23 +452,26 @@ namespace
448452 substitutionMap[" {LinkStaticFileName}" ].push_back (depLinkName);
449453 substitutionMap[" {LinkStaticFileExt}" ].push_back (depLinkExt);
450454 substitutionMap[" {LinkStaticFileDirectory}" ].push_back (depLinkDirectory);
451- substitutionMap[" {LinkStaticFilePath}" ].push_back (copiedDependenciesBinariesPaths.at (i));
455+ substitutionMap [" {LinkStaticFilePath}" ]
456+ .push_back (copiedDependenciesBinariesPaths.at (i));
452457 break ;
453458 }
454459 case Data::DependencyLibraryType::SHARED:
455460 {
456461 substitutionMap[" {LinkSharedFileName}" ].push_back (depLinkName);
457462 substitutionMap[" {LinkSharedFileExt}" ].push_back (depLinkExt);
458463 substitutionMap[" {LinkSharedFileDirectory}" ].push_back (depLinkDirectory);
459- substitutionMap[" {LinkSharedFilePath}" ].push_back (copiedDependenciesBinariesPaths.at (i));
464+ substitutionMap [" {LinkSharedFilePath}" ]
465+ .push_back (copiedDependenciesBinariesPaths.at (i));
460466 break ;
461467 }
462468 case Data::DependencyLibraryType::OBJECT:
463469 {
464470 substitutionMap[" {LinkObjectFileName}" ].push_back (depLinkName);
465471 substitutionMap[" {LinkObjectFileExt}" ].push_back (depLinkExt);
466472 substitutionMap[" {LinkObjectFileDirectory}" ].push_back (depLinkDirectory);
467- substitutionMap[" {LinkObjectFilePath}" ].push_back (copiedDependenciesBinariesPaths.at (i));
473+ substitutionMap [" {LinkObjectFilePath}" ]
474+ .push_back (copiedDependenciesBinariesPaths.at (i));
468475 break ;
469476 }
470477 case Data::DependencyLibraryType::HEADER:
@@ -505,7 +512,7 @@ namespace
505512 if ( !runcpp2::RunCommandAndGetOutput ( setupStep,
506513 setupOutput,
507514 setupResult,
508- runcpp2ScriptDir ) ||
515+ buildDir. string () ) ||
509516 setupResult != 0 )
510517 {
511518 ssLOG_ERROR (" Setup command \" " << setupStep << " \" failed" );
@@ -533,13 +540,13 @@ namespace
533540 else
534541 linkCommand = runPartSubstitutedCommand;
535542
536- ssLOG_INFO (" running link command: " << linkCommand << " in " << runcpp2ScriptDir );
543+ ssLOG_INFO (" running link command: " << linkCommand << " in " << buildDir. string () );
537544 std::string linkOutput;
538545 int resultCode = 0 ;
539546 if ( !runcpp2::RunCommandAndGetOutput ( linkCommand,
540547 linkOutput,
541548 resultCode,
542- runcpp2ScriptDir ) ||
549+ buildDir. string () ) ||
543550 resultCode != 0 )
544551 {
545552 ssLOG_ERROR (" Link command failed with result " << resultCode);
@@ -568,7 +575,7 @@ namespace
568575 if ( !runcpp2::RunCommandAndGetOutput ( cleanupStep,
569576 cleanupOutput,
570577 cleanupResult,
571- runcpp2ScriptDir ) ||
578+ buildDir. string () ) ||
572579 cleanupResult != 0 )
573580 {
574581 ssLOG_ERROR (" Cleanup command \" " << cleanupStep << " \" failed" );
@@ -582,7 +589,7 @@ namespace
582589 return true ;
583590 }
584591
585- bool RunGlobalSteps (const std::string& scriptPath ,
592+ bool RunGlobalSteps (const ghc::filesystem::path& buildDir ,
586593 const std::unordered_map< PlatformName,
587594 std::vector<std::string>>& platformSteps)
588595 {
@@ -595,9 +602,6 @@ namespace
595602 return true ;
596603 }
597604
598- std::string scriptDirectory = ghc::filesystem::path (scriptPath) .parent_path ()
599- .string ();
600- std::string runcpp2ScriptDir = runcpp2::ProcessPath (scriptDirectory + " /.runcpp2" );
601605 const std::vector<std::string>& steps = *runcpp2::GetValueFromPlatformMap (platformSteps);
602606
603607 for (int i = 0 ; i < steps.size (); ++i)
@@ -608,7 +612,7 @@ namespace
608612 if ( !runcpp2::RunCommandAndGetOutput ( steps.at (i),
609613 commandOutput,
610614 commandResult,
611- runcpp2ScriptDir ) ||
615+ buildDir. string () ) ||
612616 commandResult != 0 )
613617 {
614618 ssLOG_ERROR (" Command \" " << steps.at (i) << " \" failed" );
@@ -622,23 +626,25 @@ namespace
622626 }
623627}
624628
625- bool runcpp2::CompileAndLinkScript ( const std::string& scriptPath,
629+ bool runcpp2::CompileAndLinkScript ( const ghc::filesystem::path& buildDir,
630+ const std::string& scriptPath,
626631 const Data::ScriptInfo& scriptInfo,
627632 const std::vector<Data::DependencyInfo*>& availableDependencies,
628633 const Data::Profile& profile,
629634 const std::vector<std::string>& copiedDependenciesBinariesPaths,
630635 bool buildExecutable,
631636 const std::string exeExt)
632637{
633- if (!RunGlobalSteps (scriptPath , profile.Setup ))
638+ if (!RunGlobalSteps (buildDir , profile.Setup ))
634639 {
635640 ssLOG_ERROR (" Failed to run profile global setup steps" );
636641 return false ;
637642 }
638643
639644 std::string scriptObjectFilePath;
640645
641- if (!CompileScript ( scriptPath,
646+ if (!CompileScript ( buildDir,
647+ scriptPath,
642648 scriptInfo,
643649 availableDependencies,
644650 profile,
@@ -649,7 +655,8 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
649655 return false ;
650656 }
651657
652- if (!LinkScript ( scriptPath,
658+ if (!LinkScript ( buildDir,
659+ scriptPath,
653660 scriptInfo,
654661 availableDependencies,
655662 profile,
@@ -662,7 +669,7 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
662669 return false ;
663670 }
664671
665- if (!RunGlobalSteps (scriptPath , profile.Cleanup ))
672+ if (!RunGlobalSteps (buildDir , profile.Cleanup ))
666673 {
667674 ssLOG_ERROR (" Failed to run profile global cleanup steps" );
668675 return false ;
0 commit comments